X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Ftests_compile.c;h=bfa412a68a14d55051588b15de3ed74213096f52;hp=8a833053e9d3c9e698aa573a228fb41a20bdf507;hb=4640e61b45d8d3cdfc5301bc58ef7c96a42077ec;hpb=b931f4765272d68de3b5e35d70c1933c27bcdea4 diff --git a/tools/ccanlint/tests/tests_compile.c b/tools/ccanlint/tests/tests_compile.c index 8a833053..bfa412a6 100644 --- a/tools/ccanlint/tests/tests_compile.c +++ b/tools/ccanlint/tests/tests_compile.c @@ -15,6 +15,7 @@ #include #include #include "reduce_features.h" +#include "tests_compile.h" static const char *can_build(struct manifest *m) { @@ -23,8 +24,8 @@ static const char *can_build(struct manifest *m) return NULL; } -static char *obj_list(const struct manifest *m, bool link_with_module, - enum compile_type ctype) +char *test_obj_list(const struct manifest *m, bool link_with_module, + enum compile_type ctype, enum compile_type own_ctype) { char *list = talloc_strdup(m, ""); struct ccan_file *i; @@ -39,7 +40,7 @@ static char *obj_list(const struct manifest *m, bool link_with_module, if (link_with_module) list_for_each(&m->c_files, i, list) list = talloc_asprintf_append(list, " %s", - i->compiled[ctype]); + i->compiled[own_ctype]); /* Other ccan modules. */ list_for_each(&m->deps, subm, list) { @@ -51,7 +52,7 @@ static char *obj_list(const struct manifest *m, bool link_with_module, return list; } -static char *lib_list(const struct manifest *m, enum compile_type ctype) +char *lib_list(const struct manifest *m, enum compile_type ctype) { unsigned int i, num; char **libs = get_libs(m, m->dir, &num, @@ -77,12 +78,15 @@ static bool compile(const void *ctx, flags = talloc_asprintf(ctx, "%s%s%s", fail ? "-DFAIL " : "", cflags, - ctype == COMPILE_NOFEAT ? " -I." : ""); + ctype == COMPILE_NOFEAT + ? " "REDUCE_FEATURES_FLAGS : ""); fname = maybe_temp_file(ctx, "", keep, file->fullname); if (!compile_and_link(ctx, file->fullname, ccan_dir, - obj_list(m, link_with_module, ctype), compiler, - flags, lib_list(m, ctype), fname, output)) { + test_obj_list(m, link_with_module, + ctype, ctype), + compiler, flags, lib_list(m, ctype), fname, + output)) { talloc_free(fname); return false; } @@ -91,30 +95,57 @@ static bool compile(const void *ctx, return true; } +static void compile_async(const void *ctx, + struct manifest *m, + struct ccan_file *file, + bool link_with_module, + bool keep, + enum compile_type ctype, + unsigned int time_ms) +{ + char *flags; + + file->compiled[ctype] = maybe_temp_file(ctx, "", keep, file->fullname); + flags = talloc_asprintf(ctx, "%s%s", + cflags, + ctype == COMPILE_NOFEAT + ? " "REDUCE_FEATURES_FLAGS : ""); + + compile_and_link_async(file, time_ms, file->fullname, ccan_dir, + test_obj_list(m, link_with_module, ctype, ctype), + compiler, flags, lib_list(m, ctype), + file->compiled[ctype]); +} + static void compile_tests(struct manifest *m, bool keep, struct score *score, - enum compile_type ctype) + enum compile_type ctype, + unsigned int time_ms) { char *cmdout; struct ccan_file *i; struct list_head *list; - bool errors = false, warnings = false; + bool errors = false, warnings = false, ok; foreach_ptr(list, &m->compile_ok_tests, &m->run_tests, &m->api_tests) { list_for_each(list, i, list) { - if (!compile(score, m, i, false, - list == &m->api_tests, keep, - ctype, &cmdout)) { - score_file_error(score, i, 0, - "Compile failed:\n%s", - cmdout); - errors = true; - } else if (!streq(cmdout, "")) { - score_file_error(score, i, 0, - "Compile gave warnings:\n%s", - cmdout); - warnings = true; - } + compile_async(score, m, i, + list == &m->api_tests, keep, + ctype, time_ms); + } + } + + while ((i = collect_command(&ok, &cmdout)) != NULL) { + if (!ok) { + score_file_error(score, i, 0, + "Compile failed:\n%s", + cmdout); + errors = true; + } else if (!streq(cmdout, "")) { + score_file_error(score, i, 0, + "Compile gave warnings:\n%s", + cmdout); + warnings = true; } } @@ -152,11 +183,12 @@ static void compile_tests(struct manifest *m, bool keep, score->score = score->total - warnings; } +/* FIXME: If we time out, set *timeleft to 0 */ static void do_compile_tests(struct manifest *m, bool keep, unsigned int *timeleft, struct score *score) { - compile_tests(m, keep, score, COMPILE_NORMAL); + compile_tests(m, keep, score, COMPILE_NORMAL, *timeleft); } struct ccanlint tests_compile = { @@ -181,7 +213,7 @@ static void do_compile_tests_without_features(struct manifest *m, unsigned int *timeleft, struct score *score) { - compile_tests(m, keep, score, COMPILE_NOFEAT); + compile_tests(m, keep, score, COMPILE_NOFEAT, *timeleft); } struct ccanlint tests_compile_without_features = { @@ -189,6 +221,6 @@ struct ccanlint tests_compile_without_features = { .name = "Module tests compile (without features)", .check = do_compile_tests_without_features, .can_run = features_reduced, - .needs = "tests_helpers_compile_without_features reduce_features" + .needs = "tests_helpers_compile_without_features objects_build_without_features" }; REGISTER_TEST(tests_compile_without_features);