Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: webrtc/system_wrappers/source/condition_variable_unittest.cc

Issue 1476453002: Clean up PlatformThread. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: IsRunning DCHECK Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // We expect these calls never to time out. 137 // We expect these calls never to time out.
138 bool WaitingRunFunction(void* obj) { 138 bool WaitingRunFunction(void* obj) {
139 Baton* the_baton = static_cast<Baton*> (obj); 139 Baton* the_baton = static_cast<Baton*> (obj);
140 EXPECT_TRUE(the_baton->Grab(kLongWaitMs)); 140 EXPECT_TRUE(the_baton->Grab(kLongWaitMs));
141 EXPECT_TRUE(the_baton->Pass(kLongWaitMs)); 141 EXPECT_TRUE(the_baton->Pass(kLongWaitMs));
142 return true; 142 return true;
143 } 143 }
144 144
145 class CondVarTest : public ::testing::Test { 145 class CondVarTest : public ::testing::Test {
146 public: 146 public:
147 CondVarTest() {} 147 CondVarTest() : thread_(&WaitingRunFunction, &baton_, "CondVarTest") {}
148 148
149 virtual void SetUp() { 149 virtual void SetUp() {
150 thread_ = PlatformThread::CreateThread(&WaitingRunFunction, &baton_, 150 thread_.Start();
151 "CondVarTest");
152 ASSERT_TRUE(thread_->Start());
153 } 151 }
154 152
155 virtual void TearDown() { 153 virtual void TearDown() {
156 // We have to wake the thread in order to make it obey the stop order. 154 // We have to wake the thread in order to make it obey the stop order.
157 // But we don't know if the thread has completed the run function, so 155 // But we don't know if the thread has completed the run function, so
158 // we don't know if it will exit before or after the Pass. 156 // we don't know if it will exit before or after the Pass.
159 // Thus, we need to pin it down inside its Run function (between Grab 157 // Thus, we need to pin it down inside its Run function (between Grab
160 // and Pass). 158 // and Pass).
161 ASSERT_TRUE(baton_.Pass(kShortWaitMs)); 159 ASSERT_TRUE(baton_.Pass(kShortWaitMs));
162 ASSERT_TRUE(baton_.Grab(kShortWaitMs)); 160 ASSERT_TRUE(baton_.Grab(kShortWaitMs));
163 ASSERT_TRUE(thread_->Stop()); 161 thread_.Stop();
164 } 162 }
165 163
166 protected: 164 protected:
167 Baton baton_; 165 Baton baton_;
168 166
169 private: 167 private:
170 rtc::scoped_ptr<PlatformThread> thread_; 168 rtc::PlatformThread thread_;
171 }; 169 };
172 170
173 // The SetUp and TearDown functions use condition variables. 171 // The SetUp and TearDown functions use condition variables.
174 // This test verifies those pieces in isolation. 172 // This test verifies those pieces in isolation.
175 // Disabled due to flakiness. See bug 4262 for details. 173 // Disabled due to flakiness. See bug 4262 for details.
176 TEST_F(CondVarTest, DISABLED_InitFunctionsWork) { 174 TEST_F(CondVarTest, DISABLED_InitFunctionsWork) {
177 // All relevant asserts are in the SetUp and TearDown functions. 175 // All relevant asserts are in the SetUp and TearDown functions.
178 } 176 }
179 177
180 // This test verifies that one can use the baton multiple times. 178 // This test verifies that one can use the baton multiple times.
(...skipping 15 matching lines...) Expand all
196 int64_t start_ms = TickTime::MillisecondTimestamp(); 194 int64_t start_ms = TickTime::MillisecondTimestamp();
197 EXPECT_FALSE(cond_var->SleepCS(*(crit_sect), kVeryShortWaitMs)); 195 EXPECT_FALSE(cond_var->SleepCS(*(crit_sect), kVeryShortWaitMs));
198 int64_t end_ms = TickTime::MillisecondTimestamp(); 196 int64_t end_ms = TickTime::MillisecondTimestamp();
199 EXPECT_LE(start_ms + kVeryShortWaitMs, end_ms) 197 EXPECT_LE(start_ms + kVeryShortWaitMs, end_ms)
200 << "actual elapsed:" << end_ms - start_ms; 198 << "actual elapsed:" << end_ms - start_ms;
201 } 199 }
202 200
203 } // anonymous namespace 201 } // anonymous namespace
204 202
205 } // namespace webrtc 203 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/system_wrappers/include/data_log_impl.h ('k') | webrtc/system_wrappers/source/critical_section_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698