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

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

Issue 1337003003: Add a name to the ProcessThread constructor. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comments addressed. Created 5 years, 3 months 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 ACTION_P(Increment, counter) { 46 ACTION_P(Increment, counter) {
47 ++(*counter); 47 ++(*counter);
48 } 48 }
49 49
50 ACTION_P(SetTimestamp, ptr) { 50 ACTION_P(SetTimestamp, ptr) {
51 *ptr = TickTime::MillisecondTimestamp(); 51 *ptr = TickTime::MillisecondTimestamp();
52 } 52 }
53 53
54 TEST(ProcessThreadImpl, StartStop) { 54 TEST(ProcessThreadImpl, StartStop) {
55 ProcessThreadImpl thread; 55 ProcessThreadImpl thread("ProcessThread");
56 thread.Start(); 56 thread.Start();
57 thread.Stop(); 57 thread.Stop();
58 } 58 }
59 59
60 TEST(ProcessThreadImpl, MultipleStartStop) { 60 TEST(ProcessThreadImpl, MultipleStartStop) {
61 ProcessThreadImpl thread; 61 ProcessThreadImpl thread("ProcessThread");
62 for (int i = 0; i < 5; ++i) { 62 for (int i = 0; i < 5; ++i) {
63 thread.Start(); 63 thread.Start();
64 thread.Stop(); 64 thread.Stop();
65 } 65 }
66 } 66 }
67 67
68 // Verifies that we get at least call back to Process() on the worker thread. 68 // Verifies that we get at least call back to Process() on the worker thread.
69 TEST(ProcessThreadImpl, ProcessCall) { 69 TEST(ProcessThreadImpl, ProcessCall) {
70 ProcessThreadImpl thread; 70 ProcessThreadImpl thread("ProcessThread");
71 thread.Start(); 71 thread.Start();
72 72
73 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 73 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create());
74 74
75 MockModule module; 75 MockModule module;
76 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 76 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0));
77 EXPECT_CALL(module, Process()) 77 EXPECT_CALL(module, Process())
78 .WillOnce(DoAll(SetEvent(event.get()), Return(0))) 78 .WillOnce(DoAll(SetEvent(event.get()), Return(0)))
79 .WillRepeatedly(Return(0)); 79 .WillRepeatedly(Return(0));
80 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 80 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
81 81
82 thread.RegisterModule(&module); 82 thread.RegisterModule(&module);
83 EXPECT_EQ(kEventSignaled, event->Wait(100)); 83 EXPECT_EQ(kEventSignaled, event->Wait(100));
84 84
85 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 85 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
86 thread.Stop(); 86 thread.Stop();
87 } 87 }
88 88
89 // Same as ProcessCall except the module is registered before the 89 // Same as ProcessCall except the module is registered before the
90 // call to Start(). 90 // call to Start().
91 TEST(ProcessThreadImpl, ProcessCall2) { 91 TEST(ProcessThreadImpl, ProcessCall2) {
92 ProcessThreadImpl thread; 92 ProcessThreadImpl thread("ProcessThread");
93 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 93 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create());
94 94
95 MockModule module; 95 MockModule module;
96 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 96 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0));
97 EXPECT_CALL(module, Process()) 97 EXPECT_CALL(module, Process())
98 .WillOnce(DoAll(SetEvent(event.get()), Return(0))) 98 .WillOnce(DoAll(SetEvent(event.get()), Return(0)))
99 .WillRepeatedly(Return(0)); 99 .WillRepeatedly(Return(0));
100 100
101 thread.RegisterModule(&module); 101 thread.RegisterModule(&module);
102 102
103 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1); 103 EXPECT_CALL(module, ProcessThreadAttached(&thread)).Times(1);
104 thread.Start(); 104 thread.Start();
105 EXPECT_EQ(kEventSignaled, event->Wait(100)); 105 EXPECT_EQ(kEventSignaled, event->Wait(100));
106 106
107 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1); 107 EXPECT_CALL(module, ProcessThreadAttached(nullptr)).Times(1);
108 thread.Stop(); 108 thread.Stop();
109 } 109 }
110 110
111 // Tests setting up a module for callbacks and then unregister that module. 111 // Tests setting up a module for callbacks and then unregister that module.
112 // After unregistration, we should not receive any further callbacks. 112 // After unregistration, we should not receive any further callbacks.
113 TEST(ProcessThreadImpl, Deregister) { 113 TEST(ProcessThreadImpl, Deregister) {
114 ProcessThreadImpl thread; 114 ProcessThreadImpl thread("ProcessThread");
115 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 115 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create());
116 116
117 int process_count = 0; 117 int process_count = 0;
118 MockModule module; 118 MockModule module;
119 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0)); 119 EXPECT_CALL(module, TimeUntilNextProcess()).WillRepeatedly(Return(0));
120 EXPECT_CALL(module, Process()) 120 EXPECT_CALL(module, Process())
121 .WillOnce(DoAll(SetEvent(event.get()), 121 .WillOnce(DoAll(SetEvent(event.get()),
122 Increment(&process_count), 122 Increment(&process_count),
123 Return(0))) 123 Return(0)))
124 .WillRepeatedly(DoAll(Increment(&process_count), Return(0))); 124 .WillRepeatedly(DoAll(Increment(&process_count), Return(0)));
(...skipping 14 matching lines...) Expand all
139 // We shouldn't get any more callbacks. 139 // We shouldn't get any more callbacks.
140 EXPECT_EQ(kEventTimeout, event->Wait(20)); 140 EXPECT_EQ(kEventTimeout, event->Wait(20));
141 EXPECT_EQ(count_after_deregister, process_count); 141 EXPECT_EQ(count_after_deregister, process_count);
142 thread.Stop(); 142 thread.Stop();
143 } 143 }
144 144
145 // Helper function for testing receiving a callback after a certain amount of 145 // Helper function for testing receiving a callback after a certain amount of
146 // time. There's some variance of timing built into it to reduce chance of 146 // time. There's some variance of timing built into it to reduce chance of
147 // flakiness on bots. 147 // flakiness on bots.
148 void ProcessCallAfterAFewMs(int64_t milliseconds) { 148 void ProcessCallAfterAFewMs(int64_t milliseconds) {
149 ProcessThreadImpl thread; 149 ProcessThreadImpl thread("ProcessThread");
150 thread.Start(); 150 thread.Start();
151 151
152 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 152 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create());
153 153
154 MockModule module; 154 MockModule module;
155 int64_t start_time = 0; 155 int64_t start_time = 0;
156 int64_t called_time = 0; 156 int64_t called_time = 0;
157 EXPECT_CALL(module, TimeUntilNextProcess()) 157 EXPECT_CALL(module, TimeUntilNextProcess())
158 .WillOnce(DoAll(SetTimestamp(&start_time), 158 .WillOnce(DoAll(SetTimestamp(&start_time),
159 Return(milliseconds))) 159 Return(milliseconds)))
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 204 }
205 205
206 // Runs callbacks with the goal of getting up to 50 callbacks within a second 206 // Runs callbacks with the goal of getting up to 50 callbacks within a second
207 // (on average 1 callback every 20ms). On real hardware, we're usually pretty 207 // (on average 1 callback every 20ms). On real hardware, we're usually pretty
208 // close to that, but the test bots that run on virtual machines, will 208 // close to that, but the test bots that run on virtual machines, will
209 // typically be in the range 30-40 callbacks. 209 // typically be in the range 30-40 callbacks.
210 // DISABLED for now since this can take up to 2 seconds to run on the slowest 210 // DISABLED for now since this can take up to 2 seconds to run on the slowest
211 // build bots. 211 // build bots.
212 // TODO(tommi): Fix. 212 // TODO(tommi): Fix.
213 TEST(ProcessThreadImpl, DISABLED_Process50Times) { 213 TEST(ProcessThreadImpl, DISABLED_Process50Times) {
214 ProcessThreadImpl thread; 214 ProcessThreadImpl thread("ProcessThread");
215 thread.Start(); 215 thread.Start();
216 216
217 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create()); 217 rtc::scoped_ptr<EventWrapper> event(EventWrapper::Create());
218 218
219 MockModule module; 219 MockModule module;
220 int callback_count = 0; 220 int callback_count = 0;
221 // Ask for a callback after 20ms. 221 // Ask for a callback after 20ms.
222 EXPECT_CALL(module, TimeUntilNextProcess()) 222 EXPECT_CALL(module, TimeUntilNextProcess())
223 .WillRepeatedly(Return(20)); 223 .WillRepeatedly(Return(20));
224 EXPECT_CALL(module, Process()) 224 EXPECT_CALL(module, Process())
(...skipping 12 matching lines...) Expand all
237 // Check that we got called back up to 50 times. 237 // Check that we got called back up to 50 times.
238 // Some of the try bots run on slow virtual machines, so the lower bound 238 // Some of the try bots run on slow virtual machines, so the lower bound
239 // is much more relaxed to avoid flakiness. 239 // is much more relaxed to avoid flakiness.
240 EXPECT_GE(callback_count, 25); 240 EXPECT_GE(callback_count, 25);
241 EXPECT_LE(callback_count, 50); 241 EXPECT_LE(callback_count, 50);
242 } 242 }
243 243
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; 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 = 0;
255 int64_t called_time = 0; 255 int64_t called_time = 0;
256 // Ask for a callback after 1000ms. 256 // Ask for a callback after 1000ms.
257 // TimeUntilNextProcess will be called twice. 257 // TimeUntilNextProcess will be called twice.
(...skipping 27 matching lines...) Expand all
285 ASSERT_GT(called_time, 0); 285 ASSERT_GT(called_time, 0);
286 EXPECT_GE(called_time, start_time); 286 EXPECT_GE(called_time, start_time);
287 uint32_t diff = called_time - start_time; 287 uint32_t diff = called_time - start_time;
288 // We should have been called back much quicker than 1sec. 288 // We should have been called back much quicker than 1sec.
289 EXPECT_LE(diff, 100u); 289 EXPECT_LE(diff, 100u);
290 } 290 }
291 291
292 // Tests that we can post a task that gets run straight away on the worker 292 // Tests that we can post a task that gets run straight away on the worker
293 // thread. 293 // thread.
294 TEST(ProcessThreadImpl, PostTask) { 294 TEST(ProcessThreadImpl, PostTask) {
295 ProcessThreadImpl thread; 295 ProcessThreadImpl thread("ProcessThread");
296 rtc::scoped_ptr<EventWrapper> task_ran(EventWrapper::Create()); 296 rtc::scoped_ptr<EventWrapper> task_ran(EventWrapper::Create());
297 rtc::scoped_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get())); 297 rtc::scoped_ptr<RaiseEventTask> task(new RaiseEventTask(task_ran.get()));
298 thread.Start(); 298 thread.Start();
299 thread.PostTask(task.Pass()); 299 thread.PostTask(task.Pass());
300 EXPECT_EQ(kEventSignaled, task_ran->Wait(100)); 300 EXPECT_EQ(kEventSignaled, task_ran->Wait(100));
301 thread.Stop(); 301 thread.Stop();
302 } 302 }
303 303
304 } // namespace webrtc 304 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698