summaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-29 20:46:04 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-29 20:46:04 +0000
commit307f536386aad3abf7c0978b892ffac059eb0be5 (patch)
tree9e59dd49ecdd90a63e007c37bdd27cc045549138 /testing
parentfcbaeacfce08303236709e2603e64fc40bdba435 (diff)
downloadchromium_src-307f536386aad3abf7c0978b892ffac059eb0be5.zip
chromium_src-307f536386aad3abf7c0978b892ffac059eb0be5.tar.gz
chromium_src-307f536386aad3abf7c0978b892ffac059eb0be5.tar.bz2
1) Add a new MULTIPROCESS_TEST_MAIN macro to store child process names
in a lookup table. Previously we were using different mechanisms on each platform to look up child process names at runtime. This broke on OS X where we strip the symbol table on release executables. 2) Enable process_util_unittest on OS X. Review URL: http://codereview.chromium.org/8864 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'testing')
-rw-r--r--testing/SConscript.gtest1
-rw-r--r--testing/gtest.vcproj4
-rw-r--r--testing/gtest.xcodeproj/project.pbxproj6
-rw-r--r--testing/multiprocess_func_list.cc43
-rw-r--r--testing/multiprocess_func_list.h57
5 files changed, 111 insertions, 0 deletions
diff --git a/testing/SConscript.gtest b/testing/SConscript.gtest
index 4f6bbf0..bc5456a 100644
--- a/testing/SConscript.gtest
+++ b/testing/SConscript.gtest
@@ -28,6 +28,7 @@ input_files = [
'gtest/src/gtest-filepath.cc',
'gtest/src/gtest-port.cc',
'gtest/src/gtest.cc',
+ 'multiprocess_func_list.cc',
]
env.ChromeStaticLibrary('gtest', input_files)
diff --git a/testing/gtest.vcproj b/testing/gtest.vcproj
index 02a9834..62421c4 100644
--- a/testing/gtest.vcproj
+++ b/testing/gtest.vcproj
@@ -184,6 +184,10 @@
RelativePath="gtest\include\gtest\gtest_prod.h"
>
</File>
+ <File
+ RelativePath="multiprocess_func_list.cc"
+ >
+ </File>
</Files>
<Globals>
</Globals>
diff --git a/testing/gtest.xcodeproj/project.pbxproj b/testing/gtest.xcodeproj/project.pbxproj
index c733d65..9498879 100644
--- a/testing/gtest.xcodeproj/project.pbxproj
+++ b/testing/gtest.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ B593AFF90EB7D41B00B72887 /* multiprocess_func_list.cc in Sources */ = {isa = PBXBuildFile; fileRef = B593AFF70EB7D41B00B72887 /* multiprocess_func_list.cc */; };
E45A2BBC0E47A20200DB1196 /* gtest_main.cc in Sources */ = {isa = PBXBuildFile; fileRef = E45A2BB60E47A20200DB1196 /* gtest_main.cc */; };
E45A2BBD0E47A20200DB1196 /* gtest-death-test.cc in Sources */ = {isa = PBXBuildFile; fileRef = E45A2BB70E47A20200DB1196 /* gtest-death-test.cc */; };
E45A2BBE0E47A20200DB1196 /* gtest-filepath.cc in Sources */ = {isa = PBXBuildFile; fileRef = E45A2BB80E47A20200DB1196 /* gtest-filepath.cc */; };
@@ -20,6 +21,8 @@
7B836C760E55C8CC00F6AD31 /* release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = release.xcconfig; sourceTree = "<group>"; };
7BED30DF0E59F69A00A747DB /* executable.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = executable.xcconfig; sourceTree = "<group>"; };
7BED30E00E59F69A00A747DB /* staticlib.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = staticlib.xcconfig; sourceTree = "<group>"; };
+ B593AFF70EB7D41B00B72887 /* multiprocess_func_list.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = multiprocess_func_list.cc; sourceTree = SOURCE_ROOT; };
+ B593AFF80EB7D41B00B72887 /* multiprocess_func_list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = multiprocess_func_list.h; sourceTree = SOURCE_ROOT; };
D2AAC046055464E500DB518D /* libgtest.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
E45A2BB60E47A20200DB1196 /* gtest_main.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gtest_main.cc; sourceTree = "<group>"; };
E45A2BB70E47A20200DB1196 /* gtest-death-test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "gtest-death-test.cc"; sourceTree = "<group>"; };
@@ -59,6 +62,8 @@
E45A2BBA0E47A20200DB1196 /* gtest-port.cc */,
E45A2BBB0E47A20200DB1196 /* gtest.cc */,
E45A2BB60E47A20200DB1196 /* gtest_main.cc */,
+ B593AFF70EB7D41B00B72887 /* multiprocess_func_list.cc */,
+ B593AFF80EB7D41B00B72887 /* multiprocess_func_list.h */,
);
name = Source;
path = gtest/src;
@@ -131,6 +136,7 @@
E45A2BC00E47A20200DB1196 /* gtest-port.cc in Sources */,
E45A2BC10E47A20200DB1196 /* gtest.cc in Sources */,
E45A2BBC0E47A20200DB1196 /* gtest_main.cc in Sources */,
+ B593AFF90EB7D41B00B72887 /* multiprocess_func_list.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/testing/multiprocess_func_list.cc b/testing/multiprocess_func_list.cc
new file mode 100644
index 0000000..236edbf
--- /dev/null
+++ b/testing/multiprocess_func_list.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "multiprocess_func_list.h"
+
+#include <map>
+
+// Helper functions to maintain mapping of "test name"->test func.
+// The information is accessed via a global map.
+namespace multi_process_function_list {
+
+namespace {
+
+typedef std::map<std::string, ChildFunctionPtr> MultiProcessTestMap;
+
+// Retrieve a reference to the global 'func name' -> func ptr map.
+MultiProcessTestMap &GetMultiprocessFuncMap() {
+ static MultiProcessTestMap test_name_to_func_ptr_map;
+ return test_name_to_func_ptr_map;
+}
+
+} // namespace
+
+AppendMultiProcessTest::AppendMultiProcessTest(std::string test_name,
+ ChildFunctionPtr func_ptr) {
+ GetMultiprocessFuncMap()[test_name] = func_ptr;
+}
+
+int InvokeChildProcessTest(std::string test_name) {
+ MultiProcessTestMap &func_lookup_table = GetMultiprocessFuncMap();
+ MultiProcessTestMap::iterator it = func_lookup_table.find(test_name);
+ if (it != func_lookup_table.end()) {
+ ChildFunctionPtr func = it->second;
+ if (func) {
+ return (*func)();
+ }
+ }
+
+ return -1;
+}
+
+} // namespace multi_process_function_list
diff --git a/testing/multiprocess_func_list.h b/testing/multiprocess_func_list.h
new file mode 100644
index 0000000..0d53b2b
--- /dev/null
+++ b/testing/multiprocess_func_list.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TESTING_MULTIPROCESS_FUNC_LIST_H_
+#define TESTING_MULTIPROCESS_FUNC_LIST_H_
+
+#include <string>
+
+// This file provides the plumbing to register functions to be executed
+// as the main function of a child process in a multi-process test.
+// This complements the MultiProcessTest class which provides facilities
+// for launching such tests.
+//
+// The MULTIPROCESS_TEST_MAIN() macro registers a string -> func_ptr mapping
+// by creating a new global instance of the AppendMultiProcessTest() class
+// this means that by the time that we reach our main() function the mapping
+// is already in place.
+//
+// Example usage:
+// MULTIPROCESS_TEST_MAIN(a_test_func) {
+// // Code here runs in a child process.
+// return 0;
+// }
+//
+// The prototype of a_test_func is implicitly
+// int test_main_func_name();
+
+namespace multi_process_function_list {
+
+// Type for child process main functions.
+typedef int (*ChildFunctionPtr)();
+
+// Helper class to append a test function to the global mapping.
+// Used by the MULTIPROCESS_TEST_MAIN macro.
+class AppendMultiProcessTest {
+ public:
+ AppendMultiProcessTest(std::string test_name, ChildFunctionPtr func_ptr);
+};
+
+// Invoke the main function of a test previously registered with
+// MULTIPROCESS_TEST_MAIN()
+int InvokeChildProcessTest(std::string test_name);
+
+// This macro creates a global MultiProcessTest::AppendMultiProcessTest object
+// whose constructor does the work of adding the global mapping.
+#define MULTIPROCESS_TEST_MAIN(test_main) \
+ int test_main(); \
+ namespace { \
+ multi_process_function_list::AppendMultiProcessTest \
+ AddMultiProcessTest##_##test_main(#test_main, (test_main)); \
+ } \
+ int test_main()
+
+} // namespace multi_process_function_list
+
+#endif // TESTING_MULTIPROCESS_FUNC_LIST_H_