diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-27 20:49:55 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-27 20:49:55 +0000 |
commit | 9c73c775a14581f1b005c30242be0354afe64bfd (patch) | |
tree | 5c3de6ed874caf93886fba43d951c56ebc7c704b /base | |
parent | 467751964600388345aa537e1436b036d159ac92 (diff) | |
download | chromium_src-9c73c775a14581f1b005c30242be0354afe64bfd.zip chromium_src-9c73c775a14581f1b005c30242be0354afe64bfd.tar.gz chromium_src-9c73c775a14581f1b005c30242be0354afe64bfd.tar.bz2 |
Enable stats_tabe_unittest.cc on OS X.
Review URL: http://codereview.chromium.org/8160
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4024 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.xcodeproj/project.pbxproj | 8 | ||||
-rw-r--r-- | base/multiprocess_test.h | 5 | ||||
-rw-r--r-- | base/port.h | 5 | ||||
-rw-r--r-- | base/process_util_mac.mm | 61 | ||||
-rw-r--r-- | base/stats_table_unittest.cc | 6 | ||||
-rw-r--r-- | base/test_suite.h | 10 |
6 files changed, 86 insertions, 9 deletions
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj index ba9e8a4..8b1bad6 100644 --- a/base/base.xcodeproj/project.pbxproj +++ b/base/base.xcodeproj/project.pbxproj @@ -169,6 +169,8 @@ B52C916C0E9428F500208D01 /* clipboard_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B52C916B0E9428F500208D01 /* clipboard_unittest.cc */; }; B53C85280E9C298C000F70AB /* idle_timer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 820EB4EB0E3A60FE009668FC /* idle_timer.cc */; }; B57E4D780E9C26340090055D /* idletimer_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B57E4D770E9C26340090055D /* idletimer_unittest.cc */; }; + B5CB32AD0EAFC47900DF65F1 /* stats_table_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5CB32AC0EAFC47900DF65F1 /* stats_table_unittest.cc */; }; + B5CB32EA0EAFCD3F00DF65F1 /* process_util_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = B5CB32E90EAFCD3F00DF65F1 /* process_util_mac.mm */; }; B5D544AB0EAFB7E000272A1C /* sys_string_conversions_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = B5D544AA0EAFB7E000272A1C /* sys_string_conversions_unittest.cc */; }; B5EF235C0E89ABF500E1E114 /* platform_canvas_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = ABE1BA0C0E756EC4009041DA /* platform_canvas_unittest.cc */; }; BA0F69870E79D7980079A8A1 /* thread_local_storage_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = BA0F69860E79D7980079A8A1 /* thread_local_storage_unittest.cc */; }; @@ -626,6 +628,8 @@ ABF68B280EB0F93100E72835 /* field_trial.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = field_trial.cc; sourceTree = "<group>"; }; B52C916B0E9428F500208D01 /* clipboard_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clipboard_unittest.cc; sourceTree = "<group>"; }; B57E4D770E9C26340090055D /* idletimer_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = idletimer_unittest.cc; sourceTree = "<group>"; }; + B5CB32AC0EAFC47900DF65F1 /* stats_table_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = stats_table_unittest.cc; sourceTree = "<group>"; }; + B5CB32E90EAFCD3F00DF65F1 /* process_util_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = process_util_mac.mm; sourceTree = "<group>"; }; B5D544AA0EAFB7E000272A1C /* sys_string_conversions_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sys_string_conversions_unittest.cc; sourceTree = "<group>"; }; BA0F69860E79D7980079A8A1 /* thread_local_storage_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = thread_local_storage_unittest.cc; sourceTree = "<group>"; }; BA5CC5830E788093004EDD45 /* shared_memory_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = shared_memory_unittest.cc; sourceTree = "<group>"; }; @@ -940,6 +944,7 @@ 820EB4F10E3A6127009668FC /* process.cc */, 820EB4F20E3A6127009668FC /* process.h */, 825403510D92D24D0006B936 /* process_util.h */, + B5CB32E90EAFCD3F00DF65F1 /* process_util_mac.mm */, 7BD8F49F0E65AA2400034DE9 /* process_util_posix.cc */, 7BD8F4A00E65AA2400034DE9 /* process_util_unittest.cc */, 8254034B0D92D23C0006B936 /* prtime.cc */, @@ -988,6 +993,7 @@ 825403780D92D2CF0006B936 /* stats_counters.h */, 825403790D92D2CF0006B936 /* stats_table.cc */, 8254037A0D92D2CF0006B936 /* stats_table.h */, + B5CB32AC0EAFC47900DF65F1 /* stats_table_unittest.cc */, 7BD8F7730E65E89800034DE9 /* string16.cc */, 821B91680DAABD7F00F350D7 /* string16.h */, E4A133420E37A3C400110AA2 /* string_escape.cc */, @@ -1383,6 +1389,7 @@ 824654A60DC25CD7007C2BAA /* pickle.cc in Sources */, 7BF164F30E660CA500AA999E /* platform_thread_mac.mm in Sources */, 93E703170E5D63E00046259B /* platform_thread_posix.cc in Sources */, + B5CB32EA0EAFCD3F00DF65F1 /* process_util_mac.mm in Sources */, 7BD8F4A10E65AA4600034DE9 /* process_util_posix.cc in Sources */, 824654DF0DC26521007C2BAA /* prtime.cc in Sources */, 4D11B59A0E91730200EF7617 /* rand_util.cc in Sources */, @@ -1478,6 +1485,7 @@ 7BAE30E60E6D939F00C3F750 /* simple_thread_unittest.cc in Sources */, 7B78D39C0E54FE0100609465 /* singleton_unittest.cc in Sources */, 7B78D39D0E54FE0100609465 /* stack_container_unittest.cc in Sources */, + B5CB32AD0EAFC47900DF65F1 /* stats_table_unittest.cc in Sources */, 7B78D39E0E54FE0100609465 /* string_escape_unittest.cc in Sources */, 7B78D39F0E54FE0100609465 /* string_piece_unittest.cc in Sources */, 7B78D3A00E54FE0100609465 /* string_tokenizer_unittest.cc in Sources */, diff --git a/base/multiprocess_test.h b/base/multiprocess_test.h index 15085d9..fb02107 100644 --- a/base/multiprocess_test.h +++ b/base/multiprocess_test.h @@ -6,6 +6,7 @@ #define BASE_MULTIPROCESS_TEST_H__ #include "base/command_line.h" +#include "base/platform_test.h" #include "base/process_util.h" #include "base/string_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -30,11 +31,11 @@ static const wchar_t kRunClientProcess[] = L"client"; // 3) Create a mainline function for the child processes // 4) Call SpawnChild("foo"), where "foo" is the name of // the function you wish to run in the child processes. -// 5) On posix, add the function's name to the list in the file +// 5) On Linux, add the function's name to the list in the file // base_unittests_exported_symbols.version // That's it! // -class MultiProcessTest : public testing::Test { +class MultiProcessTest : public PlatformTest { public: // Prototype function for a client function. Multi-process // clients must provide a callback with this signature to run. diff --git a/base/port.h b/base/port.h index 9207192..9681ce8 100644 --- a/base/port.h +++ b/base/port.h @@ -54,9 +54,12 @@ inline void va_copy(va_list& a, va_list& b) { #if defined(OS_WIN) #define API_CALL __stdcall #define DYNAMIC_EXPORT __declspec(dllexport) +#elif defined(OS_MACOSX) +#define DYNAMIC_EXPORT __attribute__((visibility("default"))) +#elif defined(OS_LINUX) +#define DYNAMIC_EXPORT #elif defined(OS_POSIX) #define API_CALL -#define DYNAMIC_EXPORT #endif #endif // BASE_PORT_H_ diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm new file mode 100644 index 0000000..942dbab --- /dev/null +++ b/base/process_util_mac.mm @@ -0,0 +1,61 @@ +// 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 "base/process_util.h" + +#import <Cocoa/Cocoa.h> +#include <spawn.h> +#include <string> +#include <sys/types.h> +#include <sys/wait.h> + +namespace process_util { + +bool LaunchApp(const std::vector<std::string>& argv, + bool wait, ProcessHandle* process_handle) { + bool retval = true; + + char* argv_copy[argv.size() + 1]; + for (size_t i = 0; i < argv.size(); i++) { + argv_copy[i] = const_cast<char*>(argv[i].c_str()); + } + argv_copy[argv.size()] = NULL; + + int pid = 0; + int spawn_succeeded = (posix_spawn(&pid, + argv_copy[0], + NULL, + NULL, + argv_copy, + NULL) == 0); + + bool process_handle_valid = pid > 0; + if (!spawn_succeeded || !process_handle_valid) { + retval = false; + } else { + if (wait) + waitpid(pid, 0, 0); + + if(process_handle) + *process_handle = pid; + } + + return retval; +} + +bool LaunchApp(const CommandLine& cl, + bool wait, bool start_hidden, ProcessHandle* process_handle) { + // TODO(playmobil): Do we need to respect the start_hidden flag? + return LaunchApp(cl.argv(), wait, process_handle); +} + +bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) { + // TODO(playmobil): Do we need to support wait_milliseconds? + int status; + waitpid(handle, &status, 0); + return WIFEXITED(status); +} + +} // namespace process_util diff --git a/base/stats_table_unittest.cc b/base/stats_table_unittest.cc index c6e53e9..3214cb5 100644 --- a/base/stats_table_unittest.cc +++ b/base/stats_table_unittest.cc @@ -17,9 +17,8 @@ using base::TimeTicks; namespace { - class StatsTableTest : public MultiProcessTest { - }; -} +class StatsTableTest : public MultiProcessTest { +}; // Open a StatsTable and verify that we can write to each of the // locations in the table. @@ -379,3 +378,4 @@ TEST_F(StatsTableTest, StatsScope) { EXPECT_EQ(2, table.GetCounterValue(L"c:bar")); } +} // namespace diff --git a/base/test_suite.h b/base/test_suite.h index 9104a54..503aeda 100644 --- a/base/test_suite.h +++ b/base/test_suite.h @@ -23,6 +23,8 @@ #elif defined(OS_LINUX) #include <dlfcn.h> #include <gtk/gtk.h> +#elif defined(OS_MACOSX) +#include <dlfcn.h> #endif class TestSuite { @@ -39,7 +41,6 @@ class TestSuite { int Run() { Initialize(); -#if defined(OS_WIN) || defined(OS_LINUX) std::wstring client_func = CommandLine().GetSwitchValue(kRunClientProcess); // Check to see if we are being run as a client process. if (!client_func.empty()) { @@ -57,13 +58,16 @@ class TestSuite { MultiProcessTest::ChildFunctionPtr func = reinterpret_cast<MultiProcessTest::ChildFunctionPtr>( dlsym(exobj, func_name.c_str())); -#endif // defined(OS_LINUX) +#elif defined(OS_MACOSX) + MultiProcessTest::ChildFunctionPtr func = + reinterpret_cast<MultiProcessTest::ChildFunctionPtr>( + dlsym(RTLD_SELF, func_name.c_str())); +#endif // defined(OS_MACOSX) if (func) return (*func)(); return -1; } -#endif // defined(OS_WIN) || defined(OS_LINUX) int result = RUN_ALL_TESTS(); Shutdown(); |