]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-statbag_cc.cc
1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_NO_MAIN
7 #include <boost/test/unit_test.hpp>
8 #include <boost/assign/list_of.hpp>
10 #include <boost/tuple/tuple.hpp>
18 static void *threadMangler(void* a
)
20 AtomicCounter
* ac
=(AtomicCounter
*)a
;
21 for(unsigned int n
=0; n
< 1000000; ++n
)
26 static void *threadMangler2(void* a
)
28 StatBag
* S
= (StatBag
*)a
;
29 for(unsigned int n
=0; n
< 1000000; ++n
)
36 BOOST_AUTO_TEST_SUITE(test_misc_hh
)
38 BOOST_AUTO_TEST_CASE(test_StatBagBasic
) {
40 s
.declare("a", "description");
41 s
.declare("b", "description");
42 s
.declare("c", "description");
44 BOOST_CHECK_EQUAL(s
.read("a"), 1);
47 for(n
=0; n
< 1000000; ++n
)
50 BOOST_CHECK_EQUAL(s
.read("b"), n
);
52 AtomicCounter
* ac
= s
.getPointer("a");
53 for(n
=0; n
< 1000000; ++n
)
56 BOOST_CHECK_EQUAL(s
.read("a"), n
+1);
58 AtomicCounter
* acc
= s
.getPointer("c");
60 for(int i
=0; i
< 4; ++i
)
61 pthread_create(&tid
[i
], 0, threadMangler
, (void*)acc
);
63 for(int i
=0; i
< 4 ; ++i
)
64 pthread_join(tid
[i
], &res
);
66 BOOST_CHECK_EQUAL(s
.read("c"), 4000000U);
70 for(int i
=0; i
< 4; ++i
)
71 pthread_create(&tid
[i
], 0, threadMangler2
, (void*)&s
);
73 for(int i
=0; i
< 4 ; ++i
)
74 pthread_join(tid
[i
], &res
);
76 BOOST_CHECK_EQUAL(s
.read("c"), 4000000U);
80 BOOST_CHECK_EQUAL(s
.read("c"), (1ULL<<31) );
82 BOOST_CHECK_EQUAL(s
.read("c"), (1ULL<<31) +1 );
85 #if UINTPTR_MAX > 0xffffffffULL
86 BOOST_CHECK_EQUAL(sizeof(AtomicCounterInner
), 8);
88 BOOST_CHECK_EQUAL(s
.read("c"), (1ULL<<33) );
90 BOOST_CHECK_EQUAL(s
.read("c"), (1ULL<<33) +1 );
93 BOOST_CHECK_EQUAL(s
.read("c"), 0xffffffffffffffffULL
);
95 BOOST_CHECK_EQUAL(s
.read("c"), 0 );
97 BOOST_CHECK_EQUAL(sizeof(AtomicCounterInner
), 4);
98 BOOST_CHECK_EQUAL(~0UL, 0xffffffffUL
);
100 BOOST_CHECK_EQUAL(s
.read("c"), 0xffffffffUL
);
102 BOOST_CHECK_EQUAL(s
.read("c"), 0 );
108 BOOST_AUTO_TEST_SUITE_END()