aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhta <hta@webrtc.org>2015-10-20 09:31:01 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-20 16:31:04 +0000
commit3866c4fb460ebcf95857dbee6ec0e8664bd3b16a (patch)
tree5432e2ef56124eb8486a875962f03595d67cb1aa
parent43e83d44f01683fbd304e37d47d2f6db0d52660d (diff)
downloadwebrtc-3866c4fb460ebcf95857dbee6ec0e8664bd3b16a.tar.gz
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}
-rw-r--r--webrtc/system_wrappers/source/condition_variable_unittest.cc16
1 files changed, 16 insertions, 0 deletions
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<CriticalSectionWrapper> crit_sect(
+ CriticalSectionWrapper::CreateCriticalSection());
+ rtc::scoped_ptr<ConditionVariableWrapper> 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