| 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::EpsilonTimeout()| may be increased to | 6 // heavily-loaded system). Sorry. |test::EpsilonTimeout()| 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/system/simple_dispatcher.h" | 10 #include "mojo/system/simple_dispatcher.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 // Any new signals that are set should be satisfiable. | 37 // Any new signals that are set should be satisfiable. |
| 38 CHECK_EQ(new_satisfied_signals & ~state_.satisfied_signals, | 38 CHECK_EQ(new_satisfied_signals & ~state_.satisfied_signals, |
| 39 new_satisfied_signals & ~state_.satisfied_signals & | 39 new_satisfied_signals & ~state_.satisfied_signals & |
| 40 state_.satisfiable_signals); | 40 state_.satisfiable_signals); |
| 41 | 41 |
| 42 if (new_satisfied_signals == state_.satisfied_signals) | 42 if (new_satisfied_signals == state_.satisfied_signals) |
| 43 return; | 43 return; |
| 44 | 44 |
| 45 state_.satisfied_signals = new_satisfied_signals; | 45 state_.satisfied_signals = new_satisfied_signals; |
| 46 WaitFlagsStateChangedNoLock(); | 46 HandleSignalsStateChangedNoLock(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void SetSatisfiableSignals(MojoHandleSignals new_satisfiable_signals) { | 49 void SetSatisfiableSignals(MojoHandleSignals new_satisfiable_signals) { |
| 50 base::AutoLock locker(lock()); | 50 base::AutoLock locker(lock()); |
| 51 | 51 |
| 52 // Satisfied implies satisfiable. | 52 // Satisfied implies satisfiable. |
| 53 CHECK_EQ(new_satisfiable_signals & state_.satisfied_signals, | 53 CHECK_EQ(new_satisfiable_signals & state_.satisfied_signals, |
| 54 state_.satisfied_signals); | 54 state_.satisfied_signals); |
| 55 | 55 |
| 56 if (new_satisfiable_signals == state_.satisfiable_signals) | 56 if (new_satisfiable_signals == state_.satisfiable_signals) |
| 57 return; | 57 return; |
| 58 | 58 |
| 59 state_.satisfiable_signals = new_satisfiable_signals; | 59 state_.satisfiable_signals = new_satisfiable_signals; |
| 60 WaitFlagsStateChangedNoLock(); | 60 HandleSignalsStateChangedNoLock(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual Type GetType() const OVERRIDE { | 63 virtual Type GetType() const OVERRIDE { |
| 64 return kTypeUnknown; | 64 return kTypeUnknown; |
| 65 } | 65 } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 friend class base::RefCountedThreadSafe<MockSimpleDispatcher>; | 68 friend class base::RefCountedThreadSafe<MockSimpleDispatcher>; |
| 69 virtual ~MockSimpleDispatcher() {} | 69 virtual ~MockSimpleDispatcher() {} |
| 70 | 70 |
| 71 virtual scoped_refptr<Dispatcher> | 71 virtual scoped_refptr<Dispatcher> |
| 72 CreateEquivalentDispatcherAndCloseImplNoLock() OVERRIDE { | 72 CreateEquivalentDispatcherAndCloseImplNoLock() OVERRIDE { |
| 73 scoped_refptr<MockSimpleDispatcher> rv(new MockSimpleDispatcher()); | 73 scoped_refptr<MockSimpleDispatcher> rv(new MockSimpleDispatcher()); |
| 74 rv->state_ = state_; | 74 rv->state_ = state_; |
| 75 return scoped_refptr<Dispatcher>(rv.get()); | 75 return scoped_refptr<Dispatcher>(rv.get()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // |SimpleDispatcher| implementation: | 78 // |SimpleDispatcher| implementation: |
| 79 virtual WaitFlagsState GetWaitFlagsStateNoLock() const OVERRIDE { | 79 virtual HandleSignalsState GetHandleSignalsStateNoLock() const OVERRIDE { |
| 80 lock().AssertAcquired(); | 80 lock().AssertAcquired(); |
| 81 return state_; | 81 return state_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Protected by |lock()|: | 84 // Protected by |lock()|: |
| 85 WaitFlagsState state_; | 85 HandleSignalsState state_; |
| 86 | 86 |
| 87 DISALLOW_COPY_AND_ASSIGN(MockSimpleDispatcher); | 87 DISALLOW_COPY_AND_ASSIGN(MockSimpleDispatcher); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 TEST(SimpleDispatcherTest, Basic) { | 90 TEST(SimpleDispatcherTest, Basic) { |
| 91 test::Stopwatch stopwatch; | 91 test::Stopwatch stopwatch; |
| 92 | 92 |
| 93 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 93 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 94 Waiter w; | 94 Waiter w; |
| 95 uint32_t context = 0; | 95 uint32_t context = 0; |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 EXPECT_TRUE(did_wait[i]); | 532 EXPECT_TRUE(did_wait[i]); |
| 533 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result[i]); | 533 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result[i]); |
| 534 } | 534 } |
| 535 } | 535 } |
| 536 | 536 |
| 537 // TODO(vtl): Stress test? | 537 // TODO(vtl): Stress test? |
| 538 | 538 |
| 539 } // namespace | 539 } // namespace |
| 540 } // namespace system | 540 } // namespace system |
| 541 } // namespace mojo | 541 } // namespace mojo |
| OLD | NEW |