17 #ifndef PAGESPEED_KERNEL_THREAD_CONDVAR_TEST_BASE_H_
18 #define PAGESPEED_KERNEL_THREAD_CONDVAR_TEST_BASE_H_
22 #include "base/logging.h"
29 namespace net_instaweb {
37 startup_condvar_(NULL),
39 ready_to_start_(
false),
43 wait_after_signal_(
false),
44 helper_increments_(0),
55 startup_condvar_ = startup_condvar;
60 static void* HelperThread(
void* data) {
61 CondvarTestBase* test =
static_cast<CondvarTestBase*
>(data);
80 ready_to_start_ =
true;
81 startup_condvar_->
Signal();
88 while (!ready_to_start_) {
89 startup_condvar_->
Wait();
96 int iter = current_iter_ + 1;
100 ++helper_increments_;
101 current_iter_ = iter;
102 (condvar_->*signal_method_)();
103 while (wait_after_signal_ && current_iter_ == iter) {
114 EXPECT_TRUE(ready_to_start_);
116 EXPECT_EQ(helper_increments_, 0);
124 EXPECT_TRUE(ready_to_start_);
126 EXPECT_EQ(helper_increments_, 10);
133 wait_after_signal_ =
true;
135 int local_increments = 0;
138 while ((current_iter_ % 2) == 0 && current_iter_ < iters_) {
143 if (current_iter_ == iters_) {
150 EXPECT_EQ(local_increments, 5);
152 EXPECT_EQ(helper_increments_, 5);
170 int64 start_ms = timer()->
NowMs();
175 int64 end_ms = timer()->
NowMs();
179 EXPECT_LE(wait_ms, end_ms - start_ms);
188 wait_after_signal_ =
true;
190 int local_increments = 0;
193 if ((current_iter_ % 2) == 0) {
200 if (current_iter_ > iters_) {
208 EXPECT_LE(6, local_increments);
209 EXPECT_GE(5, helper_increments_);
210 EXPECT_EQ(11, local_increments + helper_increments_);
213 virtual Timer* timer() = 0;
218 bool ready_to_start_;
221 SignalMethod signal_method_;
222 bool wait_after_signal_;
223 int helper_increments_;
void PingPongTest()
Definition: condvar_test_base.h:131
virtual int64 NowMs() const
Returns number of milliseconds since 1970.
virtual void CreateHelper()=0
void TimeoutTest()
Make sure that TimedWait eventually progresses in the absence of a signal.
Definition: condvar_test_base.h:156
void Init(ThreadSystem::CondvarCapableMutex *mutex, ThreadSystem::Condvar *startup_condvar, ThreadSystem::Condvar *condvar)
Definition: condvar_test_base.h:50
Definition: thread_system.h:46
virtual void TimedWait(int64 timeout_ms)=0
#define ScopedMutex(x)
Definition: abstract_mutex.h:69
Definition: condvar_test_base.h:31
void LongTimeoutTest(int wait_ms)
Make sure that a long timeout doesn't exit too early.
Definition: condvar_test_base.h:167
Helper class for lexically scoped mutexing.
Definition: abstract_mutex.h:46
virtual void FinishHelper()=0
void StartupTest()
Below are the common tests that should be run by every client.
Definition: condvar_test_base.h:112
virtual void HelperThreadMethod()
Definition: condvar_test_base.h:85
void TimeoutPingPongTest()
Definition: condvar_test_base.h:186
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
void BlindSignalsTest()
Definition: condvar_test_base.h:121