Chromium Code Reviews| 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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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 | 28 |
| 29 namespace multi_process_function_list { | 29 namespace multi_process_function_list { |
| 30 | 30 |
| 31 // Type for child process main functions. | 31 // Type for child process main functions. |
| 32 typedef int (*ChildFunctionPtr)(); | 32 typedef int (*TestMainFunctionPtr)(); |
| 33 | |
| 34 // Type for child setup functions. | |
| 35 typedef void (*SetupFunctionPtr)(); | |
| 33 | 36 |
| 34 // Helper class to append a test function to the global mapping. | 37 // Helper class to append a test function to the global mapping. |
| 35 // Used by the MULTIPROCESS_TEST_MAIN macro. | 38 // Used by the MULTIPROCESS_TEST_MAIN macro. |
| 36 class AppendMultiProcessTest { | 39 class AppendMultiProcessTest { |
| 37 public: | 40 public: |
| 38 AppendMultiProcessTest(std::string test_name, ChildFunctionPtr func_ptr); | 41 // |main_func_ptr| is the main function that is run in the child process. |
| 42 // |setup_func_ptr| is a function run when the global mapping is added. | |
| 43 AppendMultiProcessTest(std::string test_name, | |
| 44 TestMainFunctionPtr main_func_ptr, | |
| 45 SetupFunctionPtr setup_func_ptr); | |
| 39 }; | 46 }; |
| 40 | 47 |
| 41 // Invoke the main function of a test previously registered with | 48 // Invoke the main function of a test previously registered with |
| 42 // MULTIPROCESS_TEST_MAIN() | 49 // MULTIPROCESS_TEST_MAIN() |
| 43 int InvokeChildProcessTest(std::string test_name); | 50 int InvokeChildProcessTest(std::string test_name); |
| 44 | 51 |
| 45 // This macro creates a global MultiProcessTest::AppendMultiProcessTest object | 52 // This macro creates a global MultiProcessTest::AppendMultiProcessTest object |
| 46 // whose constructor does the work of adding the global mapping. | 53 // whose constructor does the work of adding the global mapping. |
| 47 #define MULTIPROCESS_TEST_MAIN(test_main) \ | 54 #define MULTIPROCESS_TEST_MAIN(test_main) \ |
| 55 MULTIPROCESS_TEST_MAIN_WITH_SETUP(test_main, NULL) | |
| 56 | |
| 57 // Same as above but lets callers specify a setup method that is run when the | |
| 58 // global mapping is added. |test_setup| is a SetupFunctionPtr. | |
|
jeremy
2012/06/24 13:49:37
* when the global mapping is added -> in the child
Jay Civelli
2012/06/25 17:49:56
Done.
| |
| 59 #define MULTIPROCESS_TEST_MAIN_WITH_SETUP(test_main, test_setup) \ | |
| 48 int test_main(); \ | 60 int test_main(); \ |
| 49 namespace { \ | 61 namespace { \ |
| 50 multi_process_function_list::AppendMultiProcessTest \ | 62 multi_process_function_list::AppendMultiProcessTest \ |
| 51 AddMultiProcessTest##_##test_main(#test_main, (test_main)); \ | 63 AddMultiProcessTest##_##test_main(#test_main, (test_main), (test_setup)); \ |
| 52 } \ | 64 } \ |
| 53 int test_main() | 65 int test_main() |
| 54 | 66 |
| 55 } // namespace multi_process_function_list | 67 } // namespace multi_process_function_list |
| 56 | 68 |
| 57 #endif // TESTING_MULTIPROCESS_FUNC_LIST_H_ | 69 #endif // TESTING_MULTIPROCESS_FUNC_LIST_H_ |
| OLD | NEW |