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