92d8320a6f1f74be7c8c4427775dfeb6db18fa11
[libcds.git] / test / unit / intrusive-set / intrusive_skiplist_dhp.cpp
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 #include "test_intrusive_set_hp.h"
32
33 #include <cds/intrusive/skip_list_dhp.h>
34
35 namespace {
36     namespace ci = cds::intrusive;
37     typedef cds::gc::DHP gc_type;
38
39     class IntrusiveSkipListSet_DHP : public cds_test::intrusive_set_hp
40     {
41     protected:
42         typedef cds_test::intrusive_set_hp base_class;
43
44     protected:
45         typedef typename base_class::base_int_item< ci::skip_list::node< gc_type>>   base_item_type;
46         typedef typename base_class::member_int_item< ci::skip_list::node< gc_type>> member_item_type;
47
48         void SetUp()
49         {
50             typedef ci::SkipListSet< gc_type, base_item_type,
51                 typename ci::skip_list::make_traits<
52                     ci::opt::hook<ci::skip_list::base_hook< ci::opt::gc< gc_type >>>
53                     ,ci::opt::disposer<mock_disposer>
54                     ,ci::opt::compare<mock_disposer>
55                 >::type
56             > set_type;
57
58             cds::gc::dhp::smr::construct( set_type::c_nHazardPtrCount );
59             cds::threading::Manager::attachThread();
60         }
61
62         void TearDown()
63         {
64             cds::threading::Manager::detachThread();
65             cds::gc::dhp::smr::destruct();
66         }
67     };
68
69
70     TEST_F( IntrusiveSkipListSet_DHP, base_cmp )
71     {
72         struct traits : public ci::skip_list::traits
73         {
74             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
75             typedef mock_disposer disposer;
76             typedef cmp<base_item_type> compare;
77         };
78
79         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
80
81         set_type s;
82         test( s );
83     }
84
85     TEST_F( IntrusiveSkipListSet_DHP, base_less )
86     {
87         struct traits : public ci::skip_list::traits
88         {
89             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
90             typedef mock_disposer disposer;
91             typedef base_class::less<base_item_type> less;
92             typedef cds::atomicity::item_counter item_counter;
93         };
94
95         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
96
97         set_type s;
98         test( s );
99     }
100
101     TEST_F( IntrusiveSkipListSet_DHP, base_cmpmix )
102     {
103         struct traits : public ci::skip_list::traits
104         {
105             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
106             typedef mock_disposer disposer;
107             typedef cmp<base_item_type> compare;
108             typedef base_class::less<base_item_type> less;
109             typedef ci::skip_list::stat<> stat;
110         };
111
112         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
113
114         set_type s;
115         test( s );
116     }
117
118     TEST_F( IntrusiveSkipListSet_DHP, base_xorshift )
119     {
120         struct traits : public ci::skip_list::traits
121         {
122             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
123             typedef mock_disposer disposer;
124             typedef cmp<base_item_type> compare;
125             typedef ci::skip_list::xorshift random_level_generator;
126         };
127
128         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
129
130         set_type s;
131         test( s );
132     }
133
134
135     TEST_F( IntrusiveSkipListSet_DHP, member_cmp )
136     {
137         struct traits : public ci::skip_list::traits
138         {
139             typedef ci::skip_list::member_hook< offsetof(member_item_type, hMember), ci::opt::gc< gc_type >> hook;
140             typedef mock_disposer disposer;
141             typedef cmp<member_item_type> compare;
142         };
143
144         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
145
146         set_type s;
147         test( s );
148     }
149
150     TEST_F( IntrusiveSkipListSet_DHP, member_less )
151     {
152         struct traits : public ci::skip_list::traits
153         {
154             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
155             typedef mock_disposer disposer;
156             typedef base_class::less<member_item_type> less;
157             typedef cds::atomicity::item_counter item_counter;
158             typedef ci::opt::v::sequential_consistent memory_model;
159         };
160
161         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
162
163         set_type s;
164         test( s );
165     }
166
167     TEST_F( IntrusiveSkipListSet_DHP, member_cmpmix )
168     {
169         struct traits : public ci::skip_list::traits
170         {
171             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
172             typedef mock_disposer disposer;
173             typedef cmp<member_item_type> compare;
174             typedef base_class::less<member_item_type> less;
175             typedef ci::skip_list::stat<> stat;
176         };
177
178         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
179
180         set_type s;
181         test( s );
182     }
183
184     TEST_F( IntrusiveSkipListSet_DHP, member_xorshift )
185     {
186         struct traits : public ci::skip_list::traits
187         {
188             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
189             typedef mock_disposer disposer;
190             typedef cmp<member_item_type> compare;
191             typedef ci::skip_list::xorshift random_level_generator;
192         };
193
194         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
195
196         set_type s;
197         test( s );
198     }
199
200 } // namespace