1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
5 #include <ccan/foreach/foreach.h>
17 #include "tests_pass.h"
19 bool do_valgrind = false;
21 static const char *can_run(struct manifest *m)
23 unsigned int timeleft = default_timeout_ms;
26 return "Safe mode enabled";
28 if (!is_excluded("tests_pass_valgrind")
29 && run_command(m, &timeleft, &output,
36 static const char *concat(struct score *score, char *bits[])
39 char *ret = talloc_strdup(score, "");
41 for (i = 0; bits[i]; i++) {
43 ret = talloc_append_string(ret, " ");
44 ret = talloc_append_string(ret, bits[i]);
49 static bool run_test(void *ctx,
51 unsigned int *timeleft, char **cmdout,
58 per_file_options(&tests_pass_valgrind, i));
60 if (!streq(options, "FAIL")) {
61 /* FIXME: Valgrind's output sucks. XML is
62 * unreadable by humans *and* doesn't support
63 * children reporting. */
64 i->valgrind_log = talloc_asprintf(m,
67 talloc_set_destructor(i->valgrind_log,
68 unlink_file_destructor);
70 return run_command(ctx, timeleft, cmdout,
76 i->compiled, i->valgrind_log);
80 return run_command(m, timeleft, cmdout, "%s", i->compiled);
83 static void run_tests(struct manifest *m,
85 unsigned int *timeleft,
89 struct list_head *list;
94 foreach_ptr(list, &m->run_tests, &m->api_tests) {
95 list_for_each(list, i, list) {
97 if (run_test(score, m, timeleft, &cmdout, i,
101 score_file_error(score, i, 0, "%s", cmdout);
105 if (score->score == score->total)
109 static void do_run_tests(struct manifest *m,
111 unsigned int *timeleft,
114 run_tests(m, keep, timeleft, score, do_valgrind);
117 static void do_run_tests_without_features(struct manifest *m,
119 unsigned int *timeleft,
122 run_tests(m, keep, timeleft, score, false);
125 /* Gcc's warn_unused_result is fascist bullshit. */
126 #define doesnt_matter()
128 static void run_under_debugger(struct manifest *m, struct score *score)
131 struct file_error *first;
133 first = list_top(&score->per_file_errors, struct file_error, list);
135 if (!ask("Should I run the first failing test under the debugger?"))
138 command = talloc_asprintf(m, "gdb -ex 'break tap.c:139' -ex 'run' %s",
139 first->file->compiled);
144 struct ccanlint tests_pass = {
146 .name = "Module's run and api tests pass",
147 .check = do_run_tests,
148 .handle = run_under_debugger,
150 .needs = "tests_compile"
153 REGISTER_TEST(tests_pass);
155 struct ccanlint tests_pass_without_features = {
156 .key = "tests_pass_without_features",
157 .name = "Module's run and api tests pass (without features)",
158 .check = do_run_tests_without_features,
159 .handle = run_under_debugger,
160 .needs = "tests_compile_without_features"
163 REGISTER_TEST(tests_pass_without_features);