X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Ftests_pass_valgrind.c;h=f17fbca4f9b7fa633e1c6e2a045d36f5284586c7;hb=5bfb3995da36408ded842c36052a5eadd602c431;hp=30a806eb934bd5cf9799a8b74ab5e88c348d1187;hpb=051db34fb275491d4d5dfa5bf7970e8e525766d8;p=ccan diff --git a/tools/ccanlint/tests/tests_pass_valgrind.c b/tools/ccanlint/tests/tests_pass_valgrind.c index 30a806eb..f17fbca4 100644 --- a/tools/ccanlint/tests/tests_pass_valgrind.c +++ b/tools/ccanlint/tests/tests_pass_valgrind.c @@ -17,7 +17,7 @@ #include #include -struct ccanlint run_tests_vg; +REGISTER_TEST(tests_pass_valgrind); /* Note: we already test safe_mode in run_tests.c */ static const char *can_run_vg(struct manifest *m) @@ -52,11 +52,11 @@ static bool blank_line(const char *line) static char *get_leaks(const char *output, char **errs) { char *leaks = talloc_strdup(output, ""); - unsigned int i, num; - char **lines = strsplit(output, output, "\n", &num); + unsigned int i; + char **lines = strsplit(output, output, "\n"); *errs = talloc_strdup(output, ""); - for (i = 0; i < num; i++) { + for (i = 0; i < talloc_array_length(lines) - 1; i++) { if (strstr(lines[i], " lost ")) { /* A leak... */ if (strstr(lines[i], " definitely lost ")) { @@ -112,20 +112,22 @@ static void do_run_tests_vg(struct manifest *m, * humans, and you can't have both. */ run_command(score, timeleft, &cmdout, "valgrind -q --error-exitcode=101" + " --child-silent-after-fork=yes" " --leak-check=full" " --log-fd=3 %s %s" " 3> valgrind.log", - run_tests_vg.options ? - run_tests_vg.options : "", + tests_pass_valgrind.options ? + tests_pass_valgrind.options : "", i->compiled); output = grab_file(i, "valgrind.log", NULL); if (!output || output[0] == '\0') { err = NULL; + i->leak_info = NULL; } else { i->leak_info = get_leaks(output, &err); } if (err) - score_file_error(score, i, 0, err); + score_file_error(score, i, 0, "%s", err); else score->score++; } @@ -147,15 +149,17 @@ static void do_leakcheck_vg(struct manifest *m, foreach_ptr(list, &m->run_tests, &m->api_tests) { list_for_each(list, i, list) { if (i->leak_info) { - score_file_error(score, i, 0, i->leak_info); + score_file_error(score, i, 0, "%s", + i->leak_info); leaks = true; } } } + /* FIXME: We don't fail for this, since many tests leak. */ + score->pass = true; if (!leaks) { score->score = 1; - score->pass = true; } } @@ -172,8 +176,8 @@ static void run_under_debugger_vg(struct manifest *m, struct score *score) first = list_top(&score->per_file_errors, struct file_error, list); command = talloc_asprintf(m, "valgrind --db-attach=yes%s %s", - run_tests_vg.options ? - run_tests_vg.options : "", + tests_pass_valgrind.options ? + tests_pass_valgrind.options : "", first->file->compiled); if (system(command)) doesnt_matter(); @@ -189,11 +193,9 @@ struct ccanlint tests_pass_valgrind = { .needs = "tests_pass" }; -REGISTER_TEST(tests_pass_valgrind); - struct ccanlint tests_pass_valgrind_noleaks = { .key = "tests_pass_valgrind_noleaks", - .name = "Module's run and api tests leak memory", + .name = "Module's run and api tests have no memory leaks", .check = do_leakcheck_vg, .needs = "tests_pass_valgrind" };