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

Side by Side Diff: mojo/edk/system/dispatcher_unittest.cc

Issue 782693004: Update mojo sdk to rev f6c8ec07c01deebc13178d516225fd12695c3dc2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hack mojo_system_impl gypi for android :| Created 6 years 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
OLDNEW
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 #include "mojo/edk/system/dispatcher.h" 5 #include "mojo/edk/system/dispatcher.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 d->ReadData(NullUserPointer(), NullUserPointer(), 60 d->ReadData(NullUserPointer(), NullUserPointer(),
61 MOJO_READ_DATA_FLAG_NONE)); 61 MOJO_READ_DATA_FLAG_NONE));
62 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 62 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
63 d->BeginReadData(NullUserPointer(), NullUserPointer(), 63 d->BeginReadData(NullUserPointer(), NullUserPointer(),
64 MOJO_READ_DATA_FLAG_NONE)); 64 MOJO_READ_DATA_FLAG_NONE));
65 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0)); 65 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0));
66 Waiter w; 66 Waiter w;
67 w.Init(); 67 w.Init();
68 HandleSignalsState hss; 68 HandleSignalsState hss;
69 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 69 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
70 d->AddWaiter(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss)); 70 d->AddAwakable(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss));
71 EXPECT_EQ(0u, hss.satisfied_signals); 71 EXPECT_EQ(0u, hss.satisfied_signals);
72 EXPECT_EQ(0u, hss.satisfiable_signals); 72 EXPECT_EQ(0u, hss.satisfiable_signals);
73 // Okay to remove even if it wasn't added (or was already removed). 73 // Okay to remove even if it wasn't added (or was already removed).
74 hss = HandleSignalsState(); 74 hss = HandleSignalsState();
75 d->RemoveWaiter(&w, &hss); 75 d->RemoveAwakable(&w, &hss);
76 EXPECT_EQ(0u, hss.satisfied_signals); 76 EXPECT_EQ(0u, hss.satisfied_signals);
77 EXPECT_EQ(0u, hss.satisfiable_signals); 77 EXPECT_EQ(0u, hss.satisfiable_signals);
78 hss = HandleSignalsState(); 78 hss = HandleSignalsState();
79 d->RemoveWaiter(&w, &hss); 79 d->RemoveAwakable(&w, &hss);
80 EXPECT_EQ(0u, hss.satisfied_signals); 80 EXPECT_EQ(0u, hss.satisfied_signals);
81 EXPECT_EQ(0u, hss.satisfiable_signals); 81 EXPECT_EQ(0u, hss.satisfiable_signals);
82 82
83 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 83 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
84 84
85 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 85 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
86 d->WriteMessage(NullUserPointer(), 0, nullptr, 86 d->WriteMessage(NullUserPointer(), 0, nullptr,
87 MOJO_WRITE_MESSAGE_FLAG_NONE)); 87 MOJO_WRITE_MESSAGE_FLAG_NONE));
88 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 88 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
89 d->ReadMessage(NullUserPointer(), NullUserPointer(), nullptr, 89 d->ReadMessage(NullUserPointer(), NullUserPointer(), nullptr,
90 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); 90 nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
91 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 91 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
92 d->WriteData(NullUserPointer(), NullUserPointer(), 92 d->WriteData(NullUserPointer(), NullUserPointer(),
93 MOJO_WRITE_DATA_FLAG_NONE)); 93 MOJO_WRITE_DATA_FLAG_NONE));
94 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 94 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
95 d->BeginWriteData(NullUserPointer(), NullUserPointer(), 95 d->BeginWriteData(NullUserPointer(), NullUserPointer(),
96 MOJO_WRITE_DATA_FLAG_NONE)); 96 MOJO_WRITE_DATA_FLAG_NONE));
97 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndWriteData(0)); 97 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndWriteData(0));
98 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 98 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
99 d->ReadData(NullUserPointer(), NullUserPointer(), 99 d->ReadData(NullUserPointer(), NullUserPointer(),
100 MOJO_READ_DATA_FLAG_NONE)); 100 MOJO_READ_DATA_FLAG_NONE));
101 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 101 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
102 d->BeginReadData(NullUserPointer(), NullUserPointer(), 102 d->BeginReadData(NullUserPointer(), NullUserPointer(),
103 MOJO_READ_DATA_FLAG_NONE)); 103 MOJO_READ_DATA_FLAG_NONE));
104 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0)); 104 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0));
105 hss = HandleSignalsState(); 105 hss = HandleSignalsState();
106 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 106 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
107 d->AddWaiter(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss)); 107 d->AddAwakable(&w, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss));
108 EXPECT_EQ(0u, hss.satisfied_signals); 108 EXPECT_EQ(0u, hss.satisfied_signals);
109 EXPECT_EQ(0u, hss.satisfiable_signals); 109 EXPECT_EQ(0u, hss.satisfiable_signals);
110 hss = HandleSignalsState(); 110 hss = HandleSignalsState();
111 d->RemoveWaiter(&w, &hss); 111 d->RemoveAwakable(&w, &hss);
112 EXPECT_EQ(0u, hss.satisfied_signals); 112 EXPECT_EQ(0u, hss.satisfied_signals);
113 EXPECT_EQ(0u, hss.satisfiable_signals); 113 EXPECT_EQ(0u, hss.satisfiable_signals);
114 } 114 }
115 115
116 class ThreadSafetyStressThread : public base::SimpleThread { 116 class ThreadSafetyStressThread : public base::SimpleThread {
117 public: 117 public:
118 enum DispatcherOp { 118 enum DispatcherOp {
119 CLOSE = 0, 119 CLOSE = 0,
120 WRITE_MESSAGE, 120 WRITE_MESSAGE,
121 READ_MESSAGE, 121 READ_MESSAGE,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 205 }
206 case MAP_BUFFER: { 206 case MAP_BUFFER: {
207 scoped_ptr<embedder::PlatformSharedBufferMapping> unused; 207 scoped_ptr<embedder::PlatformSharedBufferMapping> unused;
208 EXPECT_EQ( 208 EXPECT_EQ(
209 MOJO_RESULT_INVALID_ARGUMENT, 209 MOJO_RESULT_INVALID_ARGUMENT,
210 dispatcher_->MapBuffer(0u, 0u, MOJO_MAP_BUFFER_FLAG_NONE, &unused)); 210 dispatcher_->MapBuffer(0u, 0u, MOJO_MAP_BUFFER_FLAG_NONE, &unused));
211 break; 211 break;
212 } 212 }
213 case ADD_WAITER: { 213 case ADD_WAITER: {
214 HandleSignalsState hss; 214 HandleSignalsState hss;
215 MojoResult r = 215 MojoResult r = dispatcher_->AddAwakable(
216 dispatcher_->AddWaiter(&waiter_, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss); 216 &waiter_, ~MOJO_HANDLE_SIGNAL_NONE, 0, &hss);
217 EXPECT_TRUE(r == MOJO_RESULT_FAILED_PRECONDITION || 217 EXPECT_TRUE(r == MOJO_RESULT_FAILED_PRECONDITION ||
218 r == MOJO_RESULT_INVALID_ARGUMENT); 218 r == MOJO_RESULT_INVALID_ARGUMENT);
219 EXPECT_EQ(0u, hss.satisfied_signals); 219 EXPECT_EQ(0u, hss.satisfied_signals);
220 EXPECT_EQ(0u, hss.satisfiable_signals); 220 EXPECT_EQ(0u, hss.satisfiable_signals);
221 break; 221 break;
222 } 222 }
223 case REMOVE_WAITER: { 223 case REMOVE_WAITER: {
224 HandleSignalsState hss; 224 HandleSignalsState hss;
225 dispatcher_->RemoveWaiter(&waiter_, &hss); 225 dispatcher_->RemoveAwakable(&waiter_, &hss);
226 EXPECT_EQ(0u, hss.satisfied_signals); 226 EXPECT_EQ(0u, hss.satisfied_signals);
227 EXPECT_EQ(0u, hss.satisfiable_signals); 227 EXPECT_EQ(0u, hss.satisfiable_signals);
228 break; 228 break;
229 } 229 }
230 default: 230 default:
231 NOTREACHED(); 231 NOTREACHED();
232 break; 232 break;
233 } 233 }
234 234
235 // Always try to remove the waiter, in case we added it. 235 // Always try to remove the waiter, in case we added it.
236 HandleSignalsState hss; 236 HandleSignalsState hss;
237 dispatcher_->RemoveWaiter(&waiter_, &hss); 237 dispatcher_->RemoveAwakable(&waiter_, &hss);
238 EXPECT_EQ(0u, hss.satisfied_signals); 238 EXPECT_EQ(0u, hss.satisfied_signals);
239 EXPECT_EQ(0u, hss.satisfiable_signals); 239 EXPECT_EQ(0u, hss.satisfiable_signals);
240 } 240 }
241 241
242 base::WaitableEvent* const event_; 242 base::WaitableEvent* const event_;
243 const scoped_refptr<Dispatcher> dispatcher_; 243 const scoped_refptr<Dispatcher> dispatcher_;
244 const DispatcherOp op_; 244 const DispatcherOp op_;
245 245
246 Waiter waiter_; 246 Waiter waiter_;
247 247
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 event.Signal(); 298 event.Signal();
299 } // Joins all the threads. 299 } // Joins all the threads.
300 300
301 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 301 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
302 } 302 }
303 } 303 }
304 304
305 } // namespace 305 } // namespace
306 } // namespace system 306 } // namespace system
307 } // namespace mojo 307 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698