static int run_all_tests(int childcount) { int dropMode, serverFinishedPermute, serverHelloPermute, clientFinishedPermute; int result = 0; for (dropMode = 0; dropMode != 1 << (full ? 12 : 8); dropMode++) for (serverFinishedPermute = 0; serverFinishedPermute < 2; serverFinishedPermute++) for (serverHelloPermute = 0; serverHelloPermute < (full ? 120 : 6); serverHelloPermute++) for (clientFinishedPermute = 0; clientFinishedPermute < (full ? 120 : 6); clientFinishedPermute++) { int pid; if (!(pid = fork())) { exit(run_one_test(dropMode, serverFinishedPermute, serverHelloPermute, clientFinishedPermute)); } else if (pid < 0) { rperror("fork"); result = 4; break; } else { register_child(pid); result |= wait_children(childcount); } } result |= wait_children(0); return result; }
static int tests_run_index(int i, int argc, char * const *argv) { int verbose = 0; int ch; while ((ch = getopt(argc, argv, "v")) != -1) { switch (ch) { case 'v': verbose++; break; default: usage(argv[0]); } } fprintf(stderr, "\n[BEGIN] %s\n", testlist[i].name); run_one_test(&testlist[i], argc, argv); if(testlist[i].failed_tests) { fprintf(stderr, "[FAIL] %s\n", testlist[i].name); } else { fprintf(stderr, "duration: %llu ms\n", testlist[i].duration); fprintf(stderr, "[PASS] %s\n", testlist[i].name); } return 0; }
static int tests_run_index(int i, int argc, char * const *argv) { int ch; while ((ch = getopt(argc, argv, "v")) != -1) { switch (ch) { case 'v': test_verbose++; break; default: usage(argv[0]); } } if (test_onebatstest) fprintf(stdout, "[TEST] %s\n", testlist[i].name); else fprintf(stdout, "[BEGIN] %s\n", testlist[i].name); run_one_test(&testlist[i], argc, argv); if(testlist[i].failed_tests) { fprintf(stdout, "[FAIL] %s\n", testlist[i].name); } else { fprintf(stdout, "[PASS] %s\n", testlist[i].name); if (test_verbose) fprintf(stdout, "(%lu ms)\n", testlist[i].duration); } return testlist[i].failed_tests; }
/* * Main entry point for test harness */ int run_testrunner(int argc, const char **argv, testentry_t tests[], int test_count) { const char *test_name, *target; int i; stats_t stats; int target_matched, max_errors_before_quit, redirect_stdouterr; memset(&stats, 0, sizeof(stats)); max_errors_before_quit = 1; redirect_stdouterr = 0; assert(tests != NULL); assert(test_count > 0); assert(argc > 0 && argv && *argv); while (true) { target = argc > 1 ? argv[1] : ""; assert(target); if (*target != '-') break; argc--; argv++; if (target[1] == 'f' && target[2]) max_errors_before_quit = atoi(target + 1); else if (target[1] == 'r') redirect_stdouterr = 1; } target_matched = false; for (i = 0; i < test_count && (max_errors_before_quit < 1 || stats.failed != max_errors_before_quit); i++) { test_name = tests[i].name; assert(test_name); assert(tests[i].suite); assert(tests[i].test_function); if (eql(target, test_name) || eql(target, "all") || eql(target, tests[i].suite)) { if (!target_matched) printf("Running tests...\n"); target_matched = true; run_one_test(&stats, &tests[i], redirect_stdouterr, argc - 1, argv + 1); } } if (!target_matched) { fprintf(stderr, "Test '%s' not found", (strlen(target) > 0 ? target : "(empty)")); print_targets(tests, test_count); } else { printf("\nTest Results:%d tests,%d passed,%d failed.\n", stats.ran, stats.passed, stats.failed); } return stats.passed == stats.ran && target_matched ? 0 : 1; }
void test_run(const char *name) { int i; for (i = 0; all_tests[i]; i++) if (!name || !strcmp(all_tests[i]->name, name)) run_one_test(all_tests[i]); }
static int run_tests(struct test *tests) { int result = EXIT_SUCCESS; list_for_each(t, tests) { if (run_one_test(t) < 0) result = EXIT_FAILURE; } return result; }
static int run_tests(struct test *tests, int argc, char **argv) { int result = EXIT_SUCCESS; list_for_each(t, tests) { if (! should_run(t->name, argc, argv)) continue; if (run_one_test(t) < 0) result = EXIT_FAILURE; } return result; }
static int run_all_tests(const test_table_entry_t *test_table) { const test_table_entry_t *test; int rc; for ( rc = 0, test = &test_table[0]; test->test_func != NULL && rc == 0; test++) { rc = run_one_test(test); } return rc; }
static int run_test_by_id(int id) { int pscale = full ? 120 : 6; int dropMode, serverFinishedPermute, serverHelloPermute, clientFinishedPermute; clientFinishedPermute = id % pscale; id /= pscale; serverHelloPermute = id % pscale; id /= pscale; serverFinishedPermute = id % 2; id /= 2; dropMode = id; return run_one_test(dropMode, serverFinishedPermute, serverHelloPermute, clientFinishedPermute); }
int main(int argc, const char* argv[]) { int dropMode = 0; int serverFinishedPermute = 0; int serverHelloPermute = 0; int clientFinishedPermute = 0; int batch = 0; int arg; nonblock = 0; debug = 0; timeout_seconds = 120; retransmit_milliseconds = 100; full = 0; run_to_end = 1; job_limit = 1; #define NEXT_ARG(name) \ do { \ if (++arg >= argc) { \ fprintf(stderr, "No argument for -" #name "\n"); \ exit(8); \ } \ } while (0); #define FAIL_ARG(name) \ do { \ fprintf(stderr, "Invalid argument for -" #name "\n"); \ exit(8); \ } while (0); for (arg = 1; arg < argc; arg++) { if (strcmp("-die", argv[arg]) == 0) { run_to_end = 0; } else if (strcmp("-batch", argv[arg]) == 0) { batch = 1; } else if (strcmp("-d", argv[arg]) == 0) { char* end; int level = strtol(argv[arg+1], &end, 10); if (*end == '\0') { debug = level; arg++; } else { debug++; } } else if (strcmp("-nb", argv[arg]) == 0) { nonblock = 1; } else if (strcmp("-timeout", argv[arg]) == 0) { char* end; int val; NEXT_ARG(timeout); val = strtol(argv[arg], &end, 10); if (*end == '\0') { timeout_seconds = val; } else { FAIL_ARG(timeout); } } else if (strcmp("-retransmit", argv[arg]) == 0) { char* end; int val; NEXT_ARG(retransmit); val = strtol(argv[arg], &end, 10); if (*end == '\0') { retransmit_milliseconds = val; } else { FAIL_ARG(retransmit); } } else if (strcmp("-j", argv[arg]) == 0) { char* end; int val; NEXT_ARG(timeout); val = strtol(argv[arg], &end, 10); if (*end == '\0') { job_limit = val; } else { FAIL_ARG(j); } } else if (strcmp("-full", argv[arg]) == 0) { full = 1; } else if (strcmp("-shello", argv[arg]) == 0) { NEXT_ARG(shello); if (!parse_permutation(argv[arg], full ? permutation_names5 : permutation_names3, &serverHelloPermute)) { FAIL_ARG(shell); } } else if (strcmp("-sfinished", argv[arg]) == 0) { NEXT_ARG(sfinished); if (!parse_permutation(argv[arg], permutation_names2, &serverFinishedPermute)) { FAIL_ARG(sfinished); } } else if (strcmp("-cfinished", argv[arg]) == 0) { NEXT_ARG(cfinished); if (!parse_permutation(argv[arg], full ? permutation_names5 : permutation_names3, &clientFinishedPermute)) { FAIL_ARG(cfinished); } } else { int drop; int filter_count = full ? 12 : 8; const char** local_filter_names = full ? filter_names_full : filter_names; for (drop = 0; drop < filter_count; drop++) { if (strcmp(local_filter_names[drop], argv[arg]) == 0) { dropMode |= (1 << drop); break; } } if (drop == filter_count) { fprintf(stderr, "Unknown packet %s\n", argv[arg]); exit(8); } } } setlinebuf(stdout); gnutls_global_init(); cred_init(); gnutls_global_set_log_function(logfn); gnutls_global_set_audit_log_function(auditfn); gnutls_global_set_log_level(debug); if (dropMode || serverFinishedPermute || serverHelloPermute || clientFinishedPermute) { return run_one_test(dropMode, serverFinishedPermute, serverHelloPermute, clientFinishedPermute); } else { job_pids = calloc(sizeof(int), job_limit); if (batch) { return run_tests_from_id_list(job_limit); } else { return run_all_tests(job_limit); } } }
int main(int argc, char **argv) { int nthreads; int max_nthreads; int exper_n; if (1 == argc) max_nthreads = 4; else if (2 == argc) { max_nthreads = atoi(argv[1]); if (max_nthreads < 1 || max_nthreads > MAX_NTHREADS) { fprintf(stderr, "Invalid max # of threads argument\n"); exit(1); } } else { fprintf(stderr, "Usage: %s [max # of threads]\n", argv[0]); exit(1); } for (exper_n = 0; exper_n < N_EXPERIMENTS; ++ exper_n) for (nthreads = 1; nthreads <= max_nthreads; ++nthreads) { int i; # ifdef USE_WINTHREADS DWORD thread_id; HANDLE thread[MAX_NTHREADS]; # else pthread_t thread[MAX_NTHREADS]; # endif int list_length = nthreads*(nthreads+1)/2; long long start_time; list_element * le; # ifdef VERBOSE printf("Before add_elements: exper_n=%d, nthreads=%d," " max_nthreads=%d, list_length=%d\n", exper_n, nthreads, max_nthreads, list_length); # endif add_elements(list_length); # ifdef VERBOSE printf("Initial list (nthreads = %d):\n", nthreads); print_list(); # endif ops_performed = 0; start_time = get_msecs(); for (i = 1; i < nthreads; ++i) { int code; # ifdef USE_WINTHREADS thread[i] = CreateThread(NULL, 0, run_one_test, (LPVOID)(size_t)i, 0, &thread_id); code = thread[i] != NULL ? 0 : (int)GetLastError(); # else code = pthread_create(&thread[i], 0, run_one_test, (void *)(size_t)i); # endif if (code != 0) { fprintf(stderr, "Thread creation failed %u\n", (unsigned)code); exit(3); } } /* We use the main thread to run one test. This allows gprof */ /* profiling to work, for example. */ run_one_test(0); for (i = 1; i < nthreads; ++i) { int code; # ifdef USE_WINTHREADS code = WaitForSingleObject(thread[i], INFINITE) == WAIT_OBJECT_0 ? 0 : (int)GetLastError(); # else code = pthread_join(thread[i], 0); # endif if (code != 0) { fprintf(stderr, "Thread join failed %u\n", (unsigned)code); abort(); } } times[nthreads][exper_n] = (unsigned long)(get_msecs() - start_time); # ifdef VERBOSE printf("%d %lu\n", nthreads, (unsigned long)(get_msecs() - start_time)); printf("final list (should be reordered initial list):\n"); print_list(); # endif check_list(list_length); while ((le = (list_element *)AO_stack_pop(&the_list)) != 0) free(le); } for (nthreads = 1; nthreads <= max_nthreads; ++nthreads) { # ifndef NO_TIMES unsigned long sum = 0; # endif printf("About %d pushes + %d pops in %d threads:", LIMIT, LIMIT, nthreads); # ifndef NO_TIMES for (exper_n = 0; exper_n < N_EXPERIMENTS; ++exper_n) { # if defined(VERBOSE) printf(" [%lu]", times[nthreads][exper_n]); # endif sum += times[nthreads][exper_n]; } printf(" %lu msecs\n", (sum + N_EXPERIMENTS/2)/N_EXPERIMENTS); # else printf(" completed\n"); # endif } return 0; }
int main(int argc, char **argv) { int nthreads; int max_nthreads; int exper_n; if (1 == argc) max_nthreads = 4; else if (2 == argc) { max_nthreads = atoi(argv[1]); if (max_nthreads < 1 || max_nthreads > MAX_NTHREADS) { fprintf(stderr, "Invalid max # of threads argument\n"); exit(1); } } else { fprintf(stderr, "Usage: %s [max # of threads]\n", argv[0]); exit(1); } for (exper_n = 0; exper_n < N_EXPERIMENTS; ++ exper_n) for (nthreads = 1; nthreads <= max_nthreads; ++nthreads) { int i; pthread_t thread[MAX_NTHREADS]; int list_length = nthreads*(nthreads+1)/2; long long start_time; list_element * le; add_elements(list_length); # ifdef VERBOSE printf("Initial list (nthreads = %d):\n", nthreads); print_list(); # endif ops_performed = 0; start_time = get_msecs(); for (i = 1; i < nthreads; ++i) { int code; if ((code = pthread_create(thread+i, 0, run_one_test, (void *)(long)i)) != 0) { fprintf(stderr, "Thread creation failed %u\n", code); exit(3); } } /* We use the main thread to run one test. This allows gprof */ /* profiling to work, for example. */ run_one_test(0); for (i = 1; i < nthreads; ++i) { int code; if ((code = pthread_join(thread[i], 0)) != 0) { fprintf(stderr, "Thread join failed %u\n", code); abort(); } } times[nthreads][exper_n] = (unsigned long)(get_msecs() - start_time); # ifdef VERBOSE printf("%d %lu\n", nthreads, (unsigned long)(get_msecs() - start_time)); printf("final list (should be reordered initial list):\n"); print_list(); # endif check_list(list_length); while ((le = (list_element *)AO_stack_pop(&the_list)) != 0) free(le); } # ifndef NO_TIMES for (nthreads = 1; nthreads <= max_nthreads; ++nthreads) { unsigned long sum = 0; printf("About %d pushes + %d pops in %d threads:", LIMIT, LIMIT, nthreads); for (exper_n = 0; exper_n < N_EXPERIMENTS; ++exper_n) { # if defined(VERBOSE) printf("[%lu] ", times[nthreads][exper_n]); # endif sum += times[nthreads][exper_n]; } printf(" %lu msecs\n", (sum + N_EXPERIMENTS/2)/N_EXPERIMENTS); } # endif /* !NO_TIMES */ return 0; }
static int memcpy_tests( long iterations ) { int rc; int i; dma_mem_t src[SDMA_NUM_CHANNELS]; dma_mem_t dst[SDMA_NUM_CHANNELS]; SDMA_Handle_t dmaHandle[SDMA_NUM_CHANNELS]; int chan; int run_one_test( int test_number ) { for ( chan = 0; chan < SDMA_NUM_CHANNELS; chan++ ) { /* Start DMA operation */ sdma_transfer_mem_to_mem(dmaHandle[chan], src[chan].physPtr, dst[chan].physPtr, ALLOC_SIZE ); } for ( chan = 0; chan < SDMA_NUM_CHANNELS; chan++ ) { /* Wait for DMA completion */ sdma_test_wait( chan ); /* Verify transfer */ if (( rc = dma_test_check_mem( &dst[chan], channel_to_start( chan ))) != 0 ) { printk( KERN_ERR ": ========== DMA memcpy test%d channel %d failed [%03d] ==========\n\n", test_number, chan, i ); return rc; } printk( "\n========== DMA memcpy test%d channel %d passed [%03d] ==========\n\n", test_number, chan, i ); /* Reset destination memory */ memset( dst[chan].virtPtr, 0, dst[chan].numBytes ); } return 0; } printk( "\n::Entering into test thread::\n\n"); for ( chan = 0; chan < SDMA_NUM_CHANNELS; chan++ ) { /* Allocate contiguous source memory */ if ( alloc_mem( &src[chan], ALLOC_SIZE ) == NULL ) { return -ENOMEM; } /* Allocate contiguous destination memory */ if ( alloc_mem( &dst[chan], ALLOC_SIZE ) == NULL ) { return -ENOMEM; } /* Init test settings */ sdma_test_set( chan ); /* initialize the source memory */ dma_test_init_mem( &src[chan], channel_to_start( chan )); } for ( i = 0; i < iterations; i++ ) { for ( chan = 0; chan < SDMA_NUM_CHANNELS; chan++ ) { /* Aquire a DMA channel */ dmaHandle[chan] = sdma_request_channel( device[chan] ); if ( dmaHandle[chan] < 0 ) { return (int)dmaHandle[chan]; } } if (( rc = run_one_test( 1 )) != 0 ) { return rc; } /* * Now test to see if we can do back-to-back DMA transfers * and reuse the same DMA descriptor */ if (( rc = run_one_test( 2 )) != 0 ) { return rc; } for ( chan = 0; chan < SDMA_NUM_CHANNELS; chan++ ) { sdma_free_channel( dmaHandle[chan] ); } } for ( chan = 0; chan < SDMA_NUM_CHANNELS; chan++ ) { /* Free test memory */ free_mem( &src[chan] ); free_mem( &dst[chan] ); } printk( "\n ::Exiting from test thread:: \n\n"); return 0; }