| 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 #ifndef MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ | 5 #ifndef MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ |
| 6 #define MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ | 6 #define MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
| 11 #include "base/test/multiprocess_test.h" | 11 #include "base/test/multiprocess_test.h" |
| 12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "mojo/edk/embedder/scoped_platform_handle.h" | 13 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 14 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
| 15 #include "testing/multiprocess_func_list.h" | 15 #include "testing/multiprocess_func_list.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 | 18 |
| 19 namespace embedder { | 19 namespace edk { |
| 20 class PlatformChannelPair; | 20 class PlatformChannelPair; |
| 21 } | |
| 22 | 21 |
| 23 namespace test { | 22 namespace test { |
| 24 | 23 |
| 25 class MultiprocessTestHelper { | 24 class MultiprocessTestHelper { |
| 26 public: | 25 public: |
| 27 MultiprocessTestHelper(); | 26 MultiprocessTestHelper(); |
| 28 ~MultiprocessTestHelper(); | 27 ~MultiprocessTestHelper(); |
| 29 | 28 |
| 30 // Start a child process and run the "main" function "named" |test_child_name| | 29 // Start a child process and run the "main" function "named" |test_child_name| |
| 31 // declared using |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| or | 30 // declared using |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| or |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 // Like |WaitForChildShutdown()|, but returns true on success (exit code of 0) | 47 // Like |WaitForChildShutdown()|, but returns true on success (exit code of 0) |
| 49 // and false otherwise. You probably want to do something like | 48 // and false otherwise. You probably want to do something like |
| 50 // |EXPECT_TRUE(WaitForChildTestShutdown());|. Mainly for use with | 49 // |EXPECT_TRUE(WaitForChildTestShutdown());|. Mainly for use with |
| 51 // |MOJO_MULTIPROCESS_TEST_CHILD_TEST()|. | 50 // |MOJO_MULTIPROCESS_TEST_CHILD_TEST()|. |
| 52 bool WaitForChildTestShutdown(); | 51 bool WaitForChildTestShutdown(); |
| 53 | 52 |
| 54 // For use by |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| only: | 53 // For use by |MOJO_MULTIPROCESS_TEST_CHILD_MAIN()| only: |
| 55 static void ChildSetup(); | 54 static void ChildSetup(); |
| 56 | 55 |
| 57 // For use in the main process: | 56 // For use in the main process: |
| 58 embedder::ScopedPlatformHandle server_platform_handle; | 57 ScopedPlatformHandle server_platform_handle; |
| 59 | 58 |
| 60 // For use (and only valid) in the child process: | 59 // For use (and only valid) in the child process: |
| 61 static embedder::ScopedPlatformHandle client_platform_handle; | 60 static ScopedPlatformHandle client_platform_handle; |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 scoped_ptr<embedder::PlatformChannelPair> platform_channel_pair_; | 63 scoped_ptr<PlatformChannelPair> platform_channel_pair_; |
| 65 | 64 |
| 66 // Valid after |StartChild()| and before |WaitForChildShutdown()|. | 65 // Valid after |StartChild()| and before |WaitForChildShutdown()|. |
| 67 base::Process test_child_; | 66 base::Process test_child_; |
| 68 | 67 |
| 69 MOJO_DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper); | 68 MOJO_DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper); |
| 70 }; | 69 }; |
| 71 | 70 |
| 72 // Use this to declare the child process's "main()" function for tests using | 71 // Use this to declare the child process's "main()" function for tests using |
| 73 // |MultiprocessTestHelper|. It returns an |int|, which will be the process's | 72 // |MultiprocessTestHelper|. It returns an |int|, which will be the process's |
| 74 // exit code (but see the comment about |WaitForChildShutdown()|). | 73 // exit code (but see the comment about |WaitForChildShutdown()|). |
| 75 #define MOJO_MULTIPROCESS_TEST_CHILD_MAIN(test_child_name) \ | 74 #define MOJO_MULTIPROCESS_TEST_CHILD_MAIN(test_child_name) \ |
| 76 MULTIPROCESS_TEST_MAIN_WITH_SETUP( \ | 75 MULTIPROCESS_TEST_MAIN_WITH_SETUP( \ |
| 77 test_child_name##TestChildMain, \ | 76 test_child_name##TestChildMain, \ |
| 78 ::mojo::test::MultiprocessTestHelper::ChildSetup) | 77 test::MultiprocessTestHelper::ChildSetup) |
| 79 | 78 |
| 80 // Use this (and |WaitForChildTestShutdown()|) for the child process's "main()", | 79 // Use this (and |WaitForChildTestShutdown()|) for the child process's "main()", |
| 81 // if you want to use |EXPECT_...()| or |ASSERT_...()|; it has a |void| return | 80 // if you want to use |EXPECT_...()| or |ASSERT_...()|; it has a |void| return |
| 82 // type. (Note that while an |ASSERT_...()| failure will abort the test in the | 81 // type. (Note that while an |ASSERT_...()| failure will abort the test in the |
| 83 // child, it will not abort the test in the parent.) | 82 // child, it will not abort the test in the parent.) |
| 84 #define MOJO_MULTIPROCESS_TEST_CHILD_TEST(test_child_name) \ | 83 #define MOJO_MULTIPROCESS_TEST_CHILD_TEST(test_child_name) \ |
| 85 void test_child_name##TestChildTest(); \ | 84 void test_child_name##TestChildTest(); \ |
| 86 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(test_child_name) { \ | 85 MOJO_MULTIPROCESS_TEST_CHILD_MAIN(test_child_name) { \ |
| 87 test_child_name##TestChildTest(); \ | 86 test_child_name##TestChildTest(); \ |
| 88 return (::testing::Test::HasFatalFailure() || \ | 87 return (::testing::Test::HasFatalFailure() || \ |
| 89 ::testing::Test::HasNonfatalFailure()) \ | 88 ::testing::Test::HasNonfatalFailure()) \ |
| 90 ? 1 \ | 89 ? 1 \ |
| 91 : 0; \ | 90 : 0; \ |
| 92 } \ | 91 } \ |
| 93 void test_child_name##TestChildTest() | 92 void test_child_name##TestChildTest() |
| 94 | 93 |
| 95 } // namespace test | 94 } // namespace test |
| 95 } // namespace edk |
| 96 } // namespace mojo | 96 } // namespace mojo |
| 97 | 97 |
| 98 #endif // MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ | 98 #endif // MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ |
| OLD | NEW |