#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../compulsory_tests/build.h" #include "tests_compile.h" /* Note: we already test safe_mode in run_tests.c */ static const char *can_run_coverage(struct manifest *m) { unsigned int timeleft = default_timeout_ms; char *output; if (!run_command(m, &timeleft, &output, "gcov -h")) return talloc_asprintf(m, "No gcov support: %s", output); return NULL; } static char *cov_compile(const void *ctx, struct manifest *m, struct ccan_file *file, bool link_with_module, bool keep) { char *output; char *flags = talloc_asprintf(ctx, "%s %s", cflags, COVERAGE_CFLAGS); file->compiled[COMPILE_COVERAGE] = maybe_temp_file(ctx, "", keep, file->fullname); if (!compile_and_link(ctx, file->fullname, ccan_dir, test_obj_list(m, link_with_module, COMPILE_NORMAL, COMPILE_COVERAGE), compiler, flags, lib_list(m, COMPILE_NORMAL), file->compiled[COMPILE_COVERAGE], &output)) { talloc_free(file->compiled[COMPILE_COVERAGE]); file->compiled[COMPILE_COVERAGE] = NULL; return output; } talloc_free(output); return NULL; } /* FIXME: Coverage from testable examples as well. */ static void do_compile_coverage_tests(struct manifest *m, bool keep, unsigned int *timeleft, struct score *score) { char *cmdout; struct ccan_file *i; struct list_head *h; char *f = talloc_asprintf(score, "%s %s", cflags, COVERAGE_CFLAGS); /* For API tests, we need coverage version of module. */ if (!list_empty(&m->api_tests)) { build_objects(m, keep, score, f, COMPILE_COVERAGE); if (!score->pass) { score->error = talloc_strdup(score, "Failed to compile module objects with coverage"); return; } } foreach_ptr(h, &m->run_tests, &m->api_tests) { list_for_each(h, i, list) { cmdout = cov_compile(m, m, i, h == &m->api_tests, keep); if (cmdout) { score_file_error(score, i, 0, "Failed to compile test with coverage: %s", cmdout); } } } if (!score->error) { score->pass = true; score->score = score->total; } } struct ccanlint tests_compile_coverage = { .key = "tests_compile_coverage", .name = "Module tests compile with " COVERAGE_CFLAGS, .check = do_compile_coverage_tests, .can_run = can_run_coverage, .needs = "tests_compile" }; REGISTER_TEST(tests_compile_coverage);