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

Side by Side Diff: webrtc/modules/utility/source/process_thread_impl_unittest.cc

Issue 1452843003: Several Tick counter improvements try #2." (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // Tests that we can wake up the worker thread to give us a callback right 244 // Tests that we can wake up the worker thread to give us a callback right
245 // away when we know the thread is sleeping. 245 // away when we know the thread is sleeping.
246 TEST(ProcessThreadImpl, WakeUp) { 246 TEST(ProcessThreadImpl, WakeUp) {
247 ProcessThreadImpl thread("ProcessThread"); 247 ProcessThreadImpl thread("ProcessThread");
248 thread.Start(); 248 thread.Start();
249 249
250 rtc::scoped_ptr<EventWrapper> started(EventWrapper::Create()); 250 rtc::scoped_ptr<EventWrapper> started(EventWrapper::Create());
251 rtc::scoped_ptr<EventWrapper> called(EventWrapper::Create()); 251 rtc::scoped_ptr<EventWrapper> called(EventWrapper::Create());
252 252
253 MockModule module; 253 MockModule module;
254 int64_t start_time = 0; 254 int64_t start_time;
255 int64_t called_time = 0; 255 int64_t called_time;
256
256 // Ask for a callback after 1000ms. 257 // Ask for a callback after 1000ms.
257 // TimeUntilNextProcess will be called twice. 258 // TimeUntilNextProcess will be called twice.
258 // The first time we use it to get the thread into a waiting state. 259 // The first time we use it to get the thread into a waiting state.
259 // Then we wake the thread and there should not be another call made to 260 // Then we wake the thread and there should not be another call made to
260 // TimeUntilNextProcess before Process() is called. 261 // TimeUntilNextProcess before Process() is called.
261 // The second time TimeUntilNextProcess is then called, is after Process 262 // The second time TimeUntilNextProcess is then called, is after Process
262 // has been called and we don't expect any more calls. 263 // has been called and we don't expect any more calls.
263 EXPECT_CALL(module, TimeUntilNextProcess()) 264 EXPECT_CALL(module, TimeUntilNextProcess())
264 .WillOnce(DoAll(SetTimestamp(&start_time), 265 .WillOnce(DoAll(SetTimestamp(&start_time),
265 SetEvent(started.get()), 266 SetEvent(started.get()),
266 Return(1000))) 267 Return(1000)))
267 .WillOnce(Return(1000)); 268 .WillOnce(Return(1000));
268 EXPECT_CALL(module, Process()) 269 EXPECT_CALL(module, Process())
269 .WillOnce(DoAll(SetTimestamp(&called_time), 270 .WillOnce(DoAll(SetTimestamp(&called_time),
270 SetEvent(called.get()), 271 SetEvent(called.get()),
271 Return(0))) 272 Return(0)))
272 .WillRepeatedly(Return(0)); 273 .WillRepeatedly(Return(0));
273 274
274 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 275 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
275 thread.RegisterModule(&module); 276 thread.RegisterModule(&module);
276 277
277 EXPECT_EQ(kEventSignaled, started->Wait(100)); 278 EXPECT_EQ(kEventSignaled, started->Wait(100));
278 thread.WakeUp(&module); 279 thread.WakeUp(&module);
279 EXPECT_EQ(kEventSignaled, called->Wait(100)); 280 EXPECT_EQ(kEventSignaled, called->Wait(100));
280 281
281 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 282 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
282 thread.Stop(); 283 thread.Stop();
283 284
284 ASSERT_GT(start_time, 0);
285 ASSERT_GT(called_time, 0);
286 EXPECT_GE(called_time, start_time); 285 EXPECT_GE(called_time, start_time);
287 uint32_t diff = called_time - start_time; 286 uint32_t diff = called_time - start_time;
288 // We should have been called back much quicker than 1sec. 287 // We should have been called back much quicker than 1sec.
289 EXPECT_LE(diff, 100u); 288 EXPECT_LE(diff, 100u);
290 } 289 }
291 290
292 // Tests that we can post a task that gets run straight away on the worker 291 // Tests that we can post a task that gets run straight away on the worker
293 // thread. 292 // thread.
294 TEST(ProcessThreadImpl, PostTask) { 293 TEST(ProcessThreadImpl, PostTask) {
295 ProcessThreadImpl thread("ProcessThread"); 294 ProcessThreadImpl thread("ProcessThread");
296 rtc::scoped_ptr<EventWrapper> task_ran(EventWrapper::Create()); 295 rtc::scoped_ptr<EventWrapper> task_ran(EventWrapper::Create());
297 rtc::scoped_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get())); 296 rtc::scoped_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get()));
298 thread.Start(); 297 thread.Start();
299 thread.PostTask(task.Pass()); 298 thread.PostTask(task.Pass());
300 EXPECT_EQ(kEventSignaled, task_ran->Wait(100)); 299 EXPECT_EQ(kEventSignaled, task_ran->Wait(100));
301 thread.Stop(); 300 thread.Stop();
302 } 301 }
303 302
304 } // namespace webrtc 303 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/system_wrappers/include/tick_util.h » ('j') | webrtc/system_wrappers/source/tick_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698