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/macros.h" | 10 #include "base/macros.h" |
(...skipping 22 matching lines...) Expand all Loading... |
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::Process test_child_process = | 36 // base::Process test_child_process = |
37 // base::SpawnMultiProcessTestChild("a_test_func", command_line, | 37 // base::SpawnMultiProcessTestChild("a_test_func", command_line, |
38 // options); | 38 // options); |
39 // | 39 // |
40 // // Do stuff involving |test_child_process| and the child process.... | 40 // // Do stuff involving |test_child_process| and the child process.... |
41 // | 41 // |
42 // int rv = -1; | 42 // int rv = -1; |
43 // ASSERT_TRUE(test_child_process.WaitForExitWithTimeout( | 43 // ASSERT_TRUE(base::WaitForMultiprocessTestChildExit(test_child_process, |
44 // TestTimeouts::action_timeout(), &rv)); | 44 // TestTimeouts::action_timeout(), &rv)); |
45 // EXPECT_EQ(0, rv); | 45 // EXPECT_EQ(0, rv); |
46 // } | 46 // } |
47 // | 47 // |
48 // // Note: |MULTIPROCESS_TEST_MAIN()| is defined in | 48 // // Note: |MULTIPROCESS_TEST_MAIN()| is defined in |
49 // // testing/multi_process_function_list.h. | 49 // // testing/multi_process_function_list.h. |
50 // MULTIPROCESS_TEST_MAIN(a_test_func) { | 50 // MULTIPROCESS_TEST_MAIN(a_test_func) { |
51 // // Code here runs in a child process.... | 51 // // Code here runs in a child process.... |
52 // return 0; | 52 // return 0; |
53 // } | 53 // } |
| 54 // |
| 55 // If you need to terminate the child process, use the |
| 56 // TerminateMultiProcessTestChild method to ensure that test will work on |
| 57 // Android. |
54 | 58 |
55 // Spawns a child process and executes the function |procname| declared using | 59 // Spawns a child process and executes the function |procname| declared using |
56 // |MULTIPROCESS_TEST_MAIN()| or |MULTIPROCESS_TEST_MAIN_WITH_SETUP()|. | 60 // |MULTIPROCESS_TEST_MAIN()| or |MULTIPROCESS_TEST_MAIN_WITH_SETUP()|. |
57 // |command_line| should be as provided by | 61 // |command_line| should be as provided by |
58 // |GetMultiProcessTestChildBaseCommandLine()| (below), possibly with arguments | 62 // |GetMultiProcessTestChildBaseCommandLine()| (below), possibly with arguments |
59 // added. Note: On Windows, you probably want to set |options.start_hidden|. | 63 // added. Note: On Windows, you probably want to set |options.start_hidden|. |
60 Process SpawnMultiProcessTestChild( | 64 Process SpawnMultiProcessTestChild( |
61 const std::string& procname, | 65 const std::string& procname, |
62 const CommandLine& command_line, | 66 const CommandLine& command_line, |
63 const LaunchOptions& options); | 67 const LaunchOptions& options); |
64 | 68 |
65 // Gets the base command line for |SpawnMultiProcessTestChild()|. To this, you | 69 // Gets the base command line for |SpawnMultiProcessTestChild()|. To this, you |
66 // may add any flags needed for your child process. | 70 // may add any flags needed for your child process. |
67 CommandLine GetMultiProcessTestChildBaseCommandLine(); | 71 CommandLine GetMultiProcessTestChildBaseCommandLine(); |
68 | 72 |
69 #if defined(OS_ANDROID) | 73 // Waits for the child process to exit. Returns true if the process exited |
| 74 // within |timeout| and sets |exit_code| if non null. |
| 75 bool WaitForMultiprocessTestChildExit(const Process& process, |
| 76 TimeDelta timeout, |
| 77 int* exit_code); |
70 | 78 |
71 // Enable the alternate test child implementation which support spawning a child | 79 // Terminates |process| with |exit_code|. If |wait| is true, this call blocks |
72 // after threads have been created. If used, this MUST be the first line of | 80 // until the process actually terminates. |
73 // main(). The main function is passed in to avoid a link-time dependency in | 81 bool TerminateMultiProcessTestChild(const Process& process, |
74 // component builds. | 82 int exit_code, |
75 void InitAndroidMultiProcessTestHelper(int (*main)(int, char**)); | 83 bool wait); |
76 | |
77 // Returns true if the current process is a test child. | |
78 bool AndroidIsChildProcess(); | |
79 | |
80 // Wait for a test child to exit if the alternate test child implementation is | |
81 // being used. | |
82 bool AndroidWaitForChildExitWithTimeout( | |
83 const Process& process, TimeDelta timeout, int* exit_code) | |
84 WARN_UNUSED_RESULT; | |
85 | |
86 #endif // defined(OS_ANDROID) | |
87 | 84 |
88 // MultiProcessTest ------------------------------------------------------------ | 85 // MultiProcessTest ------------------------------------------------------------ |
89 | 86 |
90 // A MultiProcessTest is a test class which makes it easier to | 87 // A MultiProcessTest is a test class which makes it easier to |
91 // write a test which requires code running out of process. | 88 // write a test which requires code running out of process. |
92 // | 89 // |
93 // To create a multiprocess test simply follow these steps: | 90 // To create a multiprocess test simply follow these steps: |
94 // | 91 // |
95 // 1) Derive your test from MultiProcessTest. Example: | 92 // 1) Derive your test from MultiProcessTest. Example: |
96 // | 93 // |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // |ModifyChildCommandLine()|; make the two divergent uses more sane. | 138 // |ModifyChildCommandLine()|; make the two divergent uses more sane. |
142 virtual CommandLine MakeCmdLine(const std::string& procname); | 139 virtual CommandLine MakeCmdLine(const std::string& procname); |
143 | 140 |
144 private: | 141 private: |
145 DISALLOW_COPY_AND_ASSIGN(MultiProcessTest); | 142 DISALLOW_COPY_AND_ASSIGN(MultiProcessTest); |
146 }; | 143 }; |
147 | 144 |
148 } // namespace base | 145 } // namespace base |
149 | 146 |
150 #endif // BASE_TEST_MULTIPROCESS_TEST_H_ | 147 #endif // BASE_TEST_MULTIPROCESS_TEST_H_ |
OLD | NEW |