Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef TESTING_MULTIPROCESS_FUNC_LIST_H_ |
michael@0 | 6 | #define TESTING_MULTIPROCESS_FUNC_LIST_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include <string> |
michael@0 | 9 | |
michael@0 | 10 | // This file provides the plumbing to register functions to be executed |
michael@0 | 11 | // as the main function of a child process in a multi-process test. |
michael@0 | 12 | // This complements the MultiProcessTest class which provides facilities |
michael@0 | 13 | // for launching such tests. |
michael@0 | 14 | // |
michael@0 | 15 | // The MULTIPROCESS_TEST_MAIN() macro registers a string -> func_ptr mapping |
michael@0 | 16 | // by creating a new global instance of the AppendMultiProcessTest() class |
michael@0 | 17 | // this means that by the time that we reach our main() function the mapping |
michael@0 | 18 | // is already in place. |
michael@0 | 19 | // |
michael@0 | 20 | // Example usage: |
michael@0 | 21 | // MULTIPROCESS_TEST_MAIN(a_test_func) { |
michael@0 | 22 | // // Code here runs in a child process. |
michael@0 | 23 | // return 0; |
michael@0 | 24 | // } |
michael@0 | 25 | // |
michael@0 | 26 | // The prototype of a_test_func is implicitly |
michael@0 | 27 | // int test_main_func_name(); |
michael@0 | 28 | |
michael@0 | 29 | namespace multi_process_function_list { |
michael@0 | 30 | |
michael@0 | 31 | // Type for child process main functions. |
michael@0 | 32 | typedef int (*ChildFunctionPtr)(); |
michael@0 | 33 | |
michael@0 | 34 | // Helper class to append a test function to the global mapping. |
michael@0 | 35 | // Used by the MULTIPROCESS_TEST_MAIN macro. |
michael@0 | 36 | class AppendMultiProcessTest { |
michael@0 | 37 | public: |
michael@0 | 38 | AppendMultiProcessTest(std::string test_name, ChildFunctionPtr func_ptr); |
michael@0 | 39 | }; |
michael@0 | 40 | |
michael@0 | 41 | // Invoke the main function of a test previously registered with |
michael@0 | 42 | // MULTIPROCESS_TEST_MAIN() |
michael@0 | 43 | int InvokeChildProcessTest(std::string test_name); |
michael@0 | 44 | |
michael@0 | 45 | // This macro creates a global MultiProcessTest::AppendMultiProcessTest object |
michael@0 | 46 | // whose constructor does the work of adding the global mapping. |
michael@0 | 47 | #define MULTIPROCESS_TEST_MAIN(test_main) \ |
michael@0 | 48 | int test_main(); \ |
michael@0 | 49 | namespace { \ |
michael@0 | 50 | multi_process_function_list::AppendMultiProcessTest \ |
michael@0 | 51 | AddMultiProcessTest##_##test_main(#test_main, (test_main)); \ |
michael@0 | 52 | } \ |
michael@0 | 53 | int test_main() |
michael@0 | 54 | |
michael@0 | 55 | } // namespace multi_process_function_list |
michael@0 | 56 | |
michael@0 | 57 | #endif // TESTING_MULTIPROCESS_FUNC_LIST_H_ |