diff --git a/webrtc/base/cpumonitor.cc b/webrtc/base/cpumonitor.cc index f5c0d063a6..c881b48c5a 100644 --- a/webrtc/base/cpumonitor.cc +++ b/webrtc/base/cpumonitor.cc @@ -31,6 +31,7 @@ #if defined(WEBRTC_MAC) #include #include +#include #include #include #endif // defined(WEBRTC_MAC) @@ -224,11 +225,14 @@ float CpuSampler::GetSystemLoad() { #endif // WEBRTC_WIN #if defined(WEBRTC_MAC) + mach_port_t mach_host = mach_host_self(); host_cpu_load_info_data_t cpu_info; mach_msg_type_number_t info_count = HOST_CPU_LOAD_INFO_COUNT; - if (KERN_SUCCESS != host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, - reinterpret_cast(&cpu_info), - &info_count)) { + kern_return_t kr = host_statistics(mach_host, HOST_CPU_LOAD_INFO, + reinterpret_cast(&cpu_info), + &info_count); + mach_port_deallocate(mach_task_self(), mach_host); + if (KERN_SUCCESS != kr) { LOG(LS_ERROR) << "::host_statistics() failed"; return 0.f; } diff --git a/webrtc/base/gunit.h b/webrtc/base/gunit.h index 9766c2c3a8..6d9c06fef0 100644 --- a/webrtc/base/gunit.h +++ b/webrtc/base/gunit.h @@ -19,11 +19,6 @@ #include "testing/base/public/gunit.h" #endif -// forward declarations -namespace rtc { -class Pathname; -} - // Wait until "ex" is true, or "timeout" expires. #define WAIT(ex, timeout) \ for (uint32 start = rtc::Time(); \ @@ -90,6 +85,4 @@ class Pathname; } \ } while (0); -rtc::Pathname GetTalkDirectory(); - #endif // WEBRTC_BASE_GUNIT_H_ diff --git a/webrtc/base/testutils.h b/webrtc/base/testutils.h index a148d91618..74fed45cdf 100644 --- a/webrtc/base/testutils.h +++ b/webrtc/base/testutils.h @@ -28,6 +28,7 @@ #include "webrtc/base/common.h" #include "webrtc/base/gunit.h" #include "webrtc/base/nethelpers.h" +#include "webrtc/base/pathutils.h" #include "webrtc/base/stream.h" #include "webrtc/base/stringencode.h" #include "webrtc/base/stringutils.h" @@ -434,6 +435,30 @@ inline bool ReadFile(const char* filename, std::string* contents) { return success; } +// Look in parent dir for parallel directory. +inline rtc::Pathname GetSiblingDirectory( + const std::string& parallel_dir) { + rtc::Pathname path = rtc::Filesystem::GetCurrentDirectory(); + while (!path.empty()) { + rtc::Pathname potential_parallel_dir = path; + potential_parallel_dir.AppendFolder(parallel_dir); + if (rtc::Filesystem::IsFolder(potential_parallel_dir)) { + return potential_parallel_dir; + } + + path.SetFolder(path.parent_folder()); + } + return path; +} + +inline rtc::Pathname GetGoogle3Directory() { + return GetSiblingDirectory("google3"); +} + +inline rtc::Pathname GetTalkDirectory() { + return GetSiblingDirectory("talk"); +} + /////////////////////////////////////////////////////////////////////////////// // Unittest predicates which are similar to STREQ, but for raw memory /////////////////////////////////////////////////////////////////////////////// diff --git a/webrtc/base/unittest_main.cc b/webrtc/base/unittest_main.cc index 7c4630e3c6..5d412d5ed5 100644 --- a/webrtc/base/unittest_main.cc +++ b/webrtc/base/unittest_main.cc @@ -18,7 +18,6 @@ #include "webrtc/base/fileutils.h" #include "webrtc/base/gunit.h" #include "webrtc/base/logging.h" -#include "webrtc/base/pathutils.h" DEFINE_bool(help, false, "prints this message"); DEFINE_string(log, "", "logging options to use"); @@ -53,28 +52,6 @@ int TestCrtReportHandler(int report_type, char* msg, int* retval) { } #endif // WEBRTC_WIN -rtc::Pathname GetTalkDirectory() { - // Locate talk directory. - rtc::Pathname path = rtc::Filesystem::GetCurrentDirectory(); - std::string talk_folder_name("talk"); - talk_folder_name += path.folder_delimiter(); - while (path.folder_name() != talk_folder_name && !path.empty()) { - path.SetFolder(path.parent_folder()); - } - - // If not running inside "talk" folder, then assume running in its parent - // folder. - if (path.empty()) { - path = rtc::Filesystem::GetCurrentDirectory(); - path.AppendFolder("talk"); - // Make sure the folder exist. - if (!rtc::Filesystem::IsFolder(path)) { - path.clear(); - } - } - return path; -} - int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, false);