int main(int argc, char** argv) { setbuf(stdout, nullptr); if(argc == 1) { print_tests(); } else if(argc >= 2) { uint32_t index; if(sscanf(argv[1], "%u", &index) == 1) { if(index < ArraySize(TestList)) { printf("Running %s...\n", TestList[index].Name); printf("%s\n", (TestList[index].Func(argc - 2, argv + 2) ? "Success!" : "Failure!")); } else { print_tests(); } } else { printf("Could not parse \"%s\" as index\n", argv[1]); } } return 0; }
void usage() { enable_more(); printf("Usage: [on <node>] [more] <command>|* [<options>]\n"); printf("\nTest commands:\n"); print_tests(TRUE); printf("\n\nControl commands:\n"); print_tests(FALSE); printf("\n\nThe '?' option reports usage for the specified command\n"); printf("\nUse <CTRL> c to interrupt\n\n"); }
static void register_tests(int print) { cp_hash_register(&tests[0].array, &tests[0].entries); print_tests(&tests[0], print); cp_skcipher_register(&tests[1].array, &tests[1].entries); print_tests(&tests[1], print); cp_rng_register(&tests[2].array, &tests[2].entries); print_tests(&tests[2], print); cp_aead_register(&tests[3].array, &tests[3].entries); print_tests(&tests[3], print); }
int main(int argc, char **argv) { const struct test_suite *test = NULL; int test_nr = -1; int opt; /* TODO it must be agreed with shell maximum command length */ char test_name[100] = { 0 }; getopt_init(); while (-1 != (opt = getopt(argc, argv, "hn:t:i"))) { switch (opt) { case 'n': if ((optarg == NULL) || (!sscanf(optarg, "%d", &test_nr))) { printf("test -n: number expected\n"); print_usage(); return -EINVAL; } break; case 't': if ((optarg == NULL) || (!sscanf(optarg, "%s", test_name))) { printf("test -t: test name expected\n"); print_usage(); return -EINVAL; } break; case '?': case 'h': print_usage(); /* FALLTHROUGH */ default: return 0; } } if (test_nr != -1) { if (NULL == (test = get_test_by_nr(test_nr))) { return -ENOENT; } } if (*test_name != 0) { if (NULL == (test = test_lookup(test_name))) { printf("Can't find test named \"%s\"\n", test_name); return -ENOENT; } } if (NULL == test) { print_tests(); return 0; } return test_suite_run(test); }
static int maybe_run_test(int argc, char **argv) { if (strcmp(argv[1], "--list") == 0) { print_tests(stdout); return 0; } if (strcmp(argv[1], "spawn_helper") == 0) { printf("hello world\n"); return 42; } return run_test(argv[1], BENCHMARK_TIMEOUT, 1, 1); }
static int maybe_run_test(int argc, char **argv) { if ((strcmp(argv[1], "--list") == 0) || (strcmp(argv[1], "-l") == 0)) { print_tests(); return 0; } if ((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0)) { print_help(argv[0]); return 0; } return run_test(argv[1], 1, 1); }
int main(int argc, char* argv[]) { bool success = true; try { std::string testGroup; int test; po::options_description optionList ("Allowed options"); optionList.add_options() ("test,t", po::value<std::string>(&testGroup)->default_value(gTestGroupDefault), "Selects which test group to run") ("number,n", po::value<int>(&test)->default_value(gTestDefault), "Select a test within a group") ("list-tests,l", "List available tests") ("disable-seg,d", "Disable the seg-fault handler to make debugging easier") ("help,h", "Prints this message") ; po::positional_options_description positionalOptions; positionalOptions.add("test", -1); po::variables_map parsedOptions; po::store (po::command_line_parser (argc, argv).options(optionList).positional(positionalOptions).run(), parsedOptions); po::notify (parsedOptions); if (parsedOptions.count("disable-seg") == 0) std::signal(SIGSEGV, segfault_handler); if (0 < parsedOptions.count("help")) { std::cout << "CS 240 Collections Pass Off" << std::endl; std::cout << optionList << std::endl; } else if (0 < parsedOptions.count("list-tests")) print_tests(); else success = run(testGroup, test); } catch (std::exception &e) { std::cerr << e.what() << std::endl; std::cerr << "Abborting" << std::endl; success = false;; } return success? boost::exit_success : boost::exit_failure; }
static int maybe_run_test(int argc, char **argv) { if (strcmp(argv[1], "--list") == 0) { print_tests(stdout); return 0; } if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) { return ipc_helper(0); } if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) { return ipc_helper(1); } if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) { return stdio_over_pipes_helper(); } if (strcmp(argv[1], "spawn_helper1") == 0) { return 1; } if (strcmp(argv[1], "spawn_helper2") == 0) { printf("hello world\n"); return 1; } if (strcmp(argv[1], "spawn_helper3") == 0) { char buffer[256]; fgets(buffer, sizeof(buffer) - 1, stdin); buffer[sizeof(buffer) - 1] = '\0'; fputs(buffer, stdout); return 1; } if (strcmp(argv[1], "spawn_helper4") == 0) { /* Never surrender, never return! */ while (1) uv_sleep(10000); } return run_test(argv[1], TEST_TIMEOUT, 0); }
static int maybe_run_test(int argc, char **argv) { if (strcmp(argv[1], "--list") == 0) { print_tests(stdout); return 0; } if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) { return ipc_helper(0); } if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) { return ipc_helper(1); } if (strcmp(argv[1], "ipc_helper_heavy_traffic_deadlock_bug") == 0) { return ipc_helper_heavy_traffic_deadlock_bug(); } if (strcmp(argv[1], "ipc_send_recv_helper") == 0) { return ipc_send_recv_helper(); } if (strcmp(argv[1], "ipc_helper_tcp_connection") == 0) { return ipc_helper_tcp_connection(); } if (strcmp(argv[1], "ipc_helper_closed_handle") == 0) { return ipc_helper_closed_handle(); } if (strcmp(argv[1], "ipc_helper_bind_twice") == 0) { return ipc_helper_bind_twice(); } if (strcmp(argv[1], "ipc_helper_send_zero") == 0) { return ipc_helper_send_zero(); } if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) { return stdio_over_pipes_helper(); } if (strcmp(argv[1], "spawn_helper1") == 0) { notify_parent_process(); return 1; } if (strcmp(argv[1], "spawn_helper2") == 0) { notify_parent_process(); printf("hello world\n"); return 1; } if (strcmp(argv[1], "spawn_tcp_server_helper") == 0) { notify_parent_process(); return spawn_tcp_server_helper(); } if (strcmp(argv[1], "spawn_helper3") == 0) { char buffer[256]; notify_parent_process(); ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin)); buffer[sizeof(buffer) - 1] = '\0'; fputs(buffer, stdout); return 1; } if (strcmp(argv[1], "spawn_helper4") == 0) { notify_parent_process(); /* Never surrender, never return! */ while (1) uv_sleep(10000); } if (strcmp(argv[1], "spawn_helper5") == 0) { const char out[] = "fourth stdio!\n"; notify_parent_process(); { #ifdef _WIN32 DWORD bytes; WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL); #else ssize_t r; do r = write(3, out, sizeof(out) - 1); while (r == -1 && errno == EINTR); fsync(3); #endif } return 1; } if (strcmp(argv[1], "spawn_helper6") == 0) { int r; notify_parent_process(); r = fprintf(stdout, "hello world\n"); ASSERT(r > 0); r = fprintf(stderr, "hello errworld\n"); ASSERT(r > 0); return 1; } if (strcmp(argv[1], "spawn_helper7") == 0) { int r; char *test; notify_parent_process(); /* Test if the test value from the parent is still set */ test = getenv("ENV_TEST"); ASSERT(test != NULL); r = fprintf(stdout, "%s", test); ASSERT(r > 0); return 1; } #ifndef _WIN32 if (strcmp(argv[1], "spawn_helper8") == 0) { int fd; notify_parent_process(); ASSERT(sizeof(fd) == read(0, &fd, sizeof(fd))); ASSERT(fd > 2); ASSERT(-1 == write(fd, "x", 1)); return 1; } #endif /* !_WIN32 */ if (strcmp(argv[1], "spawn_helper9") == 0) { notify_parent_process(); spawn_stdin_stdout(); return 1; } #ifndef _WIN32 if (strcmp(argv[1], "spawn_helper_setuid_setgid") == 0) { uv_uid_t uid = atoi(argv[2]); uv_gid_t gid = atoi(argv[3]); ASSERT(uid == getuid()); ASSERT(gid == getgid()); notify_parent_process(); return 1; } #endif /* !_WIN32 */ return run_test(argv[1], 0, 1); }
static int maybe_run_test(int argc, char **argv) { if (strcmp(argv[1], "--list") == 0) { print_tests(stdout); return 0; } if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) { return ipc_helper(0); } if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) { return ipc_helper(1); } if (strcmp(argv[1], "ipc_helper_heavy_traffic_deadlock_bug") == 0) { return ipc_helper_heavy_traffic_deadlock_bug(); } if (strcmp(argv[1], "ipc_send_recv_helper") == 0) { return ipc_send_recv_helper(); } if (strcmp(argv[1], "ipc_helper_tcp_connection") == 0) { return ipc_helper_tcp_connection(); } if (strcmp(argv[1], "ipc_helper_closed_handle") == 0) { return ipc_helper_closed_handle(); } if (strcmp(argv[1], "ipc_helper_bind_twice") == 0) { return ipc_helper_bind_twice(); } if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) { return stdio_over_pipes_helper(); } if (strcmp(argv[1], "spawn_helper1") == 0) { notify_parent_process(); return 1; } if (strcmp(argv[1], "spawn_helper2") == 0) { notify_parent_process(); printf("hello world\n"); return 1; } if (strcmp(argv[1], "spawn_tcp_server_helper") == 0) { notify_parent_process(); return spawn_tcp_server_helper(); } if (strcmp(argv[1], "spawn_helper3") == 0) { char buffer[256]; notify_parent_process(); ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin)); buffer[sizeof(buffer) - 1] = '\0'; fputs(buffer, stdout); return 1; } if (strcmp(argv[1], "spawn_helper4") == 0) { notify_parent_process(); /* Never surrender, never return! */ while (1) uv_sleep(10000); } if (strcmp(argv[1], "spawn_helper5") == 0) { const char out[] = "fourth stdio!\n"; notify_parent_process(); #ifdef _WIN32 DWORD bytes; WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL); #else { ssize_t r; do r = write(3, out, sizeof(out) - 1); while (r == -1 && errno == EINTR); fsync(3); } #endif return 1; } if (strcmp(argv[1], "spawn_helper6") == 0) { int r; notify_parent_process(); r = fprintf(stdout, "hello world\n"); ASSERT(r > 0); r = fprintf(stderr, "hello errworld\n"); ASSERT(r > 0); return 1; } if (strcmp(argv[1], "spawn_helper7") == 0) { int r; char *test; notify_parent_process(); /* Test if the test value from the parent is still set */ test = getenv("ENV_TEST"); ASSERT(test != NULL); r = fprintf(stdout, "%s", test); ASSERT(r > 0); return 1; } #ifndef _WIN32 if (strcmp(argv[1], "spawn_helper8") == 0) { int fd; notify_parent_process(); ASSERT(sizeof(fd) == read(0, &fd, sizeof(fd))); ASSERT(fd > 2); ASSERT(-1 == write(fd, "x", 1)); return 1; } #endif /* !_WIN32 */ if (strcmp(argv[1], "spawn_helper9") == 0) { notify_parent_process(); return spawn_stdin_stdout(); } #ifndef _WIN32 if (strcmp(argv[1], "spawn_helper_setuid_setgid") == 0) { uv_uid_t uid = atoi(argv[2]); uv_gid_t gid = atoi(argv[3]); ASSERT(uid == getuid()); ASSERT(gid == getgid()); notify_parent_process(); return 1; } #endif /* !_WIN32 */ #if !defined(NO_CPU_AFFINITY) if (strcmp(argv[1], "spawn_helper_affinity") == 0) { int i; int r; int cpu; int cpumask_size; #ifdef _WIN32 DWORD_PTR procmask; DWORD_PTR sysmask; #elif defined(__linux__) cpu_set_t cpuset; #else cpuset_t cpuset; #endif cpumask_size = uv_cpumask_size(); ASSERT(cpumask_size > 0); cpu = atoi(argv[2]); ASSERT(cpu >= 0); ASSERT(cpu < cpumask_size); /* verify the mask has the cpu we expect */ #ifdef _WIN32 r = GetProcessAffinityMask(GetCurrentProcess(), &procmask, &sysmask); ASSERT(r != 0); for (i = 0; i < cpumask_size; ++i) { ASSERT(((procmask & (((DWORD_PTR)1) << i)) != 0) == (i == cpu)); } #else CPU_ZERO(&cpuset); r = pthread_getaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); ASSERT(r == 0); for (i = 0; i < cpumask_size; ++i) { ASSERT(CPU_ISSET(i, &cpuset) == (i == cpu)); } #endif return 1; } #endif return run_test(argv[1], 0, 1); }
int main(int argc, char *argv[]) { int c = 0; struct cp_test_param test_params; char *cipher = NULL; int raw = 0; int ret = 1; int i = 0; int alltests = 0; memset(&test_params, 0, sizeof(test_params)); test_params.len = 1; test_params.accesstype = KCAPI_ACCESS_HEURISTIC; register_tests(0); while(1) { int opt_index = 0; static struct option opts[] = { {"all", 0, 0, 'a'}, {"list", 0, 0, 'l'}, {"cipher", 1, 0, 'c'}, {"time", 1, 0, 't'}, {"blocks", 1, 0, 'b'}, {"raw", 0, 0, 'r'}, {"sendmsg", 0, 0, 's'}, {"vmsplice", 0, 0, 'v'}, {"aio", 1, 0, 'o'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "alc:t:b:rsvo:", opts, &opt_index); if(-1 == c) break; switch(c) { case 'a': alltests = 1; break; case 'l': for (i = 0; i < 4; i++) print_tests(&tests[i], 1); return 0; case 'c': cipher = strndup(optarg, 50); break; case 't': test_params.exectime = (unsigned int)atoi(optarg); break; case 'b': test_params.len = (unsigned int)atoi(optarg); break; case 'r': raw = 1; break; case 'v': test_params.accesstype = KCAPI_ACCESS_VMSPLICE; break; case 's': test_params.accesstype = KCAPI_ACCESS_SENDMSG; break; case 'o': test_params.aio = (unsigned int)atoi(optarg); break; default: usage(); goto out; } } if (alltests) { for (i = 0; i < 4; i++) exec_all_tests(&tests[i], &test_params); return 0; } if (!cipher) { usage(); goto out; } ret = exec_subset_test(cipher, raw, &test_params); out: if (cipher) free(cipher); return ret; }
static int maybe_run_test(int argc, char **argv) { if (strcmp(argv[1], "--list") == 0) { print_tests(stdout); return 0; } if (strcmp(argv[1], "ipc_helper_listen_before_write") == 0) { return ipc_helper(0); } if (strcmp(argv[1], "ipc_helper_listen_after_write") == 0) { return ipc_helper(1); } if (strcmp(argv[1], "ipc_send_recv_helper") == 0) { return ipc_send_recv_helper(); } if (strcmp(argv[1], "ipc_helper_tcp_connection") == 0) { return ipc_helper_tcp_connection(); } if (strcmp(argv[1], "stdio_over_pipes_helper") == 0) { return stdio_over_pipes_helper(); } if (strcmp(argv[1], "spawn_helper1") == 0) { return 1; } if (strcmp(argv[1], "spawn_helper2") == 0) { printf("hello world\n"); return 1; } if (strcmp(argv[1], "spawn_helper3") == 0) { char buffer[256]; fgets(buffer, sizeof(buffer) - 1, stdin); buffer[sizeof(buffer) - 1] = '\0'; fputs(buffer, stdout); return 1; } if (strcmp(argv[1], "spawn_helper4") == 0) { /* Never surrender, never return! */ while (1) uv_sleep(10000); } if (strcmp(argv[1], "spawn_helper5") == 0) { const char* out = "fourth stdio!\n\0"; #ifdef _WIN32 DWORD bytes; WriteFile((HANDLE) _get_osfhandle(3), out, strlen(out), &bytes, NULL); #else write(3, out, strlen(out)); fsync(3); #endif return 1; } if (strcmp(argv[1], "spawn_helper6") == 0) { int r; r = fprintf(stdout, "hello world\n"); ASSERT(r > 0); r = fprintf(stderr, "hello errworld\n"); ASSERT(r > 0); return 1; } return run_test(argv[1], TEST_TIMEOUT, 0); }