| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_TEST_MULTIPROCESS_TEST_H_ | 5 #ifndef BASE_TEST_MULTIPROCESS_TEST_H_ |
| 6 #define BASE_TEST_MULTIPROCESS_TEST_H_ | 6 #define BASE_TEST_MULTIPROCESS_TEST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // CommandLine command_line( | 28 // CommandLine command_line( |
| 29 // base::GetMultiProcessTestChildBaseCommandLine()); | 29 // base::GetMultiProcessTestChildBaseCommandLine()); |
| 30 // // Maybe add our own switches to |command_line|.... | 30 // // Maybe add our own switches to |command_line|.... |
| 31 // | 31 // |
| 32 // LaunchOptions options; | 32 // LaunchOptions options; |
| 33 // // Maybe set some options (e.g., |start_hidden| on Windows).... | 33 // // Maybe set some options (e.g., |start_hidden| on Windows).... |
| 34 // | 34 // |
| 35 // // Start a child process and run |a_test_func|. | 35 // // Start a child process and run |a_test_func|. |
| 36 // base::ProcessHandle test_child_handle = | 36 // base::ProcessHandle test_child_handle = |
| 37 // base::SpawnMultiProcessTestChild("a_test_func", command_line, | 37 // base::SpawnMultiProcessTestChild("a_test_func", command_line, |
| 38 // options, false); | 38 // options); |
| 39 // | 39 // |
| 40 // // Do stuff involving |test_child_handle| and the child process.... | 40 // // Do stuff involving |test_child_handle| and the child process.... |
| 41 // | 41 // |
| 42 // int rv = -1; | 42 // int rv = -1; |
| 43 // ASSERT_TRUE(base::WaitForExitCodeWithTimeout( | 43 // ASSERT_TRUE(base::WaitForExitCodeWithTimeout( |
| 44 // test_child_handle, &rv, TestTimeouts::action_timeout())); | 44 // test_child_handle, &rv, TestTimeouts::action_timeout())); |
| 45 // base::CloseProcessHandle(test_child_handle); | 45 // base::CloseProcessHandle(test_child_handle); |
| 46 // EXPECT_EQ(0, rv); | 46 // EXPECT_EQ(0, rv); |
| 47 // } | 47 // } |
| 48 // | 48 // |
| 49 // // Note: |MULTIPROCESS_TEST_MAIN()| is defined in | 49 // // Note: |MULTIPROCESS_TEST_MAIN()| is defined in |
| 50 // // testing/multi_process_function_list.h. | 50 // // testing/multi_process_function_list.h. |
| 51 // MULTIPROCESS_TEST_MAIN(a_test_func) { | 51 // MULTIPROCESS_TEST_MAIN(a_test_func) { |
| 52 // // Code here runs in a child process.... | 52 // // Code here runs in a child process.... |
| 53 // return 0; | 53 // return 0; |
| 54 // } | 54 // } |
| 55 | 55 |
| 56 // Spawns a child process and executes the function |procname| declared using | 56 // Spawns a child process and executes the function |procname| declared using |
| 57 // |MULTIPROCESS_TEST_MAIN()| or |MULTIPROCESS_TEST_MAIN_WITH_SETUP()|. | 57 // |MULTIPROCESS_TEST_MAIN()| or |MULTIPROCESS_TEST_MAIN_WITH_SETUP()|. |
| 58 // |command_line| should be as provided by | 58 // |command_line| should be as provided by |
| 59 // |GetMultiProcessTestChildBaseCommandLine()| (below), possibly with arguments | 59 // |GetMultiProcessTestChildBaseCommandLine()| (below), possibly with arguments |
| 60 // added. Note: On Windows, you probably want to set |options.start_hidden|. | 60 // added. Note: On Windows, you probably want to set |options.start_hidden|. |
| 61 ProcessHandle SpawnMultiProcessTestChild( | 61 ProcessHandle SpawnMultiProcessTestChild( |
| 62 const std::string& procname, | 62 const std::string& procname, |
| 63 const CommandLine& command_line, | 63 const CommandLine& command_line, |
| 64 const LaunchOptions& options, | 64 const LaunchOptions& options); |
| 65 bool debug_on_start); | |
| 66 | 65 |
| 67 // Gets the base command line for |SpawnMultiProcessTestChild()|. To this, you | 66 // Gets the base command line for |SpawnMultiProcessTestChild()|. To this, you |
| 68 // may add any flags needed for your child process. | 67 // may add any flags needed for your child process. |
| 69 CommandLine GetMultiProcessTestChildBaseCommandLine(); | 68 CommandLine GetMultiProcessTestChildBaseCommandLine(); |
| 70 | 69 |
| 71 // MultiProcessTest ------------------------------------------------------------ | 70 // MultiProcessTest ------------------------------------------------------------ |
| 72 | 71 |
| 73 // A MultiProcessTest is a test class which makes it easier to | 72 // A MultiProcessTest is a test class which makes it easier to |
| 74 // write a test which requires code running out of process. | 73 // write a test which requires code running out of process. |
| 75 // | 74 // |
| (...skipping 24 matching lines...) Expand all Loading... |
| 100 // 'procname' is the name of a function which the child will | 99 // 'procname' is the name of a function which the child will |
| 101 // execute. It must be exported from this library in order to | 100 // execute. It must be exported from this library in order to |
| 102 // run. | 101 // run. |
| 103 // | 102 // |
| 104 // Example signature: | 103 // Example signature: |
| 105 // extern "C" int __declspec(dllexport) FooBar() { | 104 // extern "C" int __declspec(dllexport) FooBar() { |
| 106 // // do client work here | 105 // // do client work here |
| 107 // } | 106 // } |
| 108 // | 107 // |
| 109 // Returns the handle to the child, or NULL on failure | 108 // Returns the handle to the child, or NULL on failure |
| 110 ProcessHandle SpawnChild(const std::string& procname, bool debug_on_start); | 109 ProcessHandle SpawnChild(const std::string& procname); |
| 111 | 110 |
| 112 // Run a child process using the given launch options. | 111 // Run a child process using the given launch options. |
| 113 // | 112 // |
| 114 // Note: On Windows, you probably want to set |options.start_hidden|. | 113 // Note: On Windows, you probably want to set |options.start_hidden|. |
| 115 ProcessHandle SpawnChildWithOptions(const std::string& procname, | 114 ProcessHandle SpawnChildWithOptions(const std::string& procname, |
| 116 const LaunchOptions& options, | 115 const LaunchOptions& options); |
| 117 bool debug_on_start); | |
| 118 | 116 |
| 119 // Set up the command line used to spawn the child process. | 117 // Set up the command line used to spawn the child process. |
| 120 // Override this to add things to the command line (calling this first in the | 118 // Override this to add things to the command line (calling this first in the |
| 121 // override). | 119 // override). |
| 122 // Note that currently some tests rely on this providing a full command line, | 120 // Note that currently some tests rely on this providing a full command line, |
| 123 // which they then use directly with |LaunchProcess()|. | 121 // which they then use directly with |LaunchProcess()|. |
| 124 // TODO(viettrungluu): Remove this and add a virtual | 122 // TODO(viettrungluu): Remove this and add a virtual |
| 125 // |ModifyChildCommandLine()|; make the two divergent uses more sane. | 123 // |ModifyChildCommandLine()|; make the two divergent uses more sane. |
| 126 virtual CommandLine MakeCmdLine(const std::string& procname, | 124 virtual CommandLine MakeCmdLine(const std::string& procname); |
| 127 bool debug_on_start); | |
| 128 | 125 |
| 129 private: | 126 private: |
| 130 DISALLOW_COPY_AND_ASSIGN(MultiProcessTest); | 127 DISALLOW_COPY_AND_ASSIGN(MultiProcessTest); |
| 131 }; | 128 }; |
| 132 | 129 |
| 133 } // namespace base | 130 } // namespace base |
| 134 | 131 |
| 135 #endif // BASE_TEST_MULTIPROCESS_TEST_H_ | 132 #endif // BASE_TEST_MULTIPROCESS_TEST_H_ |
| OLD | NEW |