Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: media/midi/midi_manager_mac_unittest.cc

Issue 971593002: Web MIDI: speculative valgrind fix for a unit test on mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: speculative fix Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/valgrind/gtest_exclude/media_unittests.gtest_mac.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/midi/midi_manager_mac.h" 5 #include "media/midi/midi_manager_mac.h"
6 6
7 #include <CoreMIDI/MIDIServices.h> 7 #include <CoreMIDI/MIDIServices.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/synchronization/lock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace media { 16 namespace media {
16 17
17 namespace { 18 namespace {
18 19
19 void Noop(const MIDIPacketList*, void*, void*) {} 20 void Noop(const MIDIPacketList*, void*, void*) {}
20 21
21 class FakeMidiManagerClient : public MidiManagerClient { 22 class FakeMidiManagerClient : public MidiManagerClient {
22 public: 23 public:
23 FakeMidiManagerClient() 24 FakeMidiManagerClient() {
24 : result_(MIDI_NOT_SUPPORTED), 25 base::AutoLock lock(lock_);
yhirano 2015/03/02 04:58:37 It's hard to imagine that anyone can touch a FakeM
Takashi Toyoshima 2015/03/02 10:52:18 I placed it not to avoid from racing, but for expl
25 wait_for_result_(true), 26 result_ = MIDI_NOT_SUPPORTED;
26 wait_for_port_(true) {} 27 wait_for_result_ = true;
28 wait_for_port_ = true;
29 }
27 30
28 // MidiManagerClient implementation. 31 // MidiManagerClient implementation.
29 void AddInputPort(const MidiPortInfo& info) override {} 32 void AddInputPort(const MidiPortInfo& info) override {}
30 void AddOutputPort(const MidiPortInfo& info) override { 33 void AddOutputPort(const MidiPortInfo& info) override {
31 CHECK(!wait_for_result_); 34 base::AutoLock lock(lock_);
35 // AddOutputPort may be called before CompleteStartSession() is invoked
36 // if one or more MIDI devices including virtual ports are connected.
37 // Just ignore in such cases.
38 if (wait_for_result_)
39 return;
40
41 EXPECT_TRUE(wait_for_port_);
yhirano 2015/03/02 04:58:37 This function is not called on the test thread. I'
Takashi Toyoshima 2015/03/02 10:52:17 I placed AutoLock at line 34 since wait_for_result
Takashi Toyoshima 2015/03/02 11:06:21 Oh, I misunderstood your comment. I'll check docum
32 info_ = info; 42 info_ = info;
33 wait_for_port_ = false; 43 wait_for_port_ = false;
34 } 44 }
35 void SetInputPortState(uint32 port_index, MidiPortState state) override {} 45 void SetInputPortState(uint32 port_index, MidiPortState state) override {}
36 void SetOutputPortState(uint32 port_index, MidiPortState state) override {} 46 void SetOutputPortState(uint32 port_index, MidiPortState state) override {}
37 47
38 void CompleteStartSession(MidiResult result) override { 48 void CompleteStartSession(MidiResult result) override {
49 base::AutoLock lock(lock_);
39 EXPECT_TRUE(wait_for_result_); 50 EXPECT_TRUE(wait_for_result_);
40 result_ = result; 51 result_ = result;
41 wait_for_result_ = false; 52 wait_for_result_ = false;
42 } 53 }
43 54
44 void ReceiveMidiData(uint32 port_index, const uint8* data, size_t size, 55 void ReceiveMidiData(uint32 port_index, const uint8* data, size_t size,
45 double timestamp) override {} 56 double timestamp) override {}
46 void AccumulateMidiBytesSent(size_t size) override {} 57 void AccumulateMidiBytesSent(size_t size) override {}
47 58
59 bool GetWaitForResult() {
60 base::AutoLock lock(lock_);
61 return wait_for_result_;
62 }
63
64 bool GetWaitForPort() {
65 base::AutoLock lock(lock_);
66 return wait_for_port_;
67 }
68
48 MidiResult WaitForResult() { 69 MidiResult WaitForResult() {
49 while (wait_for_result_) { 70 while (GetWaitForResult()) {
50 base::RunLoop run_loop; 71 base::RunLoop run_loop;
51 run_loop.RunUntilIdle(); 72 run_loop.RunUntilIdle();
52 } 73 }
53 return result_; 74 return result_;
54 } 75 }
55 MidiPortInfo WaitForPort() { 76 MidiPortInfo WaitForPort() {
56 while (wait_for_port_) { 77 while (GetWaitForPort()) {
57 base::RunLoop run_loop; 78 base::RunLoop run_loop;
58 run_loop.RunUntilIdle(); 79 run_loop.RunUntilIdle();
59 } 80 }
60 return info_; 81 return info_;
61 } 82 }
62 83
63 private: 84 private:
85 base::Lock lock_;
64 MidiResult result_; 86 MidiResult result_;
65 bool wait_for_result_; 87 bool wait_for_result_;
66 MidiPortInfo info_; 88 MidiPortInfo info_;
67 bool wait_for_port_; 89 bool wait_for_port_;
68 90
69 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient); 91 DISALLOW_COPY_AND_ASSIGN(FakeMidiManagerClient);
70 }; 92 };
71 93
72 class MidiManagerMacTest : public ::testing::Test { 94 class MidiManagerMacTest : public ::testing::Test {
73 public: 95 public:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 EndSession(client.get()); 139 EndSession(client.get());
118 if (ep) 140 if (ep)
119 MIDIEndpointDispose(ep); 141 MIDIEndpointDispose(ep);
120 if (midi_client) 142 if (midi_client)
121 MIDIClientDispose(midi_client); 143 MIDIClientDispose(midi_client);
122 } 144 }
123 145
124 } // namespace 146 } // namespace
125 147
126 } // namespace media 148 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/gtest_exclude/media_unittests.gtest_mac.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698