1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/tools.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
17 static const char *can_build(struct manifest *m)
20 return "Safe mode enabled";
24 static char *obj_list(const struct manifest *m, bool link_with_module)
29 /* We expect to be linked with tap, unless that's us. */
30 if (!streq(m->basename, "tap"))
31 list = talloc_asprintf(m, "%s/ccan/tap.o", ccan_dir);
33 list = talloc_strdup(m, "");
35 /* Objects from any other C files. */
36 list_for_each(&m->other_test_c_files, i, list)
37 list = talloc_asprintf_append(list, " %s", i->compiled);
39 /* Our own object files. */
41 list_for_each(&m->c_files, i, list)
42 list = talloc_asprintf_append(list, " %s", i->compiled);
44 /* Other ccan modules. */
45 list_for_each(&m->dep_dirs, i, list) {
47 list = talloc_asprintf_append(list, " %s", i->compiled);
53 static char *lib_list(const struct manifest *m)
56 char **libs = get_libs(m, m->dir, &num, &m->info_file->compiled);
57 char *ret = talloc_strdup(m, "");
59 for (i = 0; i < num; i++)
60 ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
64 static char *compile(const void *ctx,
66 struct ccan_file *file,
68 bool link_with_module,
73 file->compiled = maybe_temp_file(ctx, "", keep, file->fullname);
74 errmsg = compile_and_link(ctx, file->fullname, ccan_dir,
75 obj_list(m, link_with_module),
77 lib_list(m), file->compiled);
79 talloc_free(file->compiled);
85 static void do_compile_tests(struct manifest *m,
87 unsigned int *timeleft, struct score *score)
92 list_for_each(&m->compile_ok_tests, i, list) {
93 cmdout = compile(score, m, i, false, false, keep);
95 score->error = "Failed to compile tests";
96 score_file_error(score, i, 0, cmdout);
100 list_for_each(&m->run_tests, i, list) {
101 cmdout = compile(score, m, i, false, false, keep);
103 score->error = "Failed to compile tests";
104 score_file_error(score, i, 0, cmdout);
108 list_for_each(&m->api_tests, i, list) {
109 cmdout = compile(score, m, i, false, true, keep);
111 score->error = "Failed to compile tests";
112 score_file_error(score, i, 0, cmdout);
116 /* The compile fail tests are a bit weird, handle them separately */
120 list_for_each(&m->compile_fail_tests, i, list) {
121 cmdout = compile(score, m, i, false, false, false);
123 score->error = "Failed to compile without -DFAIL";
124 score_file_error(score, i, 0, cmdout);
127 cmdout = compile(score, m, i, true, false, false);
129 score->error = "Compiled successfully with -DFAIL?";
130 score_file_error(score, i, 0, NULL);
136 score->score = score->total;
139 struct ccanlint compile_tests = {
140 .key = "compile-tests",
141 .name = "Module tests compile",
142 .check = do_compile_tests,
143 .can_run = can_build,
146 REGISTER_TEST(compile_tests, &compile_test_helpers, &build_objs, NULL);