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

Side by Side Diff: runtime/vm/message_handler_test.cc

Issue 2666133002: Added new type of unit test, RAW_UNIT_TEST_CASE, which is used for tests that can be flaky if run w… (Closed)
Patch Set: Fixed name of UNIT_TEST_CASE macro Created 3 years, 10 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 | « runtime/vm/memory_region_test.cc ('k') | runtime/vm/metrics_test.cc » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/message_handler.h" 5 #include "vm/message_handler.h"
6 #include "vm/port.h" 6 #include "vm/port.h"
7 #include "vm/unit_test.h" 7 #include "vm/unit_test.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 MessageHandler::MessageStatus TestStartFunction(uword data) { 110 MessageHandler::MessageStatus TestStartFunction(uword data) {
111 return (reinterpret_cast<TestMessageHandler*>(data))->Start(); 111 return (reinterpret_cast<TestMessageHandler*>(data))->Start();
112 } 112 }
113 113
114 114
115 void TestEndFunction(uword data) { 115 void TestEndFunction(uword data) {
116 return (reinterpret_cast<TestMessageHandler*>(data))->End(); 116 return (reinterpret_cast<TestMessageHandler*>(data))->End();
117 } 117 }
118 118
119 119
120 UNIT_TEST_CASE(MessageHandler_PostMessage) { 120 VM_UNIT_TEST_CASE(MessageHandler_PostMessage) {
121 TestMessageHandler handler; 121 TestMessageHandler handler;
122 MessageHandlerTestPeer handler_peer(&handler); 122 MessageHandlerTestPeer handler_peer(&handler);
123 EXPECT_EQ(0, handler.notify_count()); 123 EXPECT_EQ(0, handler.notify_count());
124 124
125 // Post a message. 125 // Post a message.
126 Message* message = new Message(1, NULL, 0, Message::kNormalPriority); 126 Message* message = new Message(1, NULL, 0, Message::kNormalPriority);
127 handler_peer.PostMessage(message); 127 handler_peer.PostMessage(message);
128 128
129 // The notify callback is called. 129 // The notify callback is called.
130 EXPECT_EQ(1, handler.notify_count()); 130 EXPECT_EQ(1, handler.notify_count());
(...skipping 10 matching lines...) Expand all
141 // The notify callback is called. 141 // The notify callback is called.
142 EXPECT_EQ(2, handler.notify_count()); 142 EXPECT_EQ(2, handler.notify_count());
143 143
144 // The message has been added to the correct queue. 144 // The message has been added to the correct queue.
145 EXPECT(message == handler_peer.oob_queue()->Dequeue()); 145 EXPECT(message == handler_peer.oob_queue()->Dequeue());
146 EXPECT(NULL == handler_peer.queue()->Dequeue()); 146 EXPECT(NULL == handler_peer.queue()->Dequeue());
147 delete message; 147 delete message;
148 } 148 }
149 149
150 150
151 UNIT_TEST_CASE(MessageHandler_HasOOBMessages) { 151 VM_UNIT_TEST_CASE(MessageHandler_HasOOBMessages) {
152 TestMessageHandler handler; 152 TestMessageHandler handler;
153 MessageHandlerTestPeer handler_peer(&handler); 153 MessageHandlerTestPeer handler_peer(&handler);
154 154
155 EXPECT(!handler.HasOOBMessages()); 155 EXPECT(!handler.HasOOBMessages());
156 156
157 // Post a normal message. 157 // Post a normal message.
158 Message* message = new Message(1, NULL, 0, Message::kNormalPriority); 158 Message* message = new Message(1, NULL, 0, Message::kNormalPriority);
159 handler_peer.PostMessage(message); 159 handler_peer.PostMessage(message);
160 EXPECT(!handler.HasOOBMessages()); 160 EXPECT(!handler.HasOOBMessages());
161 { 161 {
(...skipping 12 matching lines...) Expand all
174 MessageHandler::AcquiredQueues aq(&handler); 174 MessageHandler::AcquiredQueues aq(&handler);
175 EXPECT(aq.queue()->Length() == 1); 175 EXPECT(aq.queue()->Length() == 1);
176 EXPECT(aq.oob_queue()->Length() == 1); 176 EXPECT(aq.oob_queue()->Length() == 1);
177 } 177 }
178 178
179 // Delete all pending messages. 179 // Delete all pending messages.
180 handler_peer.CloseAllPorts(); 180 handler_peer.CloseAllPorts();
181 } 181 }
182 182
183 183
184 UNIT_TEST_CASE(MessageHandler_ClosePort) { 184 VM_UNIT_TEST_CASE(MessageHandler_ClosePort) {
185 TestMessageHandler handler; 185 TestMessageHandler handler;
186 MessageHandlerTestPeer handler_peer(&handler); 186 MessageHandlerTestPeer handler_peer(&handler);
187 Message* message1 = new Message(1, NULL, 0, Message::kNormalPriority); 187 Message* message1 = new Message(1, NULL, 0, Message::kNormalPriority);
188 handler_peer.PostMessage(message1); 188 handler_peer.PostMessage(message1);
189 Message* message2 = new Message(2, NULL, 0, Message::kNormalPriority); 189 Message* message2 = new Message(2, NULL, 0, Message::kNormalPriority);
190 handler_peer.PostMessage(message2); 190 handler_peer.PostMessage(message2);
191 191
192 handler_peer.ClosePort(1); 192 handler_peer.ClosePort(1);
193 193
194 // Closing the port does not drop the messages from the queue. 194 // Closing the port does not drop the messages from the queue.
195 EXPECT(message1 == handler_peer.queue()->Dequeue()); 195 EXPECT(message1 == handler_peer.queue()->Dequeue());
196 EXPECT(message2 == handler_peer.queue()->Dequeue()); 196 EXPECT(message2 == handler_peer.queue()->Dequeue());
197 delete message1; 197 delete message1;
198 delete message2; 198 delete message2;
199 } 199 }
200 200
201 201
202 UNIT_TEST_CASE(MessageHandler_CloseAllPorts) { 202 VM_UNIT_TEST_CASE(MessageHandler_CloseAllPorts) {
203 TestMessageHandler handler; 203 TestMessageHandler handler;
204 MessageHandlerTestPeer handler_peer(&handler); 204 MessageHandlerTestPeer handler_peer(&handler);
205 Message* message1 = new Message(1, NULL, 0, Message::kNormalPriority); 205 Message* message1 = new Message(1, NULL, 0, Message::kNormalPriority);
206 handler_peer.PostMessage(message1); 206 handler_peer.PostMessage(message1);
207 Message* message2 = new Message(2, NULL, 0, Message::kNormalPriority); 207 Message* message2 = new Message(2, NULL, 0, Message::kNormalPriority);
208 handler_peer.PostMessage(message2); 208 handler_peer.PostMessage(message2);
209 209
210 handler_peer.CloseAllPorts(); 210 handler_peer.CloseAllPorts();
211 211
212 // All messages are dropped from the queue. 212 // All messages are dropped from the queue.
213 EXPECT(NULL == handler_peer.queue()->Dequeue()); 213 EXPECT(NULL == handler_peer.queue()->Dequeue());
214 } 214 }
215 215
216 216
217 UNIT_TEST_CASE(MessageHandler_HandleNextMessage) { 217 VM_UNIT_TEST_CASE(MessageHandler_HandleNextMessage) {
218 TestMessageHandler handler; 218 TestMessageHandler handler;
219 MessageHandlerTestPeer handler_peer(&handler); 219 MessageHandlerTestPeer handler_peer(&handler);
220 Dart_Port port1 = PortMap::CreatePort(&handler); 220 Dart_Port port1 = PortMap::CreatePort(&handler);
221 Dart_Port port2 = PortMap::CreatePort(&handler); 221 Dart_Port port2 = PortMap::CreatePort(&handler);
222 Dart_Port port3 = PortMap::CreatePort(&handler); 222 Dart_Port port3 = PortMap::CreatePort(&handler);
223 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority); 223 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority);
224 handler_peer.PostMessage(message1); 224 handler_peer.PostMessage(message1);
225 Message* oob_message1 = new Message(port2, NULL, 0, Message::kOOBPriority); 225 Message* oob_message1 = new Message(port2, NULL, 0, Message::kOOBPriority);
226 handler_peer.PostMessage(oob_message1); 226 handler_peer.PostMessage(oob_message1);
227 Message* message2 = new Message(port2, NULL, 0, Message::kNormalPriority); 227 Message* message2 = new Message(port2, NULL, 0, Message::kNormalPriority);
228 handler_peer.PostMessage(message2); 228 handler_peer.PostMessage(message2);
229 Message* oob_message2 = new Message(port3, NULL, 0, Message::kOOBPriority); 229 Message* oob_message2 = new Message(port3, NULL, 0, Message::kOOBPriority);
230 handler_peer.PostMessage(oob_message2); 230 handler_peer.PostMessage(oob_message2);
231 231
232 // We handle both oob messages and a single normal message. 232 // We handle both oob messages and a single normal message.
233 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 233 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
234 EXPECT_EQ(3, handler.message_count()); 234 EXPECT_EQ(3, handler.message_count());
235 Dart_Port* ports = handler.port_buffer(); 235 Dart_Port* ports = handler.port_buffer();
236 EXPECT_EQ(port2, ports[0]); 236 EXPECT_EQ(port2, ports[0]);
237 EXPECT_EQ(port3, ports[1]); 237 EXPECT_EQ(port3, ports[1]);
238 EXPECT_EQ(port1, ports[2]); 238 EXPECT_EQ(port1, ports[2]);
239 PortMap::ClosePorts(&handler); 239 PortMap::ClosePorts(&handler);
240 } 240 }
241 241
242 242
243 UNIT_TEST_CASE(MessageHandler_HandleNextMessage_ProcessOOBAfterError) { 243 VM_UNIT_TEST_CASE(MessageHandler_HandleNextMessage_ProcessOOBAfterError) {
244 TestMessageHandler handler; 244 TestMessageHandler handler;
245 MessageHandler::MessageStatus results[] = { 245 MessageHandler::MessageStatus results[] = {
246 MessageHandler::kError, // oob_message1 246 MessageHandler::kError, // oob_message1
247 MessageHandler::kOK, // oob_message2 247 MessageHandler::kOK, // oob_message2
248 MessageHandler::kOK, // unused 248 MessageHandler::kOK, // unused
249 }; 249 };
250 handler.set_results(results); 250 handler.set_results(results);
251 MessageHandlerTestPeer handler_peer(&handler); 251 MessageHandlerTestPeer handler_peer(&handler);
252 Dart_Port port1 = PortMap::CreatePort(&handler); 252 Dart_Port port1 = PortMap::CreatePort(&handler);
253 Dart_Port port2 = PortMap::CreatePort(&handler); 253 Dart_Port port2 = PortMap::CreatePort(&handler);
254 Dart_Port port3 = PortMap::CreatePort(&handler); 254 Dart_Port port3 = PortMap::CreatePort(&handler);
255 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority); 255 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority);
256 handler_peer.PostMessage(message1); 256 handler_peer.PostMessage(message1);
257 Message* oob_message1 = new Message(port2, NULL, 0, Message::kOOBPriority); 257 Message* oob_message1 = new Message(port2, NULL, 0, Message::kOOBPriority);
258 handler_peer.PostMessage(oob_message1); 258 handler_peer.PostMessage(oob_message1);
259 Message* oob_message2 = new Message(port3, NULL, 0, Message::kOOBPriority); 259 Message* oob_message2 = new Message(port3, NULL, 0, Message::kOOBPriority);
260 handler_peer.PostMessage(oob_message2); 260 handler_peer.PostMessage(oob_message2);
261 261
262 // When we get an error, we continue processing oob messages but 262 // When we get an error, we continue processing oob messages but
263 // stop handling normal messages. 263 // stop handling normal messages.
264 EXPECT_EQ(MessageHandler::kError, handler.HandleNextMessage()); 264 EXPECT_EQ(MessageHandler::kError, handler.HandleNextMessage());
265 EXPECT_EQ(2, handler.message_count()); 265 EXPECT_EQ(2, handler.message_count());
266 Dart_Port* ports = handler.port_buffer(); 266 Dart_Port* ports = handler.port_buffer();
267 EXPECT_EQ(port2, ports[0]); // oob_message1, error 267 EXPECT_EQ(port2, ports[0]); // oob_message1, error
268 EXPECT_EQ(port3, ports[1]); // oob_message2, ok 268 EXPECT_EQ(port3, ports[1]); // oob_message2, ok
269 handler_peer.CloseAllPorts(); 269 handler_peer.CloseAllPorts();
270 } 270 }
271 271
272 272
273 UNIT_TEST_CASE(MessageHandler_HandleNextMessage_Shutdown) { 273 VM_UNIT_TEST_CASE(MessageHandler_HandleNextMessage_Shutdown) {
274 TestMessageHandler handler; 274 TestMessageHandler handler;
275 MessageHandler::MessageStatus results[] = { 275 MessageHandler::MessageStatus results[] = {
276 MessageHandler::kOK, // oob_message1 276 MessageHandler::kOK, // oob_message1
277 MessageHandler::kShutdown, // oob_message2 277 MessageHandler::kShutdown, // oob_message2
278 MessageHandler::kOK, // unused 278 MessageHandler::kOK, // unused
279 MessageHandler::kOK, // unused 279 MessageHandler::kOK, // unused
280 }; 280 };
281 handler.set_results(results); 281 handler.set_results(results);
282 MessageHandlerTestPeer handler_peer(&handler); 282 MessageHandlerTestPeer handler_peer(&handler);
283 Dart_Port port1 = PortMap::CreatePort(&handler); 283 Dart_Port port1 = PortMap::CreatePort(&handler);
(...skipping 17 matching lines...) Expand all
301 EXPECT_EQ(port3, ports[1]); // oob_message2, shutdown 301 EXPECT_EQ(port3, ports[1]); // oob_message2, shutdown
302 { 302 {
303 // The oob queue has been cleared. oob_message3 is gone. 303 // The oob queue has been cleared. oob_message3 is gone.
304 MessageHandler::AcquiredQueues aq(&handler); 304 MessageHandler::AcquiredQueues aq(&handler);
305 EXPECT(aq.oob_queue()->Length() == 0); 305 EXPECT(aq.oob_queue()->Length() == 0);
306 } 306 }
307 handler_peer.CloseAllPorts(); 307 handler_peer.CloseAllPorts();
308 } 308 }
309 309
310 310
311 UNIT_TEST_CASE(MessageHandler_HandleOOBMessages) { 311 VM_UNIT_TEST_CASE(MessageHandler_HandleOOBMessages) {
312 TestMessageHandler handler; 312 TestMessageHandler handler;
313 MessageHandlerTestPeer handler_peer(&handler); 313 MessageHandlerTestPeer handler_peer(&handler);
314 Dart_Port port1 = PortMap::CreatePort(&handler); 314 Dart_Port port1 = PortMap::CreatePort(&handler);
315 Dart_Port port2 = PortMap::CreatePort(&handler); 315 Dart_Port port2 = PortMap::CreatePort(&handler);
316 Dart_Port port3 = PortMap::CreatePort(&handler); 316 Dart_Port port3 = PortMap::CreatePort(&handler);
317 Dart_Port port4 = PortMap::CreatePort(&handler); 317 Dart_Port port4 = PortMap::CreatePort(&handler);
318 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority); 318 Message* message1 = new Message(port1, NULL, 0, Message::kNormalPriority);
319 handler_peer.PostMessage(message1); 319 handler_peer.PostMessage(message1);
320 Message* message2 = new Message(port2, NULL, 0, Message::kNormalPriority); 320 Message* message2 = new Message(port2, NULL, 0, Message::kNormalPriority);
321 handler_peer.PostMessage(message2); 321 handler_peer.PostMessage(message2);
(...skipping 24 matching lines...) Expand all
346 MessageHandler* handler = info->handler; 346 MessageHandler* handler = info->handler;
347 MessageHandlerTestPeer handler_peer(handler); 347 MessageHandlerTestPeer handler_peer(handler);
348 for (int i = 0; i < info->count; i++) { 348 for (int i = 0; i < info->count; i++) {
349 Message* message = 349 Message* message =
350 new Message(info->ports[i], NULL, 0, Message::kNormalPriority); 350 new Message(info->ports[i], NULL, 0, Message::kNormalPriority);
351 handler_peer.PostMessage(message); 351 handler_peer.PostMessage(message);
352 } 352 }
353 } 353 }
354 354
355 355
356 UNIT_TEST_CASE(MessageHandler_Run) { 356 VM_UNIT_TEST_CASE(MessageHandler_Run) {
357 ThreadPool pool; 357 ThreadPool pool;
358 TestMessageHandler handler; 358 TestMessageHandler handler;
359 MessageHandlerTestPeer handler_peer(&handler); 359 MessageHandlerTestPeer handler_peer(&handler);
360 int sleep = 0; 360 int sleep = 0;
361 const int kMaxSleep = 20 * 1000; // 20 seconds. 361 const int kMaxSleep = 20 * 1000; // 20 seconds.
362 362
363 EXPECT(!handler.HasLivePorts()); 363 EXPECT(!handler.HasLivePorts());
364 handler_peer.increment_live_ports(); 364 handler_peer.increment_live_ports();
365 365
366 handler.Run(&pool, TestStartFunction, TestEndFunction, 366 handler.Run(&pool, TestStartFunction, TestEndFunction,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 for (int i = 1; i < 11; i++) { 402 for (int i = 1; i < 11; i++) {
403 EXPECT_EQ(ports[i - 1], handler_ports[i]); 403 EXPECT_EQ(ports[i - 1], handler_ports[i]);
404 } 404 }
405 handler_peer.decrement_live_ports(); 405 handler_peer.decrement_live_ports();
406 EXPECT(!handler.HasLivePorts()); 406 EXPECT(!handler.HasLivePorts());
407 PortMap::ClosePorts(&handler); 407 PortMap::ClosePorts(&handler);
408 delete[] ports; 408 delete[] ports;
409 } 409 }
410 410
411 } // namespace dart 411 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/memory_region_test.cc ('k') | runtime/vm/metrics_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698