Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Thread.ut.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#include "Thread.hpp"
18
19#include <boost/test/unit_test.hpp>
20
21using namespace std;
22using namespace toolbox;
23
24namespace {
25uint32_t to_bitset(const cpu_set_t& cpuset) noexcept
26{
27 uint32_t bs{0};
28 for (int i{0}; i < 32; ++i) {
29 if (CPU_ISSET(i, &cpuset)) {
30 bs |= (1 << i);
31 }
32 }
33 return bs;
34}
35} // namespace
36
38
40{
41 auto config = ThreadConfig{};
42 BOOST_CHECK(config.name.empty());
43 BOOST_CHECK(config.affinity.empty());
44 BOOST_CHECK(config.sched_policy.empty());
45
46 config = "foo"s;
47 BOOST_CHECK_EQUAL(config.name, "foo"s);
48 BOOST_CHECK(config.affinity.empty());
49 BOOST_CHECK(config.sched_policy.empty());
50
51 config = ThreadConfig{"foo"s, "bar"s};
52 BOOST_CHECK_EQUAL(config.name, "foo"s);
53 BOOST_CHECK_EQUAL(config.affinity, "bar"s);
54 BOOST_CHECK(config.sched_policy.empty());
55
56 config = ThreadConfig{"foo"s, "bar"s, "baz"s};
57 BOOST_CHECK_EQUAL(config.name, "foo"s);
58 BOOST_CHECK_EQUAL(config.affinity, "bar"s);
59 BOOST_CHECK_EQUAL(config.sched_policy, "baz"s);
60}
61
71
BOOST_CHECK_EQUAL(v.size(), 10U)
BOOST_AUTO_TEST_CASE(ThreadConfigCase)
Definition Thread.ut.cpp:39
STL namespace.
cpu_set_t parse_cpu_set(string_view s) noexcept
Definition Thread.cpp:35
std::string_view sv
Definition Tokeniser.hpp:26
constexpr auto bind() noexcept
Definition Slot.hpp:92
ThreadConfig holds the thread attributes.
Definition Thread.hpp:29
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))