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>
18 #include "tests_compile.h"
20 /* Note: we already test safe_mode in run_tests.c */
21 static const char *can_run_coverage(struct manifest *m)
23 unsigned int timeleft = default_timeout_ms;
26 if (!run_command(m, &timeleft, &output, "gcov -h"))
27 return talloc_asprintf(m, "No gcov support: %s", output);
31 static void cov_compile(const void *ctx,
34 struct ccan_file *file,
35 bool link_with_module)
37 char *flags = talloc_asprintf(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
39 file->compiled[COMPILE_COVERAGE] = temp_file(ctx, "", file->fullname);
40 compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
41 test_obj_list(m, link_with_module,
45 lib_list(m, COMPILE_NORMAL),
46 file->compiled[COMPILE_COVERAGE]);
49 /* FIXME: Coverage from testable examples as well. */
50 static void do_compile_coverage_tests(struct manifest *m,
51 unsigned int *timeleft,
58 char *f = talloc_asprintf(score, "%s %s", cflags, COVERAGE_CFLAGS);
60 /* For API tests, we need coverage version of module. */
61 if (!list_empty(&m->api_tests)) {
62 build_objects(m, score, f, COMPILE_COVERAGE);
64 score->error = talloc_strdup(score,
65 "Failed to compile module objects with coverage");
70 foreach_ptr(h, &m->run_tests, &m->api_tests) {
71 list_for_each(h, i, list) {
72 cov_compile(m, *timeleft, m, i, h == &m->api_tests);
76 while ((i = collect_command(&ok, &cmdout)) != NULL) {
78 score_file_error(score, i, 0,
79 "Failed to compile test with coverage:"
85 score->score = score->total;
89 struct ccanlint tests_compile_coverage = {
90 .key = "tests_compile_coverage",
91 .name = "Module tests compile with " COVERAGE_CFLAGS,
92 .check = do_compile_coverage_tests,
93 .can_run = can_run_coverage,
94 .needs = "tests_compile"
97 REGISTER_TEST(tests_compile_coverage);