MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / test

Method test

extern/libcds/test/stress/pqueue/push_pop.cpp:119–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117
118 template <class PQueue>
119 void test( PQueue& q )
120 {
121 size_t const nThreadItemCount = s_nQueueSize / s_nPushThreadCount;
122 s_nQueueSize = nThreadItemCount * s_nPushThreadCount;
123
124 propout() << std::make_pair( "producer_count", s_nPushThreadCount )
125 << std::make_pair( "consunmer_count", s_nPopThreadCount )
126 << std::make_pair( "queue_size", s_nQueueSize );
127
128 cds_test::thread_pool& pool = get_pool();
129 pool.add( new Producer<PQueue>( pool, q ), s_nPushThreadCount );
130
131 size_t nStart = 0;
132 for ( size_t i = 0; i < pool.size(); ++i ) {
133 static_cast<Producer<PQueue>&>(pool.get( i )).prepare( nStart, nStart + nThreadItemCount );
134 nStart += nThreadItemCount;
135 }
136
137 pool.add( new Consumer<PQueue>( pool, q ), s_nPopThreadCount );
138
139 s_nProducerCount.store( s_nPushThreadCount, atomics::memory_order_release );
140
141 std::chrono::milliseconds duration = pool.run();
142 propout() << std::make_pair( "duration", duration );
143
144 // Analyze result
145 size_t nTotalPopped = 0;
146 size_t nPushFailed = 0;
147 size_t nPopFailed = 0;
148 for ( size_t i = 0; i < pool.size(); ++i ) {
149 cds_test::thread& t = pool.get(i);
150 if ( t.type() == consumer_thread ) {
151 Consumer<PQueue>& cons = static_cast<Consumer<PQueue>&>( t );
152 nTotalPopped += cons.m_nPopSuccess;
153 nPopFailed += cons.m_nPopFailed;
154 }
155 else {
156 assert( t.type() == producer_thread );
157 Producer<PQueue>& prod = static_cast<Producer<PQueue>&>(t);
158 nPushFailed += prod.m_nPushError;
159 EXPECT_EQ( prod.m_nPushError , 0u ) << "producer " << i;
160 }
161 }
162
163 propout() << std::make_pair( "total_popped", nTotalPopped )
164 << std::make_pair( "empty_pop", nPopFailed )
165 << std::make_pair( "push_error", nPushFailed );
166
167 EXPECT_EQ( nTotalPopped, s_nQueueSize );
168 EXPECT_EQ( nPushFailed, 0u );
169
170 //check_statistics( testQueue.statistics());
171 propout() << q.statistics();
172 }
173
174 public:
175 static void SetUpTestCase()

Callers

nothing calls this directly

Calls 10

make_pairFunction · 0.85
assertClass · 0.85
addMethod · 0.45
sizeMethod · 0.45
prepareMethod · 0.45
getMethod · 0.45
storeMethod · 0.45
runMethod · 0.45
typeMethod · 0.45
statisticsMethod · 0.45

Tested by

no test coverage detected