OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "third_party/mojo/src/mojo/edk/test/multiprocess_test_helper.h" | 5 #include "mojo/edk/test/multiprocess_test_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 10 #include "mojo/edk/test/test_utils.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h" | |
11 #include "third_party/mojo/src/mojo/edk/test/test_utils.h" | |
12 | 12 |
13 #if defined(OS_POSIX) | 13 #if defined(OS_POSIX) |
14 #include <fcntl.h> | 14 #include <fcntl.h> |
15 #endif | 15 #endif |
16 | 16 |
17 namespace mojo { | 17 namespace mojo { |
| 18 namespace edk { |
18 namespace test { | 19 namespace test { |
19 namespace { | 20 namespace { |
20 | 21 |
21 bool IsNonBlocking(const embedder::PlatformHandle& handle) { | 22 bool IsNonBlocking(const PlatformHandle& handle) { |
22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
23 // Haven't figured out a way to query whether a HANDLE was created with | 24 // Haven't figured out a way to query whether a HANDLE was created with |
24 // FILE_FLAG_OVERLAPPED. | 25 // FILE_FLAG_OVERLAPPED. |
25 return true; | 26 return true; |
26 #else | 27 #else |
27 return fcntl(handle.fd, F_GETFL) & O_NONBLOCK; | 28 return fcntl(handle.fd, F_GETFL) & O_NONBLOCK; |
28 #endif | 29 #endif |
29 } | 30 } |
30 | 31 |
31 bool WriteByte(const embedder::PlatformHandle& handle, char c) { | 32 bool WriteByte(const PlatformHandle& handle, char c) { |
32 size_t bytes_written = 0; | 33 size_t bytes_written = 0; |
33 BlockingWrite(handle, &c, 1, &bytes_written); | 34 BlockingWrite(handle, &c, 1, &bytes_written); |
34 return bytes_written == 1; | 35 return bytes_written == 1; |
35 } | 36 } |
36 | 37 |
37 bool ReadByte(const embedder::PlatformHandle& handle, char* c) { | 38 bool ReadByte(const PlatformHandle& handle, char* c) { |
38 size_t bytes_read = 0; | 39 size_t bytes_read = 0; |
39 BlockingRead(handle, c, 1, &bytes_read); | 40 BlockingRead(handle, c, 1, &bytes_read); |
40 return bytes_read == 1; | 41 return bytes_read == 1; |
41 } | 42 } |
42 | 43 |
43 using MultiprocessTestHelperTest = testing::Test; | 44 using MultiprocessTestHelperTest = testing::Test; |
44 | 45 |
45 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
46 // Android multi-process tests are not executing the new process. This is flaky. | 47 // Android multi-process tests are not executing the new process. This is flaky. |
47 #define MAYBE_RunChild DISABLED_RunChild | 48 #define MAYBE_RunChild DISABLED_RunChild |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 #define MAYBE_PassedChannel DISABLED_PassedChannel | 80 #define MAYBE_PassedChannel DISABLED_PassedChannel |
80 #else | 81 #else |
81 #define MAYBE_PassedChannel PassedChannel | 82 #define MAYBE_PassedChannel PassedChannel |
82 #endif // defined(OS_ANDROID) | 83 #endif // defined(OS_ANDROID) |
83 TEST_F(MultiprocessTestHelperTest, MAYBE_PassedChannel) { | 84 TEST_F(MultiprocessTestHelperTest, MAYBE_PassedChannel) { |
84 MultiprocessTestHelper helper; | 85 MultiprocessTestHelper helper; |
85 EXPECT_TRUE(helper.server_platform_handle.is_valid()); | 86 EXPECT_TRUE(helper.server_platform_handle.is_valid()); |
86 helper.StartChild("PassedChannel"); | 87 helper.StartChild("PassedChannel"); |
87 | 88 |
88 // Take ownership of the handle. | 89 // Take ownership of the handle. |
89 embedder::ScopedPlatformHandle handle = helper.server_platform_handle.Pass(); | 90 ScopedPlatformHandle handle = helper.server_platform_handle.Pass(); |
90 | 91 |
91 // The handle should be non-blocking. | 92 // The handle should be non-blocking. |
92 EXPECT_TRUE(IsNonBlocking(handle.get())); | 93 EXPECT_TRUE(IsNonBlocking(handle.get())); |
93 | 94 |
94 // Write a byte. | 95 // Write a byte. |
95 const char c = 'X'; | 96 const char c = 'X'; |
96 EXPECT_TRUE(WriteByte(handle.get(), c)); | 97 EXPECT_TRUE(WriteByte(handle.get(), c)); |
97 | 98 |
98 // It'll echo it back to us, incremented. | 99 // It'll echo it back to us, incremented. |
99 char d = 0; | 100 char d = 0; |
100 EXPECT_TRUE(ReadByte(handle.get(), &d)); | 101 EXPECT_TRUE(ReadByte(handle.get(), &d)); |
101 EXPECT_EQ(c + 1, d); | 102 EXPECT_EQ(c + 1, d); |
102 | 103 |
103 // And return it, incremented again. | 104 // And return it, incremented again. |
104 EXPECT_EQ(c + 2, helper.WaitForChildShutdown()); | 105 EXPECT_EQ(c + 2, helper.WaitForChildShutdown()); |
105 } | 106 } |
106 | 107 |
107 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannel) { | 108 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PassedChannel) { |
108 CHECK(MultiprocessTestHelper::client_platform_handle.is_valid()); | 109 CHECK(MultiprocessTestHelper::client_platform_handle.is_valid()); |
109 | 110 |
110 // Take ownership of the handle. | 111 // Take ownership of the handle. |
111 embedder::ScopedPlatformHandle handle = | 112 ScopedPlatformHandle handle = |
112 MultiprocessTestHelper::client_platform_handle.Pass(); | 113 MultiprocessTestHelper::client_platform_handle.Pass(); |
113 | 114 |
114 // The handle should be non-blocking. | 115 // The handle should be non-blocking. |
115 EXPECT_TRUE(IsNonBlocking(handle.get())); | 116 EXPECT_TRUE(IsNonBlocking(handle.get())); |
116 | 117 |
117 // Read a byte. | 118 // Read a byte. |
118 char c = 0; | 119 char c = 0; |
119 EXPECT_TRUE(ReadByte(handle.get(), &c)); | 120 EXPECT_TRUE(ReadByte(handle.get(), &c)); |
120 | 121 |
121 // Write it back, incremented. | 122 // Write it back, incremented. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 MOJO_MULTIPROCESS_TEST_CHILD_TEST(ChildTestFailsExpect) { | 185 MOJO_MULTIPROCESS_TEST_CHILD_TEST(ChildTestFailsExpect) { |
185 EXPECT_FALSE(MultiprocessTestHelper::client_platform_handle.is_valid()) | 186 EXPECT_FALSE(MultiprocessTestHelper::client_platform_handle.is_valid()) |
186 << "DISREGARD: Expected failure #1 in child process"; | 187 << "DISREGARD: Expected failure #1 in child process"; |
187 EXPECT_FALSE( | 188 EXPECT_FALSE( |
188 IsNonBlocking(MultiprocessTestHelper::client_platform_handle.get())) | 189 IsNonBlocking(MultiprocessTestHelper::client_platform_handle.get())) |
189 << "DISREGARD: Expected failure #2 in child process"; | 190 << "DISREGARD: Expected failure #2 in child process"; |
190 } | 191 } |
191 | 192 |
192 } // namespace | 193 } // namespace |
193 } // namespace test | 194 } // namespace test |
| 195 } // namespace edk |
194 } // namespace mojo | 196 } // namespace mojo |
OLD | NEW |