| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 MultiprocessMessagePipePerfTest() : message_count_(0), message_size_(0) {} | 38 MultiprocessMessagePipePerfTest() : message_count_(0), message_size_(0) {} |
| 39 | 39 |
| 40 void SetUpMeasurement(int message_count, size_t message_size) { | 40 void SetUpMeasurement(int message_count, size_t message_size) { |
| 41 message_count_ = message_count; | 41 message_count_ = message_count; |
| 42 message_size_ = message_size; | 42 message_size_ = message_size; |
| 43 payload_ = std::string(message_size, '*'); | 43 payload_ = std::string(message_size, '*'); |
| 44 read_buffer_.resize(message_size * 2); | 44 read_buffer_.resize(message_size * 2); |
| 45 } | 45 } |
| 46 | 46 |
| 47 protected: | 47 protected: |
| 48 void WriteWaitThenRead(scoped_refptr<MessagePipe> mp) { | 48 void WriteWaitThenRead(MessagePipe* mp) { |
| 49 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(payload_.data()), | 49 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(payload_.data()), |
| 50 static_cast<uint32_t>(payload_.size()), nullptr, | 50 static_cast<uint32_t>(payload_.size()), nullptr, |
| 51 MOJO_WRITE_MESSAGE_FLAG_NONE), | 51 MOJO_WRITE_MESSAGE_FLAG_NONE), |
| 52 MOJO_RESULT_OK); | 52 MOJO_RESULT_OK); |
| 53 HandleSignalsState hss; | 53 HandleSignalsState hss; |
| 54 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), | 54 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), |
| 55 MOJO_RESULT_OK); | 55 MOJO_RESULT_OK); |
| 56 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer_.size()); | 56 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer_.size()); |
| 57 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer_[0]), | 57 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer_[0]), |
| 58 MakeUserPointer(&read_buffer_size), nullptr, | 58 MakeUserPointer(&read_buffer_size), nullptr, |
| 59 nullptr, MOJO_READ_MESSAGE_FLAG_NONE), | 59 nullptr, MOJO_READ_MESSAGE_FLAG_NONE), |
| 60 MOJO_RESULT_OK); | 60 MOJO_RESULT_OK); |
| 61 CHECK_EQ(read_buffer_size, static_cast<uint32_t>(payload_.size())); | 61 CHECK_EQ(read_buffer_size, static_cast<uint32_t>(payload_.size())); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void SendQuitMessage(scoped_refptr<MessagePipe> mp) { | 64 void SendQuitMessage(MessagePipe* mp) { |
| 65 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(""), 0, nullptr, | 65 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(""), 0, nullptr, |
| 66 MOJO_WRITE_MESSAGE_FLAG_NONE), | 66 MOJO_WRITE_MESSAGE_FLAG_NONE), |
| 67 MOJO_RESULT_OK); | 67 MOJO_RESULT_OK); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void Measure(scoped_refptr<MessagePipe> mp) { | 70 void Measure(MessagePipe* mp) { |
| 71 // Have one ping-pong to ensure channel being established. | 71 // Have one ping-pong to ensure channel being established. |
| 72 WriteWaitThenRead(mp); | 72 WriteWaitThenRead(mp); |
| 73 | 73 |
| 74 std::string test_name = | 74 std::string test_name = |
| 75 base::StringPrintf("IPC_Perf_%dx_%u", message_count_, | 75 base::StringPrintf("IPC_Perf_%dx_%u", message_count_, |
| 76 static_cast<unsigned>(message_size_)); | 76 static_cast<unsigned>(message_size_)); |
| 77 base::PerfTimeLogger logger(test_name.c_str()); | 77 base::PerfTimeLogger logger(test_name.c_str()); |
| 78 | 78 |
| 79 for (int i = 0; i < message_count_; ++i) | 79 for (int i = 0; i < message_count_; ++i) |
| 80 WriteWaitThenRead(mp); | 80 WriteWaitThenRead(mp); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 94 // repeated twice, until the other end is closed or it receives "quitquitquit" | 94 // repeated twice, until the other end is closed or it receives "quitquitquit" |
| 95 // (which it doesn't reply to). It'll return the number of messages received, | 95 // (which it doesn't reply to). It'll return the number of messages received, |
| 96 // not including any "quitquitquit" message, modulo 100. | 96 // not including any "quitquitquit" message, modulo 100. |
| 97 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PingPongClient) { | 97 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PingPongClient) { |
| 98 embedder::SimplePlatformSupport platform_support; | 98 embedder::SimplePlatformSupport platform_support; |
| 99 test::ChannelThread channel_thread(&platform_support); | 99 test::ChannelThread channel_thread(&platform_support); |
| 100 embedder::ScopedPlatformHandle client_platform_handle = | 100 embedder::ScopedPlatformHandle client_platform_handle = |
| 101 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); | 101 mojo::test::MultiprocessTestHelper::client_platform_handle.Pass(); |
| 102 CHECK(client_platform_handle.is_valid()); | 102 CHECK(client_platform_handle.is_valid()); |
| 103 RefPtr<ChannelEndpoint> ep; | 103 RefPtr<ChannelEndpoint> ep; |
| 104 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); | 104 auto mp = MessagePipe::CreateLocalProxy(&ep); |
| 105 channel_thread.Start(client_platform_handle.Pass(), std::move(ep)); | 105 channel_thread.Start(client_platform_handle.Pass(), std::move(ep)); |
| 106 | 106 |
| 107 std::string buffer(1000000, '\0'); | 107 std::string buffer(1000000, '\0'); |
| 108 int rv = 0; | 108 int rv = 0; |
| 109 while (true) { | 109 while (true) { |
| 110 // Wait for our end of the message pipe to be readable. | 110 // Wait for our end of the message pipe to be readable. |
| 111 HandleSignalsState hss; | 111 HandleSignalsState hss; |
| 112 MojoResult result = | 112 MojoResult result = |
| 113 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss); | 113 test::WaitIfNecessary(mp.get(), MOJO_HANDLE_SIGNAL_READABLE, &hss); |
| 114 if (result != MOJO_RESULT_OK) { | 114 if (result != MOJO_RESULT_OK) { |
| 115 rv = result; | 115 rv = result; |
| 116 break; | 116 break; |
| 117 } | 117 } |
| 118 | 118 |
| 119 uint32_t read_size = static_cast<uint32_t>(buffer.size()); | 119 uint32_t read_size = static_cast<uint32_t>(buffer.size()); |
| 120 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&buffer[0]), | 120 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&buffer[0]), |
| 121 MakeUserPointer(&read_size), nullptr, nullptr, | 121 MakeUserPointer(&read_size), nullptr, nullptr, |
| 122 MOJO_READ_MESSAGE_FLAG_NONE), | 122 MOJO_READ_MESSAGE_FLAG_NONE), |
| 123 MOJO_RESULT_OK); | 123 MOJO_RESULT_OK); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 142 #if defined(OS_ANDROID) | 142 #if defined(OS_ANDROID) |
| 143 // Android multi-process tests are not executing the new process. This is flaky. | 143 // Android multi-process tests are not executing the new process. This is flaky. |
| 144 #define MAYBE_PingPong DISABLED_PingPong | 144 #define MAYBE_PingPong DISABLED_PingPong |
| 145 #else | 145 #else |
| 146 #define MAYBE_PingPong PingPong | 146 #define MAYBE_PingPong PingPong |
| 147 #endif // defined(OS_ANDROID) | 147 #endif // defined(OS_ANDROID) |
| 148 TEST_F(MultiprocessMessagePipePerfTest, MAYBE_PingPong) { | 148 TEST_F(MultiprocessMessagePipePerfTest, MAYBE_PingPong) { |
| 149 helper()->StartChild("PingPongClient"); | 149 helper()->StartChild("PingPongClient"); |
| 150 | 150 |
| 151 RefPtr<ChannelEndpoint> ep; | 151 RefPtr<ChannelEndpoint> ep; |
| 152 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep)); | 152 auto mp = MessagePipe::CreateLocalProxy(&ep); |
| 153 Init(std::move(ep)); | 153 Init(std::move(ep)); |
| 154 | 154 |
| 155 // This values are set to align with one at ipc_pertests.cc for comparison. | 155 // This values are set to align with one at ipc_pertests.cc for comparison. |
| 156 const size_t kMsgSize[5] = {12, 144, 1728, 20736, 248832}; | 156 const size_t kMsgSize[5] = {12, 144, 1728, 20736, 248832}; |
| 157 const int kMessageCount[5] = {50000, 50000, 50000, 12000, 1000}; | 157 const int kMessageCount[5] = {50000, 50000, 50000, 12000, 1000}; |
| 158 | 158 |
| 159 for (size_t i = 0; i < 5; i++) { | 159 for (size_t i = 0; i < 5; i++) { |
| 160 SetUpMeasurement(kMessageCount[i], kMsgSize[i]); | 160 SetUpMeasurement(kMessageCount[i], kMsgSize[i]); |
| 161 Measure(mp); | 161 Measure(mp.get()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 SendQuitMessage(mp); | 164 SendQuitMessage(mp.get()); |
| 165 mp->Close(0); | 165 mp->Close(0); |
| 166 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 166 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace | 169 } // namespace |
| 170 } // namespace system | 170 } // namespace system |
| 171 } // namespace mojo | 171 } // namespace mojo |
| OLD | NEW |