]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-statbag_cc.cc
1 #ifndef BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_NO_MAIN
10 #include <boost/test/unit_test.hpp>
11 #include <boost/assign/list_of.hpp>
21 static void threadMangler(AtomicCounter
* ac
)
23 for(unsigned int n
=0; n
< 1000000; ++n
)
27 static void threadMangler2(StatBag
* S
)
29 for(unsigned int n
=0; n
< 1000000; ++n
)
35 BOOST_AUTO_TEST_SUITE(test_misc_hh
)
37 BOOST_AUTO_TEST_CASE(test_StatBagBasic
) {
39 s
.declare("a", "description");
40 s
.declare("b", "description");
41 s
.declare("c", "description");
43 BOOST_CHECK_EQUAL(s
.read("a"), 1UL);
46 for(n
=0; n
< 1000000; ++n
)
49 BOOST_CHECK_EQUAL(s
.read("b"), n
);
51 AtomicCounter
* ac
= s
.getPointer("a");
52 for(n
=0; n
< 1000000; ++n
)
55 BOOST_CHECK_EQUAL(s
.read("a"), n
+1);
57 AtomicCounter
* acc
= s
.getPointer("c");
58 std::vector
<std::thread
> manglers
;
59 for (int i
=0; i
< 4; ++i
) {
60 manglers
.push_back(std::thread(threadMangler
, acc
));
63 for (auto& t
: manglers
) {
68 BOOST_CHECK_EQUAL(s
.read("c"), 4000000U);
72 for (int i
=0; i
< 4; ++i
) {
73 manglers
.push_back(std::thread(threadMangler2
, &s
));
76 for (auto& t
: manglers
) {
81 BOOST_CHECK_EQUAL(s
.read("c"), 4000000U);
85 BOOST_CHECK_EQUAL(s
.read("c"), (1ULL<<31) );
87 BOOST_CHECK_EQUAL(s
.read("c"), (1ULL<<31) +1 );
90 #if UINTPTR_MAX > 0xffffffffULL
91 BOOST_CHECK_EQUAL(sizeof(AtomicCounterInner
), 8U);
93 BOOST_CHECK_EQUAL(s
.read("c"), (1ULL<<33) );
95 BOOST_CHECK_EQUAL(s
.read("c"), (1ULL<<33) +1 );
98 BOOST_CHECK_EQUAL(s
.read("c"), 0xffffffffffffffffULL
);
100 BOOST_CHECK_EQUAL(s
.read("c"), 0UL );
102 BOOST_CHECK_EQUAL(sizeof(AtomicCounterInner
), 4U);
103 BOOST_CHECK_EQUAL(~0UL, 0xffffffffUL
);
105 BOOST_CHECK_EQUAL(s
.read("c"), 0xffffffffUL
);
107 BOOST_CHECK_EQUAL(s
.read("c"), 0UL );
113 BOOST_AUTO_TEST_SUITE_END()