]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/run_tests_valgrind.c
ccanlint: rename structures to match keys
[ccan] / tools / ccanlint / tests / run_tests_valgrind.c
index 21b8660af09b0dbcc2c3cdd840ffc780146c649f..30a806eb934bd5cf9799a8b74ab5e88c348d1187 100644 (file)
@@ -17,6 +17,8 @@
 #include <string.h>
 #include <ctype.h>
 
+struct ccanlint run_tests_vg;
+
 /* Note: we already test safe_mode in run_tests.c */
 static const char *can_run_vg(struct manifest *m)
 {
@@ -108,26 +110,24 @@ static void do_run_tests_vg(struct manifest *m,
                        score->total++;
                        /* FIXME: Valgrind's output sucks.  XML is unreadable by
                         * humans, and you can't have both. */
-                       if (run_command(score, timeleft, &cmdout,
-                                       "valgrind -q --leak-check=full"
-                                       " --log-fd=3 %s %s"
-                                       " 3> valgrind.log",
-                                       run_tests_vg.options ?
-                                       run_tests_vg.options : "",
-                                       i->compiled)) {
-                               output = grab_file(i, "valgrind.log", NULL);
-                               if (!output || output[0] == '\0') {
-                                       err = NULL;
-                               } else {
-                                       i->leak_info = get_leaks(output, &err);
-                               }
-                               if (err) {
-                                       score_file_error(score, i, 0, err);
-                               } else
-                                       score->score++;
+                       run_command(score, timeleft, &cmdout,
+                                   "valgrind -q --error-exitcode=101"
+                                   " --leak-check=full"
+                                   " --log-fd=3 %s %s"
+                                   " 3> valgrind.log",
+                                   run_tests_vg.options ?
+                                   run_tests_vg.options : "",
+                                   i->compiled);
+                       output = grab_file(i, "valgrind.log", NULL);
+                       if (!output || output[0] == '\0') {
+                               err = NULL;
                        } else {
-                               score_file_error(score, i, 0, cmdout);
+                               i->leak_info = get_leaks(output, &err);
                        }
+                       if (err)
+                               score_file_error(score, i, 0, err);
+                       else
+                               score->score++;
                }
        }
 
@@ -171,27 +171,31 @@ static void run_under_debugger_vg(struct manifest *m, struct score *score)
                return;
 
        first = list_top(&score->per_file_errors, struct file_error, list);
-       command = talloc_asprintf(m, "valgrind --db-attach=yes %s",
+       command = talloc_asprintf(m, "valgrind --db-attach=yes%s %s",
+                                 run_tests_vg.options ?
+                                 run_tests_vg.options : "",
                                  first->file->compiled);
        if (system(command))
                doesnt_matter();
 }
 
-struct ccanlint run_tests_vg = {
-       .key = "valgrind-tests",
+struct ccanlint tests_pass_valgrind = {
+       .key = "tests_pass_valgrind",
        .name = "Module's run and api tests succeed under valgrind",
        .can_run = can_run_vg,
        .check = do_run_tests_vg,
        .handle = run_under_debugger_vg,
-       .takes_options = true
+       .takes_options = true,
+       .needs = "tests_pass"
 };
 
-REGISTER_TEST(run_tests_vg, &run_tests, NULL);
+REGISTER_TEST(tests_pass_valgrind);
 
-struct ccanlint run_tests_vg_leak = {
-       .key = "valgrind-leaks",
+struct ccanlint tests_pass_valgrind_noleaks = {
+       .key = "tests_pass_valgrind_noleaks",
        .name = "Module's run and api tests leak memory",
        .check = do_leakcheck_vg,
+       .needs = "tests_pass_valgrind"
 };
 
-REGISTER_TEST(run_tests_vg_leak, &run_tests_vg, NULL);
+REGISTER_TEST(tests_pass_valgrind_noleaks);