aboutsummaryrefslogtreecommitdiff
path: root/src/system_wrappers/source/cpu_wrapper_unittest.cc
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2012-01-31 14:20:52 -0800
committerEric Laurent <elaurent@google.com>2012-02-02 08:57:35 -0800
commitc55a96383497a772a307b346368133960b02ad03 (patch)
tree43b7aaa9cf8b8d42d0d58e123d27e37ad96607a5 /src/system_wrappers/source/cpu_wrapper_unittest.cc
parent4b6dc1ec58105d17dc8c2f550124cc0621dc93b7 (diff)
downloadwebrtc-c55a96383497a772a307b346368133960b02ad03.tar.gz
update to webrtc revision 1349
Updated audio processing modules from revision 180 to 1349. Main changes are: - code clean up and reformating - source path reorganization - improved performance Also imported test code that was not included in initial drop from webrtc. Change-Id: Ie4eb0e29990052e5f2d7f0b271b42eead40dbb6a
Diffstat (limited to 'src/system_wrappers/source/cpu_wrapper_unittest.cc')
-rw-r--r--src/system_wrappers/source/cpu_wrapper_unittest.cc70
1 files changed, 70 insertions, 0 deletions
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..dd49c3ac94
--- /dev/null
+++ b/src/system_wrappers/source/cpu_wrapper_unittest.cc
@@ -0,0 +1,70 @@
+/*
+ * 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/cpu_info.h"
+#include "system_wrappers/interface/event_wrapper.h"
+#include "system_wrappers/interface/scoped_ptr.h"
+#include "system_wrappers/interface/trace.h"
+#include "testsupport/fileutils.h"
+
+using webrtc::CpuInfo;
+using webrtc::CpuWrapper;
+using webrtc::EventWrapper;
+using webrtc::scoped_ptr;
+using webrtc::Trace;
+
+TEST(CpuWrapperTest, Usage) {
+ Trace::CreateTrace();
+ std::string trace_file = webrtc::test::OutputPath() +
+ "cpu_wrapper_unittest.txt";
+ Trace::SetTraceFile(trace_file.c_str());
+ Trace::SetLevelFilter(webrtc::kTraceAll);
+ printf("Number of cores detected:%u\n", CpuInfo::DetectNumberOfCores());
+ scoped_ptr<CpuWrapper> cpu(CpuWrapper::CreateCpu());
+ ASSERT_TRUE(cpu.get() != NULL);
+ scoped_ptr<EventWrapper> sleep_event(EventWrapper::Create());
+ ASSERT_TRUE(sleep_event.get() != NULL);
+
+ int num_iterations = 0;
+ WebRtc_UWord32 num_cores = 0;
+ WebRtc_UWord32* cores = NULL;
+ bool cpu_usage_available = cpu->CpuUsageMultiCore(num_cores, cores) != -1;
+ // Initializing the CPU measurements may take a couple of seconds on Windows.
+ // Since the initialization is lazy we need to wait until it is completed.
+ // Should not take more than 10000 ms.
+ while (cpu_usage_available && (++num_iterations < 10000)) {
+ if (cores != NULL) {
+ ASSERT_GT(num_cores, 0u);
+ break;
+ }
+ sleep_event->Wait(1);
+ cpu_usage_available = cpu->CpuUsageMultiCore(num_cores, cores) != -1;
+ }
+ ASSERT_TRUE(cpu_usage_available);
+
+ const WebRtc_Word32 average = cpu->CpuUsageMultiCore(num_cores, cores);
+ ASSERT_TRUE(cores != NULL);
+ EXPECT_GT(num_cores, 0u);
+ EXPECT_GE(average, 0);
+ EXPECT_LE(average, 100);
+
+ printf("\nNumber of cores:%d\n", num_cores);
+ printf("Average cpu:%d\n", average);
+ for (WebRtc_UWord32 i = 0; i < num_cores; i++) {
+ printf("Core:%u CPU:%u \n", i, cores[i]);
+ EXPECT_GE(cores[i], 0u);
+ EXPECT_LE(cores[i], 100u);
+ }
+
+ Trace::ReturnTrace();
+};