Merged branch 'master' of https://github.com/Nemo1369/libcds
[libcds.git] / test / unit / intrusive-set / intrusive_skiplist_hp.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_hp.h>
34
35 namespace {
36     namespace ci = cds::intrusive;
37     typedef cds::gc::HP gc_type;
38
39     class IntrusiveSkipListSet_HP : 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             // +1 - for guarded_ptr
59             cds::gc::hp::GarbageCollector::Construct( set_type::c_nHazardPtrCount + 1, 1, 16 );
60             cds::threading::Manager::attachThread();
61         }
62
63         void TearDown()
64         {
65             cds::threading::Manager::detachThread();
66             cds::gc::hp::GarbageCollector::Destruct( true );
67         }
68     };
69
70
71     TEST_F( IntrusiveSkipListSet_HP, base_cmp )
72     {
73         struct traits : public ci::skip_list::traits
74         {
75             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
76             typedef mock_disposer disposer;
77             typedef cmp<base_item_type> compare;
78         };
79
80         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
81
82         set_type s;
83         test( s );
84     }
85
86     TEST_F( IntrusiveSkipListSet_HP, base_less )
87     {
88         struct traits : public ci::skip_list::traits
89         {
90             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
91             typedef mock_disposer disposer;
92             typedef base_class::less<base_item_type> less;
93             typedef cds::atomicity::item_counter item_counter;
94         };
95
96         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
97
98         set_type s;
99         test( s );
100     }
101
102     TEST_F( IntrusiveSkipListSet_HP, base_cmpmix )
103     {
104         struct traits : public ci::skip_list::traits
105         {
106             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
107             typedef mock_disposer disposer;
108             typedef cmp<base_item_type> compare;
109             typedef base_class::less<base_item_type> less;
110             typedef ci::skip_list::stat<> stat;
111         };
112
113         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
114
115         set_type s;
116         test( s );
117     }
118
119     TEST_F( IntrusiveSkipListSet_HP, base_xorshift )
120     {
121         struct traits : public ci::skip_list::traits
122         {
123             typedef ci::skip_list::base_hook< ci::opt::gc< gc_type >> hook;
124             typedef mock_disposer disposer;
125             typedef cmp<base_item_type> compare;
126             typedef ci::skip_list::xorshift random_level_generator;
127         };
128
129         typedef ci::SkipListSet< gc_type, base_item_type, traits > set_type;
130
131         set_type s;
132         test( s );
133     }
134
135
136     TEST_F( IntrusiveSkipListSet_HP, member_cmp )
137     {
138         struct traits : public ci::skip_list::traits
139         {
140             typedef ci::skip_list::member_hook< offsetof(member_item_type, hMember), ci::opt::gc< gc_type >> hook;
141             typedef mock_disposer disposer;
142             typedef cmp<member_item_type> compare;
143         };
144
145         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
146
147         set_type s;
148         test( s );
149     }
150
151     TEST_F( IntrusiveSkipListSet_HP, member_less )
152     {
153         struct traits : public ci::skip_list::traits
154         {
155             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
156             typedef mock_disposer disposer;
157             typedef base_class::less<member_item_type> less;
158             typedef cds::atomicity::item_counter item_counter;
159             typedef ci::opt::v::sequential_consistent memory_model;
160         };
161
162         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
163
164         set_type s;
165         test( s );
166     }
167
168     TEST_F( IntrusiveSkipListSet_HP, member_cmpmix )
169     {
170         struct traits : public ci::skip_list::traits
171         {
172             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
173             typedef mock_disposer disposer;
174             typedef cmp<member_item_type> compare;
175             typedef base_class::less<member_item_type> less;
176             typedef ci::skip_list::stat<> stat;
177         };
178
179         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
180
181         set_type s;
182         test( s );
183     }
184
185     TEST_F( IntrusiveSkipListSet_HP, member_xorshift )
186     {
187         struct traits : public ci::skip_list::traits
188         {
189             typedef ci::skip_list::member_hook< offsetof( member_item_type, hMember ), ci::opt::gc< gc_type >> hook;
190             typedef mock_disposer disposer;
191             typedef cmp<member_item_type> compare;
192             typedef ci::skip_list::xorshift random_level_generator;
193         };
194
195         typedef ci::SkipListSet< gc_type, member_item_type, traits > set_type;
196
197         set_type s;
198         test( s );
199     }
200
201 } // namespace