| 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/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/process/process.h" | 12 #include "base/process/process.h" |
| 13 #include "base/test/multiprocess_test.h" | 13 #include "base/test/multiprocess_test.h" |
| 14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
| 15 #include "mojo/edk/embedder/embedder.h" |
| 15 #include "mojo/public/cpp/system/message_pipe.h" | 16 #include "mojo/public/cpp/system/message_pipe.h" |
| 16 #include "testing/multiprocess_func_list.h" | 17 #include "testing/multiprocess_func_list.h" |
| 17 | 18 |
| 18 namespace mojo { | 19 namespace mojo { |
| 19 | 20 |
| 20 namespace edk { | 21 namespace edk { |
| 21 class PlatformChannelPair; | 22 class PlatformChannelPair; |
| 22 | 23 |
| 23 namespace test { | 24 namespace test { |
| 24 | 25 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 ScopedMessagePipeHandle StartChild(const std::string& test_child_name); | 36 ScopedMessagePipeHandle StartChild(const std::string& test_child_name); |
| 36 | 37 |
| 37 // Like |StartChild()|, but appends an extra switch (with ASCII value) to the | 38 // Like |StartChild()|, but appends an extra switch (with ASCII value) to the |
| 38 // command line. (The switch must not already be present in the default | 39 // command line. (The switch must not already be present in the default |
| 39 // command line.) | 40 // command line.) |
| 40 ScopedMessagePipeHandle StartChildWithExtraSwitch( | 41 ScopedMessagePipeHandle StartChildWithExtraSwitch( |
| 41 const std::string& test_child_name, | 42 const std::string& test_child_name, |
| 42 const std::string& switch_string, | 43 const std::string& switch_string, |
| 43 const std::string& switch_value); | 44 const std::string& switch_value); |
| 44 | 45 |
| 46 void set_process_error_callback(const ProcessErrorCallback& callback) { |
| 47 process_error_callback_ = callback; |
| 48 } |
| 49 |
| 45 // Wait for the child process to terminate. | 50 // Wait for the child process to terminate. |
| 46 // Returns the exit code of the child process. Note that, though it's declared | 51 // Returns the exit code of the child process. Note that, though it's declared |
| 47 // to be an |int|, the exit code is subject to mangling by the OS. E.g., we | 52 // to be an |int|, the exit code is subject to mangling by the OS. E.g., we |
| 48 // usually return -1 on error in the child (e.g., if |test_child_name| was not | 53 // usually return -1 on error in the child (e.g., if |test_child_name| was not |
| 49 // found), but this is mangled to 255 on Linux. You should only rely on codes | 54 // found), but this is mangled to 255 on Linux. You should only rely on codes |
| 50 // 0-127 being preserved, and -1 being outside the range 0-127. | 55 // 0-127 being preserved, and -1 being outside the range 0-127. |
| 51 int WaitForChildShutdown(); | 56 int WaitForChildShutdown(); |
| 52 | 57 |
| 53 // Like |WaitForChildShutdown()|, but returns true on success (exit code of 0) | 58 // Like |WaitForChildShutdown()|, but returns true on success (exit code of 0) |
| 54 // and false otherwise. You probably want to do something like | 59 // and false otherwise. You probably want to do something like |
| 55 // |EXPECT_TRUE(WaitForChildTestShutdown());|. | 60 // |EXPECT_TRUE(WaitForChildTestShutdown());|. |
| 56 bool WaitForChildTestShutdown(); | 61 bool WaitForChildTestShutdown(); |
| 57 | 62 |
| 58 const base::Process& test_child() const { return test_child_; } | 63 const base::Process& test_child() const { return test_child_; } |
| 59 | 64 |
| 60 // Used by macros in mojo/edk/test/mojo_test_base.h to support multiprocess | 65 // Used by macros in mojo/edk/test/mojo_test_base.h to support multiprocess |
| 61 // test client initialization. | 66 // test client initialization. |
| 62 static void ChildSetup(); | 67 static void ChildSetup(); |
| 63 static int RunClientMain(const base::Callback<int(MojoHandle)>& main); | 68 static int RunClientMain(const base::Callback<int(MojoHandle)>& main); |
| 64 static int RunClientTestMain(const base::Callback<void(MojoHandle)>& main); | 69 static int RunClientTestMain(const base::Callback<void(MojoHandle)>& main); |
| 65 | 70 |
| 66 // For use (and only valid) in the child process: | 71 // For use (and only valid) in the child process: |
| 67 static std::string primordial_pipe_token; | 72 static std::string primordial_pipe_token; |
| 68 | 73 |
| 69 private: | 74 private: |
| 70 // Valid after |StartChild()| and before |WaitForChildShutdown()|. | 75 // Valid after |StartChild()| and before |WaitForChildShutdown()|. |
| 71 base::Process test_child_; | 76 base::Process test_child_; |
| 72 | 77 |
| 78 ProcessErrorCallback process_error_callback_; |
| 79 |
| 73 DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper); | 80 DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper); |
| 74 }; | 81 }; |
| 75 | 82 |
| 76 } // namespace test | 83 } // namespace test |
| 77 } // namespace edk | 84 } // namespace edk |
| 78 } // namespace mojo | 85 } // namespace mojo |
| 79 | 86 |
| 80 #endif // MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ | 87 #endif // MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ |
| OLD | NEW |