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 "../compulsory_tests/build.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,
38 char *flags = talloc_asprintf(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
40 file->compiled[COMPILE_COVERAGE]
41 = maybe_temp_file(ctx, "", keep, file->fullname);
42 compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
43 test_obj_list(m, link_with_module,
47 lib_list(m, COMPILE_NORMAL),
48 file->compiled[COMPILE_COVERAGE]);
51 /* FIXME: Coverage from testable examples as well. */
52 static void do_compile_coverage_tests(struct manifest *m,
54 unsigned int *timeleft,
61 char *f = talloc_asprintf(score, "%s %s", cflags, COVERAGE_CFLAGS);
63 /* For API tests, we need coverage version of module. */
64 if (!list_empty(&m->api_tests)) {
65 build_objects(m, keep, score, f, COMPILE_COVERAGE);
67 score->error = talloc_strdup(score,
68 "Failed to compile module objects with coverage");
73 foreach_ptr(h, &m->run_tests, &m->api_tests) {
74 list_for_each(h, i, list) {
75 cov_compile(m, *timeleft, m, i, h == &m->api_tests,
80 while ((i = collect_command(&ok, &cmdout)) != NULL) {
82 score_file_error(score, i, 0,
83 "Failed to compile test with coverage:"
89 score->score = score->total;
93 struct ccanlint tests_compile_coverage = {
94 .key = "tests_compile_coverage",
95 .name = "Module tests compile with " COVERAGE_CFLAGS,
96 .check = do_compile_coverage_tests,
97 .can_run = can_run_coverage,
98 .needs = "tests_compile"
101 REGISTER_TEST(tests_compile_coverage);