1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/take/take.h>
4 #include <ccan/str/str.h>
5 #include <ccan/foreach/foreach.h>
6 #include <ccan/tal/path/path.h>
18 #include "tests_pass.h"
20 bool do_valgrind = false;
21 const char *valgrind_suppress = "";
23 static const char *can_run(struct manifest *m)
25 unsigned int timeleft = default_timeout_ms;
28 return "Safe mode enabled";
30 if (!is_excluded("tests_pass_valgrind")
31 && run_command(m, &timeleft, &output,
32 "valgrind -q true")) {
37 /* Check for suppressions file for all of CCAN. */
38 sfile = path_join(m, ccan_dir, ".valgrind_suppressions");
39 if (path_is_file(sfile))
40 valgrind_suppress = tal_fmt(m, "--suppressions=%s",
47 static const char *concat(struct score *score, char *bits[])
50 char *ret = tal_strdup(score, "");
52 for (i = 0; bits[i]; i++) {
54 ret = tal_strcat(score, take(ret), " ");
55 ret = tal_strcat(score, take(ret), bits[i]);
60 static void run_test(void *ctx,
62 unsigned int *timeleft,
68 per_file_options(&tests_pass_valgrind, i));
70 if (!streq(options, "FAIL")) {
71 /* FIXME: Valgrind's output sucks. XML is
72 * unreadable by humans *and* doesn't support
73 * children reporting. */
74 i->valgrind_log = tal_fmt(m,
76 i->compiled[COMPILE_NORMAL]);
78 run_command_async(i, *timeleft,
81 " --log-fd=3 %s %s %s"
83 valgrind_suppress, options,
84 i->compiled[COMPILE_NORMAL],
90 run_command_async(i, *timeleft, "%s",
91 i->compiled[COMPILE_NORMAL]);
94 static void do_run_tests(struct manifest *m,
95 unsigned int *timeleft,
98 struct list_head *list;
104 foreach_ptr(list, &m->run_tests, &m->api_tests) {
105 list_for_each(list, i, list) {
108 printf(" %s...\n", i->name);
109 run_test(score, m, timeleft, i);
113 while ((i = collect_command(&ok, &cmdout)) != NULL) {
115 score_file_error(score, i, 0, "%s", cmdout);
119 printf(" ...%s\n", i->name);
122 if (score->score == score->total)
127 /* Gcc's warn_unused_result is fascist bullshit. */
128 #define doesnt_matter()
130 static void run_under_debugger(struct manifest *m, struct score *score)
133 struct file_error *first;
135 first = list_top(&score->per_file_errors, struct file_error, list);
137 if (!ask("Should I run the first failing test under the debugger?"))
140 command = tal_fmt(m, "gdb -ex 'break tap.c:139' -ex 'run' %s",
141 first->file->compiled[COMPILE_NORMAL]);
146 struct ccanlint tests_pass = {
148 .name = "Module's run and api tests pass",
149 .check = do_run_tests,
150 .handle = run_under_debugger,
152 .needs = "tests_compile"
155 REGISTER_TEST(tests_pass);