Index: webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc |
diff --git a/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc b/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc |
index b82643057d65ec85adb26615411dd24ac032606b..6aaf2c3bbd2d7a096ed814616a64f031da824db6 100644 |
--- a/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc |
+++ b/webrtc/modules/audio_processing/audio_processing_impl_locking_unittest.cc |
@@ -16,11 +16,11 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
#include "webrtc/base/array_view.h" |
#include "webrtc/base/criticalsection.h" |
+#include "webrtc/base/event.h" |
#include "webrtc/base/platform_thread.h" |
#include "webrtc/config.h" |
#include "webrtc/modules/audio_processing/test/test_utils.h" |
#include "webrtc/modules/include/module_common_types.h" |
-#include "webrtc/system_wrappers/include/event_wrapper.h" |
#include "webrtc/system_wrappers/include/sleep.h" |
#include "webrtc/test/random.h" |
@@ -299,31 +299,12 @@ class FrameCounters { |
int capture_count GUARDED_BY(crit_) = 0; |
}; |
-// Checker for whether the capture side has been called. |
-class CaptureSideCalledChecker { |
- public: |
- bool CaptureSideCalled() { |
- rtc::CritScope cs(&crit_); |
- return capture_side_called_; |
- } |
- |
- void FlagCaptureSideCalled() { |
- rtc::CritScope cs(&crit_); |
- capture_side_called_ = true; |
- } |
- |
- private: |
- rtc::CriticalSection crit_; |
- bool capture_side_called_ GUARDED_BY(crit_) = false; |
-}; |
- |
// Class for handling the capture side processing. |
class CaptureProcessor { |
public: |
CaptureProcessor(int max_frame_size, |
RandomGenerator* rand_gen, |
FrameCounters* shared_counters_state, |
- CaptureSideCalledChecker* capture_call_checker, |
AudioProcessingImplLockTest* test_framework, |
TestConfig* test_config, |
AudioProcessing* apm); |
@@ -340,7 +321,6 @@ class CaptureProcessor { |
RandomGenerator* rand_gen_ = nullptr; |
FrameCounters* frame_counters_ = nullptr; |
- CaptureSideCalledChecker* capture_call_checker_ = nullptr; |
AudioProcessingImplLockTest* test_ = nullptr; |
TestConfig* test_config_ = nullptr; |
AudioProcessing* apm_ = nullptr; |
@@ -367,7 +347,6 @@ class RenderProcessor { |
RenderProcessor(int max_frame_size, |
RandomGenerator* rand_gen, |
FrameCounters* shared_counters_state, |
- CaptureSideCalledChecker* capture_call_checker, |
AudioProcessingImplLockTest* test_framework, |
TestConfig* test_config, |
AudioProcessing* apm); |
@@ -384,20 +363,22 @@ class RenderProcessor { |
RandomGenerator* rand_gen_ = nullptr; |
FrameCounters* frame_counters_ = nullptr; |
- CaptureSideCalledChecker* capture_call_checker_ = nullptr; |
AudioProcessingImplLockTest* test_ = nullptr; |
TestConfig* test_config_ = nullptr; |
AudioProcessing* apm_ = nullptr; |
- bool first_render_side_call_ = true; |
AudioFrameData frame_data_; |
+ bool first_render_call_ = true; |
}; |
class AudioProcessingImplLockTest |
: public ::testing::TestWithParam<TestConfig> { |
public: |
AudioProcessingImplLockTest(); |
- EventTypeWrapper RunTest(); |
- void CheckTestCompleteness(); |
+ bool RunTest(); |
+ bool MaybeEndTest(); |
+ |
+ rtc::Event& get_render_call_event() { return render_call_event_; } |
pbos-webrtc
2015/12/02 13:01:12
no non-const references allowed (googlestyle), use
pbos-webrtc
2015/12/02 13:01:12
remove get_ prefix
peah-webrtc
2015/12/02 15:02:27
Thanks! I revised this according to your feedback
peah-webrtc
2015/12/02 15:02:27
Acknowledged.
|
+ rtc::Event& get_capture_call_event() { return capture_call_event_; } |
private: |
static const int kTestTimeOutLimit = 10 * 60 * 1000; |
@@ -442,8 +423,10 @@ class AudioProcessingImplLockTest |
stats_thread_.SetPriority(rtc::kNormalPriority); |
} |
- // Event handler for the test. |
- const rtc::scoped_ptr<EventWrapper> test_complete_; |
+ // Event handlers for the test. |
+ rtc::Event test_complete_; |
+ rtc::Event render_call_event_; |
+ rtc::Event capture_call_event_; |
// Thread related variables. |
rtc::PlatformThread render_thread_; |
@@ -454,7 +437,6 @@ class AudioProcessingImplLockTest |
rtc::scoped_ptr<AudioProcessing> apm_; |
TestConfig test_config_; |
FrameCounters frame_counters_; |
- CaptureSideCalledChecker capture_call_checker_; |
RenderProcessor render_thread_state_; |
CaptureProcessor capture_thread_state_; |
StatsProcessor stats_thread_state_; |
@@ -497,7 +479,9 @@ void PopulateAudioFrame(AudioFrame* frame, |
} |
AudioProcessingImplLockTest::AudioProcessingImplLockTest() |
- : test_complete_(EventWrapper::Create()), |
+ : test_complete_(rtc::Event(false, false)), |
pbos-webrtc
2015/12/02 13:01:12
remove rtc::Event here and below (no copy-construc
peah-webrtc
2015/12/02 15:02:27
Done.
|
+ render_call_event_(rtc::Event(false, false)), |
+ capture_call_event_(rtc::Event(false, false)), |
render_thread_(RenderProcessorThreadFunc, this, "render"), |
capture_thread_(CaptureProcessorThreadFunc, this, "capture"), |
stats_thread_(StatsProcessorThreadFunc, this, "stats"), |
@@ -505,29 +489,29 @@ AudioProcessingImplLockTest::AudioProcessingImplLockTest() |
render_thread_state_(kMaxFrameSize, |
&rand_gen_, |
&frame_counters_, |
- &capture_call_checker_, |
this, |
&test_config_, |
apm_.get()), |
capture_thread_state_(kMaxFrameSize, |
&rand_gen_, |
&frame_counters_, |
- &capture_call_checker_, |
this, |
&test_config_, |
apm_.get()), |
stats_thread_state_(&rand_gen_, &test_config_, apm_.get()) {} |
// Run the test with a timeout. |
-EventTypeWrapper AudioProcessingImplLockTest::RunTest() { |
+bool AudioProcessingImplLockTest::RunTest() { |
StartThreads(); |
- return test_complete_->Wait(kTestTimeOutLimit); |
+ return test_complete_.Wait(kTestTimeOutLimit); |
} |
-void AudioProcessingImplLockTest::CheckTestCompleteness() { |
+bool AudioProcessingImplLockTest::MaybeEndTest() { |
if (HasFatalFailure() || TestDone()) { |
- test_complete_->Set(); |
+ test_complete_.Set(); |
+ return true; |
} |
+ return false; |
} |
// Setup of test and APM. |
@@ -572,6 +556,8 @@ void AudioProcessingImplLockTest::SetUp() { |
} |
void AudioProcessingImplLockTest::TearDown() { |
+ render_call_event_.Set(); |
+ capture_call_event_.Set(); |
render_thread_.Stop(); |
capture_thread_.Stop(); |
stats_thread_.Stop(); |
@@ -613,13 +599,11 @@ CaptureProcessor::CaptureProcessor( |
int max_frame_size, |
RandomGenerator* rand_gen, |
FrameCounters* shared_counters_state, |
- CaptureSideCalledChecker* capture_call_checker, |
AudioProcessingImplLockTest* test_framework, |
TestConfig* test_config, |
pbos-webrtc
2015/12/02 13:01:12
supply events on construction instead of having th
peah-webrtc
2015/12/02 15:02:27
Done.
|
AudioProcessing* apm) |
: rand_gen_(rand_gen), |
frame_counters_(shared_counters_state), |
- capture_call_checker_(capture_call_checker), |
test_(test_framework), |
test_config_(test_config), |
apm_(apm), |
@@ -630,15 +614,11 @@ bool CaptureProcessor::Process() { |
// Sleep a random time to simulate thread jitter. |
SleepRandomMs(3, rand_gen_); |
- // End the test if complete. |
- test_->CheckTestCompleteness(); |
- |
// Ensure that there are not more capture side calls than render side |
// calls. |
- if (capture_call_checker_->CaptureSideCalled()) { |
- while (kMaxCallDifference < frame_counters_->CaptureMinusRenderCounters()) { |
- SleepMs(1); |
- } |
+ while (!test_->MaybeEndTest() && |
+ frame_counters_->CaptureMinusRenderCounters() > kMaxCallDifference) { |
+ test_->get_render_call_event().Wait(1); |
} |
// Apply any specified capture side APM non-processing runtime calls. |
@@ -650,11 +630,8 @@ bool CaptureProcessor::Process() { |
// Increase the number of capture-side calls. |
frame_counters_->IncreaseCaptureCounter(); |
- // Flag that the capture side has been called at least once |
- // (needed to ensure that a capture call has been done |
- // before the first render call is performed (implicitly |
- // required by the APM API). |
- capture_call_checker_->FlagCaptureSideCalled(); |
+ // Set api call flag. |
+ test_->get_capture_call_event().Set(); |
return true; |
} |
@@ -874,13 +851,11 @@ const float RenderProcessor::kRenderInputFloatLevel = 0.5f; |
RenderProcessor::RenderProcessor(int max_frame_size, |
RandomGenerator* rand_gen, |
FrameCounters* shared_counters_state, |
- CaptureSideCalledChecker* capture_call_checker, |
AudioProcessingImplLockTest* test_framework, |
TestConfig* test_config, |
AudioProcessing* apm) |
: rand_gen_(rand_gen), |
frame_counters_(shared_counters_state), |
- capture_call_checker_(capture_call_checker), |
test_(test_framework), |
test_config_(test_config), |
apm_(apm), |
@@ -891,24 +866,19 @@ bool RenderProcessor::Process() { |
// Conditional wait to ensure that a capture call has been done |
// before the first render call is performed (implicitly |
// required by the APM API). |
- if (first_render_side_call_) { |
- while (!capture_call_checker_->CaptureSideCalled()) { |
- SleepRandomMs(3, rand_gen_); |
- } |
- |
- first_render_side_call_ = false; |
+ if (first_render_call_) { |
+ test_->get_capture_call_event().Wait(rtc::Event::kForever); |
+ first_render_call_ = false; |
} |
// Sleep a random time to simulate thread jitter. |
SleepRandomMs(3, rand_gen_); |
- // End the test early if a fatal failure (ASSERT_*) has occurred. |
- test_->CheckTestCompleteness(); |
- |
// Ensure that the number of render and capture calls do not |
// differ too much. |
- while (kMaxCallDifference < -frame_counters_->CaptureMinusRenderCounters()) { |
- SleepMs(1); |
+ while (!test_->MaybeEndTest() && |
+ -frame_counters_->CaptureMinusRenderCounters() > kMaxCallDifference) { |
pbos-webrtc
2015/12/02 13:01:12
document the unary minus, or a function that's ren
peah-webrtc
2015/12/02 15:02:27
Good point!
I instead created a function for that.
|
+ test_->get_capture_call_event().Wait(1); |
} |
// Apply any specified render side APM non-processing runtime calls. |
@@ -920,6 +890,8 @@ bool RenderProcessor::Process() { |
// Increase the number of render-side calls. |
frame_counters_->IncreaseRenderCounter(); |
+ // Set api call flag. |
pbos-webrtc
2015/12/02 13:01:12
put in comment what this should do/trigger
peah-webrtc
2015/12/02 15:02:27
Done.
|
+ test_->get_render_call_event().Set(); |
return true; |
} |
@@ -1114,7 +1086,7 @@ void RenderProcessor::ApplyRuntimeSettingScheme() { |
TEST_P(AudioProcessingImplLockTest, LockTest) { |
// Run test and verify that it did not time out. |
- ASSERT_EQ(kEventSignaled, RunTest()); |
+ ASSERT_EQ(true, RunTest()); |
pbos-webrtc
2015/12/02 13:01:12
ASSERT_TRUE(RunTest())
peah-webrtc
2015/12/02 15:02:27
Done.
|
} |
// Instantiate tests from the extreme test configuration set. |