X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Ftests_compile.c;h=733aebdb88d1b7d0a977f1285523ecb878fb32ea;hp=9e6d5dc7c52ea78055484424da9757a83e6fe8da;hb=fa7a78f9d3553292b5088b1e7a89d63a2393ab2c;hpb=6c1d3e2739e97674069862ec7369677d25e80312 diff --git a/tools/ccanlint/tests/tests_compile.c b/tools/ccanlint/tests/tests_compile.c index 9e6d5dc7..733aebdb 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; } -/* FIXME: Merge this into one place. */ -static char *obj_list(const struct manifest *m, bool link_with_module) +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; @@ -32,30 +33,33 @@ static char *obj_list(const struct manifest *m, bool link_with_module) /* Objects from any other C files. */ list_for_each(&m->other_test_c_files, i, list) - list = talloc_asprintf_append(list, " %s", i->compiled); + list = talloc_asprintf_append(list, " %s", + i->compiled[ctype]); /* Our own object files. */ if (link_with_module) list_for_each(&m->c_files, i, list) - list = talloc_asprintf_append(list, " %s", i->compiled); + list = talloc_asprintf_append(list, " %s", + i->compiled[own_ctype]); /* Other ccan modules. */ list_for_each(&m->deps, subm, list) { - if (subm->compiled) + if (subm->compiled[ctype]) list = talloc_asprintf_append(list, " %s", - subm->compiled); + subm->compiled[ctype]); } return list; } -static char *lib_list(const struct manifest *m) +char *lib_list(const struct manifest *m, enum compile_type ctype) { - unsigned int i, num; - char **libs = get_libs(m, m->dir, &num, &m->info_file->compiled); + unsigned int i; + char **libs; char *ret = talloc_strdup(m, ""); - for (i = 0; i < num; i++) + libs = get_libs(m, m->dir, true, get_or_compile_info); + for (i = 0; libs[i]; i++) ret = talloc_asprintf_append(ret, "-l%s ", libs[i]); return ret; } @@ -63,46 +67,83 @@ static char *lib_list(const struct manifest *m) static bool compile(const void *ctx, struct manifest *m, struct ccan_file *file, - const char *flags, bool fail, bool link_with_module, - bool keep, char **output) + enum compile_type ctype, + char **output) { - char *f = talloc_asprintf(ctx, "%s%s%s", - flags, fail ? "-DFAIL " : "", cflags); + char *fname, *flags; + + flags = talloc_asprintf(ctx, "%s%s%s", + fail ? "-DFAIL " : "", + cflags, + ctype == COMPILE_NOFEAT + ? " "REDUCE_FEATURES_FLAGS : ""); - file->compiled = maybe_temp_file(ctx, "", keep, file->fullname); + fname = temp_file(ctx, "", file->fullname); if (!compile_and_link(ctx, file->fullname, ccan_dir, - obj_list(m, link_with_module), compiler, f, - lib_list(m), file->compiled, output)) { - talloc_free(file->compiled); + test_obj_list(m, link_with_module, + ctype, ctype), + compiler, flags, lib_list(m, ctype), fname, + output)) { + talloc_free(fname); return false; } + + file->compiled[ctype] = fname; return true; } -static void compile_tests(struct manifest *m, bool keep, - struct score *score, const char *incl) +static void compile_async(const void *ctx, + struct manifest *m, + struct ccan_file *file, + bool link_with_module, + enum compile_type ctype, + unsigned int time_ms) +{ + char *flags; + + file->compiled[ctype] = temp_file(ctx, "", 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, + struct score *score, + 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, incl, false, - list == &m->api_tests, keep, &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, + 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; } } @@ -112,7 +153,7 @@ static void compile_tests(struct manifest *m, bool keep, /* For historical reasons, "fail" often means "gives warnings" */ list_for_each(&m->compile_fail_tests, i, list) { - if (!compile(score, m, i, incl, false, false, false, &cmdout)) { + if (!compile(score, m, i, false, false, ctype, &cmdout)) { score_file_error(score, i, 0, "Compile without -DFAIL failed:\n%s", cmdout); @@ -125,24 +166,24 @@ static void compile_tests(struct manifest *m, bool keep, cmdout); return; } - if (compile(score, m, i, incl, true, false, false, &cmdout) + if (compile(score, m, i, true, false, ctype, &cmdout) && streq(cmdout, "")) { score_file_error(score, i, 0, "Compiled successfully with -DFAIL?"); return; } + score->total++; } score->pass = true; - score->total = 2; - score->score = 1 + !warnings; + 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) { - return compile_tests(m, keep, score, ""); + compile_tests(m, score, COMPILE_NORMAL, *timeleft); } struct ccanlint tests_compile = { @@ -163,11 +204,10 @@ static const char *features_reduced(struct manifest *m) } static void do_compile_tests_without_features(struct manifest *m, - bool keep, unsigned int *timeleft, struct score *score) { - return compile_tests(m, keep, score, "-I. "); + compile_tests(m, score, COMPILE_NOFEAT, *timeleft); } struct ccanlint tests_compile_without_features = { @@ -175,6 +215,6 @@ struct ccanlint tests_compile_without_features = { .name = "Module tests compile (without features)", .check = do_compile_tests_without_features, .can_run = features_reduced, - .needs = "reduce_features" + .needs = "module_builds tests_helpers_compile_without_features objects_build_without_features" }; REGISTER_TEST(tests_compile_without_features);