[email protected] | 97c652b | 2012-06-27 01:12:24 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 307f536 | 2008-10-29 20:46:04 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "multiprocess_func_list.h" | ||||
6 | |||||
7 | #include <map> | ||||
8 | |||||
9 | // Helper functions to maintain mapping of "test name"->test func. | ||||
10 | // The information is accessed via a global map. | ||||
11 | namespace multi_process_function_list { | ||||
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 12 | |
[email protected] | 307f536 | 2008-10-29 20:46:04 | [diff] [blame] | 13 | namespace { |
14 | |||||
[email protected] | 97c652b | 2012-06-27 01:12:24 | [diff] [blame] | 15 | struct ProcessFunctions { |
16 | ProcessFunctions() : main(NULL), setup(NULL) {} | ||||
17 | ProcessFunctions(TestMainFunctionPtr main, SetupFunctionPtr setup) | ||||
18 | : main(main), | ||||
19 | setup(setup) { | ||||
20 | } | ||||
21 | TestMainFunctionPtr main; | ||||
22 | SetupFunctionPtr setup; | ||||
23 | }; | ||||
24 | |||||
25 | typedef std::map<std::string, ProcessFunctions> MultiProcessTestMap; | ||||
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 26 | |
[email protected] | 307f536 | 2008-10-29 20:46:04 | [diff] [blame] | 27 | // Retrieve a reference to the global 'func name' -> func ptr map. |
[email protected] | 97c652b | 2012-06-27 01:12:24 | [diff] [blame] | 28 | MultiProcessTestMap& GetMultiprocessFuncMap() { |
[email protected] | 307f536 | 2008-10-29 20:46:04 | [diff] [blame] | 29 | static MultiProcessTestMap test_name_to_func_ptr_map; |
30 | return test_name_to_func_ptr_map; | ||||
31 | } | ||||
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 32 | |
[email protected] | 307f536 | 2008-10-29 20:46:04 | [diff] [blame] | 33 | } // namespace |
34 | |||||
[email protected] | 97c652b | 2012-06-27 01:12:24 | [diff] [blame] | 35 | AppendMultiProcessTest::AppendMultiProcessTest( |
36 | std::string test_name, | ||||
37 | TestMainFunctionPtr main_func_ptr, | ||||
38 | SetupFunctionPtr setup_func_ptr) { | ||||
39 | GetMultiprocessFuncMap()[test_name] = | ||||
40 | ProcessFunctions(main_func_ptr, setup_func_ptr); | ||||
[email protected] | 307f536 | 2008-10-29 20:46:04 | [diff] [blame] | 41 | } |
42 | |||||
43 | int InvokeChildProcessTest(std::string test_name) { | ||||
[email protected] | 97c652b | 2012-06-27 01:12:24 | [diff] [blame] | 44 | MultiProcessTestMap& func_lookup_table = GetMultiprocessFuncMap(); |
[email protected] | 307f536 | 2008-10-29 20:46:04 | [diff] [blame] | 45 | MultiProcessTestMap::iterator it = func_lookup_table.find(test_name); |
46 | if (it != func_lookup_table.end()) { | ||||
[email protected] | 97c652b | 2012-06-27 01:12:24 | [diff] [blame] | 47 | const ProcessFunctions& process_functions = it->second; |
48 | if (process_functions.setup) | ||||
49 | (*process_functions.setup)(); | ||||
50 | if (process_functions.main) | ||||
51 | return (*process_functions.main)(); | ||||
[email protected] | 307f536 | 2008-10-29 20:46:04 | [diff] [blame] | 52 | } |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 53 | |
[email protected] | 307f536 | 2008-10-29 20:46:04 | [diff] [blame] | 54 | return -1; |
55 | } | ||||
56 | |||||
57 | } // namespace multi_process_function_list |