int main(/* int argc, char **argv */) { ngx_pool_t *pool = NULL; ngx_array_t *array = NULL; ngx_hash_t *hash; printf("--------------------------------\n"); printf("create a new pool:\n"); printf("--------------------------------\n"); pool = ngx_create_pool(1024, &ngx_log); dump_pool(pool); printf("--------------------------------\n"); printf("create and add urls to it:\n"); printf("--------------------------------\n"); array = add_urls_to_array(pool); //in fact, here should validate array dump_hash_array(array); printf("--------------------------------\n"); printf("the pool:\n"); printf("--------------------------------\n"); dump_pool(pool); hash = init_hash(pool, array); if (hash == NULL) { printf("Failed to initialize hash!\n"); return -1; } printf("--------------------------------\n"); printf("the hash:\n"); printf("--------------------------------\n"); dump_hash(hash, array); printf("\n"); printf("--------------------------------\n"); printf("the pool:\n"); printf("--------------------------------\n"); dump_pool(pool); //find test printf("--------------------------------\n"); printf("find test:\n"); printf("--------------------------------\n"); find_test(hash, urls, Max_Num); printf("\n"); find_test(hash, urls2, Max_Num2); //release ngx_array_destroy(array); ngx_destroy_pool(pool); return 0; }
static int exec_subset_test(const char *name, int raw, struct cp_test_param *test_params) { struct cp_test *test = NULL; int i = 0; for (i = 0; i < 4; i++) { int ret = 0; while (1) { char *out = NULL; ret = find_test(name, &tests[i], ret, &test); if (ret < 0) break; ret++; test->test_params = test_params; if (cp_exec_test(test)) return -EFAULT; out = cp_print_status(test, raw); if (!out) return -ENOMEM; printf("%s\n", out); free(out); } } return 0; }
int main() { conversion_test(); to_view_test(); equal_test(); unequal_test(); less_test(); greater_test(); less_equal_test(); greater_equal_test(); constructor_test(); assignment_test(); assign_test(); plus_equal_test(); append_test(); insert_test(); replace_test(); find_test(); rfind_test(); find_first_of_test(); find_last_of_test(); find_first_not_of_test(); find_last_not_of_test(); compare_test(); return boost::report_errors(); }
gboolean moo_test_run_tests (char **tests, const char *coverage_file, MooTestOptions opts) { if (coverage_file) moo_test_coverage_enable (); fprintf (stdout, "\n"); if (tests && *tests) { char *name; while ((name = *tests++)) { MooTestSuite *single_ts = NULL; MooTest *single_test = NULL; if (!find_test (name, &single_ts, &single_test)) { g_printerr ("could not find test %s", name); exit (EXIT_FAILURE); } run_suite (single_ts, single_test, opts); } } else { GSList *l; for (l = registry.test_suites; l != NULL; l = l->next) run_suite (reinterpret_cast<MooTestSuite*> (l->data), NULL, opts); } fprintf (stdout, "\n"); if (!(opts & MOO_TEST_LIST_ONLY)) { fprintf (stdout, "Run Summary: Type Total Ran Passed Failed\n"); fprintf (stdout, " suites %5d %4d %6d %6d\n", registry.tr.suites, registry.tr.suites, registry.tr.suites_passed, registry.tr.suites - registry.tr.suites_passed); fprintf (stdout, " tests %5d %4d %6d %6d\n", registry.tr.tests, registry.tr.tests, registry.tr.tests_passed, registry.tr.tests - registry.tr.tests_passed); fprintf (stdout, " asserts %5d %4d %6d %6d\n", registry.tr.asserts, registry.tr.asserts, registry.tr.asserts_passed, registry.tr.asserts - registry.tr.asserts_passed); fprintf (stdout, "\n"); if (coverage_file) moo_test_coverage_write (coverage_file); } return moo_test_get_result (); }
int main(int argc, char *argv[]) { const struct weston_test *t; int total = 0; int pass = 0; int skip = 0; if (argc == 2) { const char *testname = argv[1]; if (strcmp(testname, "--help") == 0 || strcmp(testname, "-h") == 0) { fprintf(stderr, "Usage: %s [test-name]\n", program_invocation_short_name); list_tests(); exit(EXIT_SUCCESS); } if (strcmp(testname, "--params") == 0 || strcmp(testname, "-p") == 0) { printf("%s", server_parameters); exit(EXIT_SUCCESS); } t = find_test(argv[1]); if (t == NULL) { fprintf(stderr, "unknown test: \"%s\"\n", argv[1]); list_tests(); exit(EXIT_FAILURE); } int number_passed_in_test = 0, number_skipped_in_test = 0; total += iterate_test(t, &number_passed_in_test, &number_skipped_in_test); pass += number_passed_in_test; skip += number_skipped_in_test; } else { for (t = &__start_test_section; t < &__stop_test_section; t++) { int number_passed_in_test = 0, number_skipped_in_test = 0; total += iterate_test(t, &number_passed_in_test, &number_skipped_in_test); pass += number_passed_in_test; skip += number_skipped_in_test; } } fprintf(stderr, "%d tests, %d pass, %d skip, %d fail\n", total, pass, skip, total - pass - skip); if (skip == total) return SKIP; else if (pass + skip == total) return EXIT_SUCCESS; return EXIT_FAILURE; }
int run_test(int test_num, testspec_t *t, FILE *ofp) { test_t info; /* Look up and reality check test parameters */ if(find_test(t->code, &info) < 0) { fprintf(stderr, "Line %d: Test code '%s' is unknown.\n", t->line, t->code); return -1; } else { int errs = 0; if(info.num_inputs >= 0 && t->num_inputs != info.num_inputs) { fprintf(stderr, "Line %d: Wrong number of inputs to %s (want %d, have %d)\n", t->line, t->code, info.num_inputs, t->num_inputs); ++errs; } if(info.num_outputs >= 0 && t->num_outputs != info.num_outputs) { fprintf(stderr, "Line %d: Wrong number of outputs to %s (want %d, have %d)\n", t->line, t->code, info.num_outputs, t->num_outputs); ++errs; } if(errs) { fprintf(stderr, "Line %d: %d error(s), skipping this test.\n", t->line, errs); return -1; } } /* If return value is true, just print a generic OK message; otherwise, it is assumed that imath_errno has been set to a value indicating the problem. */ if((info.call)(t, ofp)) { fprintf(ofp, "%d\t%d\tOK\n", t->line, test_num); return 1; } else if(imath_errno >= MP_BADARG) { fprintf(ofp, "%d\t%d\t%s\n", t->line, test_num, error_string(imath_errno)); } else { fprintf(ofp, "%d\t%d\tFAILED\t%s\n", t->line, test_num, imath_errmsg); } return 0; }
bool Framework::combine_tests_subset(CPPUNIT_NS::TextUi::TestRunner &runner) const { FindTest find_test; for (auto &name : m_program_options.get_tests_to_run()) { CPPUNIT_NS::Test *test = find_test(name, get_registry()->makeTest()); if (test == nullptr) { std::cerr << "Cannot find test '" << name << "'!" << std::endl; return false; } runner.addTest(test); } return true; }
int main( ) { int rc = 0; int original_count = heap_count( ); try { if( !construct_test( ) || !heap_ok( "t01" ) ) rc = 1; if( !assign_test( ) || !heap_ok( "t02" ) ) rc = 1; if( !access_test( ) || !heap_ok( "t03" ) ) rc = 1; if( !relational_test( ) || !heap_ok( "t04" ) ) rc = 1; if( !capacity_test( ) || !heap_ok( "t05" ) ) rc = 1; if( !iterator_test( ) || !heap_ok( "t06" ) ) rc = 1; if( !append_test( ) || !heap_ok( "t07" ) ) rc = 1; if( !insert_test( ) || !heap_ok( "t08" ) ) rc = 1; if( !erase_test( ) || !heap_ok( "t09" ) ) rc = 1; if( !replace_test( ) || !heap_ok( "t10" ) ) rc = 1; if( !iterator_replace_test( ) || !heap_ok( "t11" ) ) rc = 1; if( !copy_test( ) || !heap_ok( "t12" ) ) rc = 1; if( !swap_test( ) || !heap_ok( "t13" ) ) rc = 1; if( !cstr_test( ) || !heap_ok( "t14" ) ) rc = 1; if( !find_test( ) || !heap_ok( "t15" ) ) rc = 1; if( !rfind_test( ) || !heap_ok( "t16" ) ) rc = 1; if( !find_first_of_test( ) || !heap_ok( "t17" ) ) rc = 1; if( !find_last_of_test( ) || !heap_ok( "t18" ) ) rc = 1; if( !find_first_not_of_test( ) || !heap_ok( "t19" ) ) rc = 1; if( !find_last_not_of_test( ) || !heap_ok( "t20" ) ) rc = 1; if( !substr_test( ) || !heap_ok( "t21" ) ) rc = 1; } catch( std::out_of_range e ) { std::cout << "Unexpected out_of_range exception: " << e.what( ) << "\n"; rc = 1; } catch( std::length_error e ) { std::cout << "Unexpected length_error exception: " << e.what( ) << "\n"; rc = 1; } catch( ... ) { std::cout << "Unexpected exception of unexpected type.\n"; rc = 1; } if( heap_count( ) != original_count ) { std::cout << "Possible memory leak!\n"; rc = 1; } return( rc ); }
int main () { std::cout << "STL generic algorithms -- Searching Algorithms\n"; find_test (); find_adjacent_test (); search_test (); max_min_example (); mismatch_test ("goody", "goody"); mismatch_test ("good", "goody"); mismatch_test ("goody", "good"); mismatch_test ("good", "fred"); mismatch_test ("fred", "good"); std::cout << "End of search algorithms test program\n"; return 0; }
int main() { find_test(); find_if_test(); find_end_test(); find_first_of_test(); adjacent_find_test(); count_test(); count_if_test(); distance_test(); mismatch_test(); equal_test(); search_test(); lower_bound_test(); upper_bound_test(); equal_range_test(); binary_search_test(); return boost::report_errors(); }
int main(int argc, char *argv[]) { const struct weston_test *t; pid_t pid; int total, pass; siginfo_t info; if (argc == 2) { t = find_test(argv[1]); if (t == NULL) { fprintf(stderr, "unknown test: \"%s\"\n", argv[1]); exit(EXIT_FAILURE); } run_test(t); } pass = 0; for (t = &__start_test_section; t < &__stop_test_section; t++) { int success = 0; int hardfail = 0; pid = fork(); assert(pid >= 0); if (pid == 0) run_test(t); /* never returns */ if (waitid(P_ALL, 0, &info, WEXITED)) { fprintf(stderr, "waitid failed: %m\n"); abort(); } fprintf(stderr, "test \"%s\":\t", t->name); switch (info.si_code) { case CLD_EXITED: fprintf(stderr, "exit status %d", info.si_status); if (info.si_status == EXIT_SUCCESS) success = 1; break; case CLD_KILLED: case CLD_DUMPED: fprintf(stderr, "signal %d", info.si_status); if (info.si_status != SIGABRT) hardfail = 1; break; } if (t->must_fail) success = !success; if (success && !hardfail) { pass++; fprintf(stderr, ", pass.\n"); } else fprintf(stderr, ", fail.\n"); } total = &__stop_test_section - &__start_test_section; fprintf(stderr, "%d tests, %d pass, %d fail\n", total, pass, total - pass); return pass == total ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char **argv) { test_init_data_t *init_data; struct env env; assert(argc >= 2); /* in order to have some shitty almost-fork-like semantics * main can get run multiple times. Look in src/helpers.c * for where this is used. Just means we check the first * arg, and if not NULL jmp to it */ void (*helper_thread)(int argc,char **argv) = (void(*)(int, char**))atol(argv[1]); if (helper_thread) { helper_thread(argc, argv); } /* parse args */ assert(argc == 3); endpoint = (seL4_CPtr) atoi(argv[2]); /* read in init data */ init_data = receive_init_data(endpoint); /* configure env */ env.cspace_root = init_data->root_cnode; env.page_directory = init_data->page_directory; env.endpoint = endpoint; env.priority = init_data->priority; env.cspace_size_bits = init_data->cspace_size_bits; env.tcb = init_data->tcb; env.domain = init_data->domain; #ifndef CONFIG_KERNEL_STABLE env.asid_pool = init_data->asid_pool; env.asid_ctrl = init_data->asid_ctrl; #endif /* CONFIG_KERNEL_STABLE */ #ifdef CONFIG_IOMMU env.io_space = init_data->io_space; #endif env.num_regions = init_data->num_elf_regions; memcpy(env.regions, init_data->elf_regions, sizeof(sel4utils_elf_region_t) * env.num_regions); /* initialse cspace, vspace and untyped memory allocation */ init_allocator(&env, init_data); /* initialise the timer */ init_timer(&env, init_data); /* find the test */ testcase_t *test = find_test(init_data->name); /* run the test */ int result = 0; if (test) { printf("Running test %s (%s)\n", test->name, test->description); result = test->function(&env); } else { result = FAILURE; ZF_LOGF("Cannot find test %s\n", init_data->name); } printf("Test %s %s\n", init_data->name, result == SUCCESS ? "passed" : "failed"); /* send our result back */ seL4_MessageInfo_t info = seL4_MessageInfo_new(seL4_NoFault, 0, 0, 1); seL4_SetMR(0, result); seL4_Send(endpoint, info); /* It is expected that we are torn down by the test driver before we are * scheduled to run again after signalling them with the above send. */ assert(!"unreachable"); return 0; }
int main(/* int argc, char **argv */) { ngx_pool_t *pool = NULL; ngx_hash_keys_arrays_t array; ngx_hash_combined_t hash; ngx_int_t loop; ngx_array_t *url, *value; ngx_str_t *temp; printf("--------------------------------\n"); printf("create a new pool:\n"); printf("--------------------------------\n"); pool = ngx_create_pool(1024, &ngx_log); dump_pool(pool); printf("--------------------------------\n"); printf("create and add urls to it:\n"); printf("--------------------------------\n"); if ((url = ngx_array_create(pool, Max_Num, sizeof(ngx_str_t))) == NULL) { printf("Failed to initialize url!\n"); return -1; } if ((value = ngx_array_create(pool, Max_Num, sizeof(ngx_str_t))) == NULL) { printf("Failed to initialize value!\n"); return -1; } //常量字符串是不可修改的,而后面需要修改,所以重新拷贝一份 for (loop = 0; loop < Max_Num; loop++) { temp = ngx_array_push(url); temp->len = urls[loop].len; temp->data = ngx_palloc(pool, urls[loop].len); ngx_memcpy(temp->data, urls[loop].data, temp->len); } //由于key-value中的value的地址必须是4对齐的,所以需要重新拷贝一份vaule for (loop = 0; loop < Max_Num; loop++) { temp = ngx_array_push(value); temp->len = values[loop].len; temp->data = ngx_palloc(pool, values[loop].len); ngx_memcpy(temp->data, values[loop].data, temp->len); } if (add_urls_to_array(pool, &array, url, value) == NULL) { printf("Failed to initialize array!\n"); return -1; } dump_hash_array(&array.keys); dump_hash_array(&array.dns_wc_head); dump_hash_array(&array.dns_wc_tail); printf("--------------------------------\n"); printf("the pool:\n"); printf("--------------------------------\n"); dump_pool(pool); if (init_hash(pool, &array, &hash) == NULL) { printf("Failed to initialize hash!\n"); return -1; } printf("buckets = %p\n", hash.hash.buckets); printf("--------------------------------\n"); printf("the hash:\n"); printf("--------------------------------\n"); dump_combined_hash(&hash, &array); printf("\n"); printf("--------------------------------\n"); printf("the pool:\n"); printf("--------------------------------\n"); dump_pool(pool); //find test printf("--------------------------------\n"); printf("find test:\n"); printf("--------------------------------\n"); find_test(&hash, urls, Max_Num); printf("\n"); find_test(&hash, urls2, Max_Num2); //release return 0; }
static bool run_test(const char *cmd, struct test *test) { char *output, *newcmd; FILE *outf; int status; if (test->done) return test->answer; if (test->depends) { size_t len; const char *deps = test->depends; char *dep; /* Space-separated dependencies, could be ! for inverse. */ while ((len = strcspn(deps, " ")) != 0) { bool positive = true; if (deps[len]) { dep = strdup(deps); dep[len] = '\0'; } else { dep = (char *)deps; } if (dep[0] == '!') { dep++; positive = false; } if (run_test(cmd, find_test(dep)) != positive) { test->answer = false; test->done = true; return test->answer; } if (deps[len]) free(dep); deps += len; deps += strspn(deps, " "); } } outf = fopen(INPUT_FILE, verbose > 1 ? "w+" : "w"); if (!outf) c12r_err(EXIT_TROUBLE_RUNNING, "creating %s", INPUT_FILE); fprintf(outf, "%s", PRE_BOILERPLATE); if (strstr(test->style, "INSIDE_MAIN")) { fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_END_BOILERPLATE); } else if (strstr(test->style, "OUTSIDE_MAIN")) { fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", MAIN_BODY_BOILERPLATE); fprintf(outf, "%s", MAIN_END_BOILERPLATE); } else if (strstr(test->style, "DEFINES_FUNC")) { fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", USE_FUNC_BOILERPLATE); fprintf(outf, "%s", MAIN_BODY_BOILERPLATE); fprintf(outf, "%s", MAIN_END_BOILERPLATE); } else if (strstr(test->style, "DEFINES_EVERYTHING")) { fprintf(outf, "%s", test->fragment); } else c12r_errx(EXIT_BAD_TEST, "Unknown style for test %s: %s", test->name, test->style); if (verbose > 1) { fseek(outf, 0, SEEK_SET); fcopy(outf, stdout); } fclose(outf); newcmd = strdup(cmd); if (test->flags) { newcmd = realloc(newcmd, strlen(newcmd) + strlen(" ") + strlen(test->flags) + 1); strcat(newcmd, " "); strcat(newcmd, test->flags); if (verbose > 1) printf("Extra flags line: %s", newcmd); } if (test->link) { newcmd = realloc(newcmd, strlen(newcmd) + strlen(" ") + strlen(test->link) + 1); strcat(newcmd, " "); strcat(newcmd, test->link); if (verbose > 1) printf("Extra link line: %s", newcmd); } start_test("checking for ", test->desc); output = run(newcmd, &status); free(newcmd); if (status != 0 || strstr(output, "warning")) { if (verbose) printf("Compile %s for %s, status %i: %s\n", status ? "fail" : "warning", test->name, status, output); if (strstr(test->style, "EXECUTE") && !strstr(test->style, "MAY_NOT_COMPILE")) c12r_errx(EXIT_BAD_TEST, "Test for %s did not compile:\n%s", test->name, output); test->answer = false; free(output); } else { /* Compile succeeded. */ free(output); /* We run INSIDE_MAIN tests for sanity checking. */ if (strstr(test->style, "EXECUTE") || strstr(test->style, "INSIDE_MAIN")) { output = run("." DIR_SEP OUTPUT_FILE, &status); if (!strstr(test->style, "EXECUTE") && status != 0) c12r_errx(EXIT_BAD_TEST, "Test for %s failed with %i:\n%s", test->name, status, output); if (verbose && status) printf("%s exited %i\n", test->name, status); free(output); } test->answer = (status == 0); } test->done = true; end_test(test->answer); if (test->answer && test->overrides) { struct test *override = find_test(test->overrides); override->done = true; override->answer = true;
int main(int argc, char *argv[]) { const struct test *t; pid_t pid; int total, pass; siginfo_t info; /* Load system malloc, free, and realloc */ sys_calloc = dlsym(RTLD_NEXT, "calloc"); sys_realloc = dlsym(RTLD_NEXT, "realloc"); sys_malloc = dlsym(RTLD_NEXT, "malloc"); sys_free = dlsym(RTLD_NEXT, "free"); leak_check_enabled = !getenv("NO_ASSERT_LEAK_CHECK"); if (argc == 2 && strcmp(argv[1], "--help") == 0) usage(argv[0], EXIT_SUCCESS); if (argc == 2) { t = find_test(argv[1]); if (t == NULL) { fprintf(stderr, "unknown test: \"%s\"\n", argv[1]); usage(argv[0], EXIT_FAILURE); } run_test(t); } pass = 0; for (t = &__start_test_section; t < &__stop_test_section; t++) { int success = 0; pid = fork(); assert(pid >= 0); if (pid == 0) run_test(t); /* never returns */ if (waitid(P_ALL, 0, &info, WEXITED)) { fprintf(stderr, "waitid failed: %m\n"); abort(); } fprintf(stderr, "test \"%s\":\t", t->name); switch (info.si_code) { case CLD_EXITED: fprintf(stderr, "exit status %d", info.si_status); if (info.si_status == EXIT_SUCCESS) success = 1; break; case CLD_KILLED: case CLD_DUMPED: fprintf(stderr, "signal %d", info.si_status); break; } if (t->must_fail) success = !success; if (success) { pass++; fprintf(stderr, ", pass.\n"); } else fprintf(stderr, ", fail.\n"); } total = &__stop_test_section - &__start_test_section; fprintf(stderr, "%d tests, %d pass, %d fail\n", total, pass, total - pass); return pass == total ? EXIT_SUCCESS : EXIT_FAILURE; }
void big_test() { linked_list list = l_create(); l_add_front(list, 3); length_test(list, 1); front_test(list, 3); back_test(list, 3); //list = 3 l_add_back(list, 4); length_test(list, 2); front_test(list, 3); back_test(list, 4); //list = 3, 4 l_add_front(list, 2); length_test(list, 3); front_test(list, 2); back_test(list, 4); //list = 2, 3, 4 int array1[] = {2, 3, 4}; print_test(list, array1, 3); l_add_front(list, 1); l_add_back(list, 5); length_test(list, 5); front_test(list, 1); back_test(list, 5); //list = 1, 2, 3, 4, 5 find_test(list, 3, 1); link l = l_find(list, 3); l_remove(list, l); find_test(list, 3, 0); length_test(list, 4); front_test(list, 1); back_test(list, 5); //list = 1, 2, 4, 5 int array2[] = {1, 2, 4, 5}; print_test(list, array2, 4); l_remove_back(list); length_test(list, 3); back_test(list, 4); //list = 1, 2, 4 l_remove_front(list); length_test(list, 2); front_test(list, 2); //list = 2, 4 l_destroy(list); }
static bool run_test(const char *cmd, struct test *test) { char *output; FILE *outf; int status; if (test->done) return test->answer; if (test->depends) { size_t len; const char *deps = test->depends; char *dep; /* Space-separated dependencies, could be ! for inverse. */ while ((len = strcspn(deps, " "))) { bool positive = true; if (deps[len]) { dep = strdup(deps); dep[len] = '\0'; } else { dep = (char *)deps; } if (dep[0] == '!') { dep++; positive = false; } if (run_test(cmd, find_test(dep)) != positive) { test->answer = false; test->done = true; return test->answer; } if (deps[len]) free(dep); deps += len; deps += strspn(deps, " "); } } outf = fopen(INPUT_FILE, "w"); if (!outf) err(1, "creating %s", INPUT_FILE); fprintf(outf, "%s", PRE_BOILERPLATE); switch (test->style & ~(EXECUTE|MAY_NOT_COMPILE)) { case INSIDE_MAIN: fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_END_BOILERPLATE); break; case OUTSIDE_MAIN: fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", MAIN_BODY_BOILERPLATE); fprintf(outf, "%s", MAIN_END_BOILERPLATE); break; case DEFINES_FUNC: fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", USE_FUNC_BOILERPLATE); fprintf(outf, "%s", MAIN_BODY_BOILERPLATE); fprintf(outf, "%s", MAIN_END_BOILERPLATE); break; case DEFINES_EVERYTHING: fprintf(outf, "%s", test->fragment); break; default: abort(); } fclose(outf); if (verbose > 1) system("cat " INPUT_FILE); if (test->link) { char *newcmd; newcmd = malloc(strlen(cmd) + strlen(" ") + strlen(test->link) + 1); sprintf(newcmd, "%s %s", cmd, test->link); if (verbose > 1) printf("Extra link line: %s", newcmd); cmd = newcmd; } output = run(cmd, &status); if (status != 0 || strstr(output, "warning")) { if (verbose) printf("Compile %s for %s, status %i: %s\n", status ? "fail" : "warning", test->name, status, output); if ((test->style & EXECUTE) && !(test->style & MAY_NOT_COMPILE)) errx(1, "Test for %s did not compile:\n%s", test->name, output); test->answer = false; free(output); } else { /* Compile succeeded. */ free(output); /* We run INSIDE_MAIN tests for sanity checking. */ if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) { output = run("./" OUTPUT_FILE, &status); if (!(test->style & EXECUTE) && status != 0) errx(1, "Test for %s failed with %i:\n%s", test->name, status, output); if (verbose && status) printf("%s exited %i\n", test->name, status); free(output); } test->answer = (status == 0); } test->done = true; if (test->answer && test->overrides) { struct test *override = find_test(test->overrides); override->done = true; override->answer = true;
int main() { find_test(); return boost::report_errors(); }
static bool run_test(const char *cmd, struct test *test) { char *output; FILE *outf; int status; if (test->done) return test->answer; if (test->depends && !run_test(cmd, find_test(test->depends))) { test->answer = false; test->done = true; return test->answer; } outf = fopen(INPUT_FILE, "w"); if (!outf) err(1, "creating %s", INPUT_FILE); fprintf(outf, "%s", PRE_BOILERPLATE); switch (test->style & ~(EXECUTE|MAY_NOT_COMPILE)) { case INSIDE_MAIN: fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_END_BOILERPLATE); break; case OUTSIDE_MAIN: fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", MAIN_BODY_BOILERPLATE); fprintf(outf, "%s", MAIN_END_BOILERPLATE); break; case DEFINES_FUNC: fprintf(outf, "%s", test->fragment); fprintf(outf, "%s", MAIN_START_BOILERPLATE); fprintf(outf, "%s", USE_FUNC_BOILERPLATE); fprintf(outf, "%s", MAIN_BODY_BOILERPLATE); fprintf(outf, "%s", MAIN_END_BOILERPLATE); break; case DEFINES_EVERYTHING: fprintf(outf, "%s", test->fragment); break; default: abort(); } fclose(outf); if (verbose > 1) if (system("cat " INPUT_FILE) == -1); output = run(cmd, &status); if (status != 0 || strstr(output, "warning")) { if (verbose) printf("Compile %s for %s, status %i: %s\n", status ? "fail" : "warning", test->name, status, output); if ((test->style & EXECUTE) && !(test->style & MAY_NOT_COMPILE)) errx(1, "Test for %s did not compile:\n%s", test->name, output); test->answer = false; free(output); } else { /* Compile succeeded. */ free(output); /* We run INSIDE_MAIN tests for sanity checking. */ if ((test->style & EXECUTE) || (test->style & INSIDE_MAIN)) { output = run("./" OUTPUT_FILE, &status); if (!(test->style & EXECUTE) && status != 0) errx(1, "Test for %s failed with %i:\n%s", test->name, status, output); if (verbose && status) printf("%s exited %i\n", test->name, status); free(output); } test->answer = (status == 0); } test->done = true; return test->answer; }