| 90 | |
| 91 | template <class PQueue> |
| 92 | void test( PQueue& q ) |
| 93 | { |
| 94 | cds_test::thread_pool& pool = get_pool(); |
| 95 | |
| 96 | // push |
| 97 | { |
| 98 | std::vector< size_t > arr; |
| 99 | arr.reserve( s_nQueueSize ); |
| 100 | for ( size_t i = 0; i < s_nQueueSize; ++i ) |
| 101 | arr.push_back( i ); |
| 102 | shuffle( arr.begin(), arr.end()); |
| 103 | |
| 104 | size_t nPushError = 0; |
| 105 | typedef typename PQueue::value_type value_type; |
| 106 | for ( auto it = arr.begin(); it != arr.end(); ++it ) { |
| 107 | if ( !q.push( value_type( *it ))) |
| 108 | ++nPushError; |
| 109 | } |
| 110 | s_nQueueSize -= nPushError; |
| 111 | } |
| 112 | |
| 113 | propout() << std::make_pair( "thread_count", s_nThreadCount ) |
| 114 | << std::make_pair( "push_count", s_nQueueSize ); |
| 115 | |
| 116 | // pop |
| 117 | { |
| 118 | pool.add( new Consumer<PQueue>( pool, q ), s_nThreadCount ); |
| 119 | |
| 120 | std::chrono::milliseconds duration = pool.run(); |
| 121 | propout() << std::make_pair( "consumer_duration", duration ); |
| 122 | |
| 123 | // Analyze result |
| 124 | size_t nTotalPopped = 0; |
| 125 | size_t nTotalError = 0; |
| 126 | size_t nTotalErrorEq = 0; |
| 127 | size_t nTotalFailed = 0; |
| 128 | for ( size_t i = 0; i < pool.size(); ++i ) { |
| 129 | Consumer<PQueue>& cons = static_cast<Consumer<PQueue>&>( pool.get(i)); |
| 130 | |
| 131 | nTotalPopped += cons.m_nPopSuccess; |
| 132 | nTotalError += cons.m_nPopError; |
| 133 | nTotalErrorEq += cons.m_nPopErrorEq; |
| 134 | nTotalFailed += cons.m_nPopFailed; |
| 135 | |
| 136 | if ( !cons.m_arrFailedPops.empty()) { |
| 137 | std::cerr << "Priority violations, thread " << i; |
| 138 | for ( size_t k = 0; k < cons.m_arrFailedPops.size(); ++k ) { |
| 139 | std::cerr << "\n " << "prev_key=" << cons.m_arrFailedPops[k].prev_key << " popped_key=" << cons.m_arrFailedPops[k].popped_key; |
| 140 | if ( cons.m_arrFailedPops[k].next_key != static_cast<size_t>(-1)) |
| 141 | std::cerr << " next_key=" << cons.m_arrFailedPops[k].next_key; |
| 142 | else |
| 143 | std::cerr << " next_key unspecified"; |
| 144 | } |
| 145 | std::cerr << std::endl; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | propout() |
nothing calls this directly
no test coverage detected