blob: 1e19704830f37ba9778aeffd48dcb30d3ada4527 [file] [log] [blame]
jeremy@chromium.org012e9992008-10-30 05:46:04 +09001// Copyright (c) 2008 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 {
maruel@chromium.orge5743442009-03-05 21:46:38 +090012
jeremy@chromium.org012e9992008-10-30 05:46:04 +090013namespace {
14
15typedef std::map<std::string, ChildFunctionPtr> MultiProcessTestMap;
maruel@chromium.orge5743442009-03-05 21:46:38 +090016
jeremy@chromium.org012e9992008-10-30 05:46:04 +090017// Retrieve a reference to the global 'func name' -> func ptr map.
18MultiProcessTestMap &GetMultiprocessFuncMap() {
19 static MultiProcessTestMap test_name_to_func_ptr_map;
20 return test_name_to_func_ptr_map;
21}
maruel@chromium.orge5743442009-03-05 21:46:38 +090022
jeremy@chromium.org012e9992008-10-30 05:46:04 +090023} // namespace
24
maruel@chromium.orge5743442009-03-05 21:46:38 +090025AppendMultiProcessTest::AppendMultiProcessTest(std::string test_name,
jeremy@chromium.org012e9992008-10-30 05:46:04 +090026 ChildFunctionPtr func_ptr) {
27 GetMultiprocessFuncMap()[test_name] = func_ptr;
28}
29
30int InvokeChildProcessTest(std::string test_name) {
31 MultiProcessTestMap &func_lookup_table = GetMultiprocessFuncMap();
32 MultiProcessTestMap::iterator it = func_lookup_table.find(test_name);
33 if (it != func_lookup_table.end()) {
34 ChildFunctionPtr func = it->second;
35 if (func) {
36 return (*func)();
37 }
38 }
maruel@chromium.orge5743442009-03-05 21:46:38 +090039
jeremy@chromium.org012e9992008-10-30 05:46:04 +090040 return -1;
41}
42
43} // namespace multi_process_function_list