1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
17 /* Note: we already test safe_mode in run_tests.c */
18 static const char *can_run_vg(struct manifest *m)
20 char *output = run_command(m, "valgrind -q true");
23 return talloc_asprintf(m, "No valgrind support: %s", output);
27 struct run_tests_result {
28 struct list_node list;
29 struct ccan_file *file;
33 static void *do_run_tests_vg(struct manifest *m)
35 struct list_head *list = talloc(m, struct list_head);
36 struct run_tests_result *res;
41 /* We run tests in the module directory, so any paths
42 * referenced can all be module-local. */
43 olddir = talloc_getcwd(m);
45 err(1, "Could not save cwd");
46 if (chdir(m->dir) != 0)
47 err(1, "Could not chdir to %s", m->dir);
51 list_for_each(&m->run_tests, i, list) {
52 run_tests_vg.total_score++;
53 /* FIXME: timeout here */
54 cmdout = run_command(m, "valgrind -q %s", i->compiled);
56 res = talloc(list, struct run_tests_result);
58 res->output = talloc_steal(res, cmdout);
59 list_add_tail(list, &res->list);
63 list_for_each(&m->api_tests, i, list) {
64 run_tests_vg.total_score++;
65 /* FIXME: timeout here */
66 cmdout = run_command(m, "valgrind -q %s", i->compiled);
68 res = talloc(list, struct run_tests_result);
70 res->output = talloc_steal(res, cmdout);
71 list_add_tail(list, &res->list);
75 if (list_empty(list)) {
80 if (chdir(olddir) != 0)
81 err(1, "Could not chdir to %s", olddir);
86 static unsigned int score_run_tests_vg(struct manifest *m, void *check_result)
88 struct list_head *list = check_result;
89 struct run_tests_result *i;
90 unsigned int score = run_tests_vg.total_score;
92 list_for_each(list, i, list)
97 static const char *describe_run_tests_vg(struct manifest *m,
100 struct list_head *list = check_result;
101 char *descrip = talloc_strdup(check_result, "Running tests under valgrind failed:\n");
102 struct run_tests_result *i;
104 list_for_each(list, i, list)
105 descrip = talloc_asprintf_append(descrip, "Running %s:\n%s",
106 i->file->name, i->output);
110 /* Gcc's warn_unused_result is fascist bullshit. */
111 #define doesnt_matter()
113 static void run_under_debugger_vg(struct manifest *m, void *check_result)
115 struct list_head *list = check_result;
116 struct run_tests_result *first;
119 if (!ask("Should I run the first failing test under the debugger?"))
122 first = list_top(list, struct run_tests_result, list);
123 command = talloc_asprintf(m, "valgrind --db-attach=yes %s",
124 first->file->compiled);
129 struct ccanlint run_tests_vg = {
130 .name = "run and api tests under valgrind",
131 .score = score_run_tests_vg,
132 .check = do_run_tests_vg,
133 .describe = describe_run_tests_vg,
134 .can_run = can_run_vg,
135 .handle = run_under_debugger_vg
138 REGISTER_TEST(run_tests_vg, &run_tests, NULL);