Hazard Pointer docfix
[libcds.git] / tests / test-hdr / stack / hdr_treiber_stack.h
1 //$$CDS-header$$
2
3 #include "cppunit/cppunit_proxy.h"
4
5 namespace stack {
6
7     class TestStack: public CppUnitMini::TestCase
8     {
9         template <class Stack>
10         void test()
11         {
12             Stack s;
13             test_with( s );
14         }
15
16         template <class Stack>
17         void test_elimination()
18         {
19             Stack s(2);
20             test_with( s );
21         }
22
23         template <class Stack>
24         void test_with( Stack& stack)
25         {
26             typedef typename Stack::value_type  value_type;
27             value_type v;
28
29             CPPUNIT_ASSERT( stack.empty() );
30
31             CPPUNIT_ASSERT( stack.push(1));
32             CPPUNIT_ASSERT( !stack.empty() );
33             CPPUNIT_ASSERT( stack.push(2));
34             CPPUNIT_ASSERT( !stack.empty() );
35             CPPUNIT_ASSERT( stack.push(3));
36             CPPUNIT_ASSERT( !stack.empty() );
37
38             CPPUNIT_ASSERT( stack.pop(v) );
39             CPPUNIT_ASSERT( v == 3 );
40             CPPUNIT_ASSERT( !stack.empty() );
41             CPPUNIT_ASSERT( stack.pop_with( [&v]( value_type& src ) { v = src; } ));
42             CPPUNIT_ASSERT( v == 2 );
43             CPPUNIT_ASSERT( !stack.empty() );
44             CPPUNIT_ASSERT( stack.pop(v) );
45             CPPUNIT_ASSERT( v == 1 );
46             CPPUNIT_ASSERT( stack.empty() );
47             v = 1000;
48             CPPUNIT_ASSERT( !stack.pop(v) );
49             CPPUNIT_ASSERT( v == 1000 );
50             CPPUNIT_ASSERT( stack.empty() );
51
52             CPPUNIT_ASSERT( stack.push(10));
53             CPPUNIT_ASSERT( stack.push(20));
54             CPPUNIT_ASSERT( stack.push(30));
55             CPPUNIT_ASSERT( !stack.empty());
56
57             CPPUNIT_ASSERT( stack.emplace(100));
58             CPPUNIT_ASSERT( stack.pop(v));
59             CPPUNIT_ASSERT( v == 100 );
60
61             stack.clear();
62             CPPUNIT_ASSERT( stack.empty() );
63
64             Stack::gc::scan();
65         }
66
67         void Treiber_HP();
68         void Treiber_DHP();
69         void Treiber_HP_yield();
70         void Treiber_DHP_yield();
71         void Treiber_HP_pause_alloc();
72         void Treiber_DHP_pause_alloc();
73
74         void Treiber_HP_relaxed();
75         void Treiber_DHP_relaxed();
76         void Treiber_HP_yield_relaxed();
77         void Treiber_DHP_yield_relaxed();
78         void Treiber_HP_pause_alloc_relaxed();
79         void Treiber_DHP_pause_alloc_relaxed();
80
81         void Elimination_HP();
82         void Elimination_HP_dyn();
83         void Elimination_HP_stat();
84         void Elimination_DHP();
85         void Elimination_DHP_dyn();
86         void Elimination_DHP_stat();
87         void Elimination_HP_yield();
88         void Elimination_DHP_yield();
89         void Elimination_HP_pause_alloc();
90         void Elimination_DHP_pause_alloc();
91
92         void Elimination_HP_relaxed();
93         void Elimination_DHP_relaxed();
94         void Elimination_HP_yield_relaxed();
95         void Elimination_DHP_yield_relaxed();
96         void Elimination_HP_pause_alloc_relaxed();
97         void Elimination_DHP_pause_alloc_relaxed();
98
99         CPPUNIT_TEST_SUITE(TestStack);
100             CPPUNIT_TEST(Treiber_HP)
101             CPPUNIT_TEST(Treiber_HP_relaxed)
102             CPPUNIT_TEST(Treiber_DHP)
103             CPPUNIT_TEST(Treiber_DHP_relaxed)
104             CPPUNIT_TEST(Treiber_HP_yield)
105             CPPUNIT_TEST(Treiber_HP_yield_relaxed)
106             CPPUNIT_TEST(Treiber_DHP_yield)
107             CPPUNIT_TEST(Treiber_DHP_yield_relaxed)
108             CPPUNIT_TEST(Treiber_HP_pause_alloc)
109             CPPUNIT_TEST(Treiber_HP_pause_alloc_relaxed)
110             CPPUNIT_TEST(Treiber_DHP_pause_alloc)
111             CPPUNIT_TEST(Treiber_DHP_pause_alloc_relaxed)
112
113             CPPUNIT_TEST(Elimination_HP)
114             CPPUNIT_TEST(Elimination_HP_dyn)
115             CPPUNIT_TEST(Elimination_HP_stat)
116             CPPUNIT_TEST(Elimination_HP_relaxed)
117             CPPUNIT_TEST(Elimination_DHP)
118             CPPUNIT_TEST(Elimination_DHP_dyn)
119             CPPUNIT_TEST(Elimination_DHP_stat)
120             CPPUNIT_TEST(Elimination_DHP_relaxed)
121             CPPUNIT_TEST(Elimination_HP_yield)
122             CPPUNIT_TEST(Elimination_HP_yield_relaxed)
123             CPPUNIT_TEST(Elimination_DHP_yield)
124             CPPUNIT_TEST(Elimination_DHP_yield_relaxed)
125             CPPUNIT_TEST(Elimination_HP_pause_alloc)
126             CPPUNIT_TEST(Elimination_HP_pause_alloc_relaxed)
127             CPPUNIT_TEST(Elimination_DHP_pause_alloc)
128             CPPUNIT_TEST(Elimination_DHP_pause_alloc_relaxed)
129         CPPUNIT_TEST_SUITE_END();
130     };
131 }   // namespace stack
132