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

Unified Diff: mojo/edk/system/multiprocess_message_pipe_unittest.cc

Issue 795593004: Update mojo sdk to rev cc531b32182099a5a034a99daff35ed5d38a61c8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More workarounds for MSVC Created 6 years 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/edk/system/message_pipe.cc ('k') | mojo/edk/system/raw_channel.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/multiprocess_message_pipe_unittest.cc
diff --git a/mojo/edk/system/multiprocess_message_pipe_unittest.cc b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
index 4d8380b2ea9c1a21eaa2c8a6949288f6868ea573..af3b3bb245613eff946995affd970ee49b963e6b 100644
--- a/mojo/edk/system/multiprocess_message_pipe_unittest.cc
+++ b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
@@ -409,7 +409,7 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) {
std::string read_buffer(100, '\0');
uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
DispatcherVector dispatchers;
- uint32_t num_dispatchers = 10; // Maximum number to receive.
+ uint32_t num_dispatchers = 30; // Maximum number to receive.
CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
MakeUserPointer(&num_bytes), &dispatchers,
&num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE),
@@ -417,35 +417,38 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) {
mp->Close(0);
read_buffer.resize(num_bytes);
- CHECK_EQ(read_buffer, std::string("hello"));
- CHECK_EQ(num_dispatchers, 1u);
-
- CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::kTypePlatformHandle);
-
- scoped_refptr<PlatformHandleDispatcher> dispatcher(
- static_cast<PlatformHandleDispatcher*>(dispatchers[0].get()));
- embedder::ScopedPlatformHandle h = dispatcher->PassPlatformHandle().Pass();
- CHECK(h.is_valid());
- dispatcher->Close();
-
- base::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h.Pass(), "r"));
- CHECK(fp);
- std::string fread_buffer(100, '\0');
- size_t bytes_read = fread(&fread_buffer[0], 1, fread_buffer.size(), fp.get());
- fread_buffer.resize(bytes_read);
- CHECK_EQ(fread_buffer, "world");
+ char hello[32];
+ int num_handles = 0;
+ sscanf(read_buffer.c_str(), "%s %d", hello, &num_handles);
+ CHECK_EQ(std::string("hello"), std::string(hello));
+ CHECK_GT(num_handles, 0);
+
+ for (int i = 0; i < num_handles; ++i) {
+ CHECK_EQ(dispatchers[i]->GetType(), Dispatcher::kTypePlatformHandle);
+
+ scoped_refptr<PlatformHandleDispatcher> dispatcher(
+ static_cast<PlatformHandleDispatcher*>(dispatchers[i].get()));
+ embedder::ScopedPlatformHandle h = dispatcher->PassPlatformHandle().Pass();
+ CHECK(h.is_valid());
+ dispatcher->Close();
+
+ base::ScopedFILE fp(mojo::test::FILEFromPlatformHandle(h.Pass(), "r"));
+ CHECK(fp);
+ std::string fread_buffer(100, '\0');
+ size_t bytes_read =
+ fread(&fread_buffer[0], 1, fread_buffer.size(), fp.get());
+ fread_buffer.resize(bytes_read);
+ CHECK_EQ(fread_buffer, "world");
+ }
return 0;
}
-#if defined(OS_POSIX) && !defined(OS_ANDROID)
-#define MAYBE_PlatformHandlePassing PlatformHandlePassing
-#else
-// Not yet implemented (on Windows).
-// Android multi-process tests are not executing the new process. This is flaky.
-#define MAYBE_PlatformHandlePassing DISABLED_PlatformHandlePassing
-#endif
-TEST_F(MultiprocessMessagePipeTest, MAYBE_PlatformHandlePassing) {
+class MultiprocessMessagePipeTestWithPipeCount
+ : public test::MultiprocessMessagePipeTestBase,
+ public testing::WithParamInterface<size_t> {};
+
+TEST_P(MultiprocessMessagePipeTestWithPipeCount, PlatformHandlePassing) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
@@ -455,34 +458,42 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_PlatformHandlePassing) {
scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy(&ep));
Init(ep);
- base::FilePath unused;
- base::ScopedFILE fp(
- CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused));
- const std::string world("world");
- ASSERT_EQ(fwrite(&world[0], 1, world.size(), fp.get()), world.size());
- fflush(fp.get());
- rewind(fp.get());
-
- embedder::ScopedPlatformHandle h(
- mojo::test::PlatformHandleFromFILE(fp.Pass()));
- scoped_refptr<PlatformHandleDispatcher> dispatcher(
- new PlatformHandleDispatcher(h.Pass()));
+ std::vector<scoped_refptr<PlatformHandleDispatcher>> dispatchers;
+ std::vector<DispatcherTransport> transports;
- const std::string hello("hello");
- DispatcherTransport transport(
- test::DispatcherTryStartTransport(dispatcher.get()));
- ASSERT_TRUE(transport.is_valid());
+ size_t pipe_count = GetParam();
+ for (size_t i = 0; i < pipe_count; ++i) {
+ base::FilePath unused;
+ base::ScopedFILE fp(
+ CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused));
+ const std::string world("world");
+ CHECK_EQ(fwrite(&world[0], 1, world.size(), fp.get()), world.size());
+ fflush(fp.get());
+ rewind(fp.get());
+
+ scoped_refptr<PlatformHandleDispatcher> dispatcher(
+ new PlatformHandleDispatcher(embedder::ScopedPlatformHandle(
+ mojo::test::PlatformHandleFromFILE(fp.Pass()))));
+ dispatchers.push_back(dispatcher);
+ DispatcherTransport transport(
+ test::DispatcherTryStartTransport(dispatcher.get()));
+ ASSERT_TRUE(transport.is_valid());
+ transports.push_back(transport);
+ }
- std::vector<DispatcherTransport> transports;
- transports.push_back(transport);
+ char message[128];
+ sprintf(message, "hello %d", static_cast<int>(pipe_count));
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(&hello[0]),
- static_cast<uint32_t>(hello.size()), &transports,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
- transport.End();
+ mp->WriteMessage(0, UserPointer<const void>(message),
+ static_cast<uint32_t>(strlen(message)),
+ &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
- EXPECT_TRUE(dispatcher->HasOneRef());
- dispatcher = nullptr;
+ for (size_t i = 0; i < pipe_count; ++i) {
+ transports[i].End();
+ EXPECT_TRUE(dispatchers[i]->HasOneRef());
+ }
+
+ dispatchers.clear();
// Wait for it to become readable, which should fail.
HandleSignalsState hss;
@@ -496,6 +507,14 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_PlatformHandlePassing) {
EXPECT_EQ(0, helper()->WaitForChildShutdown());
}
+// Not yet implemented (on Windows).
+// Android multi-process tests are not executing the new process. This is flaky.
+#if defined(OS_POSIX) && !defined(OS_ANDROID)
+INSTANTIATE_TEST_CASE_P(PipeCount,
+ MultiprocessMessagePipeTestWithPipeCount,
+ testing::Values(1u, 10u, 25u));
+#endif
+
} // namespace
} // namespace system
} // namespace mojo
« no previous file with comments | « mojo/edk/system/message_pipe.cc ('k') | mojo/edk/system/raw_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698