OLD | NEW |
---|---|
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 TESTING_MULTIPROCESS_FUNC_LIST_H_ | 5 #ifndef TESTING_MULTIPROCESS_FUNC_LIST_H_ |
6 #define TESTING_MULTIPROCESS_FUNC_LIST_H_ | 6 #define TESTING_MULTIPROCESS_FUNC_LIST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 // This file provides the plumbing to register functions to be executed | 10 // This file provides the plumbing to register functions to be executed |
11 // as the main function of a child process in a multi-process test. | 11 // as the main function of a child process in a multi-process test. |
12 // This complements the MultiProcessTest class which provides facilities | 12 // This complements the MultiProcessTest class which provides facilities |
13 // for launching such tests. | 13 // for launching such tests. |
14 // | 14 // |
15 // The MULTIPROCESS_TEST_MAIN() macro registers a string -> func_ptr mapping | 15 // The MULTIPROCESS_TEST_MAIN() macro registers a string -> func_ptr mapping |
16 // by creating a new global instance of the AppendMultiProcessTest() class | 16 // by creating a new global instance of the AppendMultiProcessTest() class |
17 // this means that by the time that we reach our main() function the mapping | 17 // this means that by the time that we reach our main() function the mapping |
18 // is already in place. | 18 // is already in place. |
19 // | 19 // |
20 // Example usage: | 20 // Example usage: |
21 // MULTIPROCESS_TEST_MAIN(a_test_func) { | 21 // MULTIPROCESS_TEST_MAIN(a_test_func) { |
22 // // Code here runs in a child process. | 22 // // Code here runs in a child process. |
23 // return 0; | 23 // return 0; |
24 // } | 24 // } |
25 // | 25 // |
26 // The prototype of a_test_func is implicitly | 26 // The prototype of a_test_func is implicitly |
27 // int test_main_func_name(); | 27 // int test_main_func_name(); |
28 | |
29 namespace multi_process_function_list { | 28 namespace multi_process_function_list { |
30 | 29 |
31 // Type for child process main functions. | 30 // Type for child process main functions. |
32 typedef int (*ChildFunctionPtr)(); | 31 typedef int (*ChildFunctionPtr)(); |
jeremy
2012/06/13 20:46:28
I'd rename this to TestMainFunctionPtr or somesuch
Jay Civelli
2012/06/22 23:28:29
Done.
| |
33 | 32 |
34 // Helper class to append a test function to the global mapping. | 33 // Helper class to append a test function to the global mapping. |
35 // Used by the MULTIPROCESS_TEST_MAIN macro. | 34 // Used by the MULTIPROCESS_TEST_MAIN macro. |
36 class AppendMultiProcessTest { | 35 class AppendMultiProcessTest { |
37 public: | 36 public: |
38 AppendMultiProcessTest(std::string test_name, ChildFunctionPtr func_ptr); | 37 AppendMultiProcessTest(std::string test_name, |
jeremy
2012/06/13 20:46:28
Need a short comment explaining the arguments.
Jay Civelli
2012/06/22 23:28:29
Done.
| |
38 ChildFunctionPtr main_func_ptr, | |
39 ChildFunctionPtr setup_func_ptr); | |
39 }; | 40 }; |
40 | 41 |
41 // Invoke the main function of a test previously registered with | 42 // Invoke the main function of a test previously registered with |
42 // MULTIPROCESS_TEST_MAIN() | 43 // MULTIPROCESS_TEST_MAIN() |
43 int InvokeChildProcessTest(std::string test_name); | 44 int InvokeChildProcessTest(std::string test_name); |
44 | 45 |
45 // This macro creates a global MultiProcessTest::AppendMultiProcessTest object | 46 // This macro creates a global MultiProcessTest::AppendMultiProcessTest object |
46 // whose constructor does the work of adding the global mapping. | 47 // whose constructor does the work of adding the global mapping. |
47 #define MULTIPROCESS_TEST_MAIN(test_main) \ | 48 #define MULTIPROCESS_TEST_MAIN(test_main) \ |
49 MULTIPROCESS_TEST_MAIN_WITH_SETUP(test_main, NULL) | |
50 | |
51 // Same as above but lets callers specify a setup method that should be run when | |
jeremy
2012/06/13 20:46:28
nit: should be -> is
Jay Civelli
2012/06/22 23:28:29
Done.
| |
52 // the global mapping is added. |test_setup| is a ChildFunctionPtr, its return | |
53 // value is ignored. | |
jeremy
2012/06/13 20:46:28
per comment above - should return void, and then y
Jay Civelli
2012/06/22 23:28:29
Done.
| |
54 #define MULTIPROCESS_TEST_MAIN_WITH_SETUP(test_main, test_setup) \ | |
48 int test_main(); \ | 55 int test_main(); \ |
49 namespace { \ | 56 namespace { \ |
50 multi_process_function_list::AppendMultiProcessTest \ | 57 multi_process_function_list::AppendMultiProcessTest \ |
51 AddMultiProcessTest##_##test_main(#test_main, (test_main)); \ | 58 AddMultiProcessTest##_##test_main(#test_main, (test_main), (test_setup)); \ |
52 } \ | 59 } \ |
53 int test_main() | 60 int test_main() |
54 | 61 |
55 } // namespace multi_process_function_list | 62 } // namespace multi_process_function_list |
56 | 63 |
57 #endif // TESTING_MULTIPROCESS_FUNC_LIST_H_ | 64 #endif // TESTING_MULTIPROCESS_FUNC_LIST_H_ |
OLD | NEW |