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

Side by Side Diff: base/test/test_io_thread.cc

Issue 488003003: Add ChannelProxy benchmark to ipc_perftests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Landing. Created 6 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
« no previous file with comments | « base/test/test_io_thread.h ('k') | ipc/ipc_perftests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/system/test_utils.h" 5 #include "base/test/test_io_thread.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/test/test_timeouts.h"
11 #include "build/build_config.h"
12
13 namespace mojo {
14 namespace system {
15 namespace test {
16 10
17 namespace { 11 namespace {
18 12
19 void PostTaskAndWaitHelper(base::WaitableEvent* event, 13 void PostTaskAndWaitHelper(base::WaitableEvent* event,
20 const base::Closure& task) { 14 const base::Closure& task) {
21 task.Run(); 15 task.Run();
22 event->Signal(); 16 event->Signal();
23 } 17 }
24 18
25 } // namespace 19 } // namespace
26 20
27 void PostTaskAndWait(scoped_refptr<base::TaskRunner> task_runner, 21 namespace base {
28 const tracked_objects::Location& from_here,
29 const base::Closure& task) {
30 base::WaitableEvent event(false, false);
31 task_runner->PostTask(from_here,
32 base::Bind(&PostTaskAndWaitHelper, &event, task));
33 event.Wait();
34 }
35
36 base::TimeDelta EpsilonTimeout() {
37 // Originally, our epsilon timeout was 10 ms, which was mostly fine but flaky on
38 // some Windows bots. I don't recall ever seeing flakes on other bots. At 30 ms
39 // tests seem reliable on Windows bots, but not at 25 ms. We'd like this timeout
40 // to be as small as possible (see the description in the .h file).
41 //
42 // Currently, |tiny_timeout()| is usually 100 ms (possibly scaled under ASAN,
43 // etc.). Based on this, set it to (usually be) 30 ms on Windows and 20 ms
44 // elsewhere.
45 #if defined(OS_WIN)
46 return (TestTimeouts::tiny_timeout() * 3) / 10;
47 #else
48 return (TestTimeouts::tiny_timeout() * 2) / 10;
49 #endif
50 }
51
52 // TestIOThread ----------------------------------------------------------------
53 22
54 TestIOThread::TestIOThread(Mode mode) 23 TestIOThread::TestIOThread(Mode mode)
55 : io_thread_("test_io_thread"), io_thread_started_(false) { 24 : io_thread_("test_io_thread"), io_thread_started_(false) {
56 switch (mode) { 25 switch (mode) {
57 case kAutoStart: 26 case kAutoStart:
58 Start(); 27 Start();
59 return; 28 return;
60 case kManualStart: 29 case kManualStart:
61 return; 30 return;
62 } 31 }
(...skipping 17 matching lines...) Expand all
80 io_thread_started_ = false; 49 io_thread_started_ = false;
81 } 50 }
82 51
83 void TestIOThread::PostTask(const tracked_objects::Location& from_here, 52 void TestIOThread::PostTask(const tracked_objects::Location& from_here,
84 const base::Closure& task) { 53 const base::Closure& task) {
85 task_runner()->PostTask(from_here, task); 54 task_runner()->PostTask(from_here, task);
86 } 55 }
87 56
88 void TestIOThread::PostTaskAndWait(const tracked_objects::Location& from_here, 57 void TestIOThread::PostTaskAndWait(const tracked_objects::Location& from_here,
89 const base::Closure& task) { 58 const base::Closure& task) {
90 ::mojo::system::test::PostTaskAndWait(task_runner(), from_here, task); 59 base::WaitableEvent event(false, false);
60 task_runner()->PostTask(from_here,
61 base::Bind(&PostTaskAndWaitHelper, &event, task));
62 event.Wait();
91 } 63 }
92 64
93 } // namespace test 65 } // namespace base
94 } // namespace system
95 } // namespace mojo
OLDNEW
« no previous file with comments | « base/test/test_io_thread.h ('k') | ipc/ipc_perftests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698