blob: a40055744555ca35cf988a28e79bfb7ef47186a0 [file] [log] [blame]
dsinclair685bb882016-04-20 07:32:39 -07001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
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.
11namespace multi_process_function_list {
12
13namespace {
14
15struct ProcessFunctions {
16 ProcessFunctions() : main(NULL), setup(NULL) {}
17 ProcessFunctions(TestMainFunctionPtr main, SetupFunctionPtr setup)
18 : main(main), setup(setup) {}
19 TestMainFunctionPtr main;
20 SetupFunctionPtr setup;
21};
22
23typedef std::map<std::string, ProcessFunctions> MultiProcessTestMap;
24
25// Retrieve a reference to the global 'func name' -> func ptr map.
26MultiProcessTestMap& GetMultiprocessFuncMap() {
27 static MultiProcessTestMap test_name_to_func_ptr_map;
28 return test_name_to_func_ptr_map;
29}
30
31} // namespace
32
33AppendMultiProcessTest::AppendMultiProcessTest(
34 std::string test_name,
35 TestMainFunctionPtr main_func_ptr,
36 SetupFunctionPtr setup_func_ptr) {
37 GetMultiprocessFuncMap()[test_name] =
38 ProcessFunctions(main_func_ptr, setup_func_ptr);
39}
40
41int InvokeChildProcessTest(std::string test_name) {
42 MultiProcessTestMap& func_lookup_table = GetMultiprocessFuncMap();
43 MultiProcessTestMap::iterator it = func_lookup_table.find(test_name);
44 if (it != func_lookup_table.end()) {
45 const ProcessFunctions& process_functions = it->second;
46 if (process_functions.setup)
47 (*process_functions.setup)();
48 if (process_functions.main)
49 return (*process_functions.main)();
50 }
51
52 return -1;
53}
54
55} // namespace multi_process_function_list