OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a | 5 // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a |
6 // heavily-loaded system). Sorry. |test::EpsilonDeadline()| may be increased to | 6 // heavily-loaded system). Sorry. |test::EpsilonDeadline()| may be increased to |
7 // increase tolerance and reduce observed flakiness (though doing so reduces the | 7 // increase tolerance and reduce observed flakiness (though doing so reduces the |
8 // meaningfulness of the test). | 8 // meaningfulness of the test). |
9 | 9 |
10 #include "mojo/edk/system/simple_dispatcher.h" | 10 #include "mojo/edk/system/simple_dispatcher.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 namespace mojo { | 22 namespace mojo { |
23 namespace system { | 23 namespace system { |
24 namespace { | 24 namespace { |
25 | 25 |
26 class MockSimpleDispatcher final : public SimpleDispatcher { | 26 class MockSimpleDispatcher final : public SimpleDispatcher { |
27 public: | 27 public: |
28 MockSimpleDispatcher() | 28 MockSimpleDispatcher() |
29 : state_(MOJO_HANDLE_SIGNAL_NONE, | 29 : state_(MOJO_HANDLE_SIGNAL_NONE, |
30 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE) {} | 30 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE) {} |
31 explicit MockSimpleDispatcher(const HandleSignalsState& state) | |
32 : state_(state) {} | |
33 | 31 |
34 void SetSatisfiedSignals(MojoHandleSignals new_satisfied_signals) { | 32 void SetSatisfiedSignals(MojoHandleSignals new_satisfied_signals) { |
35 MutexLocker locker(&mutex()); | 33 base::AutoLock locker(lock()); |
36 | 34 |
37 // Any new signals that are set should be satisfiable. | 35 // Any new signals that are set should be satisfiable. |
38 CHECK_EQ(new_satisfied_signals & ~state_.satisfied_signals, | 36 CHECK_EQ(new_satisfied_signals & ~state_.satisfied_signals, |
39 new_satisfied_signals & ~state_.satisfied_signals & | 37 new_satisfied_signals & ~state_.satisfied_signals & |
40 state_.satisfiable_signals); | 38 state_.satisfiable_signals); |
41 | 39 |
42 if (new_satisfied_signals == state_.satisfied_signals) | 40 if (new_satisfied_signals == state_.satisfied_signals) |
43 return; | 41 return; |
44 | 42 |
45 state_.satisfied_signals = new_satisfied_signals; | 43 state_.satisfied_signals = new_satisfied_signals; |
46 HandleSignalsStateChangedNoLock(); | 44 HandleSignalsStateChangedNoLock(); |
47 } | 45 } |
48 | 46 |
49 void SetSatisfiableSignals(MojoHandleSignals new_satisfiable_signals) { | 47 void SetSatisfiableSignals(MojoHandleSignals new_satisfiable_signals) { |
50 MutexLocker locker(&mutex()); | 48 base::AutoLock locker(lock()); |
51 | 49 |
52 // Satisfied implies satisfiable. | 50 // Satisfied implies satisfiable. |
53 CHECK_EQ(new_satisfiable_signals & state_.satisfied_signals, | 51 CHECK_EQ(new_satisfiable_signals & state_.satisfied_signals, |
54 state_.satisfied_signals); | 52 state_.satisfied_signals); |
55 | 53 |
56 if (new_satisfiable_signals == state_.satisfiable_signals) | 54 if (new_satisfiable_signals == state_.satisfiable_signals) |
57 return; | 55 return; |
58 | 56 |
59 state_.satisfiable_signals = new_satisfiable_signals; | 57 state_.satisfiable_signals = new_satisfiable_signals; |
60 HandleSignalsStateChangedNoLock(); | 58 HandleSignalsStateChangedNoLock(); |
61 } | 59 } |
62 | 60 |
63 Type GetType() const override { return Type::UNKNOWN; } | 61 Type GetType() const override { return Type::UNKNOWN; } |
64 | 62 |
65 private: | 63 private: |
66 friend class base::RefCountedThreadSafe<MockSimpleDispatcher>; | 64 friend class base::RefCountedThreadSafe<MockSimpleDispatcher>; |
67 ~MockSimpleDispatcher() override {} | 65 ~MockSimpleDispatcher() override {} |
68 | 66 |
69 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() | 67 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() |
70 override { | 68 override { |
71 scoped_refptr<MockSimpleDispatcher> rv(new MockSimpleDispatcher(state_)); | 69 scoped_refptr<MockSimpleDispatcher> rv(new MockSimpleDispatcher()); |
| 70 rv->state_ = state_; |
72 return scoped_refptr<Dispatcher>(rv.get()); | 71 return scoped_refptr<Dispatcher>(rv.get()); |
73 } | 72 } |
74 | 73 |
75 // |Dispatcher| override: | 74 // |Dispatcher| override: |
76 HandleSignalsState GetHandleSignalsStateImplNoLock() const override { | 75 HandleSignalsState GetHandleSignalsStateImplNoLock() const override { |
77 mutex().AssertHeld(); | 76 lock().AssertAcquired(); |
78 return state_; | 77 return state_; |
79 } | 78 } |
80 | 79 |
81 HandleSignalsState state_ MOJO_GUARDED_BY(mutex()); | 80 // Protected by |lock()|: |
| 81 HandleSignalsState state_; |
82 | 82 |
83 MOJO_DISALLOW_COPY_AND_ASSIGN(MockSimpleDispatcher); | 83 MOJO_DISALLOW_COPY_AND_ASSIGN(MockSimpleDispatcher); |
84 }; | 84 }; |
85 | 85 |
86 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
87 // http://crbug.com/396404 | 87 // http://crbug.com/396404 |
88 #define MAYBE_Basic DISABLED_Basic | 88 #define MAYBE_Basic DISABLED_Basic |
89 #else | 89 #else |
90 #define MAYBE_Basic Basic | 90 #define MAYBE_Basic Basic |
91 #endif | 91 #endif |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 // Since we closed before joining, we can't say much about what each thread | 595 // Since we closed before joining, we can't say much about what each thread |
596 // saw as the state. | 596 // saw as the state. |
597 } | 597 } |
598 } | 598 } |
599 | 599 |
600 // TODO(vtl): Stress test? | 600 // TODO(vtl): Stress test? |
601 | 601 |
602 } // namespace | 602 } // namespace |
603 } // namespace system | 603 } // namespace system |
604 } // namespace mojo | 604 } // namespace mojo |
OLD | NEW |