Merged branch 'master' of https://github.com/Nemo1369/libcds
[libcds.git] / test / unit / list / test_michael_rcu.h
1 /*
2     This file is a part of libcds - Concurrent Data Structures library
3
4     (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
5
6     Source code repo: http://github.com/khizmax/libcds/
7     Download: http://sourceforge.net/projects/libcds/files/
8
9     Redistribution and use in source and binary forms, with or without
10     modification, are permitted provided that the following conditions are met:
11
12     * Redistributions of source code must retain the above copyright notice, this
13       list of conditions and the following disclaimer.
14
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.
18
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.
29 */
30 #ifndef CDSUNIT_LIST_TEST_MICHAEL_LIST_RCU_H
31 #define CDSUNIT_LIST_TEST_MICHAEL_LIST_RCU_H
32
33 #include "test_list_rcu.h"
34 #include <cds/container/michael_list_rcu.h>
35
36 namespace cc = cds::container;
37
38 template <class RCU>
39 class MichaelList : public cds_test::list_rcu
40 {
41     typedef cds_test::list_rcu base_class;
42 public:
43     typedef cds::urcu::gc<RCU> rcu_type;
44
45 protected:
46     void SetUp()
47     {
48         RCU::Construct();
49         cds::threading::Manager::attachThread();
50     }
51
52     void TearDown()
53     {
54         cds::threading::Manager::detachThread();
55         RCU::Destruct();
56     }
57 };
58
59 TYPED_TEST_CASE_P( MichaelList );
60
61 TYPED_TEST_P( MichaelList, less_ordered )
62 {
63     typedef cc::MichaelList< typename TestFixture::rcu_type, typename TestFixture::item,
64         typename cc::michael_list::make_traits<
65             cds::opt::less< typename TestFixture::template lt< typename TestFixture::item>>
66         >::type
67     > list_type;
68
69     list_type l;
70     this->test_common( l );
71     this->test_ordered_iterator( l );
72     this->test_rcu( l );
73 }
74
75 TYPED_TEST_P( MichaelList, compare_ordered )
76 {
77     typedef cc::MichaelList< typename TestFixture::rcu_type, typename TestFixture::item,
78         typename cc::michael_list::make_traits<
79             cds::opt::compare< typename TestFixture::template cmp<typename TestFixture::item>>
80         >::type
81     > list_type;
82
83     list_type l;
84     this->test_common( l );
85     this->test_ordered_iterator( l );
86     this->test_rcu( l );
87 }
88
89 TYPED_TEST_P( MichaelList, mix_ordered )
90 {
91     typedef cc::MichaelList< typename TestFixture::rcu_type, typename TestFixture::item,
92         typename cc::michael_list::make_traits<
93             cds::opt::compare< typename TestFixture::template cmp<typename TestFixture::item>>
94             ,cds::opt::less< typename TestFixture::template lt< typename TestFixture::item>>
95         >::type
96     > list_type;
97
98     list_type l;
99     this->test_common( l );
100     this->test_ordered_iterator( l );
101     this->test_rcu( l );
102 }
103
104 TYPED_TEST_P( MichaelList, item_counting )
105 {
106     struct traits : public cc::michael_list::traits
107     {
108         typedef typename TestFixture::template lt< typename TestFixture::item> less;
109         typedef cds::atomicity::item_counter item_counter;
110     };
111     typedef cc::MichaelList<typename TestFixture::rcu_type, typename TestFixture::item, traits > list_type;
112
113     list_type l;
114     this->test_common( l );
115     this->test_ordered_iterator( l );
116     this->test_rcu( l );
117 }
118
119 TYPED_TEST_P( MichaelList, backoff )
120 {
121     struct traits : public cc::michael_list::traits
122     {
123         typedef typename TestFixture::template lt< typename TestFixture::item> less;
124         typedef cds::atomicity::item_counter item_counter;
125         typedef cds::backoff::empty back_off;
126     };
127     typedef cc::MichaelList<typename TestFixture::rcu_type, typename TestFixture::item, traits > list_type;
128
129     list_type l;
130     this->test_common( l );
131     this->test_ordered_iterator( l );
132     this->test_rcu( l );
133 }
134
135 TYPED_TEST_P( MichaelList, seq_cst )
136 {
137     struct traits : public cc::michael_list::traits
138     {
139         typedef typename TestFixture::template lt< typename TestFixture::item> less;
140         typedef cds::atomicity::item_counter item_counter;
141         typedef cds::opt::v::sequential_consistent memory_model;
142     };
143     typedef cc::MichaelList<typename TestFixture::rcu_type, typename TestFixture::item, traits > list_type;
144
145     list_type l;
146     this->test_common( l );
147     this->test_ordered_iterator( l );
148     this->test_rcu( l );
149 }
150
151 TYPED_TEST_P( MichaelList, stat )
152 {
153     struct traits: public cc::michael_list::traits
154     {
155         typedef typename TestFixture::template lt< typename TestFixture::item> less;
156         typedef cds::atomicity::item_counter item_counter;
157         typedef cds::container::michael_list::stat<> stat;
158     };
159     typedef cc::MichaelList<typename TestFixture::rcu_type, typename TestFixture::item, traits > list_type;
160
161     list_type l;
162     this->test_common( l );
163     this->test_ordered_iterator( l );
164     this->test_rcu( l );
165 }
166
167 TYPED_TEST_P( MichaelList, wrapped_stat )
168 {
169     struct traits: public cc::michael_list::traits
170     {
171         typedef typename TestFixture::template lt< typename TestFixture::item> less;
172         typedef cds::atomicity::item_counter item_counter;
173         typedef cds::container::michael_list::wrapped_stat<> stat;
174     };
175     typedef cc::MichaelList<typename TestFixture::rcu_type, typename TestFixture::item, traits > list_type;
176
177     cds::container::michael_list::stat<> st;
178     list_type l( st );
179     this->test_common( l );
180     this->test_ordered_iterator( l );
181     this->test_rcu( l );
182 }
183
184 // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as
185 // "No test named <test_name> can be found in this test case"
186 REGISTER_TYPED_TEST_CASE_P( MichaelList,
187     less_ordered, compare_ordered, mix_ordered, item_counting, backoff, seq_cst, stat, wrapped_stat
188     );
189
190 #endif // CDSUNIT_LIST_TEST_MICHAEL_LIST_RCU_H