2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017
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,
14 list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "../misc/common.h"
36 #include "../stack/stack_type.h"
40 #define CDSSTRESS_SequentialTreiberStack_F(test_fixture, type_name) \
41 TEST_F(test_fixture, type_name) { \
42 typedef stack::Types<value_type>::type_name stack_type; \
47 #define CDSSTRESS_SequentialEliminationStack_F(test_fixture, type_name) \
48 TEST_F(test_fixture, type_name) { \
49 typedef stack::Types<value_type>::type_name stack_type; \
50 stack_type stack(s_nSequentialEliminationSize); \
54 #define CDSSTRESS_SequentialTreiberStack(test_fixture) \
55 CDSSTRESS_SequentialTreiberStack_F(test_fixture, Treiber_HP); \
56 CDSSTRESS_SequentialTreiberStack_F(test_fixture, Treiber_DHP); \
58 #define CDSSTRESS_SequentialEliminationStack(test_fixture) \
59 CDSSTRESS_SequentialEliminationStack_F(test_fixture, Elimination_HP); \
60 CDSSTRESS_SequentialEliminationStack_F(test_fixture, Elimination_HP_dyn); \
61 CDSSTRESS_SequentialEliminationStack_F(test_fixture, Elimination_DHP); \
62 CDSSTRESS_SequentialEliminationStack_F(test_fixture, Elimination_DHP_dyn)
64 static size_t s_nSequentialStackPushCount = 100000;
65 static size_t s_nSequentialEliminationSize = 4;
67 class sequential_stack : public cds_test::stress_fixture {
73 value_type() : nNo(0), nThread(0) {}
74 value_type(size_t n) : nNo(n), nThread(0) {}
78 static void SetUpTestCase() {
79 cds_test::config const &cfg = get_config("SequentialStack");
80 GetConfig(SequentialStackPushCount);
81 GetConfig(SequentialEliminationSize);
84 template <typename Stack> void test(Stack &stack) {
85 size_t push_error_cnt = 0;
88 size_t m_nStartItem = 0;
89 size_t m_nEndItem = s_nSequentialStackPushCount;
90 for (v.nNo = m_nStartItem; v.nNo < m_nEndItem; ++v.nNo) {
95 while (stack.pop(v)) {
100 std::cout << "Sequential stack push error count: " << push_error_cnt
103 size_t supposed_sum =
104 (m_nStartItem + m_nEndItem - 1) * (m_nEndItem - m_nStartItem) / 2;
105 if (pop_sum != supposed_sum) {
106 std::cout << "Sequential stack pop sum: " << pop_sum
107 << " != " << supposed_sum << "\n";
112 CDSSTRESS_SequentialTreiberStack(sequential_stack)
113 CDSSTRESS_SequentialEliminationStack(sequential_stack)