X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Ftests_pass.c;h=af71dbe4c9f58cce4cc5da90a8e58da2c84b129b;hb=bdb8d75154d7aefe01788e5dd5adb11e3c943c11;hp=15df1ed69e7cefc8315a780cf47d3904732ab76d;hpb=ad6a6711a1b703793e49206e10d6dcf1722eb424;p=ccan diff --git a/tools/ccanlint/tests/tests_pass.c b/tools/ccanlint/tests/tests_pass.c index 15df1ed6..af71dbe4 100644 --- a/tools/ccanlint/tests/tests_pass.c +++ b/tools/ccanlint/tests/tests_pass.c @@ -1,8 +1,9 @@ #include #include -#include +#include #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include "tests_pass.h" bool do_valgrind = false; +const char *valgrind_suppress = ""; static const char *can_run(struct manifest *m) { @@ -27,32 +29,40 @@ static const char *can_run(struct manifest *m) if (!is_excluded("tests_pass_valgrind") && run_command(m, &timeleft, &output, - "valgrind -q true")) + "valgrind -q true")) { + const char *sfile; + do_valgrind = true; + /* Check for suppressions file for all of CCAN. */ + sfile = path_join(m, ccan_dir, ".valgrind_suppressions"); + if (path_is_file(sfile)) + valgrind_suppress = tal_fmt(m, "--suppressions=%s", + sfile); + } + return NULL; } static const char *concat(struct score *score, char *bits[]) { unsigned int i; - char *ret = talloc_strdup(score, ""); + char *ret = tal_strdup(score, ""); for (i = 0; bits[i]; i++) { if (i) - ret = talloc_append_string(ret, " "); - ret = talloc_append_string(ret, bits[i]); + ret = tal_strcat(score, take(ret), " "); + ret = tal_strcat(score, take(ret), bits[i]); } return ret; } -static bool run_test(void *ctx, +static void run_test(void *ctx, struct manifest *m, - unsigned int *timeleft, char **cmdout, - struct ccan_file *i, - bool use_valgrind) + unsigned int *timeleft, + struct ccan_file *i) { - if (use_valgrind) { + if (do_valgrind) { const char *options; options = concat(ctx, per_file_options(&tests_pass_valgrind, i)); @@ -61,66 +71,58 @@ static bool run_test(void *ctx, /* FIXME: Valgrind's output sucks. XML is * unreadable by humans *and* doesn't support * children reporting. */ - i->valgrind_log = talloc_asprintf(m, - "%s.valgrind-log", - i->compiled); - talloc_set_destructor(i->valgrind_log, - unlink_file_destructor); - - return run_command(ctx, timeleft, cmdout, - "valgrind -q" - " --leak-check=full" - " --log-fd=3 %s %s" - " 3> %s", - options, - i->compiled, i->valgrind_log); + i->valgrind_log = tal_fmt(m, + "%s.valgrind-log", + i->compiled[COMPILE_NORMAL]); + + run_command_async(i, *timeleft, + "valgrind -q" + " --leak-check=full" + " --log-fd=3 %s %s %s" + " 3> %s", + valgrind_suppress, options, + i->compiled[COMPILE_NORMAL], + i->valgrind_log); + return; } } - return run_command(m, timeleft, cmdout, "%s", i->compiled); + run_command_async(i, *timeleft, "%s", + i->compiled[COMPILE_NORMAL]); } -static void run_tests(struct manifest *m, - bool keep, - unsigned int *timeleft, - struct score *score, - bool use_valgrind) +static void do_run_tests(struct manifest *m, + unsigned int *timeleft, + struct score *score) { struct list_head *list; struct ccan_file *i; char *cmdout; + bool ok; score->total = 0; foreach_ptr(list, &m->run_tests, &m->api_tests) { list_for_each(list, i, list) { score->total++; - if (run_test(score, m, timeleft, &cmdout, i, - use_valgrind)) - score->score++; - else - score_file_error(score, i, 0, "%s", cmdout); + if (verbose >= 2) + printf(" %s...\n", i->name); + run_test(score, m, timeleft, i); } } + while ((i = collect_command(&ok, &cmdout)) != NULL) { + if (!ok) + score_file_error(score, i, 0, "%s", cmdout); + else + score->score++; + if (verbose >= 2) + printf(" ...%s\n", i->name); + } + if (score->score == score->total) score->pass = true; } -static void do_run_tests(struct manifest *m, - bool keep, - unsigned int *timeleft, - struct score *score) -{ - run_tests(m, keep, timeleft, score, do_valgrind); -} - -static void do_run_tests_without_features(struct manifest *m, - bool keep, - unsigned int *timeleft, - struct score *score) -{ - run_tests(m, keep, timeleft, score, false); -} /* Gcc's warn_unused_result is fascist bullshit. */ #define doesnt_matter() @@ -135,8 +137,8 @@ static void run_under_debugger(struct manifest *m, struct score *score) if (!ask("Should I run the first failing test under the debugger?")) return; - command = talloc_asprintf(m, "gdb -ex 'break tap.c:139' -ex 'run' %s", - first->file->compiled); + command = tal_fmt(m, "gdb -ex 'break tap.c:139' -ex 'run' %s", + first->file->compiled[COMPILE_NORMAL]); if (system(command)) doesnt_matter(); } @@ -151,13 +153,3 @@ struct ccanlint tests_pass = { }; REGISTER_TEST(tests_pass); - -struct ccanlint tests_pass_without_features = { - .key = "tests_pass_without_features", - .name = "Module's run and api tests pass (without features)", - .check = do_run_tests_without_features, - .handle = run_under_debugger, - .needs = "tests_compile_without_features" -}; - -REGISTER_TEST(tests_pass_without_features);