Toolbox
snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
toolbox
sys
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
21
using namespace
std
;
22
using namespace
toolbox
;
23
24
namespace
{
25
uint32_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
37
BOOST_AUTO_TEST_SUITE
(
ThreadSuite
)
38
39
BOOST_AUTO_TEST_CASE
(
ThreadConfigCase
)
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
62
BOOST_AUTO_TEST_CASE
(
ThreadParseCpuSetCase
)
63
{
64
BOOST_CHECK_EQUAL
(
to_bitset
(
parse_cpu_set
(
""
sv
)), 0b0);
65
BOOST_CHECK_EQUAL
(
to_bitset
(
parse_cpu_set
(
"0"
sv
)), 0b1);
66
BOOST_CHECK_EQUAL
(
to_bitset
(
parse_cpu_set
(
"1,2"
sv
)), 0b110);
67
BOOST_CHECK_EQUAL
(
to_bitset
(
parse_cpu_set
(
"0-3"
sv
)), 0b1111);
68
BOOST_CHECK_EQUAL
(
to_bitset
(
parse_cpu_set
(
"1,2,4-7"
sv
)), 0b11110110);
69
BOOST_CHECK_EQUAL
(
to_bitset
(
parse_cpu_set
(
"0-3,5,6,8-11"
sv
)), 0b111101101111);
70
}
71
72
BOOST_AUTO_TEST_SUITE_END
()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(v.size(), 10U)
Thread.hpp
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(ThreadConfigCase)
Definition
Thread.ut.cpp:39
std
STL namespace.
toolbox::sys::parse_cpu_set
cpu_set_t parse_cpu_set(string_view s) noexcept
Definition
Thread.cpp:35
toolbox::util::sv
std::string_view sv
Definition
Tokeniser.hpp:26
toolbox::util::bind
constexpr auto bind() noexcept
Definition
Slot.hpp:92
toolbox
Definition
Benchmark.cpp:26
toolbox::ThreadConfig
ThreadConfig holds the thread attributes.
Definition
Thread.hpp:29
BOOST_CHECK
BOOST_CHECK(isnan(stod(""sv, numeric_limits< double >::quiet_NaN())))
Generated by
1.9.8