| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "native_client/src/include/nacl_assert.h" | 9 #include "native_client/src/include/nacl_assert.h" |
| 10 #include "native_client/src/include/nacl_macros.h" | 10 #include "native_client/src/include/nacl_macros.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 uint64_t sleep_usec; | 83 uint64_t sleep_usec; |
| 84 uint64_t cond_timeout_usec; | 84 uint64_t cond_timeout_usec; |
| 85 int abort_on_wake; | 85 int abort_on_wake; |
| 86 struct NaClMutex mu; | 86 struct NaClMutex mu; |
| 87 struct NaClThread thr; | 87 struct NaClThread thr; |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 void AlarmerStateCtor(struct AlarmerState *sp, | 90 void AlarmerStateCtor(struct AlarmerState *sp, |
| 91 uint64_t sleep_usec, | 91 uint64_t sleep_usec, |
| 92 uint64_t cond_timeout_usec) { | 92 uint64_t cond_timeout_usec) { |
| 93 NaClMutexCtor(&sp->mu); | 93 NaClXMutexCtor(&sp->mu); |
| 94 sp->abort_on_wake = 1; | 94 sp->abort_on_wake = 1; |
| 95 sp->sleep_usec = sleep_usec; | 95 sp->sleep_usec = sleep_usec; |
| 96 sp->cond_timeout_usec = cond_timeout_usec; | 96 sp->cond_timeout_usec = cond_timeout_usec; |
| 97 } | 97 } |
| 98 | 98 |
| 99 void AlarmerStateDtor(struct AlarmerState *sp) { | 99 void AlarmerStateDtor(struct AlarmerState *sp) { |
| 100 NaClMutexDtor(&sp->mu); | 100 NaClMutexDtor(&sp->mu); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void AlarmerDisable(struct AlarmerState *sp) { | 103 void AlarmerDisable(struct AlarmerState *sp) { |
| 104 NaClMutexLock(&sp->mu); | 104 NaClXMutexLock(&sp->mu); |
| 105 sp->abort_on_wake = 0; | 105 sp->abort_on_wake = 0; |
| 106 NaClMutexUnlock(&sp->mu); | 106 NaClXMutexUnlock(&sp->mu); |
| 107 } | 107 } |
| 108 | 108 |
| 109 static void PrintFailureSuggestions() { | 109 static void PrintFailureSuggestions() { |
| 110 printf("If this test is running on a very busy machine,\n" | 110 printf("If this test is running on a very busy machine,\n" |
| 111 " try using the -F flag to increase the timeout\n" | 111 " try using the -F flag to increase the timeout\n" |
| 112 " (this is a multiplier of actual requested timeout time)\n" | 112 " (this is a multiplier of actual requested timeout time)\n" |
| 113 " or -C to increase the minium value for maximum elapsed\n" | 113 " or -C to increase the minium value for maximum elapsed\n" |
| 114 " time permitted\n" | 114 " time permitted\n" |
| 115 "Current fuzz factor %g\n", | 115 "Current fuzz factor %g\n", |
| 116 gSchedulerMaxFuzzFactor); | 116 gSchedulerMaxFuzzFactor); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 133 fflush(NULL); | 133 fflush(NULL); |
| 134 } | 134 } |
| 135 #if NACL_WINDOWS | 135 #if NACL_WINDOWS |
| 136 Sleep(millisec); | 136 Sleep(millisec); |
| 137 #else | 137 #else |
| 138 usleep((useconds_t) sp->sleep_usec); | 138 usleep((useconds_t) sp->sleep_usec); |
| 139 #endif | 139 #endif |
| 140 if (gVerbosity) { | 140 if (gVerbosity) { |
| 141 printf("Alarmer %p: woke up\n", (void *) sp); | 141 printf("Alarmer %p: woke up\n", (void *) sp); |
| 142 } | 142 } |
| 143 NaClMutexLock(&sp->mu); | 143 NaClXMutexLock(&sp->mu); |
| 144 should_abort = sp->abort_on_wake; | 144 should_abort = sp->abort_on_wake; |
| 145 cond_timeout_usec = sp->cond_timeout_usec; | 145 cond_timeout_usec = sp->cond_timeout_usec; |
| 146 NaClMutexUnlock(&sp->mu); | 146 NaClXMutexUnlock(&sp->mu); |
| 147 if (should_abort) { | 147 if (should_abort) { |
| 148 printf("Alarmer %p: woke up after %"NACL_PRId64".%06"NACL_PRId64" seconds" | 148 printf("Alarmer %p: woke up after %"NACL_PRId64".%06"NACL_PRId64" seconds" |
| 149 " without condition\n", | 149 " without condition\n", |
| 150 (void *) sp, | 150 (void *) sp, |
| 151 sp->sleep_usec / kMicroXinX, | 151 sp->sleep_usec / kMicroXinX, |
| 152 sp->sleep_usec % kMicroXinX); | 152 sp->sleep_usec % kMicroXinX); |
| 153 printf("condvar timeout was %"NACL_PRId64".%06"NACL_PRId64" sec\n", | 153 printf("condvar timeout was %"NACL_PRId64".%06"NACL_PRId64" sec\n", |
| 154 cond_timeout_usec / kMicroXinX, | 154 cond_timeout_usec / kMicroXinX, |
| 155 cond_timeout_usec % kMicroXinX); | 155 cond_timeout_usec % kMicroXinX); |
| 156 printf("Alarmer %p: variable timing out.\n", (void *) sp); | 156 printf("Alarmer %p: variable timing out.\n", (void *) sp); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 if (NULL != asp) { | 248 if (NULL != asp) { |
| 249 AlarmerDisable(asp); | 249 AlarmerDisable(asp); |
| 250 } | 250 } |
| 251 TimerCheckElapsed(&t, cond_timeout_usec, min_elapsed_usec, max_elapsed_usec); | 251 TimerCheckElapsed(&t, cond_timeout_usec, min_elapsed_usec, max_elapsed_usec); |
| 252 } | 252 } |
| 253 | 253 |
| 254 struct NaClMutex gMu; | 254 struct NaClMutex gMu; |
| 255 struct NaClCondVar gCv; | 255 struct NaClCondVar gCv; |
| 256 | 256 |
| 257 void TestInit() { | 257 void TestInit() { |
| 258 (void) NaClMutexCtor(&gMu); | 258 NaClXMutexCtor(&gMu); |
| 259 (void) NaClCondVarCtor(&gCv); | 259 NaClXCondVarCtor(&gCv); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void TestFini() { | 262 void TestFini() { |
| 263 NaClMutexDtor(&gMu); | 263 NaClMutexDtor(&gMu); |
| 264 NaClCondVarDtor(&gCv); | 264 NaClCondVarDtor(&gCv); |
| 265 } | 265 } |
| 266 | 266 |
| 267 struct TestFunctorArg { | 267 struct TestFunctorArg { |
| 268 uint64_t sleep_usec; | 268 uint64_t sleep_usec; |
| 269 }; | 269 }; |
| 270 | 270 |
| 271 void TestRelWait(void *arg) { | 271 void TestRelWait(void *arg) { |
| 272 uint64_t sleep_usec; | 272 uint64_t sleep_usec; |
| 273 struct nacl_abi_timespec t; | 273 struct nacl_abi_timespec t; |
| 274 | 274 |
| 275 sleep_usec = ((struct TestFunctorArg *) arg)->sleep_usec; | 275 sleep_usec = ((struct TestFunctorArg *) arg)->sleep_usec; |
| 276 t.tv_sec = (nacl_abi_time_t) (sleep_usec / kMicroXinX); | 276 t.tv_sec = (nacl_abi_time_t) (sleep_usec / kMicroXinX); |
| 277 t.tv_nsec = (long int) (kNanoXinMicroX * (sleep_usec % kMicroXinX)); | 277 t.tv_nsec = (long int) (kNanoXinMicroX * (sleep_usec % kMicroXinX)); |
| 278 if (gVerbosity > 1) { | 278 if (gVerbosity > 1) { |
| 279 printf("TestRelWait: locking\n"); | 279 printf("TestRelWait: locking\n"); |
| 280 } | 280 } |
| 281 NaClXMutexLock(&gMu); | 281 NaClXMutexLock(&gMu); |
| 282 if (gVerbosity > 1) { | 282 if (gVerbosity > 1) { |
| 283 printf("TestRelWait: waiting\n"); | 283 printf("TestRelWait: waiting\n"); |
| 284 } | 284 } |
| 285 NaClCondVarTimedWaitRelative(&gCv, &gMu, &t); | 285 NaClXCondVarTimedWaitRelative(&gCv, &gMu, &t); |
| 286 if (gVerbosity > 1) { | 286 if (gVerbosity > 1) { |
| 287 printf("TestRelWait: unlocking\n"); | 287 printf("TestRelWait: unlocking\n"); |
| 288 } | 288 } |
| 289 NaClXMutexUnlock(&gMu); | 289 NaClXMutexUnlock(&gMu); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void TestAbsWait(void *arg) { | 292 void TestAbsWait(void *arg) { |
| 293 uint64_t sleep_usec; | 293 uint64_t sleep_usec; |
| 294 struct nacl_abi_timeval now; | 294 struct nacl_abi_timeval now; |
| 295 struct nacl_abi_timespec t; | 295 struct nacl_abi_timespec t; |
| 296 | 296 |
| 297 sleep_usec = ((struct TestFunctorArg *) arg)->sleep_usec; | 297 sleep_usec = ((struct TestFunctorArg *) arg)->sleep_usec; |
| 298 (void) NaClGetTimeOfDay(&now); | 298 (void) NaClGetTimeOfDay(&now); |
| 299 t.tv_sec = (nacl_abi_time_t) (now.nacl_abi_tv_sec + sleep_usec / kMicroXinX); | 299 t.tv_sec = (nacl_abi_time_t) (now.nacl_abi_tv_sec + sleep_usec / kMicroXinX); |
| 300 t.tv_nsec = (long int) (kNanoXinMicroX * (now.nacl_abi_tv_usec | 300 t.tv_nsec = (long int) (kNanoXinMicroX * (now.nacl_abi_tv_usec |
| 301 + (sleep_usec % kMicroXinX))); | 301 + (sleep_usec % kMicroXinX))); |
| 302 while (t.tv_nsec > kNanoXinX) { | 302 while (t.tv_nsec > kNanoXinX) { |
| 303 t.tv_nsec -= kNanoXinX; | 303 t.tv_nsec -= kNanoXinX; |
| 304 ++t.tv_sec; | 304 ++t.tv_sec; |
| 305 } | 305 } |
| 306 if (gVerbosity > 1) { | 306 if (gVerbosity > 1) { |
| 307 printf("TestAbsWait: locking\n"); | 307 printf("TestAbsWait: locking\n"); |
| 308 } | 308 } |
| 309 NaClXMutexLock(&gMu); | 309 NaClXMutexLock(&gMu); |
| 310 if (gVerbosity > 1) { | 310 if (gVerbosity > 1) { |
| 311 printf("TestAbsWait: waiting\n"); | 311 printf("TestAbsWait: waiting\n"); |
| 312 } | 312 } |
| 313 NaClCondVarTimedWaitAbsolute(&gCv, &gMu, &t); | 313 NaClXCondVarTimedWaitAbsolute(&gCv, &gMu, &t); |
| 314 if (gVerbosity > 1) { | 314 if (gVerbosity > 1) { |
| 315 printf("TestAbsWait: unlocking\n"); | 315 printf("TestAbsWait: unlocking\n"); |
| 316 } | 316 } |
| 317 NaClXMutexUnlock(&gMu); | 317 NaClXMutexUnlock(&gMu); |
| 318 } | 318 } |
| 319 | 319 |
| 320 | 320 |
| 321 int main(int argc, | 321 int main(int argc, |
| 322 char **argv) { | 322 char **argv) { |
| 323 int opt; | 323 int opt; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 FunctorDelays(test_tbl[ix], &arg, sleep_usec, min_sleep, max_sleep, | 437 FunctorDelays(test_tbl[ix], &arg, sleep_usec, min_sleep, max_sleep, |
| 438 alarmer); | 438 alarmer); |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 TestFini(); | 441 TestFini(); |
| 442 | 442 |
| 443 NaClAllModulesFini(); | 443 NaClAllModulesFini(); |
| 444 printf("PASS\n"); | 444 printf("PASS\n"); |
| 445 return 0; | 445 return 0; |
| 446 } | 446 } |
| OLD | NEW |