2 This file is a part of libcds - Concurrent Data Structures library
4 (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2016
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, this
13 list of conditions and the following disclaimer.
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.
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.
31 #include "queue_type.h"
36 The test checks the behaviour of bounded queue when it is almost full.
37 Many algorithms says the queue is full when it is not, and vice versa.
41 static size_t s_nThreadCount = 8;
42 static size_t s_nQueueSize = 1024;
43 static size_t s_nPassCount = 1000000;
45 class bounded_queue_fulness: public cds_test::stress_fixture
47 typedef cds_test::stress_fixture base_class;
50 template <class Queue>
51 class Strain: public cds_test::thread
53 typedef cds_test::thread base_class;
57 size_t m_nPushError = 0;
58 size_t m_nPopError = 0;
61 Strain( cds_test::thread_pool& pool, Queue& q )
68 , m_Queue( src.m_Queue )
71 virtual thread * clone()
73 return new Strain( *this );
78 for ( size_t i = 0; i < s_nPassCount; ++i ) {
79 if ( !m_Queue.push( i ))
82 if ( !m_Queue.pop( item ))
89 static void SetUpTestCase()
\r
91 cds_test::config const& cfg = get_config( "bounded_queue_fulness" );
\r
93 s_nThreadCount = cfg.get_size_t( "ThreadCount", s_nThreadCount );
94 s_nQueueSize = cfg.get_size_t( "QueueSize", s_nQueueSize );
95 s_nPassCount = cfg.get_size_t( "PassCount", s_nPassCount );
97 if ( s_nThreadCount == 0 )
99 if ( s_nQueueSize == 0 )
101 if ( s_nPassCount == 0 )
105 //static void TearDownTestCase();
\r
108 template <class Queue>
109 void analyze( Queue& q )
111 cds_test::thread_pool& pool = get_pool();
113 size_t nPushError = 0;
114 size_t nPopError = 0;
115 for ( size_t i = 0; i < pool.size(); ++i ) {
116 Strain<Queue>& strain = static_cast<Strain<Queue> &>(pool.get( i ));
117 nPushError += strain.m_nPushError;
118 nPopError += strain.m_nPopError;
120 EXPECT_TRUE( !q.empty());
121 EXPECT_EQ( nPushError, 0 );
122 EXPECT_EQ( nPopError, 0 );
125 template <class Queue>
126 void test( Queue& q )
128 cds_test::thread_pool& pool = get_pool();
129 pool.add( new Strain<Queue>( pool, q ), s_nThreadCount );
131 size_t nSize = q.capacity() - s_nThreadCount;
132 for ( size_t i = 0; i < nSize; ++i )
135 propout() << std::make_pair( "thread_count", s_nThreadCount )
136 << std::make_pair( "push_count", s_nQueueSize )
137 << std::make_pair( "pass_count", s_nPassCount );
139 std::chrono::milliseconds duration = pool.run();
140 propout() << std::make_pair( "duration", duration );
144 propout() << q.statistics();
148 #undef CDSSTRESS_Queue_F
149 #define CDSSTRESS_Queue_F( test_fixture, type_name, level ) \
150 TEST_F( test_fixture, type_name ) \
152 /*if ( !check_detail_level( level )) return;*/ \
153 typedef queue::Types< size_t >::type_name queue_type; \
154 queue_type queue( s_nQueueSize ); \
158 CDSSTRESS_TsigasQueue( bounded_queue_fulness )
159 CDSSTRESS_VyukovQueue( bounded_queue_fulness )
161 #undef CDSSTRESS_Queue_F