Clean data races from system_wrappers_unittests.

- Remove unittest_utilities that are not used.
 - Remove SetLevelFilter that does not seems necessary and anyhow was racy.

BUG=3549
R=henrike@webrtc.org, henrike

Review URL: https://webrtc-codereview.appspot.com/16819004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6617 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andresp@webrtc.org 2014-07-07 20:37:39 +00:00
parent 285e9bc84d
commit 3c637cdaa5
6 changed files with 2 additions and 133 deletions

View File

@ -14,13 +14,11 @@
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
#include "webrtc/system_wrappers/interface/trace.h"
#include "webrtc/system_wrappers/source/unittest_utilities.h"
namespace webrtc {
namespace {
const int kLogTrace = false; // Set to true to enable debug logging to stdout.
const int kLongWaitMs = 100 * 1000; // A long time in testing terms
const int kShortWaitMs = 2 * 1000; // Long enough for process switches to happen
@ -143,9 +141,7 @@ bool WaitingRunFunction(void* obj) {
class CondVarTest : public ::testing::Test {
public:
CondVarTest()
: trace_(kLogTrace) {
}
CondVarTest() {}
virtual void SetUp() {
thread_ = ThreadWrapper::CreateThread(&WaitingRunFunction,
@ -171,7 +167,6 @@ class CondVarTest : public ::testing::Test {
Baton baton_;
private:
ScopedTracing trace_;
ThreadWrapper* thread_;
};

View File

@ -14,14 +14,11 @@
#include "webrtc/system_wrappers/interface/sleep.h"
#include "webrtc/system_wrappers/interface/thread_wrapper.h"
#include "webrtc/system_wrappers/interface/trace.h"
#include "webrtc/system_wrappers/source/unittest_utilities.h"
namespace webrtc {
namespace {
const bool kLogTrace = false; // Set to true to enable debug logging to stdout.
// Cause a process switch. Needed to avoid depending on
// busy-wait in tests.
static void SwitchProcess() {
@ -54,8 +51,7 @@ private:
class CritSectTest : public ::testing::Test {
public:
CritSectTest() : trace_(kLogTrace) {
}
CritSectTest() {}
// Waits a number of cycles for the count to reach a given value.
// Returns true if the target is reached or passed.
@ -70,9 +66,6 @@ public:
}
return (count->Count() >= target);
}
private:
ScopedTracing trace_;
};
bool LockUnlockThenStopRunFunction(void* obj) {

View File

@ -46,8 +46,6 @@ class LoggingTest : public ::testing::Test, public TraceCallback {
void SetUp() {
Trace::CreateTrace();
Trace::SetTraceCallback(this);
// Reduce the chance that spurious traces will ruin the test.
Trace::set_level_filter(kTraceWarning | kTraceError);
}
void TearDown() {

View File

@ -35,7 +35,6 @@
'stl_util_unittest.cc',
'thread_unittest.cc',
'thread_posix_unittest.cc',
'unittest_utilities_unittest.cc',
],
'conditions': [
['enable_data_logging==1', {

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2012 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.
*/
#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_UNITTEST_UTILITIES_H_
#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_UNITTEST_UTILITIES_H_
// This file contains utilities that make it simpler to write unittests
// that are appropriate for the system_wrappers classes.
#include <stdio.h>
#include <string.h>
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
class TestTraceCallback : public TraceCallback {
public:
virtual void Print(TraceLevel level, const char* msg, int length) {
if (msg) {
char* cmd_print = new char[length+1];
memcpy(cmd_print, msg, length);
cmd_print[length] = '\0';
printf("%s\n", cmd_print);
fflush(stdout);
delete[] cmd_print;
}
}
};
// A class that turns on tracing to stdout at the beginning of the test,
// and turns it off once the test is finished.
// Intended usage:
// class SomeTest : public ::testing::Test {
// protected:
// SomeTest()
// : trace_(false) {} // Change to true to turn on tracing.
// private:
// ScopedTracing trace_;
// }
class ScopedTracing {
public:
explicit ScopedTracing(bool logOn) {
logging_ = logOn;
StartTrace();
}
~ScopedTracing() {
StopTrace();
}
private:
void StartTrace() {
if (logging_) {
Trace::CreateTrace();
Trace::set_level_filter(webrtc::kTraceAll);
Trace::SetTraceCallback(&trace_);
}
}
void StopTrace() {
if (logging_) {
Trace::SetTraceCallback(NULL);
Trace::ReturnTrace();
}
}
private:
bool logging_;
TestTraceCallback trace_;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_UNITTEST_UTILITIES_H_

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012 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 "webrtc/system_wrappers/source/unittest_utilities.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/system_wrappers/interface/trace.h"
namespace webrtc {
// These tests merely check that the code compiles and that no
// fatal accidents happen when logging.
TEST(UnittestUtilities, TraceOn) {
ScopedTracing trace(true);
WEBRTC_TRACE(kTraceInfo, kTraceUtility, 0, "Log line that should appear");
// TODO(hta): Verify that output appears.
// Note - output is written on another thread, so can take time to appear.
}
TEST(UnittestUtilities, TraceOff) {
ScopedTracing trace(false);
WEBRTC_TRACE(kTraceInfo, kTraceUtility, 0,
"Log line that should not appear");
// TODO(hta): Verify that no output appears.
}
} // namespace webrtc