| 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" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 ScopedMessagePipeHandle StartChild(const std::string& test_child_name); | 35 ScopedMessagePipeHandle StartChild(const std::string& test_child_name); |
| 36 | 36 |
| 37 // Like |StartChild()|, but appends an extra switch (with ASCII value) to the | 37 // 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 | 38 // command line. (The switch must not already be present in the default |
| 39 // command line.) | 39 // command line.) |
| 40 ScopedMessagePipeHandle StartChildWithExtraSwitch( | 40 ScopedMessagePipeHandle StartChildWithExtraSwitch( |
| 41 const std::string& test_child_name, | 41 const std::string& test_child_name, |
| 42 const std::string& switch_string, | 42 const std::string& switch_string, |
| 43 const std::string& switch_value); | 43 const std::string& switch_value); |
| 44 | 44 |
| 45 void set_bad_message_callback(const base::Closure& callback) { |
| 46 bad_message_callback_ = callback; |
| 47 } |
| 48 |
| 45 // Wait for the child process to terminate. | 49 // Wait for the child process to terminate. |
| 46 // Returns the exit code of the child process. Note that, though it's declared | 50 // 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 | 51 // 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 | 52 // 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 | 53 // 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. | 54 // 0-127 being preserved, and -1 being outside the range 0-127. |
| 51 int WaitForChildShutdown(); | 55 int WaitForChildShutdown(); |
| 52 | 56 |
| 53 // Like |WaitForChildShutdown()|, but returns true on success (exit code of 0) | 57 // Like |WaitForChildShutdown()|, but returns true on success (exit code of 0) |
| 54 // and false otherwise. You probably want to do something like | 58 // and false otherwise. You probably want to do something like |
| 55 // |EXPECT_TRUE(WaitForChildTestShutdown());|. | 59 // |EXPECT_TRUE(WaitForChildTestShutdown());|. |
| 56 bool WaitForChildTestShutdown(); | 60 bool WaitForChildTestShutdown(); |
| 57 | 61 |
| 58 const base::Process& test_child() const { return test_child_; } | 62 const base::Process& test_child() const { return test_child_; } |
| 59 | 63 |
| 60 // Used by macros in mojo/edk/test/mojo_test_base.h to support multiprocess | 64 // Used by macros in mojo/edk/test/mojo_test_base.h to support multiprocess |
| 61 // test client initialization. | 65 // test client initialization. |
| 62 static void ChildSetup(); | 66 static void ChildSetup(); |
| 63 static int RunClientMain(const base::Callback<int(MojoHandle)>& main); | 67 static int RunClientMain(const base::Callback<int(MojoHandle)>& main); |
| 64 static int RunClientTestMain(const base::Callback<void(MojoHandle)>& main); | 68 static int RunClientTestMain(const base::Callback<void(MojoHandle)>& main); |
| 65 | 69 |
| 66 // For use (and only valid) in the child process: | 70 // For use (and only valid) in the child process: |
| 67 static std::string primordial_pipe_token; | 71 static std::string primordial_pipe_token; |
| 68 | 72 |
| 69 private: | 73 private: |
| 70 // Valid after |StartChild()| and before |WaitForChildShutdown()|. | 74 // Valid after |StartChild()| and before |WaitForChildShutdown()|. |
| 71 base::Process test_child_; | 75 base::Process test_child_; |
| 72 | 76 |
| 77 base::Closure bad_message_callback_; |
| 78 |
| 73 DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper); | 79 DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper); |
| 74 }; | 80 }; |
| 75 | 81 |
| 76 } // namespace test | 82 } // namespace test |
| 77 } // namespace edk | 83 } // namespace edk |
| 78 } // namespace mojo | 84 } // namespace mojo |
| 79 | 85 |
| 80 #endif // MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ | 86 #endif // MOJO_EDK_TEST_MULTIPROCESS_TEST_HELPER_H_ |
| OLD | NEW |