blob: 982e71572643e3578b9bd7732f80988331a89aae [file] [log] [blame]
henrike@webrtc.org0e7c0602012-02-08 18:53:50 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "system_wrappers/interface/trace.h"
12
13#include "gtest/gtest.h"
14#include "system_wrappers/source/cpu_measurement_harness.h"
15#include "testsupport/fileutils.h"
16
17using webrtc::CpuMeasurementHarness;
18using webrtc::Trace;
19using webrtc::kTraceWarning;
20using webrtc::kTraceUtility;
21
22class Logger : public webrtc::CpuTarget {
23 public:
24 Logger() {
25 Trace::CreateTrace();
26 std::string trace_file = webrtc::test::OutputPath() +
27 "trace_unittest.txt";
28 Trace::SetTraceFile(trace_file.c_str());
29 Trace::SetLevelFilter(webrtc::kTraceAll);
30 }
31 virtual ~Logger() {
32 Trace::ReturnTrace();
33 }
34
35 virtual bool DoWork() {
36 // Use input paremeters to WEBRTC_TRACE that are not likely to be removed
37 // in future code. E.g. warnings will likely be kept and this file is in
38 // utility so it should use kTraceUtility.
39 WEBRTC_TRACE(kTraceWarning, kTraceUtility, 0, "Log line");
40 return true;
41 }
42};
43
44// This test is disabled because it measures CPU usage. This is flaky because
45// the CPU usage for a machine may spike due to OS or other application.
46TEST(TraceTest, DISABLED_CpuUsage) {
47 Logger logger;
48 const int periodicity_ms = 1;
49 const int iterations_per_period = 10;
50 const int duration_ms = 1000;
51 CpuMeasurementHarness* cpu_harness =
52 CpuMeasurementHarness::Create(&logger, periodicity_ms,
53 iterations_per_period, duration_ms);
54 cpu_harness->Run();
55 const int average_cpu = cpu_harness->AverageCpu();
56 EXPECT_GE(5, average_cpu);
57}