Removed signal_threaded uRCU
[libcds.git] / test / unit / list / test_kv_lazy_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
31 #ifndef CDSUNIT_LIST_TEST_KV_LAZY_LIST_RCU_H
32 #define CDSUNIT_LIST_TEST_KV_LAZY_LIST_RCU_H
33
34 #include "test_kv_list_rcu.h"
35 #include <cds/container/lazy_kvlist_rcu.h>
36
37 namespace cc = cds::container;
38
39 template <class RCU>
40 class LazyKVList : public cds_test::kv_list_rcu
41 {
42     typedef cds_test::kv_list_rcu base_class;
43 public:
44     typedef cds::urcu::gc<RCU> rcu_type;
45
46 protected:
47     void SetUp()
48     {
49         RCU::Construct();
50         cds::threading::Manager::attachThread();
51     }
52
53     void TearDown()
54     {
55         cds::threading::Manager::detachThread();
56         RCU::Destruct();
57     }
58 };
59
60 TYPED_TEST_CASE_P( LazyKVList );
61
62 TYPED_TEST_P( LazyKVList, less_ordered )
63 {
64     typedef cc::LazyKVList< typename TestFixture::rcu_type, typename TestFixture::key_type, typename TestFixture::value_type,
65         typename cc::lazy_list::make_traits<
66             cds::opt::less< typename TestFixture::lt>
67         >::type
68     > list_type;
69
70     list_type l;
71     this->test_common( l );
72     this->test_ordered_iterator( l );
73     this->test_rcu( l );
74 }
75
76 TYPED_TEST_P( LazyKVList, compare_ordered )
77 {
78     typedef cc::LazyKVList< typename TestFixture::rcu_type, typename TestFixture::key_type, typename TestFixture::value_type,
79         typename cc::lazy_list::make_traits<
80             cds::opt::compare< typename TestFixture::cmp>
81         >::type
82     > list_type;
83
84     list_type l;
85     this->test_common( l );
86     this->test_ordered_iterator( l );
87     this->test_rcu( l );
88 }
89
90 TYPED_TEST_P( LazyKVList, mix_ordered )
91 {
92     typedef cc::LazyKVList< typename TestFixture::rcu_type, typename TestFixture::key_type, typename TestFixture::value_type,
93         typename cc::lazy_list::make_traits<
94             cds::opt::less< typename TestFixture::lt>
95             ,cds::opt::compare< typename TestFixture::cmp>
96         >::type
97     > list_type;
98
99     list_type l;
100     this->test_common( l );
101     this->test_ordered_iterator( l );
102     this->test_rcu( l );
103 }
104
105 TYPED_TEST_P( LazyKVList, item_counting )
106 {
107     struct traits : public cc::lazy_list::traits
108     {
109         typedef typename TestFixture::lt less;
110         typedef cds::atomicity::item_counter item_counter;
111     };
112     typedef cc::LazyKVList<typename TestFixture::rcu_type, typename TestFixture::key_type, typename TestFixture::value_type, traits > list_type;
113
114     list_type l;
115     this->test_common( l );
116     this->test_ordered_iterator( l );
117     this->test_rcu( l );
118 }
119
120 TYPED_TEST_P( LazyKVList, backoff )
121 {
122     struct traits : public cc::lazy_list::traits
123     {
124         typedef typename TestFixture::lt less;
125         typedef cds::atomicity::item_counter item_counter;
126         typedef cds::backoff::empty back_off;
127     };
128     typedef cc::LazyKVList<typename TestFixture::rcu_type, typename TestFixture::key_type, typename TestFixture::value_type, traits > list_type;
129
130     list_type l;
131     this->test_common( l );
132     this->test_ordered_iterator( l );
133     this->test_rcu( l );
134 }
135
136 TYPED_TEST_P( LazyKVList, seq_cst )
137 {
138     struct traits : public cc::lazy_list::traits
139     {
140         typedef typename TestFixture::lt less;
141         typedef cds::atomicity::item_counter item_counter;
142         typedef cds::opt::v::sequential_consistent memory_model;
143     };
144     typedef cc::LazyKVList<typename TestFixture::rcu_type, typename TestFixture::key_type, typename TestFixture::value_type, traits > list_type;
145
146     list_type l;
147     this->test_common( l );
148     this->test_ordered_iterator( l );
149     this->test_rcu( l );
150 }
151
152 TYPED_TEST_P( LazyKVList, mutex )
153 {
154     struct traits : public cc::lazy_list::traits
155     {
156         typedef typename TestFixture::lt less;
157         typedef cds::atomicity::item_counter item_counter;
158         typedef std::mutex lock_type;
159     };
160     typedef cc::LazyKVList<typename TestFixture::rcu_type, typename TestFixture::key_type, typename TestFixture::value_type, traits > list_type;
161
162     list_type l;
163     this->test_common( l );
164     this->test_ordered_iterator( l );
165     this->test_rcu( l );
166 }
167
168 TYPED_TEST_P( LazyKVList, stat )
169 {
170     struct traits: public cc::lazy_list::traits
171     {
172         typedef typename TestFixture::lt less;
173         typedef cds::atomicity::item_counter item_counter;
174         typedef cds::container::lazy_list::stat<> stat;
175     };
176     typedef cc::LazyKVList<typename TestFixture::rcu_type, typename TestFixture::key_type, typename TestFixture::value_type, traits > list_type;
177
178     list_type l;
179     this->test_common( l );
180     this->test_ordered_iterator( l );
181     this->test_rcu( l );
182 }
183
184 TYPED_TEST_P( LazyKVList, wrapped_stat )
185 {
186     struct traits: public cc::lazy_list::traits
187     {
188         typedef typename TestFixture::lt less;
189         typedef cds::atomicity::item_counter item_counter;
190         typedef cds::container::lazy_list::wrapped_stat<> stat;
191     };
192     typedef cc::LazyKVList<typename TestFixture::rcu_type, typename TestFixture::key_type, typename TestFixture::value_type, traits > list_type;
193
194     cds::container::lazy_list::stat<> st;
195     list_type l( st );
196     this->test_common( l );
197     this->test_ordered_iterator( l );
198     this->test_rcu( l );
199 }
200
201 // GCC 5: All test names should be written on single line, otherwise a runtime error will be encountered like as
202 // "No test named <test_name> can be found in this test case"
203 REGISTER_TYPED_TEST_CASE_P( LazyKVList,
204     less_ordered, compare_ordered, mix_ordered, item_counting, backoff, seq_cst, mutex, stat, wrapped_stat
205     );
206
207 #endif // CDSUNIT_LIST_TEST_KV_LAZY_LIST_RCU_H