1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/str/str.h>
4 #include <ccan/foreach/foreach.h>
17 #include "tests_compile.h"
19 /* Note: we already test safe_mode in run_tests.c */
20 static const char *can_run_coverage(struct manifest *m)
22 return gcov_unavailable(m);
25 static char *cflags_list(const struct manifest *m)
28 char *ret = tal_strdup(m, cflags);
30 char **flags = get_cflags(m, m->dir, get_or_compile_info);
31 for (i = 0; flags[i]; i++)
32 tal_append_fmt(&ret, " %s", flags[i]);
36 static char *cflags_list_append(const struct manifest *m, char *iflags)
40 char **flags = get_cflags(m, m->dir, get_or_compile_info);
41 for (i = 0; flags[i]; i++)
42 tal_append_fmt(&iflags, " %s", flags[i]);
46 static void cov_compile(const void *ctx,
49 struct ccan_file *file,
50 bool link_with_module)
52 char *flags = tal_fmt(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
53 flags = cflags_list_append(m, flags);
55 file->compiled[COMPILE_COVERAGE] = temp_file(ctx, "", file->fullname);
56 compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
57 test_obj_list(m, link_with_module,
61 test_lib_list(m, COMPILE_NORMAL),
62 file->compiled[COMPILE_COVERAGE]);
65 /* FIXME: Coverage from testable examples as well. */
66 static void do_compile_coverage_tests(struct manifest *m,
67 unsigned int *timeleft,
74 char *f = cflags_list(m);
75 tal_append_fmt(&f, " %s", COVERAGE_CFLAGS);
77 /* For API tests, we need coverage version of module. */
78 if (!list_empty(&m->api_tests)) {
79 build_objects(m, score, f, COMPILE_COVERAGE);
81 score->error = tal_strdup(score,
82 "Failed to compile module objects with coverage");
87 foreach_ptr(h, &m->run_tests, &m->api_tests) {
88 list_for_each(h, i, list) {
89 cov_compile(m, *timeleft, m, i, h == &m->api_tests);
93 while ((i = collect_command(&ok, &cmdout)) != NULL) {
95 score_file_error(score, i, 0,
96 "Failed to compile test with coverage:"
102 score->score = score->total;
106 struct ccanlint tests_compile_coverage = {
107 .key = "tests_compile_coverage",
108 .name = "Module tests compile with " COVERAGE_CFLAGS,
109 .check = do_compile_coverage_tests,
110 .can_run = can_run_coverage,
111 .needs = "tests_compile"
114 REGISTER_TEST(tests_compile_coverage);