blob: 49ae07dd3e8d99d57ba806851b9e53474c95128c [file] [log] [blame]
[email protected]97c652b2012-06-27 01:12:241// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]307f5362008-10-29 20:46:042// 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 {
[email protected]f0a51fb52009-03-05 12:46:3812
[email protected]307f5362008-10-29 20:46:0413namespace {
14
[email protected]97c652b2012-06-27 01:12:2415struct 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
25typedef std::map<std::string, ProcessFunctions> MultiProcessTestMap;
[email protected]f0a51fb52009-03-05 12:46:3826
[email protected]307f5362008-10-29 20:46:0427// Retrieve a reference to the global 'func name' -> func ptr map.
[email protected]97c652b2012-06-27 01:12:2428MultiProcessTestMap& GetMultiprocessFuncMap() {
[email protected]307f5362008-10-29 20:46:0429 static MultiProcessTestMap test_name_to_func_ptr_map;
30 return test_name_to_func_ptr_map;
31}
[email protected]f0a51fb52009-03-05 12:46:3832
[email protected]307f5362008-10-29 20:46:0433} // namespace
34
[email protected]97c652b2012-06-27 01:12:2435AppendMultiProcessTest::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]307f5362008-10-29 20:46:0441}
42
43int InvokeChildProcessTest(std::string test_name) {
[email protected]97c652b2012-06-27 01:12:2444 MultiProcessTestMap& func_lookup_table = GetMultiprocessFuncMap();
[email protected]307f5362008-10-29 20:46:0445 MultiProcessTestMap::iterator it = func_lookup_table.find(test_name);
46 if (it != func_lookup_table.end()) {
[email protected]97c652b2012-06-27 01:12:2447 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]307f5362008-10-29 20:46:0452 }
[email protected]f0a51fb52009-03-05 12:46:3853
[email protected]307f5362008-10-29 20:46:0454 return -1;
55}
56
57} // namespace multi_process_function_list