michael@0: // Copyright (c) 2008 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef TESTING_MULTIPROCESS_FUNC_LIST_H_ michael@0: #define TESTING_MULTIPROCESS_FUNC_LIST_H_ michael@0: michael@0: #include michael@0: michael@0: // This file provides the plumbing to register functions to be executed michael@0: // as the main function of a child process in a multi-process test. michael@0: // This complements the MultiProcessTest class which provides facilities michael@0: // for launching such tests. michael@0: // michael@0: // The MULTIPROCESS_TEST_MAIN() macro registers a string -> func_ptr mapping michael@0: // by creating a new global instance of the AppendMultiProcessTest() class michael@0: // this means that by the time that we reach our main() function the mapping michael@0: // is already in place. michael@0: // michael@0: // Example usage: michael@0: // MULTIPROCESS_TEST_MAIN(a_test_func) { michael@0: // // Code here runs in a child process. michael@0: // return 0; michael@0: // } michael@0: // michael@0: // The prototype of a_test_func is implicitly michael@0: // int test_main_func_name(); michael@0: michael@0: namespace multi_process_function_list { michael@0: michael@0: // Type for child process main functions. michael@0: typedef int (*ChildFunctionPtr)(); michael@0: michael@0: // Helper class to append a test function to the global mapping. michael@0: // Used by the MULTIPROCESS_TEST_MAIN macro. michael@0: class AppendMultiProcessTest { michael@0: public: michael@0: AppendMultiProcessTest(std::string test_name, ChildFunctionPtr func_ptr); michael@0: }; michael@0: michael@0: // Invoke the main function of a test previously registered with michael@0: // MULTIPROCESS_TEST_MAIN() michael@0: int InvokeChildProcessTest(std::string test_name); michael@0: michael@0: // This macro creates a global MultiProcessTest::AppendMultiProcessTest object michael@0: // whose constructor does the work of adding the global mapping. michael@0: #define MULTIPROCESS_TEST_MAIN(test_main) \ michael@0: int test_main(); \ michael@0: namespace { \ michael@0: multi_process_function_list::AppendMultiProcessTest \ michael@0: AddMultiProcessTest##_##test_main(#test_main, (test_main)); \ michael@0: } \ michael@0: int test_main() michael@0: michael@0: } // namespace multi_process_function_list michael@0: michael@0: #endif // TESTING_MULTIPROCESS_FUNC_LIST_H_