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

Unified Diff: mojo/system/multiprocess_message_pipe_unittest.cc

Issue 501983003: Mojo: add mojo_message_pipe_perftests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing Windows build error Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/system/message_pipe_test_utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/multiprocess_message_pipe_unittest.cc
diff --git a/mojo/system/multiprocess_message_pipe_unittest.cc b/mojo/system/multiprocess_message_pipe_unittest.cc
index 7b228b3a031dcf58fab7d451bbc2bda1d66c80be..b3238abd0af851d969510f0ea661cf8e84c7f84f 100644
--- a/mojo/system/multiprocess_message_pipe_unittest.cc
+++ b/mojo/system/multiprocess_message_pipe_unittest.cc
@@ -17,134 +17,26 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
-#include "base/threading/platform_thread.h" // For |Sleep()|.
#include "build/build_config.h" // TODO(vtl): Remove this.
-#include "mojo/common/test/multiprocess_test_helper.h"
#include "mojo/common/test/test_utils.h"
#include "mojo/embedder/platform_shared_buffer.h"
#include "mojo/embedder/scoped_platform_handle.h"
-#include "mojo/embedder/simple_platform_support.h"
#include "mojo/system/channel.h"
#include "mojo/system/dispatcher.h"
#include "mojo/system/message_pipe.h"
+#include "mojo/system/message_pipe_test_utils.h"
#include "mojo/system/platform_handle_dispatcher.h"
#include "mojo/system/raw_channel.h"
#include "mojo/system/shared_buffer_dispatcher.h"
#include "mojo/system/test_utils.h"
-#include "mojo/system/waiter.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
namespace system {
namespace {
-class ChannelThread {
- public:
- explicit ChannelThread(embedder::PlatformSupport* platform_support)
- : platform_support_(platform_support),
- test_io_thread_(test::TestIOThread::kManualStart) {}
- ~ChannelThread() { Stop(); }
-
- void Start(embedder::ScopedPlatformHandle platform_handle,
- scoped_refptr<MessagePipe> message_pipe) {
- test_io_thread_.Start();
- test_io_thread_.PostTaskAndWait(
- FROM_HERE,
- base::Bind(&ChannelThread::InitChannelOnIOThread,
- base::Unretained(this),
- base::Passed(&platform_handle),
- message_pipe));
- }
-
- void Stop() {
- if (channel_.get()) {
- // Hack to flush write buffers before quitting.
- // TODO(vtl): Remove this once |Channel| has a
- // |FlushWriteBufferAndShutdown()| (or whatever).
- while (!channel_->IsWriteBufferEmpty())
- base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
-
- test_io_thread_.PostTaskAndWait(
- FROM_HERE,
- base::Bind(&ChannelThread::ShutdownChannelOnIOThread,
- base::Unretained(this)));
- }
- test_io_thread_.Stop();
- }
-
- private:
- void InitChannelOnIOThread(embedder::ScopedPlatformHandle platform_handle,
- scoped_refptr<MessagePipe> message_pipe) {
- CHECK_EQ(base::MessageLoop::current(), test_io_thread_.message_loop());
- CHECK(platform_handle.is_valid());
-
- // Create and initialize |Channel|.
- channel_ = new Channel(platform_support_);
- CHECK(channel_->Init(RawChannel::Create(platform_handle.Pass())));
-
- // Attach the message pipe endpoint.
- // Note: On the "server" (parent process) side, we need not attach the
- // message pipe endpoint immediately. However, on the "client" (child
- // process) side, this *must* be done here -- otherwise, the |Channel| may
- // receive/process messages (which it can do as soon as it's hooked up to
- // the IO thread message loop, and that message loop runs) before the
- // message pipe endpoint is attached.
- CHECK_EQ(channel_->AttachMessagePipeEndpoint(message_pipe, 1),
- Channel::kBootstrapEndpointId);
- CHECK(channel_->RunMessagePipeEndpoint(Channel::kBootstrapEndpointId,
- Channel::kBootstrapEndpointId));
- }
-
- void ShutdownChannelOnIOThread() {
- CHECK(channel_.get());
- channel_->Shutdown();
- channel_ = NULL;
- }
-
- embedder::PlatformSupport* const platform_support_;
- test::TestIOThread test_io_thread_;
- scoped_refptr<Channel> channel_;
-
- DISALLOW_COPY_AND_ASSIGN(ChannelThread);
-};
-
-class MultiprocessMessagePipeTest : public testing::Test {
- public:
- MultiprocessMessagePipeTest() : channel_thread_(&platform_support_) {}
- virtual ~MultiprocessMessagePipeTest() {}
-
- protected:
- void Init(scoped_refptr<MessagePipe> mp) {
- channel_thread_.Start(helper_.server_platform_handle.Pass(), mp);
- }
-
- embedder::PlatformSupport* platform_support() { return &platform_support_; }
- mojo::test::MultiprocessTestHelper* helper() { return &helper_; }
-
- private:
- embedder::SimplePlatformSupport platform_support_;
- ChannelThread channel_thread_;
- mojo::test::MultiprocessTestHelper helper_;
-
- DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTest);
-};
-
-MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp,
- MojoHandleSignals signals,
- HandleSignalsState* signals_state) {
- Waiter waiter;
- waiter.Init();
-
- MojoResult add_result = mp->AddWaiter(0, &waiter, signals, 0, signals_state);
- if (add_result != MOJO_RESULT_OK) {
- return (add_result == MOJO_RESULT_ALREADY_EXISTS) ? MOJO_RESULT_OK
- : add_result;
- }
-
- MojoResult wait_result = waiter.Wait(MOJO_DEADLINE_INDEFINITE, NULL);
- mp->RemoveWaiter(0, &waiter, signals_state);
- return wait_result;
-}
+class MultiprocessMessagePipeTest
+ : public test::MultiprocessMessagePipeTestBase {};
// For each message received, sends a reply message with the same contents
// repeated twice, until the other end is closed or it receives "quitquitquit"
@@ -152,7 +44,7 @@ MojoResult WaitIfNecessary(scoped_refptr<MessagePipe> mp,
// not including any "quitquitquit" message, modulo 100.
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
embedder::SimplePlatformSupport platform_support;
- ChannelThread channel_thread(&platform_support);
+ test::ChannelThread channel_thread(&platform_support);
embedder::ScopedPlatformHandle client_platform_handle =
mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
CHECK(client_platform_handle.is_valid());
@@ -164,7 +56,8 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
for (;; rv = (rv + 1) % 100) {
// Wait for our end of the message pipe to be readable.
HandleSignalsState hss;
- MojoResult result = WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss);
+ MojoResult result =
+ test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss);
if (result != MOJO_RESULT_OK) {
// It was closed, probably.
CHECK_EQ(result, MOJO_RESULT_FAILED_PRECONDITION);
@@ -223,7 +116,7 @@ TEST_F(MultiprocessMessagePipeTest, Basic) {
HandleSignalsState hss;
EXPECT_EQ(MOJO_RESULT_OK,
- WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
+ test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
// The child may or may not have closed its end of the message pipe and died
// (and we may or may not know it yet), so our end may or may not appear as
// writable.
@@ -279,7 +172,7 @@ TEST_F(MultiprocessMessagePipeTest, QueueMessages) {
for (size_t i = 0; i < kNumMessages; i++) {
HandleSignalsState hss;
EXPECT_EQ(MOJO_RESULT_OK,
- WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
+ test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
// The child may or may not have closed its end of the message pipe and died
// (and we may or may not know it yet), so our end may or may not appear as
// writable.
@@ -304,7 +197,7 @@ TEST_F(MultiprocessMessagePipeTest, QueueMessages) {
// "quitquitquit").
HandleSignalsState hss;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
+ test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
EXPECT_EQ(0u, hss.satisfied_signals);
EXPECT_EQ(0u, hss.satisfiable_signals);
@@ -316,7 +209,7 @@ TEST_F(MultiprocessMessagePipeTest, QueueMessages) {
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
embedder::SimplePlatformSupport platform_support;
- ChannelThread channel_thread(&platform_support);
+ test::ChannelThread channel_thread(&platform_support);
embedder::ScopedPlatformHandle client_platform_handle =
mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
CHECK(client_platform_handle.is_valid());
@@ -325,7 +218,7 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
// Wait for the first message from our parent.
HandleSignalsState hss;
- CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
+ CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
MOJO_RESULT_OK);
// In this test, the parent definitely doesn't close its end of the message
// pipe before we do.
@@ -381,7 +274,7 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
// Now wait for our parent to send us a message.
hss = HandleSignalsState();
- CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
+ CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
MOJO_RESULT_OK);
CHECK_EQ(hss.satisfied_signals,
MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE);
@@ -462,7 +355,7 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
// Wait for a message from the child.
HandleSignalsState hss;
EXPECT_EQ(MOJO_RESULT_OK,
- WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
+ test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
EXPECT_TRUE((hss.satisfied_signals & MOJO_HANDLE_SIGNAL_READABLE));
EXPECT_TRUE((hss.satisfiable_signals & MOJO_HANDLE_SIGNAL_READABLE));
@@ -499,7 +392,7 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
// Wait for |mp| to become readable, which should fail.
hss = HandleSignalsState();
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
+ test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
EXPECT_EQ(0u, hss.satisfied_signals);
EXPECT_EQ(0u, hss.satisfiable_signals);
@@ -510,7 +403,7 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) {
embedder::SimplePlatformSupport platform_support;
- ChannelThread channel_thread(&platform_support);
+ test::ChannelThread channel_thread(&platform_support);
embedder::ScopedPlatformHandle client_platform_handle =
mojo::test::MultiprocessTestHelper::client_platform_handle.Pass();
CHECK(client_platform_handle.is_valid());
@@ -518,7 +411,7 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) {
channel_thread.Start(client_platform_handle.Pass(), mp);
HandleSignalsState hss;
- CHECK_EQ(WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
+ CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
MOJO_RESULT_OK);
CHECK_EQ(hss.satisfied_signals,
MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE);
@@ -609,7 +502,7 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_PlatformHandlePassing) {
// Wait for it to become readable, which should fail.
HandleSignalsState hss;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
+ test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss));
EXPECT_EQ(0u, hss.satisfied_signals);
EXPECT_EQ(0u, hss.satisfiable_signals);
« no previous file with comments | « mojo/system/message_pipe_test_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698