diff options
author | toyoshim <toyoshim@chromium.org> | 2015-03-03 02:30:54 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-03 10:31:20 +0000 |
commit | efd39d0198de405210b6d7d5aa38aafd0bfa462c (patch) | |
tree | b110b81a25261e44048138db5af5dc56ea339a08 /media | |
parent | b5020725ac56d11c064086295af7db628b4fe64b (diff) | |
download | chromium_src-efd39d0198de405210b6d7d5aa38aafd0bfa462c.zip chromium_src-efd39d0198de405210b6d7d5aa38aafd0bfa462c.tar.gz chromium_src-efd39d0198de405210b6d7d5aa38aafd0bfa462c.tar.bz2 |
Web MIDI: speculative valgrind fix for a unit test on mac
MidiManagerMacTest.MidiNotification was marked in
valgrind/gtest_exclude/media_unittests.gtest_mac.txt.
Remove the entry with some speculative fixes.
Since the problem can not be reproduced with the latest
valgrind on Yosemite.
If this patch is not enough, let's suppress it again.
BUG=462483
TEST=media_unittests --gtest_filter=MidiManagerMacTest.MidiNotification
TEST=valgrind media_unittests --gtest_filter=MidiManagerMacTest.MidiNotification # does not hangup on yosemite
Review URL: https://codereview.chromium.org/971593002
Cr-Commit-Position: refs/heads/master@{#318860}
Diffstat (limited to 'media')
-rw-r--r-- | media/midi/midi_manager_mac_unittest.cc | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/media/midi/midi_manager_mac_unittest.cc b/media/midi/midi_manager_mac_unittest.cc index e608d7c..a74ccad 100644 --- a/media/midi/midi_manager_mac_unittest.cc +++ b/media/midi/midi_manager_mac_unittest.cc @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" +#include "base/synchronization/lock.h" #include "testing/gtest/include/gtest/gtest.h" namespace media { @@ -23,12 +24,24 @@ class FakeMidiManagerClient : public MidiManagerClient { FakeMidiManagerClient() : result_(MIDI_NOT_SUPPORTED), wait_for_result_(true), - wait_for_port_(true) {} + wait_for_port_(true), + unexpected_callback_(false) {} // MidiManagerClient implementation. void AddInputPort(const MidiPortInfo& info) override {} void AddOutputPort(const MidiPortInfo& info) override { - CHECK(!wait_for_result_); + base::AutoLock lock(lock_); + // AddOutputPort may be called before CompleteStartSession() is invoked + // if one or more MIDI devices including virtual ports are connected. + // Just ignore in such cases. + if (wait_for_result_) + return; + + // Check if this is the first call after CompleteStartSession(), and + // the case should not happen twice. + if (!wait_for_port_) + unexpected_callback_ = true; + info_ = info; wait_for_port_ = false; } @@ -36,7 +49,10 @@ class FakeMidiManagerClient : public MidiManagerClient { void SetOutputPortState(uint32 port_index, MidiPortState state) override {} void CompleteStartSession(MidiResult result) override { - EXPECT_TRUE(wait_for_result_); + base::AutoLock lock(lock_); + if (!wait_for_result_) + unexpected_callback_ = true; + result_ = result; wait_for_result_ = false; } @@ -45,26 +61,40 @@ class FakeMidiManagerClient : public MidiManagerClient { double timestamp) override {} void AccumulateMidiBytesSent(size_t size) override {} + bool GetWaitForResult() { + base::AutoLock lock(lock_); + return wait_for_result_; + } + + bool GetWaitForPort() { + base::AutoLock lock(lock_); + return wait_for_port_; + } + MidiResult WaitForResult() { - while (wait_for_result_) { + while (GetWaitForResult()) { base::RunLoop run_loop; run_loop.RunUntilIdle(); } + EXPECT_FALSE(unexpected_callback_); return result_; } MidiPortInfo WaitForPort() { - while (wait_for_port_) { + while (GetWaitForPort()) { base::RunLoop run_loop; run_loop.RunUntilIdle(); } + EXPECT_FALSE(unexpected_callback_); return info_; } private: + base::Lock lock_; MidiResult result_; bool wait_for_result_; MidiPortInfo info_; bool wait_for_port_; + bool unexpected_callback_; DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); }; |