]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/tests_pass.c
ccanlint: show each test as we execute it with -vv
[ccan] / tools / ccanlint / tests / tests_pass.c
index 15a97363098c0786790aad7c9ab433d9accd3d5d..f90b5858f236bf41bd0ef6d0298e05d13e5f8707 100644 (file)
 #include <err.h>
 #include <string.h>
 #include <ctype.h>
+#include "tests_pass.h"
+
+bool do_valgrind = false;
 
 static const char *can_run(struct manifest *m)
 {
+       unsigned int timeleft = default_timeout_ms;
+       char *output;
        if (safe_mode)
                return "Safe mode enabled";
+
+       if (!is_excluded("tests_pass_valgrind")
+           && run_command(m, &timeleft, &output,
+                          "valgrind -q true"))
+               do_valgrind = true;
+
        return NULL;
 }
 
+static const char *concat(struct score *score, char *bits[])
+{
+       unsigned int i;
+       char *ret = talloc_strdup(score, "");
+
+       for (i = 0; bits[i]; i++) {
+               if (i)
+                       ret = talloc_append_string(ret, " ");
+               ret = talloc_append_string(ret, bits[i]);
+       }
+       return ret;
+}
+
+static bool run_test(void *ctx,
+                    struct manifest *m,
+                    unsigned int *timeleft, char **cmdout,
+                    struct ccan_file *i)
+{
+       if (do_valgrind) {
+               const char *options;
+               options = concat(ctx,
+                                per_file_options(&tests_pass_valgrind, i));
+
+               if (!streq(options, "FAIL")) {
+                       /* 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[COMPILE_NORMAL]);
+                       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[COMPILE_NORMAL],
+                                          i->valgrind_log);
+               }
+       }
+
+       return run_command(m, timeleft, cmdout, "%s",
+                          i->compiled[COMPILE_NORMAL]);
+}
+
 static void do_run_tests(struct manifest *m,
                         bool keep,
                         unsigned int *timeleft,
@@ -35,8 +94,9 @@ static void do_run_tests(struct manifest *m,
        foreach_ptr(list, &m->run_tests, &m->api_tests) {
                list_for_each(list, i, list) {
                        score->total++;
-                       if (run_command(m, timeleft, &cmdout, "%s",
-                                       i->compiled))
+                       if (verbose >= 2)
+                               printf("   %s\n", i->name);
+                       if (run_test(score, m, timeleft, &cmdout, i))
                                score->score++;
                        else
                                score_file_error(score, i, 0, "%s", cmdout);
@@ -47,6 +107,7 @@ static void do_run_tests(struct manifest *m,
                score->pass = true;
 }
 
+
 /* Gcc's warn_unused_result is fascist bullshit. */
 #define doesnt_matter()
 
@@ -55,12 +116,13 @@ static void run_under_debugger(struct manifest *m, struct score *score)
        char *command;
        struct file_error *first;
 
+       first = list_top(&score->per_file_errors, struct file_error, list);
+
        if (!ask("Should I run the first failing test under the debugger?"))
                return;
 
-       first = list_top(&score->per_file_errors, struct file_error, list);
-       command = talloc_asprintf(m, "gdb -ex 'break tap.c:132' -ex 'run' %s",
-                                 first->file->compiled);
+       command = talloc_asprintf(m, "gdb -ex 'break tap.c:139' -ex 'run' %s",
+                                 first->file->compiled[COMPILE_NORMAL]);
        if (system(command))
                doesnt_matter();
 }
@@ -75,13 +137,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,
-       .handle = run_under_debugger,
-       .needs = "tests_compile_without_features"
-};
-
-REGISTER_TEST(tests_pass_without_features);