From 177bb523bdd368e07c2461ac5fc04891b85ef1f2 Mon Sep 17 00:00:00 2001 From: "kjellander@webrtc.org" Date: Mon, 31 Oct 2011 17:10:01 +0000 Subject: [PATCH] Fixing system_wrappers unittests. Not complete, but enough to include them in the build again. Review URL: http://webrtc-codereview.appspot.com/241008 git-svn-id: http://webrtc.googlecode.com/svn/trunk@842 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../source/cpu_wrapper_unittest.cc | 43 ++++++++++++ .../source/data_log_unittest_disabled.cc | 55 ++++++++++++++++ src/system_wrappers/source/list_unittest.cc | 10 --- .../source/system_wrappers.gyp | 23 +++++-- .../source/system_wrappers_tests.gyp | 47 -------------- src/system_wrappers/test/Test.cpp | 65 ------------------- webrtc.gyp | 2 +- 7 files changed, 118 insertions(+), 127 deletions(-) create mode 100644 src/system_wrappers/source/cpu_wrapper_unittest.cc create mode 100644 src/system_wrappers/source/data_log_unittest_disabled.cc delete mode 100644 src/system_wrappers/source/system_wrappers_tests.gyp delete mode 100644 src/system_wrappers/test/Test.cpp diff --git a/src/system_wrappers/source/cpu_wrapper_unittest.cc b/src/system_wrappers/source/cpu_wrapper_unittest.cc new file mode 100644 index 0000000000..16f6fe1b9d --- /dev/null +++ b/src/system_wrappers/source/cpu_wrapper_unittest.cc @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "system_wrappers/interface/cpu_wrapper.h" + +#include "gtest/gtest.h" +#include "system_wrappers/interface/trace.h" + +using webrtc::CpuWrapper; +using webrtc::Trace; + +// Only utilizes some of the cpu_wrapper.h code. Does not very anything except +// that it doesn't crash. +// TODO(kjellander): Improve this test so it verifies the implementation +// executes as expected. +TEST(CpuWrapperTest, Usage) { + Trace::CreateTrace(); + Trace::SetTraceFile("cpu_wrapper_unittest.txt"); + Trace::SetLevelFilter(webrtc::kTraceAll); + printf("Number of cores detected:%u\n", CpuWrapper::DetectNumberOfCores()); + CpuWrapper* cpu = CpuWrapper::CreateCpu(); + WebRtc_UWord32 numCores; + WebRtc_UWord32* cores; + for (int i = 0; i < 10; i++) { + WebRtc_Word32 total = cpu->CpuUsageMultiCore(numCores, cores); + + printf("\nNumCores:%d\n", numCores); + printf("Total cpu:%d\n", total); + + for (WebRtc_UWord32 i = 0; i < numCores; i++) { + printf("Core:%u CPU:%u \n", i, cores[i]); + } + } + delete cpu; + Trace::ReturnTrace(); +}; diff --git a/src/system_wrappers/source/data_log_unittest_disabled.cc b/src/system_wrappers/source/data_log_unittest_disabled.cc new file mode 100644 index 0000000000..9d630b6ba5 --- /dev/null +++ b/src/system_wrappers/source/data_log_unittest_disabled.cc @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "system_wrappers/interface/data_log.h" + +#include + +#include "gtest/gtest.h" + +using ::webrtc::DataLog; + +const char* kDataLogFileName = "table_1.txt"; + +void PerformLogging(std::string table_name) { + // Simulate normal DataTable logging behavior using this table name. + ASSERT_EQ(0, DataLog::AddTable(table_name)); + ASSERT_EQ(0, DataLog::AddColumn(table_name, "test", 1)); + for (int i = 0; i < 10; ++i) { + // TODO(kjellander): Check InsertCell result when the DataLog dummy is + // fixed. + DataLog::InsertCell(table_name, "test", static_cast(i)); + ASSERT_EQ(0, DataLog::NextRow(table_name)); + } +} + +// Simple test to verify DataLog is still working when the GYP variable +// enable_data_logging==0 (the default case). +TEST(TestDataLogDisabled, VerifyLoggingWorks) { + ASSERT_EQ(0, DataLog::CreateLog()); + // Generate a table_name name and assure it's an empty string + // (dummy behavior). + std::string table_name = DataLog::Combine("table", 1); + ASSERT_EQ("", table_name); + PerformLogging(table_name); + DataLog::ReturnLog(); +} + +TEST(TestDataLogDisabled, EnsureNoFileIsWritten) { + // Remove any previous data files on disk: + std::remove(kDataLogFileName); + ASSERT_EQ(0, DataLog::CreateLog()); + // Don't use the table name we would get from Combine on a disabled DataLog. + // Use "table_1" instead (which is what an enabled DataLog would give us). + PerformLogging("table_1"); + DataLog::ReturnLog(); + // Verify no data log file have been written: + ASSERT_EQ(NULL, fopen(kDataLogFileName, "r")); +} diff --git a/src/system_wrappers/source/list_unittest.cc b/src/system_wrappers/source/list_unittest.cc index fde82e9a07..5000eeef89 100644 --- a/src/system_wrappers/source/list_unittest.cc +++ b/src/system_wrappers/source/list_unittest.cc @@ -463,13 +463,3 @@ TEST(ListWrapperTest,InterLeaveTestII) { ASSERT_TRUE(CompareLists(interleaved_list,interleave_list)); } - -int main(int argc, char **argv) -{ - ::testing::InitGoogleTest(&argc, argv); - // Added return_value so that it's convenient to put a breakpoint before - // exiting please note that the return value from RUN_ALL_TESTS() must - // be returned by the main function. - const int return_value = RUN_ALL_TESTS(); - return return_value; -} diff --git a/src/system_wrappers/source/system_wrappers.gyp b/src/system_wrappers/source/system_wrappers.gyp index 02221df967..3eabc4edf2 100644 --- a/src/system_wrappers/source/system_wrappers.gyp +++ b/src/system_wrappers/source/system_wrappers.gyp @@ -144,17 +144,32 @@ ] # conditions }, ], # targets - 'conditions': [ + 'conditions': [ ['build_with_chromium==0', { 'targets': [ { - 'target_name': 'system_wrappersTest', + 'target_name': 'system_wrappers_unittests', 'type': 'executable', 'dependencies': [ - 'system_wrappers' + 'system_wrappers', + '<(webrtc_root)/../testing/gtest.gyp:gtest', + '<(webrtc_root)/../test/test.gyp:test_support', ], 'sources': [ - '../test/Test.cpp', + 'cpu_wrapper_unittest.cc', + 'list_unittest.cc', + 'map_unittest.cc', + 'data_log_helpers_unittest.cc', + 'data_log_c_helpers_unittest.c', + 'data_log_c_helpers_unittest.h', + '<(webrtc_root)/../test/run_all_unittests.cc', + ], + 'conditions': [ + ['enable_data_logging==1', { + 'sources': [ 'data_log_unittest.cc', ], + }, { + 'sources': [ 'data_log_unittest_disabled.cc', ], + }], ], }, ], # targets diff --git a/src/system_wrappers/source/system_wrappers_tests.gyp b/src/system_wrappers/source/system_wrappers_tests.gyp deleted file mode 100644 index 6c126301aa..0000000000 --- a/src/system_wrappers/source/system_wrappers_tests.gyp +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. -# -# Use of this source code is governed by a BSD-style license -# that can be found in the LICENSE file in the root of the source -# tree. An additional intellectual property rights grant can be found -# in the file PATENTS. All contributing project authors may -# be found in the AUTHORS file in the root of the source tree. - -{ - 'includes': [ - '../../common_settings.gypi', - ], - 'targets': [ - { - 'target_name': 'unittest', - 'type': 'executable', - 'dependencies': [ - '../../system_wrappers/source/system_wrappers.gyp:system_wrappers', - '../../../testing/gtest.gyp:gtest', - '../../../testing/gtest.gyp:gtest_main', - ], - 'include_dirs': [ - '../../../testing/gtest/include', - ], - 'sources': [ - 'list_unittest.cc', - 'map_unittest.cc', - 'data_log_helpers_unittest.cc', - 'data_log_c_helpers_unittest.c', - 'data_log_c_helpers_unittest.h', - ], - 'conditions': [ - ['enable_data_logging==1', { - 'sources': [ - 'data_log_unittest.cc', - ], - },], - ], - }, - ], -} - -# Local Variables: -# tab-width:2 -# indent-tabs-mode:nil -# End: -# vim: set expandtab tabstop=2 shiftwidth=2: diff --git a/src/system_wrappers/test/Test.cpp b/src/system_wrappers/test/Test.cpp deleted file mode 100644 index 7a34166b0d..0000000000 --- a/src/system_wrappers/test/Test.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include -#include - -#ifdef _WIN32 - #include - #include -#else - #include - #define Sleep(x) usleep(x*1000) -#endif - -#include "common_types.h" -#include "trace.h" -#include "cpu_wrapper.h" - - -#ifdef _WIN32 -int _tmain(int argc, _TCHAR* argv[]) -#else -int main(int argc, char* argv[]) -#endif -{ - Trace::CreateTrace(); - Trace::SetTraceFile("testTrace.txt"); - Trace::SetLevelFilter(webrtc::kTraceAll); - - printf("Start system wrapper test\n"); - - printf("Number of cores detected:%u\n", (unsigned int)CpuWrapper::DetectNumberOfCores()); - - CpuWrapper* cpu = CpuWrapper::CreateCpu(); - - WebRtc_UWord32 numCores; - WebRtc_UWord32* cores; - - for(int i = 0; i< 10;i++) - { - WebRtc_Word32 total = cpu->CpuUsageMultiCore(numCores, cores); - - printf("\nNumCores:%d\n", (int)numCores); - printf("Total cpu:%d\n", (int)total); - - for (WebRtc_UWord32 i = 0; i< numCores;i++) - { - printf("Core:%lu CPU:%lu \n", i, cores[i]); - } - Sleep(1000); - } - - printf("Done system wrapper test\n"); - - delete cpu; - - Trace::ReturnTrace(); -}; diff --git a/webrtc.gyp b/webrtc.gyp index fe97e8fafd..878870e84a 100644 --- a/webrtc.gyp +++ b/webrtc.gyp @@ -19,7 +19,7 @@ # TODO(andrew): enable these when all tests build. #'src/common_video/common_video.gyp:*', #'src/modules/modules.gyp:*', - #'src/system_wrappers/source/system_wrappers.gyp:*', + 'src/system_wrappers/source/system_wrappers.gyp:*', 'src/video_engine/video_engine.gyp:*', 'src/voice_engine/voice_engine.gyp:*', ],