]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/run_tests_valgrind.c
ccanlint: make tests non-compulsory, always print score.
[ccan] / tools / ccanlint / tests / run_tests_valgrind.c
index 6312a0a864327988c53b39f080eb0b6daedcaecc..caf8323c2cfa26cf53257d226f698e69ac6a9a6c 100644 (file)
@@ -17,7 +17,8 @@
 /* Note: we already test safe_mode in run_tests.c */
 static const char *can_run_vg(struct manifest *m)
 {
-       char *output = run_command(m, "valgrind -q true");
+       unsigned int timeleft = default_timeout_ms;
+       char *output = run_command(m, &timeleft, "valgrind -q --error-exitcode=0 true");
 
        if (output)
                return talloc_asprintf(m, "No valgrind support: %s", output);
@@ -30,28 +31,23 @@ struct run_tests_result {
        const char *output;
 };
 
-static void *do_run_tests_vg(struct manifest *m)
+static void *do_run_tests_vg(struct manifest *m,
+                            bool keep,
+                            unsigned int *timeleft)
 {
        struct list_head *list = talloc(m, struct list_head);
        struct run_tests_result *res;
        struct ccan_file *i;
        char *cmdout;
-       char *olddir;
-
-       /* We run tests in the module directory, so any paths
-        * referenced can all be module-local. */
-       olddir = talloc_getcwd(m);
-       if (!olddir)
-               err(1, "Could not save cwd");
-       if (chdir(m->dir) != 0)
-               err(1, "Could not chdir to %s", m->dir);
 
        list_head_init(list);
+       run_tests_vg.total_score = 0;
 
        list_for_each(&m->run_tests, i, list) {
                run_tests_vg.total_score++;
-               /* FIXME: timeout here */
-               cmdout = run_command(m, "valgrind -q %s", i->compiled);
+               cmdout = run_command(m, timeleft,
+                                    "valgrind -q --error-exitcode=100 %s",
+                                    i->compiled);
                if (cmdout) {
                        res = talloc(list, struct run_tests_result);
                        res->file = i;
@@ -62,8 +58,9 @@ static void *do_run_tests_vg(struct manifest *m)
 
        list_for_each(&m->api_tests, i, list) {
                run_tests_vg.total_score++;
-               /* FIXME: timeout here */
-               cmdout = run_command(m, "valgrind -q %s", i->compiled);
+               cmdout = run_command(m, timeleft,
+                                    "valgrind -q --error-exitcode=100 %s",
+                                    i->compiled);
                if (cmdout) {
                        res = talloc(list, struct run_tests_result);
                        res->file = i;
@@ -77,9 +74,6 @@ static void *do_run_tests_vg(struct manifest *m)
                list = NULL;
        }
 
-       if (chdir(olddir) != 0)
-               err(1, "Could not chdir to %s", olddir);
-
        return list;
 }
 
@@ -127,9 +121,10 @@ static void run_under_debugger_vg(struct manifest *m, void *check_result)
 }
 
 struct ccanlint run_tests_vg = {
-       .key = "valgrind",
-       .name = "run and api tests under valgrind",
+       .key = "valgrind-tests",
+       .name = "Module's run and api tests succeed under valgrind",
        .score = score_run_tests_vg,
+       .total_score = 1,
        .check = do_run_tests_vg,
        .describe = describe_run_tests_vg,
        .can_run = can_run_vg,