2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
6 Source code repo: http://github.com/khizmax/libcds/
7 Download: http://sourceforge.net/projects/libcds/files/
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 this list of conditions and the following disclaimer in the documentation
17 and/or other materials provided with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef CDSTEST_HDR_TREIBER_STACK_H
32 #define CDSTEST_HDR_TREIBER_STACK_H
34 #include "cppunit/cppunit_proxy.h"
38 class TestStack: public CppUnitMini::TestCase
40 template <class Stack>
47 template <class Stack>
48 void test_elimination()
54 template <class Stack>
55 void test_with( Stack& stack)
57 typedef typename Stack::value_type value_type;
60 CPPUNIT_ASSERT( stack.empty() );
62 CPPUNIT_ASSERT( stack.push(1));
63 CPPUNIT_ASSERT( !stack.empty() );
64 CPPUNIT_ASSERT( stack.push(2));
65 CPPUNIT_ASSERT( !stack.empty() );
66 CPPUNIT_ASSERT( stack.push(3));
67 CPPUNIT_ASSERT( !stack.empty() );
69 CPPUNIT_ASSERT( stack.pop(v) );
70 CPPUNIT_ASSERT( v == 3 );
71 CPPUNIT_ASSERT( !stack.empty() );
72 CPPUNIT_ASSERT( stack.pop_with( [&v]( value_type& src ) { v = src; } ));
73 CPPUNIT_ASSERT( v == 2 );
74 CPPUNIT_ASSERT( !stack.empty() );
75 CPPUNIT_ASSERT( stack.pop(v) );
76 CPPUNIT_ASSERT( v == 1 );
77 CPPUNIT_ASSERT( stack.empty() );
79 CPPUNIT_ASSERT( !stack.pop(v) );
80 CPPUNIT_ASSERT( v == 1000 );
81 CPPUNIT_ASSERT( stack.empty() );
83 CPPUNIT_ASSERT( stack.push(10));
84 CPPUNIT_ASSERT( stack.push(20));
85 CPPUNIT_ASSERT( stack.push(30));
86 CPPUNIT_ASSERT( !stack.empty());
88 CPPUNIT_ASSERT( stack.emplace(100));
89 CPPUNIT_ASSERT( stack.pop(v));
90 CPPUNIT_ASSERT( v == 100 );
93 CPPUNIT_ASSERT( stack.empty() );
100 void Treiber_HP_yield();
101 void Treiber_DHP_yield();
102 void Treiber_HP_pause_alloc();
103 void Treiber_DHP_pause_alloc();
105 void Treiber_HP_relaxed();
106 void Treiber_DHP_relaxed();
107 void Treiber_HP_yield_relaxed();
108 void Treiber_DHP_yield_relaxed();
109 void Treiber_HP_pause_alloc_relaxed();
110 void Treiber_DHP_pause_alloc_relaxed();
112 void Elimination_HP();
113 void Elimination_HP_dyn();
114 void Elimination_HP_stat();
115 void Elimination_DHP();
116 void Elimination_DHP_dyn();
117 void Elimination_DHP_stat();
118 void Elimination_HP_yield();
119 void Elimination_DHP_yield();
120 void Elimination_HP_pause_alloc();
121 void Elimination_DHP_pause_alloc();
123 void Elimination_HP_relaxed();
124 void Elimination_DHP_relaxed();
125 void Elimination_HP_yield_relaxed();
126 void Elimination_DHP_yield_relaxed();
127 void Elimination_HP_pause_alloc_relaxed();
128 void Elimination_DHP_pause_alloc_relaxed();
130 CPPUNIT_TEST_SUITE(TestStack);
131 CPPUNIT_TEST(Treiber_HP)
132 CPPUNIT_TEST(Treiber_HP_relaxed)
133 CPPUNIT_TEST(Treiber_DHP)
134 CPPUNIT_TEST(Treiber_DHP_relaxed)
135 CPPUNIT_TEST(Treiber_HP_yield)
136 CPPUNIT_TEST(Treiber_HP_yield_relaxed)
137 CPPUNIT_TEST(Treiber_DHP_yield)
138 CPPUNIT_TEST(Treiber_DHP_yield_relaxed)
139 CPPUNIT_TEST(Treiber_HP_pause_alloc)
140 CPPUNIT_TEST(Treiber_HP_pause_alloc_relaxed)
141 CPPUNIT_TEST(Treiber_DHP_pause_alloc)
142 CPPUNIT_TEST(Treiber_DHP_pause_alloc_relaxed)
144 CPPUNIT_TEST(Elimination_HP)
145 CPPUNIT_TEST(Elimination_HP_dyn)
146 CPPUNIT_TEST(Elimination_HP_stat)
147 CPPUNIT_TEST(Elimination_HP_relaxed)
148 CPPUNIT_TEST(Elimination_DHP)
149 CPPUNIT_TEST(Elimination_DHP_dyn)
150 CPPUNIT_TEST(Elimination_DHP_stat)
151 CPPUNIT_TEST(Elimination_DHP_relaxed)
152 CPPUNIT_TEST(Elimination_HP_yield)
153 CPPUNIT_TEST(Elimination_HP_yield_relaxed)
154 CPPUNIT_TEST(Elimination_DHP_yield)
155 CPPUNIT_TEST(Elimination_DHP_yield_relaxed)
156 CPPUNIT_TEST(Elimination_HP_pause_alloc)
157 CPPUNIT_TEST(Elimination_HP_pause_alloc_relaxed)
158 CPPUNIT_TEST(Elimination_DHP_pause_alloc)
159 CPPUNIT_TEST(Elimination_DHP_pause_alloc_relaxed)
160 CPPUNIT_TEST_SUITE_END();
164 #endif // #ifndef CDSTEST_HDR_TREIBER_STACK_H