| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/test/perf_time_logger.h" | 13 #include "base/test/perf_time_logger.h" |
| 14 #include "mojo/edk/embedder/embedder.h" | 14 #include "mojo/edk/embedder/embedder.h" |
| 15 #include "mojo/edk/embedder/scoped_platform_handle.h" | 15 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 16 #include "mojo/edk/system/handle_signals_state.h" | 16 #include "mojo/edk/system/handle_signals_state.h" |
| 17 #include "mojo/edk/system/message_pipe_test_utils.h" | |
| 18 #include "mojo/edk/system/test_utils.h" | 17 #include "mojo/edk/system/test_utils.h" |
| 18 #include "mojo/edk/test/mojo_test_base.h" |
| 19 #include "mojo/edk/test/test_utils.h" | 19 #include "mojo/edk/test/test_utils.h" |
| 20 #include "mojo/public/c/system/functions.h" | 20 #include "mojo/public/c/system/functions.h" |
| 21 #include "mojo/public/cpp/system/message_pipe.h" | 21 #include "mojo/public/cpp/system/message_pipe.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 namespace mojo { | 24 namespace mojo { |
| 25 namespace edk { | 25 namespace edk { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class MultiprocessMessagePipePerfTest | 28 class MultiprocessMessagePipePerfTest : public test::MojoTestBase { |
| 29 : public test::MultiprocessMessagePipeTestBase { | |
| 30 public: | 29 public: |
| 31 MultiprocessMessagePipePerfTest() | 30 MultiprocessMessagePipePerfTest() |
| 32 : message_count_(0), | 31 : message_count_(0), |
| 33 message_size_(0) {} | 32 message_size_(0) {} |
| 34 | 33 |
| 35 void SetUpMeasurement(int message_count, size_t message_size) { | 34 void SetUpMeasurement(int message_count, size_t message_size) { |
| 36 message_count_ = message_count; | 35 message_count_ = message_count; |
| 37 message_size_ = message_size; | 36 message_size_ = message_size; |
| 38 payload_ = std::string(message_size, '*'); | 37 payload_ = std::string(message_size, '*'); |
| 39 read_buffer_.resize(message_size * 2); | 38 read_buffer_.resize(message_size * 2); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 size_t message_size_; | 81 size_t message_size_; |
| 83 std::string payload_; | 82 std::string payload_; |
| 84 std::string read_buffer_; | 83 std::string read_buffer_; |
| 85 scoped_ptr<base::PerfTimeLogger> perf_logger_; | 84 scoped_ptr<base::PerfTimeLogger> perf_logger_; |
| 86 }; | 85 }; |
| 87 | 86 |
| 88 // For each message received, sends a reply message with the same contents | 87 // For each message received, sends a reply message with the same contents |
| 89 // repeated twice, until the other end is closed or it receives "quitquitquit" | 88 // repeated twice, until the other end is closed or it receives "quitquitquit" |
| 90 // (which it doesn't reply to). It'll return the number of messages received, | 89 // (which it doesn't reply to). It'll return the number of messages received, |
| 91 // not including any "quitquitquit" message, modulo 100. | 90 // not including any "quitquitquit" message, modulo 100. |
| 92 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PingPongClient) { | 91 DEFINE_TEST_CLIENT_WITH_PIPE(PingPongClient, MultiprocessMessagePipePerfTest, |
| 93 ScopedPlatformHandle client_platform_handle = | 92 h) { |
| 94 std::move(test::MultiprocessTestHelper::client_platform_handle); | |
| 95 CHECK(client_platform_handle.is_valid()); | |
| 96 ScopedMessagePipeHandle mp = | |
| 97 CreateMessagePipe(std::move(client_platform_handle)); | |
| 98 | |
| 99 std::string buffer(1000000, '\0'); | 93 std::string buffer(1000000, '\0'); |
| 100 int rv = 0; | 94 int rv = 0; |
| 101 while (true) { | 95 while (true) { |
| 102 // Wait for our end of the message pipe to be readable. | 96 // Wait for our end of the message pipe to be readable. |
| 103 HandleSignalsState hss; | 97 HandleSignalsState hss; |
| 104 MojoResult result = | 98 MojoResult result = |
| 105 MojoWait(mp.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 99 MojoWait(h, MOJO_HANDLE_SIGNAL_READABLE, |
| 106 MOJO_DEADLINE_INDEFINITE, &hss); | 100 MOJO_DEADLINE_INDEFINITE, &hss); |
| 107 if (result != MOJO_RESULT_OK) { | 101 if (result != MOJO_RESULT_OK) { |
| 108 rv = result; | 102 rv = result; |
| 109 break; | 103 break; |
| 110 } | 104 } |
| 111 | 105 |
| 112 uint32_t read_size = static_cast<uint32_t>(buffer.size()); | 106 uint32_t read_size = static_cast<uint32_t>(buffer.size()); |
| 113 CHECK_EQ(MojoReadMessage(mp.get().value(), &buffer[0], | 107 CHECK_EQ(MojoReadMessage(h, &buffer[0], |
| 114 &read_size, nullptr, | 108 &read_size, nullptr, |
| 115 0, MOJO_READ_MESSAGE_FLAG_NONE), | 109 0, MOJO_READ_MESSAGE_FLAG_NONE), |
| 116 MOJO_RESULT_OK); | 110 MOJO_RESULT_OK); |
| 117 | 111 |
| 118 // Empty message indicates quit. | 112 // Empty message indicates quit. |
| 119 if (read_size == 0) | 113 if (read_size == 0) |
| 120 break; | 114 break; |
| 121 | 115 |
| 122 CHECK_EQ(MojoWriteMessage(mp.get().value(), &buffer[0], | 116 CHECK_EQ(MojoWriteMessage(h, &buffer[0], |
| 123 read_size, | 117 read_size, |
| 124 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE), | 118 nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE), |
| 125 MOJO_RESULT_OK); | 119 MOJO_RESULT_OK); |
| 126 } | 120 } |
| 127 | 121 |
| 128 return rv; | 122 return rv; |
| 129 } | 123 } |
| 130 | 124 |
| 131 // Repeatedly sends messages as previous one got replied by the child. | 125 // Repeatedly sends messages as previous one got replied by the child. |
| 132 // Waits for the child to close its end before quitting once specified | 126 // Waits for the child to close its end before quitting once specified |
| 133 // number of messages has been sent. | 127 // number of messages has been sent. |
| 134 #if defined(OS_ANDROID) | 128 #if defined(OS_ANDROID) |
| 135 // Android multi-process tests are not executing the new process. This is flaky. | 129 // Android multi-process tests are not executing the new process. This is flaky. |
| 136 #define MAYBE_PingPong DISABLED_PingPong | 130 #define MAYBE_PingPong DISABLED_PingPong |
| 137 #else | 131 #else |
| 138 #define MAYBE_PingPong PingPong | 132 #define MAYBE_PingPong PingPong |
| 139 #endif // defined(OS_ANDROID) | 133 #endif // defined(OS_ANDROID) |
| 140 TEST_F(MultiprocessMessagePipePerfTest, MAYBE_PingPong) { | 134 TEST_F(MultiprocessMessagePipePerfTest, MAYBE_PingPong) { |
| 141 helper()->StartChild("PingPongClient"); | 135 RUN_CHILD_ON_PIPE(PingPongClient, h) |
| 136 // This values are set to align with one at ipc_pertests.cc for comparison. |
| 137 const size_t kMsgSize[5] = {12, 144, 1728, 20736, 248832}; |
| 138 const int kMessageCount[5] = {50000, 50000, 50000, 12000, 1000}; |
| 142 | 139 |
| 143 ScopedMessagePipeHandle mp = | 140 for (size_t i = 0; i < 5; i++) { |
| 144 CreateMessagePipe(std::move(helper()->server_platform_handle)); | 141 SetUpMeasurement(kMessageCount[i], kMsgSize[i]); |
| 142 Measure(h); |
| 143 } |
| 145 | 144 |
| 146 // This values are set to align with one at ipc_pertests.cc for comparison. | 145 SendQuitMessage(h); |
| 147 const size_t kMsgSize[5] = {12, 144, 1728, 20736, 248832}; | 146 END_CHILD() |
| 148 const int kMessageCount[5] = {50000, 50000, 50000, 12000, 1000}; | |
| 149 | |
| 150 for (size_t i = 0; i < 5; i++) { | |
| 151 SetUpMeasurement(kMessageCount[i], kMsgSize[i]); | |
| 152 Measure(mp.get().value()); | |
| 153 } | |
| 154 | |
| 155 SendQuitMessage(mp.get().value()); | |
| 156 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | |
| 157 } | 147 } |
| 158 | 148 |
| 159 } // namespace | 149 } // namespace |
| 160 } // namespace edk | 150 } // namespace edk |
| 161 } // namespace mojo | 151 } // namespace mojo |
| OLD | NEW |