From 3866c4fb460ebcf95857dbee6ec0e8664bd3b16a Mon Sep 17 00:00:00 2001 From: hta Date: Tue, 20 Oct 2015 09:31:01 -0700 Subject: [PATCH] Testing that waiting for a condition variable waits. Added a test that verifies that waiting for a condition variable actually waits for a non-zero time. This used to fail due to a TSAN / CLANG bug, but this failure is supposed to have been fixed. This was originally https://webrtc-codereview.appspot.com/2145004 BUG=2259 Review URL: https://codereview.webrtc.org/1416873002 Cr-Commit-Position: refs/heads/master@{#10341} --- .../source/condition_variable_unittest.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/webrtc/system_wrappers/source/condition_variable_unittest.cc b/webrtc/system_wrappers/source/condition_variable_unittest.cc index c34c4ea0d8..6e8a1ec3b5 100644 --- a/webrtc/system_wrappers/source/condition_variable_unittest.cc +++ b/webrtc/system_wrappers/source/condition_variable_unittest.cc @@ -11,8 +11,10 @@ #include "webrtc/system_wrappers/interface/condition_variable_wrapper.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/base/scoped_ptr.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" #include "webrtc/system_wrappers/interface/thread_wrapper.h" +#include "webrtc/system_wrappers/interface/tick_util.h" #include "webrtc/system_wrappers/interface/trace.h" namespace webrtc { @@ -21,6 +23,7 @@ namespace { const int kLongWaitMs = 100 * 1000; // A long time in testing terms const int kShortWaitMs = 2 * 1000; // Long enough for process switches to happen +const int kVeryShortWaitMs = 20; // Used when we want a timeout // A Baton is one possible control structure one can build using // conditional variables. @@ -184,6 +187,19 @@ TEST_F(CondVarTest, DISABLED_PassBatonMultipleTimes) { EXPECT_EQ(2 * kNumberOfRounds, baton_.PassCount()); } +TEST(CondVarWaitTest, WaitingWaits) { + rtc::scoped_ptr crit_sect( + CriticalSectionWrapper::CreateCriticalSection()); + rtc::scoped_ptr cond_var( + ConditionVariableWrapper::CreateConditionVariable()); + CriticalSectionScoped cs(crit_sect.get()); + int64_t start_ms = TickTime::MillisecondTimestamp(); + EXPECT_FALSE(cond_var->SleepCS(*(crit_sect), kVeryShortWaitMs)); + int64_t end_ms = TickTime::MillisecondTimestamp(); + EXPECT_LE(start_ms + kVeryShortWaitMs, end_ms) + << "actual elapsed:" << end_ms - start_ms; +} + } // anonymous namespace } // namespace webrtc