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
This commit is contained in:
kjellander@webrtc.org 2011-10-31 17:10:01 +00:00
parent 066f9e5a2f
commit 177bb523bd
7 changed files with 118 additions and 127 deletions

View File

@ -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();
};

View File

@ -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 <cstdio>
#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<double>(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"));
}

View File

@ -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;
}

View File

@ -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

View File

@ -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:

View File

@ -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 <cassert>
#include <iostream>
#ifdef _WIN32
#include <windows.h>
#include <tchar.h>
#else
#include <stdio.h>
#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();
};

View File

@ -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:*',
],