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

Side by Side Diff: mojo/public/cpp/bindings/tests/e2e_perftest.cc

Issue 2608163003: Change single-interface mojo bindings to use SequencedTaskRunner. (Closed)
Patch Set: Created 3 years, 10 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/test/perf_time_logger.h" 14 #include "base/test/perf_time_logger.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/sequenced_task_runner_handle.h"
16 #include "mojo/edk/embedder/embedder.h" 16 #include "mojo/edk/embedder/embedder.h"
17 #include "mojo/edk/test/mojo_test_base.h" 17 #include "mojo/edk/test/mojo_test_base.h"
18 #include "mojo/public/cpp/bindings/strong_binding.h" 18 #include "mojo/public/cpp/bindings/strong_binding.h"
19 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" 19 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace mojo { 22 namespace mojo {
23 namespace { 23 namespace {
24 24
25 class EchoServiceImpl : public test::EchoService { 25 class EchoServiceImpl : public test::EchoService {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 void PingPongTest::RunTest(int iterations, int batch_size, int message_size) { 78 void PingPongTest::RunTest(int iterations, int batch_size, int message_size) {
79 iterations_ = iterations; 79 iterations_ = iterations;
80 batch_size_ = batch_size; 80 batch_size_ = batch_size;
81 message_ = std::string(message_size, 'a'); 81 message_ = std::string(message_size, 'a');
82 current_iterations_ = 0; 82 current_iterations_ = 0;
83 calls_outstanding_ = 0; 83 calls_outstanding_ = 0;
84 84
85 base::MessageLoop::current()->SetNestableTasksAllowed(true); 85 base::MessageLoop::current()->SetNestableTasksAllowed(true);
86 base::RunLoop run_loop; 86 base::RunLoop run_loop;
87 quit_closure_ = run_loop.QuitClosure(); 87 quit_closure_ = run_loop.QuitClosure();
88 base::ThreadTaskRunnerHandle::Get()->PostTask( 88 base::SequencedTaskRunnerHandle::Get()->PostTask(
89 FROM_HERE, base::Bind(&PingPongTest::DoPing, base::Unretained(this))); 89 FROM_HERE, base::Bind(&PingPongTest::DoPing, base::Unretained(this)));
90 run_loop.Run(); 90 run_loop.Run();
91 } 91 }
92 92
93 void PingPongTest::DoPing() { 93 void PingPongTest::DoPing() {
94 DCHECK_EQ(0, calls_outstanding_); 94 DCHECK_EQ(0, calls_outstanding_);
95 current_iterations_++; 95 current_iterations_++;
96 if (current_iterations_ > iterations_) { 96 if (current_iterations_ > iterations_) {
97 quit_closure_.Run(); 97 quit_closure_.Run();
98 return; 98 return;
(...skipping 11 matching lines...) Expand all
110 110
111 if (!calls_outstanding_) 111 if (!calls_outstanding_)
112 DoPing(); 112 DoPing();
113 } 113 }
114 114
115 class MojoE2EPerftest : public edk::test::MojoTestBase { 115 class MojoE2EPerftest : public edk::test::MojoTestBase {
116 public: 116 public:
117 void RunTestOnTaskRunner(base::TaskRunner* runner, 117 void RunTestOnTaskRunner(base::TaskRunner* runner,
118 MojoHandle client_mp, 118 MojoHandle client_mp,
119 const std::string& test_name) { 119 const std::string& test_name) {
120 if (runner == base::ThreadTaskRunnerHandle::Get().get()) { 120 if (runner == base::SequencedTaskRunnerHandle::Get().get()) {
121 RunTests(client_mp, test_name); 121 RunTests(client_mp, test_name);
122 } else { 122 } else {
123 base::RunLoop run_loop; 123 base::RunLoop run_loop;
124 runner->PostTaskAndReply( 124 runner->PostTaskAndReply(
125 FROM_HERE, base::Bind(&MojoE2EPerftest::RunTests, 125 FROM_HERE, base::Bind(&MojoE2EPerftest::RunTests,
126 base::Unretained(this), client_mp, test_name), 126 base::Unretained(this), client_mp, test_name),
127 run_loop.QuitClosure()); 127 run_loop.QuitClosure());
128 run_loop.Run(); 128 run_loop.Run();
129 } 129 }
130 } 130 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 MojoHandle client_mp, service_mp; 195 MojoHandle client_mp, service_mp;
196 CreateMessagePipe(&client_mp, &service_mp); 196 CreateMessagePipe(&client_mp, &service_mp);
197 WriteMessageWithHandles(mp, "hello", &service_mp, 1); 197 WriteMessageWithHandles(mp, "hello", &service_mp, 1);
198 RunTestOnTaskRunner(edk::GetIOTaskRunner().get(), client_mp, 198 RunTestOnTaskRunner(edk::GetIOTaskRunner().get(), client_mp,
199 "MultiProcessEchoIoThread"); 199 "MultiProcessEchoIoThread");
200 END_CHILD() 200 END_CHILD()
201 } 201 }
202 202
203 } // namespace 203 } // namespace
204 } // namespace mojo 204 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/BUILD.gn ('k') | mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698