int main(int ac, char **av) { uint64_t sleep_nanos = DEFAULT_NANOSLEEP_TIME; int opt; uint32_t num_failures = 0; puts("This is a basic functionality test being repurposed as an"); puts(" unit/regression test. The test parameters default to values that"); puts("are more appropriate for heavily loaded continuous-testing robots."); printf("\nThe default values are:\n -S %"NACL_PRIu64 " -f %f -o %"NACL_PRIu64" -s %"NACL_PRIu64"\n\n", sleep_nanos, g_fuzzy_factor, g_syscall_overhead, g_slop_ms); puts("For testing functionality, this test should be run with a different"); puts("set of parameters. On an unloaded i7, a sleep duration (-S) of"); puts("1000000 ns (one millisecond), with a fuzziness factor (-f) of 1.25,"); puts("a constant test overhead of 100000 ns (100 us), and a"); puts("sleep duration \"slop\" (-s) of 0 is fine."); while (-1 != (opt = getopt(ac, av, "f:o:s:S:"))) { switch (opt) { case 'f': g_fuzzy_factor = strtod(optarg, (char **) NULL); break; case 'o': g_syscall_overhead = strtoul(optarg, (char **) NULL, 0); break; case 's': g_slop_ms = strtoul(optarg, (char **) NULL, 0); break; case 'S': sleep_nanos = strtoul(optarg, (char **) NULL, 0); break; default: fprintf(stderr, "nacl_clock_test: unrecognized option `%c'.\n", opt); fprintf(stderr, "Usage: nacl_clock_test [-f fuzz_factor] [-s sleep_nanos]\n" " [-o syscall_overhead_nanos]\n"); return -1; } } NaClPlatformInit(); num_failures += ClockMonotonicAccuracyTest(sleep_nanos); num_failures += ClockRealtimeAccuracyTest(); NaClPlatformFini(); return num_failures; }
/* * It is the responsibility of the invoking environment to delete the * file passed as command-line argument. See the build.scons file. */ int main(int ac, char **av) { char const *test_dir_name = "/tmp/nacl_host_desc_test"; struct NaClHostDesc hd; struct NaClHostDesc hd_ro; size_t error_count; size_t ix; int test_passed; int opt; int num_runs = 1; int test_run; while (EOF != (opt = getopt(ac, av, "c:t:"))) { switch (opt) { case 'c': num_runs = atoi(optarg); break; case 't': test_dir_name = optarg; break; default: fprintf(stderr, "Usage: nacl_host_desc_mmap_test [-c run_count]\n" " [-t test_temp_dir]\n"); exit(1); } } NaClPlatformInit(); error_count = 0; for (test_run = 0; test_run < num_runs; ++test_run) { printf("Test run %d\n\n", test_run); for (ix = 0; ix < NACL_ARRAY_SIZE(tests); ++ix) { char test_file_name[PATH_MAX]; SNPRINTF(test_file_name, sizeof test_file_name, "%s/f%d.%"NACL_PRIuS, test_dir_name, test_run, ix); printf("%s\n", tests[ix].test_name); CreateTestFile(&hd, &hd_ro, test_file_name, &tests[ix]); test_passed = (*tests[ix].test_func)(&hd, &hd_ro, tests[ix].test_params); CloseTestFile(&hd); error_count += !test_passed; printf("%s\n", test_passed ? "PASSED" : "FAILED"); } } NaClPlatformFini(); /* we ignore the 2^32 or 2^64 total errors case */ return (error_count > 255) ? 255 : error_count; }
/* * It is the responsibility of the invoking environment to delete the * file passed as command-line argument. See the build.scons file. */ int main(int ac, char **av) { char const *test_dir_name = "/tmp/nacl_host_desc_mmap_win_test"; struct NaClHostDesc hd; int test_passed; size_t error_count; size_t ix; int opt; int num_runs = 1; int test_run; HANDLE h; int d; while (EOF != (opt = getopt(ac, av, "c:t:"))) { switch (opt) { case 'c': num_runs = atoi(optarg); break; case 't': test_dir_name = optarg; break; default: fprintf(stderr, "Usage: nacl_host_desc_mmap_win_test [-c run_count]\n" " [-t test_temp_dir]\n"); exit(1); } } NaClPlatformInit(); error_count = 0; for (test_run = 0; test_run < num_runs; ++test_run) { printf("Test run %d\n\n", test_run); for (ix = 0; ix < NACL_ARRAY_SIZE(tests); ++ix) { char test_file_name[PATH_MAX]; _snprintf_s(test_file_name, sizeof test_file_name, _TRUNCATE, "%s/f%d.%"NACL_PRIuS, test_dir_name, test_run, ix); printf("%s\n", tests[ix].test_info); printf("-- %s\n", tests[ix].file_type->file_type_description); h = CreateTestFile(test_file_name, tests[ix].file_type); if (ERROR_SUCCESS == tests[ix].expected_open_error) { if (INVALID_HANDLE_VALUE == h) { DWORD err = GetLastError(); NaClLog(LOG_ERROR, "CreateTestFile for %s failed, error %d\n", test_file_name, err); printf("FAILED\n"); ++error_count; continue; } d = _open_osfhandle((intptr_t) h, tests[ix].oflags); NaClHostDescPosixTake(&hd, d, tests[ix].posix_flags); test_passed = TryToMap(&hd, tests[ix].map_bytes, tests[ix].prot, tests[ix].map_flags, tests[ix].expected_mmap_errno); error_count += !test_passed; printf("%s\n", test_passed ? "PASSED" : "FAILED"); CHECK(0 == NaClHostDescClose(&hd)); AttemptToDeleteTestFile(test_file_name); } else { if (INVALID_HANDLE_VALUE == h) { DWORD err = GetLastError(); if (err != tests[ix].expected_open_error) { NaClLog(LOG_ERROR, "Expected CreateTestFile for %s to failed with" " error %d, but got error %d\n", test_file_name, err, tests[ix].expected_open_error); printf("FAILED\n"); ++error_count; } else { printf("PASSED (open failed)\n"); } continue; } else { NaClLog(LOG_ERROR, "Expected CreateTestFile for %s to fail with error %d," " but succeeded instead!\n", test_file_name, tests[ix].expected_open_error); (void) CloseHandle(h); AttemptToDeleteTestFile(test_file_name); printf("FAILED\n"); ++error_count; continue; } } } } printf("Total of %d error%s.\n", error_count, (error_count == 1) ? "" : "s"); NaClPlatformFini(); /* we ignore the 2^32 or 2^64 total errors case */ return (error_count > 255) ? 255 : error_count; }
int main(int ac, char **av) { int exit_status = -1; int opt; size_t num_threads = 16; size_t n; struct NaClThread thr; while (EOF != (opt = getopt(ac, av, "n:s:t:"))) { switch (opt) { case 'n': num_threads = strtoul(optarg, (char **) NULL, 0); break; case 't': gNumTriesSufficient = strtoul(optarg, (char **) NULL, 0); break; default: fprintf(stderr, "Usage: nacl_semaphore_test [args]\n" " -n n number of threads used to test semaphore\n" " -t n number of TryWait operations before blocking Try\n"); goto cleanup0; } } NaClPlatformInit(); if (!NaClSemCtor(&gSem, 0)) { fprintf(stderr, "nacl_semaphore_test: NaClSemCtor failed!\n"); goto cleanup1; } if (!NaClMutexCtor(&gMu)) { fprintf(stderr, "nacl_semaphore_test: NaClMutexCtor failed!\n"); goto cleanup2; } if (!NaClCondVarCtor(&gCv)) { fprintf(stderr, "nacl_semaphore_test: NaClCondVarCtor failed!\n"); goto cleanup3; } for (n = 0; n < num_threads; ++n) { if (!NaClThreadCtor(&thr, ThreadMain, (void *) (uintptr_t) n, STACK_SIZE_BYTES)) { fprintf(stderr, "nacl_semaphore_test: could not create thread %"NACL_PRIdS"\n", n); goto cleanup4; /* osx leak semaphore otherwise */ } } NaClMutexLock(&gMu); while (gNumThreadsTried != num_threads) { NaClCondVarWait(&gCv, &gMu); } NaClMutexUnlock(&gMu); for (n = 0; n < num_threads; ++n) { NaClSemPost(&gSem); /* let a thread go */ } NaClMutexLock(&gMu); while (gNumThreadsDone != num_threads) { NaClCondVarWait(&gCv, &gMu); } exit_status = gFailure; NaClMutexUnlock(&gMu); if (0 == exit_status) { printf("SUCCESS\n"); } cleanup4: /* single exit with (ah hem) simulation of RAII via cleanup sled */ NaClCondVarDtor(&gCv); cleanup3: NaClMutexDtor(&gMu); cleanup2: NaClSemDtor(&gSem); cleanup1: NaClPlatformFini(); cleanup0: return exit_status; }