| OLD | NEW |
| 1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 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 | 5 |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <sys/time.h> | 10 #include <sys/time.h> |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 EXPECT_LT(TIMEOUT_LONG - TIMEOUT_SLOP, duration); | 318 EXPECT_LT(TIMEOUT_LONG - TIMEOUT_SLOP, duration); |
| 319 EXPECT_GT(TIMEOUT_LONG + SCHEDULING_GRANULARITY, duration); | 319 EXPECT_GT(TIMEOUT_LONG + SCHEDULING_GRANULARITY, duration); |
| 320 } | 320 } |
| 321 | 321 |
| 322 struct SignalInfo { | 322 struct SignalInfo { |
| 323 EventEmitterTester* em; | 323 EventEmitterTester* em; |
| 324 unsigned int ms_wait; | 324 unsigned int ms_wait; |
| 325 uint32_t events; | 325 uint32_t events; |
| 326 }; | 326 }; |
| 327 | 327 |
| 328 void *SignalEmitter(void *ptr) { | 328 static void *SignalEmitterThread(void *ptr) { |
| 329 SignalInfo* info = (SignalInfo*) ptr; | 329 SignalInfo* info = (SignalInfo*) ptr; |
| 330 struct timespec ts; | 330 struct timespec ts; |
| 331 ts.tv_sec = 0; | 331 ts.tv_sec = 0; |
| 332 ts.tv_nsec = info->ms_wait * 1000000; | 332 ts.tv_nsec = info->ms_wait * 1000000; |
| 333 | 333 |
| 334 nanosleep(&ts, NULL); | 334 nanosleep(&ts, NULL); |
| 335 | 335 |
| 336 info->em->RaiseEvent(info->events); | 336 info->em->RaiseEvent(info->events); |
| 337 return NULL; | 337 return NULL; |
| 338 } | 338 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 349 EventData ev[MAX_EVENTS]; | 349 EventData ev[MAX_EVENTS]; |
| 350 memset(ev, 0, sizeof(ev)); | 350 memset(ev, 0, sizeof(ev)); |
| 351 EXPECT_EQ(0, listener->Track(ID_EMITTER, emitter, KE_EXPECTED, USER_DATA_A)); | 351 EXPECT_EQ(0, listener->Track(ID_EMITTER, emitter, KE_EXPECTED, USER_DATA_A)); |
| 352 | 352 |
| 353 // Setup another thread to wait 1/4 of the max time, and signal both | 353 // Setup another thread to wait 1/4 of the max time, and signal both |
| 354 // an expected, and unexpected value. | 354 // an expected, and unexpected value. |
| 355 siginfo.em = emitter.get(); | 355 siginfo.em = emitter.get(); |
| 356 siginfo.ms_wait = TIMEOUT_SHORT; | 356 siginfo.ms_wait = TIMEOUT_SHORT; |
| 357 siginfo.events = KE_EXPECTED | KE_FILTERED; | 357 siginfo.events = KE_EXPECTED | KE_FILTERED; |
| 358 pthread_t tid; | 358 pthread_t tid; |
| 359 pthread_create(&tid, NULL, SignalEmitter, &siginfo); | 359 pthread_create(&tid, NULL, SignalEmitterThread, &siginfo); |
| 360 | 360 |
| 361 // Wait for the signal from the other thread and time it. | 361 // Wait for the signal from the other thread and time it. |
| 362 gettimeofday(&start, NULL); | 362 gettimeofday(&start, NULL); |
| 363 int cnt = 0; | 363 int cnt = 0; |
| 364 EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, TIMEOUT_VERY_LONG, &cnt)); | 364 EXPECT_EQ(0, listener->Wait(ev, MAX_EVENTS, TIMEOUT_VERY_LONG, &cnt)); |
| 365 EXPECT_EQ(1, cnt); | 365 EXPECT_EQ(1, cnt); |
| 366 gettimeofday(&end, NULL); | 366 gettimeofday(&end, NULL); |
| 367 | 367 |
| 368 // Verify the wait duration, and that we only recieved the expected signal. | 368 // Verify the wait duration, and that we only recieved the expected signal. |
| 369 duration = Duration(&start, &end); | 369 duration = Duration(&start, &end); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 // Expect normal files to be read/write and one pollable node to be read. | 471 // Expect normal files to be read/write and one pollable node to be read. |
| 472 SetFDs(&rd_set, fds); | 472 SetFDs(&rd_set, fds); |
| 473 SetFDs(&wr_set, fds); | 473 SetFDs(&wr_set, fds); |
| 474 cnt = select(fdnum, &rd_set, &wr_set, NULL, NULL); | 474 cnt = select(fdnum, &rd_set, &wr_set, NULL, NULL); |
| 475 EXPECT_EQ(7, cnt); | 475 EXPECT_EQ(7, cnt); |
| 476 EXPECT_NE(0, FD_ISSET(fds[0], &rd_set)); | 476 EXPECT_NE(0, FD_ISSET(fds[0], &rd_set)); |
| 477 EXPECT_EQ(0, FD_ISSET(fds[0], &wr_set)); | 477 EXPECT_EQ(0, FD_ISSET(fds[0], &wr_set)); |
| 478 } | 478 } |
| 479 | 479 |
| 480 | 480 |
| OLD | NEW |