| 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 "mojo/edk/test/multiprocess_test_helper.h" | 5 #include "mojo/edk/test/multiprocess_test_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool ReadByte(const PlatformHandle& handle, char* c) { | 43 bool ReadByte(const PlatformHandle& handle, char* c) { |
| 44 size_t bytes_read = 0; | 44 size_t bytes_read = 0; |
| 45 BlockingRead(handle, c, 1, &bytes_read); | 45 BlockingRead(handle, c, 1, &bytes_read); |
| 46 return bytes_read == 1; | 46 return bytes_read == 1; |
| 47 } | 47 } |
| 48 | 48 |
| 49 using MultiprocessTestHelperTest = testing::Test; | 49 using MultiprocessTestHelperTest = testing::Test; |
| 50 | 50 |
| 51 #if defined(OS_ANDROID) | 51 TEST_F(MultiprocessTestHelperTest, RunChild) { |
| 52 // Android multi-process tests are not executing the new process. This is flaky. | |
| 53 #define MAYBE_RunChild DISABLED_RunChild | |
| 54 #else | |
| 55 #define MAYBE_RunChild RunChild | |
| 56 #endif // defined(OS_ANDROID) | |
| 57 TEST_F(MultiprocessTestHelperTest, MAYBE_RunChild) { | |
| 58 MultiprocessTestHelper helper; | 52 MultiprocessTestHelper helper; |
| 59 EXPECT_TRUE(helper.server_platform_handle.is_valid()); | 53 EXPECT_TRUE(helper.server_platform_handle.is_valid()); |
| 60 | 54 |
| 61 helper.StartChild("RunChild"); | 55 helper.StartChild("RunChild"); |
| 62 EXPECT_EQ(123, helper.WaitForChildShutdown()); | 56 EXPECT_EQ(123, helper.WaitForChildShutdown()); |
| 63 } | 57 } |
| 64 | 58 |
| 65 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(RunChild) { | 59 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(RunChild) { |
| 66 CHECK(MultiprocessTestHelper::client_platform_handle.is_valid()); | 60 CHECK(MultiprocessTestHelper::client_platform_handle.is_valid()); |
| 67 return 123; | 61 return 123; |
| 68 } | 62 } |
| 69 | 63 |
| 70 #if defined(OS_ANDROID) | 64 TEST_F(MultiprocessTestHelperTest, TestChildMainNotFound) { |
| 71 // Android multi-process tests are not executing the new process. This is flaky. | |
| 72 #define MAYBE_TestChildMainNotFound DISABLED_TestChildMainNotFound | |
| 73 #else | |
| 74 #define MAYBE_TestChildMainNotFound TestChildMainNotFound | |
| 75 #endif // defined(OS_ANDROID) | |
| 76 TEST_F(MultiprocessTestHelperTest, MAYBE_TestChildMainNotFound) { | |
| 77 MultiprocessTestHelper helper; | 65 MultiprocessTestHelper helper; |
| 78 helper.StartChild("NoSuchTestChildMain"); | 66 helper.StartChild("NoSuchTestChildMain"); |
| 79 int result = helper.WaitForChildShutdown(); | 67 int result = helper.WaitForChildShutdown(); |
| 80 EXPECT_FALSE(result >= 0 && result <= 127); | 68 EXPECT_FALSE(result >= 0 && result <= 127); |
| 81 } | 69 } |
| 82 | 70 |
| 83 #if defined(OS_ANDROID) | 71 TEST_F(MultiprocessTestHelperTest, PassedChannel) { |
| 84 // Android multi-process tests are not executing the new process. This is flaky. | |
| 85 #define MAYBE_PassedChannel DISABLED_PassedChannel | |
| 86 #else | |
| 87 #define MAYBE_PassedChannel PassedChannel | |
| 88 #endif // defined(OS_ANDROID) | |
| 89 TEST_F(MultiprocessTestHelperTest, MAYBE_PassedChannel) { | |
| 90 MultiprocessTestHelper helper; | 72 MultiprocessTestHelper helper; |
| 91 EXPECT_TRUE(helper.server_platform_handle.is_valid()); | 73 EXPECT_TRUE(helper.server_platform_handle.is_valid()); |
| 92 helper.StartChild("PassedChannel"); | 74 helper.StartChild("PassedChannel"); |
| 93 | 75 |
| 94 // Take ownership of the handle. | 76 // Take ownership of the handle. |
| 95 ScopedPlatformHandle handle = std::move(helper.server_platform_handle); | 77 ScopedPlatformHandle handle = std::move(helper.server_platform_handle); |
| 96 | 78 |
| 97 // The handle should be non-blocking. | 79 // The handle should be non-blocking. |
| 98 EXPECT_TRUE(IsNonBlocking(handle.get())); | 80 EXPECT_TRUE(IsNonBlocking(handle.get())); |
| 99 | 81 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 126 | 108 |
| 127 // Write it back, incremented. | 109 // Write it back, incremented. |
| 128 c++; | 110 c++; |
| 129 EXPECT_TRUE(WriteByte(handle.get(), c)); | 111 EXPECT_TRUE(WriteByte(handle.get(), c)); |
| 130 | 112 |
| 131 // And return it, incremented again. | 113 // And return it, incremented again. |
| 132 c++; | 114 c++; |
| 133 return static_cast<int>(c); | 115 return static_cast<int>(c); |
| 134 } | 116 } |
| 135 | 117 |
| 136 #if defined(OS_ANDROID) | 118 TEST_F(MultiprocessTestHelperTest, ChildTestPasses) { |
| 137 // Android multi-process tests are not executing the new process. This is flaky. | |
| 138 #define MAYBE_ChildTestPasses DISABLED_ChildTestPasses | |
| 139 #else | |
| 140 #define MAYBE_ChildTestPasses ChildTestPasses | |
| 141 #endif // defined(OS_ANDROID) | |
| 142 TEST_F(MultiprocessTestHelperTest, MAYBE_ChildTestPasses) { | |
| 143 MultiprocessTestHelper helper; | 119 MultiprocessTestHelper helper; |
| 144 EXPECT_TRUE(helper.server_platform_handle.is_valid()); | 120 EXPECT_TRUE(helper.server_platform_handle.is_valid()); |
| 145 helper.StartChild("ChildTestPasses"); | 121 helper.StartChild("ChildTestPasses"); |
| 146 EXPECT_TRUE(helper.WaitForChildTestShutdown()); | 122 EXPECT_TRUE(helper.WaitForChildTestShutdown()); |
| 147 } | 123 } |
| 148 | 124 |
| 149 MOJO_MULTIPROCESS_TEST_CHILD_TEST(ChildTestPasses) { | 125 MOJO_MULTIPROCESS_TEST_CHILD_TEST(ChildTestPasses) { |
| 150 ASSERT_TRUE(MultiprocessTestHelper::client_platform_handle.is_valid()); | 126 ASSERT_TRUE(MultiprocessTestHelper::client_platform_handle.is_valid()); |
| 151 EXPECT_TRUE( | 127 EXPECT_TRUE( |
| 152 IsNonBlocking(MultiprocessTestHelper::client_platform_handle.get())); | 128 IsNonBlocking(MultiprocessTestHelper::client_platform_handle.get())); |
| 153 } | 129 } |
| 154 | 130 |
| 155 #if defined(OS_ANDROID) | 131 TEST_F(MultiprocessTestHelperTest, ChildTestFailsAssert) { |
| 156 // Android multi-process tests are not executing the new process. This is flaky. | |
| 157 #define MAYBE_ChildTestFailsAssert DISABLED_ChildTestFailsAssert | |
| 158 #else | |
| 159 #define MAYBE_ChildTestFailsAssert ChildTestFailsAssert | |
| 160 #endif // defined(OS_ANDROID) | |
| 161 TEST_F(MultiprocessTestHelperTest, MAYBE_ChildTestFailsAssert) { | |
| 162 MultiprocessTestHelper helper; | 132 MultiprocessTestHelper helper; |
| 163 EXPECT_TRUE(helper.server_platform_handle.is_valid()); | 133 EXPECT_TRUE(helper.server_platform_handle.is_valid()); |
| 164 helper.StartChild("ChildTestFailsAssert"); | 134 helper.StartChild("ChildTestFailsAssert"); |
| 165 EXPECT_FALSE(helper.WaitForChildTestShutdown()); | 135 EXPECT_FALSE(helper.WaitForChildTestShutdown()); |
| 166 } | 136 } |
| 167 | 137 |
| 168 MOJO_MULTIPROCESS_TEST_CHILD_TEST(ChildTestFailsAssert) { | 138 MOJO_MULTIPROCESS_TEST_CHILD_TEST(ChildTestFailsAssert) { |
| 169 ASSERT_FALSE(MultiprocessTestHelper::client_platform_handle.is_valid()) | 139 ASSERT_FALSE(MultiprocessTestHelper::client_platform_handle.is_valid()) |
| 170 << "DISREGARD: Expected failure in child process"; | 140 << "DISREGARD: Expected failure in child process"; |
| 171 ASSERT_FALSE( | 141 ASSERT_FALSE( |
| 172 IsNonBlocking(MultiprocessTestHelper::client_platform_handle.get())) | 142 IsNonBlocking(MultiprocessTestHelper::client_platform_handle.get())) |
| 173 << "Not reached"; | 143 << "Not reached"; |
| 174 CHECK(false) << "Not reached"; | 144 CHECK(false) << "Not reached"; |
| 175 } | 145 } |
| 176 | 146 |
| 177 #if defined(OS_ANDROID) | 147 TEST_F(MultiprocessTestHelperTest, ChildTestFailsExpect) { |
| 178 // Android multi-process tests are not executing the new process. This is flaky. | |
| 179 #define MAYBE_ChildTestFailsExpect DISABLED_ChildTestFailsExpect | |
| 180 #else | |
| 181 #define MAYBE_ChildTestFailsExpect ChildTestFailsExpect | |
| 182 #endif // defined(OS_ANDROID) | |
| 183 TEST_F(MultiprocessTestHelperTest, MAYBE_ChildTestFailsExpect) { | |
| 184 MultiprocessTestHelper helper; | 148 MultiprocessTestHelper helper; |
| 185 EXPECT_TRUE(helper.server_platform_handle.is_valid()); | 149 EXPECT_TRUE(helper.server_platform_handle.is_valid()); |
| 186 helper.StartChild("ChildTestFailsExpect"); | 150 helper.StartChild("ChildTestFailsExpect"); |
| 187 EXPECT_FALSE(helper.WaitForChildTestShutdown()); | 151 EXPECT_FALSE(helper.WaitForChildTestShutdown()); |
| 188 } | 152 } |
| 189 | 153 |
| 190 MOJO_MULTIPROCESS_TEST_CHILD_TEST(ChildTestFailsExpect) { | 154 MOJO_MULTIPROCESS_TEST_CHILD_TEST(ChildTestFailsExpect) { |
| 191 EXPECT_FALSE(MultiprocessTestHelper::client_platform_handle.is_valid()) | 155 EXPECT_FALSE(MultiprocessTestHelper::client_platform_handle.is_valid()) |
| 192 << "DISREGARD: Expected failure #1 in child process"; | 156 << "DISREGARD: Expected failure #1 in child process"; |
| 193 EXPECT_FALSE( | 157 EXPECT_FALSE( |
| 194 IsNonBlocking(MultiprocessTestHelper::client_platform_handle.get())) | 158 IsNonBlocking(MultiprocessTestHelper::client_platform_handle.get())) |
| 195 << "DISREGARD: Expected failure #2 in child process"; | 159 << "DISREGARD: Expected failure #2 in child process"; |
| 196 } | 160 } |
| 197 | 161 |
| 198 } // namespace | 162 } // namespace |
| 199 } // namespace test | 163 } // namespace test |
| 200 } // namespace edk | 164 } // namespace edk |
| 201 } // namespace mojo | 165 } // namespace mojo |
| OLD | NEW |