| 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 10 matching lines...) Expand all Loading... |
| 21 #include "mojo/system/waiter_test_utils.h" | 21 #include "mojo/system/waiter_test_utils.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 namespace mojo { | 24 namespace mojo { |
| 25 namespace system { | 25 namespace system { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class MockSimpleDispatcher : public SimpleDispatcher { | 28 class MockSimpleDispatcher : public SimpleDispatcher { |
| 29 public: | 29 public: |
| 30 MockSimpleDispatcher() | 30 MockSimpleDispatcher() |
| 31 : state_(MOJO_WAIT_FLAG_NONE, | 31 : state_(MOJO_HANDLE_SIGNAL_NONE, |
| 32 MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE) {} | 32 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE) {} |
| 33 | 33 |
| 34 void SetSatisfiedSignals(MojoHandleSignals new_satisfied_signals) { | 34 void SetSatisfiedSignals(MojoHandleSignals new_satisfied_signals) { |
| 35 base::AutoLock locker(lock()); | 35 base::AutoLock locker(lock()); |
| 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) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 96 | 96 |
| 97 // Try adding a readable waiter when already readable. | 97 // Try adding a readable waiter when already readable. |
| 98 w.Init(); | 98 w.Init(); |
| 99 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 99 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 100 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, | 100 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, |
| 101 d->AddWaiter(&w, MOJO_WAIT_FLAG_READABLE, 0)); | 101 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 0)); |
| 102 // Shouldn't need to remove the waiter (it was not added). | 102 // Shouldn't need to remove the waiter (it was not added). |
| 103 | 103 |
| 104 // Wait (forever) for writable when already writable. | 104 // Wait (forever) for writable when already writable. |
| 105 w.Init(); | 105 w.Init(); |
| 106 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 106 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 107 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 1)); | 107 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 1)); |
| 108 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_WRITABLE); | 108 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); |
| 109 stopwatch.Start(); | 109 stopwatch.Start(); |
| 110 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 110 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 111 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 111 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 112 EXPECT_EQ(1u, context); | 112 EXPECT_EQ(1u, context); |
| 113 d->RemoveWaiter(&w); | 113 d->RemoveWaiter(&w); |
| 114 | 114 |
| 115 // Wait for zero time for writable when already writable. | 115 // Wait for zero time for writable when already writable. |
| 116 w.Init(); | 116 w.Init(); |
| 117 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 117 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 118 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 2)); | 118 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2)); |
| 119 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_WRITABLE); | 119 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); |
| 120 stopwatch.Start(); | 120 stopwatch.Start(); |
| 121 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, &context)); | 121 EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, &context)); |
| 122 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 122 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 123 EXPECT_EQ(2u, context); | 123 EXPECT_EQ(2u, context); |
| 124 d->RemoveWaiter(&w); | 124 d->RemoveWaiter(&w); |
| 125 | 125 |
| 126 // Wait for non-zero, finite time for writable when already writable. | 126 // Wait for non-zero, finite time for writable when already writable. |
| 127 w.Init(); | 127 w.Init(); |
| 128 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 128 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 129 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 3)); | 129 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3)); |
| 130 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_WRITABLE); | 130 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); |
| 131 stopwatch.Start(); | 131 stopwatch.Start(); |
| 132 EXPECT_EQ(MOJO_RESULT_OK, | 132 EXPECT_EQ(MOJO_RESULT_OK, |
| 133 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); | 133 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); |
| 134 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 134 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 135 EXPECT_EQ(3u, context); | 135 EXPECT_EQ(3u, context); |
| 136 d->RemoveWaiter(&w); | 136 d->RemoveWaiter(&w); |
| 137 | 137 |
| 138 // Wait for zero time for writable when not writable (will time out). | 138 // Wait for zero time for writable when not writable (will time out). |
| 139 w.Init(); | 139 w.Init(); |
| 140 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 140 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 141 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 4)); | 141 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4)); |
| 142 stopwatch.Start(); | 142 stopwatch.Start(); |
| 143 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, NULL)); | 143 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, NULL)); |
| 144 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 144 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 145 d->RemoveWaiter(&w); | 145 d->RemoveWaiter(&w); |
| 146 | 146 |
| 147 // Wait for non-zero, finite time for writable when not writable (will time | 147 // Wait for non-zero, finite time for writable when not writable (will time |
| 148 // out). | 148 // out). |
| 149 w.Init(); | 149 w.Init(); |
| 150 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 150 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 151 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 5)); | 151 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 5)); |
| 152 stopwatch.Start(); | 152 stopwatch.Start(); |
| 153 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, | 153 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, |
| 154 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), NULL)); | 154 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), NULL)); |
| 155 base::TimeDelta elapsed = stopwatch.Elapsed(); | 155 base::TimeDelta elapsed = stopwatch.Elapsed(); |
| 156 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); | 156 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); |
| 157 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); | 157 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); |
| 158 d->RemoveWaiter(&w); | 158 d->RemoveWaiter(&w); |
| 159 | 159 |
| 160 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 160 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST(SimpleDispatcherTest, BasicUnsatisfiable) { | 163 TEST(SimpleDispatcherTest, BasicUnsatisfiable) { |
| 164 test::Stopwatch stopwatch; | 164 test::Stopwatch stopwatch; |
| 165 | 165 |
| 166 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 166 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 167 Waiter w; | 167 Waiter w; |
| 168 uint32_t context = 0; | 168 uint32_t context = 0; |
| 169 | 169 |
| 170 // Try adding a writable waiter when it can never be writable. | 170 // Try adding a writable waiter when it can never be writable. |
| 171 w.Init(); | 171 w.Init(); |
| 172 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); | 172 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 173 d->SetSatisfiedSignals(0); | 173 d->SetSatisfiedSignals(0); |
| 174 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 174 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 175 d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 1)); | 175 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 1)); |
| 176 // Shouldn't need to remove the waiter (it was not added). | 176 // Shouldn't need to remove the waiter (it was not added). |
| 177 | 177 |
| 178 // Wait (forever) for writable and then it becomes never writable. | 178 // Wait (forever) for writable and then it becomes never writable. |
| 179 w.Init(); | 179 w.Init(); |
| 180 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE); | 180 d->SetSatisfiableSignals( |
| 181 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 2)); | 181 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
| 182 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); | 182 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2)); |
| 183 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 183 stopwatch.Start(); | 184 stopwatch.Start(); |
| 184 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 185 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 185 w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 186 w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 186 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 187 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 187 EXPECT_EQ(2u, context); | 188 EXPECT_EQ(2u, context); |
| 188 d->RemoveWaiter(&w); | 189 d->RemoveWaiter(&w); |
| 189 | 190 |
| 190 // Wait for zero time for writable and then it becomes never writable. | 191 // Wait for zero time for writable and then it becomes never writable. |
| 191 w.Init(); | 192 w.Init(); |
| 192 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE); | 193 d->SetSatisfiableSignals( |
| 193 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 3)); | 194 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
| 194 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); | 195 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3)); |
| 196 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 195 stopwatch.Start(); | 197 stopwatch.Start(); |
| 196 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, w.Wait(0, &context)); | 198 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, w.Wait(0, &context)); |
| 197 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 199 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 198 EXPECT_EQ(3u, context); | 200 EXPECT_EQ(3u, context); |
| 199 d->RemoveWaiter(&w); | 201 d->RemoveWaiter(&w); |
| 200 | 202 |
| 201 // Wait for non-zero, finite time for writable and then it becomes never | 203 // Wait for non-zero, finite time for writable and then it becomes never |
| 202 // writable. | 204 // writable. |
| 203 w.Init(); | 205 w.Init(); |
| 204 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE | MOJO_WAIT_FLAG_WRITABLE); | 206 d->SetSatisfiableSignals( |
| 205 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 4)); | 207 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE); |
| 206 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); | 208 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4)); |
| 209 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 207 stopwatch.Start(); | 210 stopwatch.Start(); |
| 208 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 211 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 209 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); | 212 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); |
| 210 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 213 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 211 EXPECT_EQ(4u, context); | 214 EXPECT_EQ(4u, context); |
| 212 d->RemoveWaiter(&w); | 215 d->RemoveWaiter(&w); |
| 213 | 216 |
| 214 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 217 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 215 } | 218 } |
| 216 | 219 |
| 217 TEST(SimpleDispatcherTest, BasicClosed) { | 220 TEST(SimpleDispatcherTest, BasicClosed) { |
| 218 test::Stopwatch stopwatch; | 221 test::Stopwatch stopwatch; |
| 219 | 222 |
| 220 scoped_refptr<MockSimpleDispatcher> d; | 223 scoped_refptr<MockSimpleDispatcher> d; |
| 221 Waiter w; | 224 Waiter w; |
| 222 uint32_t context = 0; | 225 uint32_t context = 0; |
| 223 | 226 |
| 224 // Try adding a writable waiter when the dispatcher has been closed. | 227 // Try adding a writable waiter when the dispatcher has been closed. |
| 225 d = new MockSimpleDispatcher(); | 228 d = new MockSimpleDispatcher(); |
| 226 w.Init(); | 229 w.Init(); |
| 227 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 230 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 228 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, | 231 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, |
| 229 d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 1)); | 232 d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 1)); |
| 230 // Shouldn't need to remove the waiter (it was not added). | 233 // Shouldn't need to remove the waiter (it was not added). |
| 231 | 234 |
| 232 // Wait (forever) for writable and then the dispatcher is closed. | 235 // Wait (forever) for writable and then the dispatcher is closed. |
| 233 d = new MockSimpleDispatcher(); | 236 d = new MockSimpleDispatcher(); |
| 234 w.Init(); | 237 w.Init(); |
| 235 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 2)); | 238 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 2)); |
| 236 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 239 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 237 stopwatch.Start(); | 240 stopwatch.Start(); |
| 238 EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); | 241 EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); |
| 239 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 242 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 240 EXPECT_EQ(2u, context); | 243 EXPECT_EQ(2u, context); |
| 241 // Don't need to remove waiters from closed dispatchers. | 244 // Don't need to remove waiters from closed dispatchers. |
| 242 | 245 |
| 243 // Wait for zero time for writable and then the dispatcher is closed. | 246 // Wait for zero time for writable and then the dispatcher is closed. |
| 244 d = new MockSimpleDispatcher(); | 247 d = new MockSimpleDispatcher(); |
| 245 w.Init(); | 248 w.Init(); |
| 246 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 3)); | 249 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3)); |
| 247 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 250 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 248 stopwatch.Start(); | 251 stopwatch.Start(); |
| 249 EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(0, &context)); | 252 EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(0, &context)); |
| 250 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 253 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 251 EXPECT_EQ(3u, context); | 254 EXPECT_EQ(3u, context); |
| 252 // Don't need to remove waiters from closed dispatchers. | 255 // Don't need to remove waiters from closed dispatchers. |
| 253 | 256 |
| 254 // Wait for non-zero, finite time for writable and then the dispatcher is | 257 // Wait for non-zero, finite time for writable and then the dispatcher is |
| 255 // closed. | 258 // closed. |
| 256 d = new MockSimpleDispatcher(); | 259 d = new MockSimpleDispatcher(); |
| 257 w.Init(); | 260 w.Init(); |
| 258 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_WAIT_FLAG_WRITABLE, 4)); | 261 EXPECT_EQ(MOJO_RESULT_OK, d->AddWaiter(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4)); |
| 259 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 262 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 260 stopwatch.Start(); | 263 stopwatch.Start(); |
| 261 EXPECT_EQ(MOJO_RESULT_CANCELLED, | 264 EXPECT_EQ(MOJO_RESULT_CANCELLED, |
| 262 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); | 265 w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); |
| 263 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 266 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 264 EXPECT_EQ(4u, context); | 267 EXPECT_EQ(4u, context); |
| 265 // Don't need to remove waiters from closed dispatchers. | 268 // Don't need to remove waiters from closed dispatchers. |
| 266 } | 269 } |
| 267 | 270 |
| 268 TEST(SimpleDispatcherTest, BasicThreaded) { | 271 TEST(SimpleDispatcherTest, BasicThreaded) { |
| 269 test::Stopwatch stopwatch; | 272 test::Stopwatch stopwatch; |
| 270 bool did_wait; | 273 bool did_wait; |
| 271 MojoResult result; | 274 MojoResult result; |
| 272 uint32_t context; | 275 uint32_t context; |
| 273 | 276 |
| 274 // Wait for readable (already readable). | 277 // Wait for readable (already readable). |
| 275 { | 278 { |
| 276 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 279 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 277 { | 280 { |
| 278 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 281 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 279 test::WaiterThread thread(d, | 282 test::WaiterThread thread(d, |
| 280 MOJO_WAIT_FLAG_READABLE, | 283 MOJO_HANDLE_SIGNAL_READABLE, |
| 281 MOJO_DEADLINE_INDEFINITE, | 284 MOJO_DEADLINE_INDEFINITE, |
| 282 1, | 285 1, |
| 283 &did_wait, &result, &context); | 286 &did_wait, &result, &context); |
| 284 stopwatch.Start(); | 287 stopwatch.Start(); |
| 285 thread.Start(); | 288 thread.Start(); |
| 286 } // Joins the thread. | 289 } // Joins the thread. |
| 287 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. | 290 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. |
| 288 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 291 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 289 } | 292 } |
| 290 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); | 293 EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); |
| 291 EXPECT_FALSE(did_wait); | 294 EXPECT_FALSE(did_wait); |
| 292 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result); | 295 EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result); |
| 293 | 296 |
| 294 // Wait for readable and becomes readable after some time. | 297 // Wait for readable and becomes readable after some time. |
| 295 { | 298 { |
| 296 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 299 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 297 test::WaiterThread thread(d, | 300 test::WaiterThread thread(d, |
| 298 MOJO_WAIT_FLAG_READABLE, | 301 MOJO_HANDLE_SIGNAL_READABLE, |
| 299 MOJO_DEADLINE_INDEFINITE, | 302 MOJO_DEADLINE_INDEFINITE, |
| 300 2, | 303 2, |
| 301 &did_wait, &result, &context); | 304 &did_wait, &result, &context); |
| 302 stopwatch.Start(); | 305 stopwatch.Start(); |
| 303 thread.Start(); | 306 thread.Start(); |
| 304 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 307 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
| 305 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 308 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 306 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 309 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 307 } // Joins the thread. | 310 } // Joins the thread. |
| 308 base::TimeDelta elapsed = stopwatch.Elapsed(); | 311 base::TimeDelta elapsed = stopwatch.Elapsed(); |
| 309 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); | 312 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); |
| 310 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); | 313 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); |
| 311 EXPECT_TRUE(did_wait); | 314 EXPECT_TRUE(did_wait); |
| 312 EXPECT_EQ(MOJO_RESULT_OK, result); | 315 EXPECT_EQ(MOJO_RESULT_OK, result); |
| 313 EXPECT_EQ(2u, context); | 316 EXPECT_EQ(2u, context); |
| 314 | 317 |
| 315 // Wait for readable and becomes never-readable after some time. | 318 // Wait for readable and becomes never-readable after some time. |
| 316 { | 319 { |
| 317 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 320 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 318 test::WaiterThread thread(d, | 321 test::WaiterThread thread(d, |
| 319 MOJO_WAIT_FLAG_READABLE, | 322 MOJO_HANDLE_SIGNAL_READABLE, |
| 320 MOJO_DEADLINE_INDEFINITE, | 323 MOJO_DEADLINE_INDEFINITE, |
| 321 3, | 324 3, |
| 322 &did_wait, &result, &context); | 325 &did_wait, &result, &context); |
| 323 stopwatch.Start(); | 326 stopwatch.Start(); |
| 324 thread.Start(); | 327 thread.Start(); |
| 325 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 328 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
| 326 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_NONE); | 329 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_NONE); |
| 327 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 330 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 328 } // Joins the thread. | 331 } // Joins the thread. |
| 329 elapsed = stopwatch.Elapsed(); | 332 elapsed = stopwatch.Elapsed(); |
| 330 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); | 333 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); |
| 331 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); | 334 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); |
| 332 EXPECT_TRUE(did_wait); | 335 EXPECT_TRUE(did_wait); |
| 333 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 336 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
| 334 EXPECT_EQ(3u, context); | 337 EXPECT_EQ(3u, context); |
| 335 | 338 |
| 336 // Wait for readable and dispatcher gets closed. | 339 // Wait for readable and dispatcher gets closed. |
| 337 { | 340 { |
| 338 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 341 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 339 test::WaiterThread thread(d, | 342 test::WaiterThread thread(d, |
| 340 MOJO_WAIT_FLAG_READABLE, | 343 MOJO_HANDLE_SIGNAL_READABLE, |
| 341 MOJO_DEADLINE_INDEFINITE, | 344 MOJO_DEADLINE_INDEFINITE, |
| 342 4, | 345 4, |
| 343 &did_wait, &result, &context); | 346 &did_wait, &result, &context); |
| 344 stopwatch.Start(); | 347 stopwatch.Start(); |
| 345 thread.Start(); | 348 thread.Start(); |
| 346 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 349 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
| 347 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 350 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 348 } // Joins the thread. | 351 } // Joins the thread. |
| 349 elapsed = stopwatch.Elapsed(); | 352 elapsed = stopwatch.Elapsed(); |
| 350 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); | 353 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); |
| 351 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); | 354 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); |
| 352 EXPECT_TRUE(did_wait); | 355 EXPECT_TRUE(did_wait); |
| 353 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); | 356 EXPECT_EQ(MOJO_RESULT_CANCELLED, result); |
| 354 EXPECT_EQ(4u, context); | 357 EXPECT_EQ(4u, context); |
| 355 | 358 |
| 356 // Wait for readable and times out. | 359 // Wait for readable and times out. |
| 357 { | 360 { |
| 358 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 361 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 359 { | 362 { |
| 360 test::WaiterThread thread(d, | 363 test::WaiterThread thread(d, |
| 361 MOJO_WAIT_FLAG_READABLE, | 364 MOJO_HANDLE_SIGNAL_READABLE, |
| 362 2 * test::EpsilonTimeout().InMicroseconds(), | 365 2 * test::EpsilonTimeout().InMicroseconds(), |
| 363 5, | 366 5, |
| 364 &did_wait, &result, &context); | 367 &did_wait, &result, &context); |
| 365 stopwatch.Start(); | 368 stopwatch.Start(); |
| 366 thread.Start(); | 369 thread.Start(); |
| 367 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 370 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
| 368 // Not what we're waiting for. | 371 // Not what we're waiting for. |
| 369 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_WRITABLE); | 372 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); |
| 370 } // Joins the thread (after its wait times out). | 373 } // Joins the thread (after its wait times out). |
| 371 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. | 374 // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. |
| 372 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 375 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 373 } | 376 } |
| 374 elapsed = stopwatch.Elapsed(); | 377 elapsed = stopwatch.Elapsed(); |
| 375 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); | 378 EXPECT_GT(elapsed, (2-1) * test::EpsilonTimeout()); |
| 376 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); | 379 EXPECT_LT(elapsed, (2+1) * test::EpsilonTimeout()); |
| 377 EXPECT_TRUE(did_wait); | 380 EXPECT_TRUE(did_wait); |
| 378 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result); | 381 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result); |
| 379 } | 382 } |
| 380 | 383 |
| 381 TEST(SimpleDispatcherTest, MultipleWaiters) { | 384 TEST(SimpleDispatcherTest, MultipleWaiters) { |
| 382 static const uint32_t kNumWaiters = 20; | 385 static const uint32_t kNumWaiters = 20; |
| 383 | 386 |
| 384 bool did_wait[kNumWaiters]; | 387 bool did_wait[kNumWaiters]; |
| 385 MojoResult result[kNumWaiters]; | 388 MojoResult result[kNumWaiters]; |
| 386 uint32_t context[kNumWaiters]; | 389 uint32_t context[kNumWaiters]; |
| 387 | 390 |
| 388 // All wait for readable and becomes readable after some time. | 391 // All wait for readable and becomes readable after some time. |
| 389 { | 392 { |
| 390 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 393 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 391 ScopedVector<test::WaiterThread> threads; | 394 ScopedVector<test::WaiterThread> threads; |
| 392 for (uint32_t i = 0; i < kNumWaiters; i++) { | 395 for (uint32_t i = 0; i < kNumWaiters; i++) { |
| 393 threads.push_back(new test::WaiterThread(d, | 396 threads.push_back(new test::WaiterThread(d, |
| 394 MOJO_WAIT_FLAG_READABLE, | 397 MOJO_HANDLE_SIGNAL_READABLE, |
| 395 MOJO_DEADLINE_INDEFINITE, | 398 MOJO_DEADLINE_INDEFINITE, |
| 396 i, | 399 i, |
| 397 &did_wait[i], | 400 &did_wait[i], |
| 398 &result[i], | 401 &result[i], |
| 399 &context[i])); | 402 &context[i])); |
| 400 threads.back()->Start(); | 403 threads.back()->Start(); |
| 401 } | 404 } |
| 402 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 405 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
| 403 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 406 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 404 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 407 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 405 } // Joins the threads. | 408 } // Joins the threads. |
| 406 for (uint32_t i = 0; i < kNumWaiters; i++) { | 409 for (uint32_t i = 0; i < kNumWaiters; i++) { |
| 407 EXPECT_TRUE(did_wait[i]); | 410 EXPECT_TRUE(did_wait[i]); |
| 408 EXPECT_EQ(MOJO_RESULT_OK, result[i]); | 411 EXPECT_EQ(MOJO_RESULT_OK, result[i]); |
| 409 EXPECT_EQ(i, context[i]); | 412 EXPECT_EQ(i, context[i]); |
| 410 } | 413 } |
| 411 | 414 |
| 412 // Some wait for readable, some for writable, and becomes readable after some | 415 // Some wait for readable, some for writable, and becomes readable after some |
| 413 // time. | 416 // time. |
| 414 { | 417 { |
| 415 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 418 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 416 ScopedVector<test::WaiterThread> threads; | 419 ScopedVector<test::WaiterThread> threads; |
| 417 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { | 420 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { |
| 418 threads.push_back(new test::WaiterThread(d, | 421 threads.push_back(new test::WaiterThread(d, |
| 419 MOJO_WAIT_FLAG_READABLE, | 422 MOJO_HANDLE_SIGNAL_READABLE, |
| 420 MOJO_DEADLINE_INDEFINITE, | 423 MOJO_DEADLINE_INDEFINITE, |
| 421 i, | 424 i, |
| 422 &did_wait[i], | 425 &did_wait[i], |
| 423 &result[i], | 426 &result[i], |
| 424 &context[i])); | 427 &context[i])); |
| 425 threads.back()->Start(); | 428 threads.back()->Start(); |
| 426 } | 429 } |
| 427 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 430 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
| 428 threads.push_back(new test::WaiterThread(d, | 431 threads.push_back(new test::WaiterThread(d, |
| 429 MOJO_WAIT_FLAG_WRITABLE, | 432 MOJO_HANDLE_SIGNAL_WRITABLE, |
| 430 MOJO_DEADLINE_INDEFINITE, | 433 MOJO_DEADLINE_INDEFINITE, |
| 431 i, | 434 i, |
| 432 &did_wait[i], | 435 &did_wait[i], |
| 433 &result[i], | 436 &result[i], |
| 434 &context[i])); | 437 &context[i])); |
| 435 threads.back()->Start(); | 438 threads.back()->Start(); |
| 436 } | 439 } |
| 437 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 440 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
| 438 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 441 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 439 // This will wake up the ones waiting to write. | 442 // This will wake up the ones waiting to write. |
| 440 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 443 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 441 } // Joins the threads. | 444 } // Joins the threads. |
| 442 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { | 445 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { |
| 443 EXPECT_TRUE(did_wait[i]); | 446 EXPECT_TRUE(did_wait[i]); |
| 444 EXPECT_EQ(MOJO_RESULT_OK, result[i]); | 447 EXPECT_EQ(MOJO_RESULT_OK, result[i]); |
| 445 EXPECT_EQ(i, context[i]); | 448 EXPECT_EQ(i, context[i]); |
| 446 } | 449 } |
| 447 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 450 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
| 448 EXPECT_TRUE(did_wait[i]); | 451 EXPECT_TRUE(did_wait[i]); |
| 449 EXPECT_EQ(MOJO_RESULT_CANCELLED, result[i]); | 452 EXPECT_EQ(MOJO_RESULT_CANCELLED, result[i]); |
| 450 EXPECT_EQ(i, context[i]); | 453 EXPECT_EQ(i, context[i]); |
| 451 } | 454 } |
| 452 | 455 |
| 453 // Some wait for readable, some for writable, and becomes readable and | 456 // Some wait for readable, some for writable, and becomes readable and |
| 454 // never-writable after some time. | 457 // never-writable after some time. |
| 455 { | 458 { |
| 456 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 459 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 457 ScopedVector<test::WaiterThread> threads; | 460 ScopedVector<test::WaiterThread> threads; |
| 458 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { | 461 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { |
| 459 threads.push_back(new test::WaiterThread(d, | 462 threads.push_back(new test::WaiterThread(d, |
| 460 MOJO_WAIT_FLAG_READABLE, | 463 MOJO_HANDLE_SIGNAL_READABLE, |
| 461 MOJO_DEADLINE_INDEFINITE, | 464 MOJO_DEADLINE_INDEFINITE, |
| 462 i, | 465 i, |
| 463 &did_wait[i], | 466 &did_wait[i], |
| 464 &result[i], | 467 &result[i], |
| 465 &context[i])); | 468 &context[i])); |
| 466 threads.back()->Start(); | 469 threads.back()->Start(); |
| 467 } | 470 } |
| 468 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 471 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
| 469 threads.push_back(new test::WaiterThread(d, | 472 threads.push_back(new test::WaiterThread(d, |
| 470 MOJO_WAIT_FLAG_WRITABLE, | 473 MOJO_HANDLE_SIGNAL_WRITABLE, |
| 471 MOJO_DEADLINE_INDEFINITE, | 474 MOJO_DEADLINE_INDEFINITE, |
| 472 i, | 475 i, |
| 473 &did_wait[i], | 476 &did_wait[i], |
| 474 &result[i], | 477 &result[i], |
| 475 &context[i])); | 478 &context[i])); |
| 476 threads.back()->Start(); | 479 threads.back()->Start(); |
| 477 } | 480 } |
| 478 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 481 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
| 479 d->SetSatisfiableSignals(MOJO_WAIT_FLAG_READABLE); | 482 d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 480 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); | 483 base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); |
| 481 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 484 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 482 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 485 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 483 } // Joins the threads. | 486 } // Joins the threads. |
| 484 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { | 487 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { |
| 485 EXPECT_TRUE(did_wait[i]); | 488 EXPECT_TRUE(did_wait[i]); |
| 486 EXPECT_EQ(MOJO_RESULT_OK, result[i]); | 489 EXPECT_EQ(MOJO_RESULT_OK, result[i]); |
| 487 EXPECT_EQ(i, context[i]); | 490 EXPECT_EQ(i, context[i]); |
| 488 } | 491 } |
| 489 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 492 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
| 490 EXPECT_TRUE(did_wait[i]); | 493 EXPECT_TRUE(did_wait[i]); |
| 491 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result[i]); | 494 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result[i]); |
| 492 EXPECT_EQ(i, context[i]); | 495 EXPECT_EQ(i, context[i]); |
| 493 } | 496 } |
| 494 | 497 |
| 495 // Some wait for readable, some for writable, and becomes readable after some | 498 // Some wait for readable, some for writable, and becomes readable after some |
| 496 // time. | 499 // time. |
| 497 { | 500 { |
| 498 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); | 501 scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher()); |
| 499 ScopedVector<test::WaiterThread> threads; | 502 ScopedVector<test::WaiterThread> threads; |
| 500 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { | 503 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { |
| 501 threads.push_back( | 504 threads.push_back( |
| 502 new test::WaiterThread(d, | 505 new test::WaiterThread(d, |
| 503 MOJO_WAIT_FLAG_READABLE, | 506 MOJO_HANDLE_SIGNAL_READABLE, |
| 504 3 * test::EpsilonTimeout().InMicroseconds(), | 507 3 * test::EpsilonTimeout().InMicroseconds(), |
| 505 i, | 508 i, |
| 506 &did_wait[i], &result[i], &context[i])); | 509 &did_wait[i], &result[i], &context[i])); |
| 507 threads.back()->Start(); | 510 threads.back()->Start(); |
| 508 } | 511 } |
| 509 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 512 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
| 510 threads.push_back( | 513 threads.push_back( |
| 511 new test::WaiterThread(d, | 514 new test::WaiterThread(d, |
| 512 MOJO_WAIT_FLAG_WRITABLE, | 515 MOJO_HANDLE_SIGNAL_WRITABLE, |
| 513 1 * test::EpsilonTimeout().InMicroseconds(), | 516 1 * test::EpsilonTimeout().InMicroseconds(), |
| 514 i, | 517 i, |
| 515 &did_wait[i], &result[i], &context[i])); | 518 &did_wait[i], &result[i], &context[i])); |
| 516 threads.back()->Start(); | 519 threads.back()->Start(); |
| 517 } | 520 } |
| 518 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); | 521 base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); |
| 519 d->SetSatisfiedSignals(MOJO_WAIT_FLAG_READABLE); | 522 d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); |
| 520 // All those waiting for writable should have timed out. | 523 // All those waiting for writable should have timed out. |
| 521 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 524 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 522 } // Joins the threads. | 525 } // Joins the threads. |
| 523 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { | 526 for (uint32_t i = 0; i < kNumWaiters / 2; i++) { |
| 524 EXPECT_TRUE(did_wait[i]); | 527 EXPECT_TRUE(did_wait[i]); |
| 525 EXPECT_EQ(MOJO_RESULT_OK, result[i]); | 528 EXPECT_EQ(MOJO_RESULT_OK, result[i]); |
| 526 EXPECT_EQ(i, context[i]); | 529 EXPECT_EQ(i, context[i]); |
| 527 } | 530 } |
| 528 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { | 531 for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) { |
| 529 EXPECT_TRUE(did_wait[i]); | 532 EXPECT_TRUE(did_wait[i]); |
| 530 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result[i]); | 533 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result[i]); |
| 531 } | 534 } |
| 532 } | 535 } |
| 533 | 536 |
| 534 // TODO(vtl): Stress test? | 537 // TODO(vtl): Stress test? |
| 535 | 538 |
| 536 } // namespace | 539 } // namespace |
| 537 } // namespace system | 540 } // namespace system |
| 538 } // namespace mojo | 541 } // namespace mojo |
| OLD | NEW |