X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Ftests_compile.c;h=0bafcc64e5ddb6124d956eb265c24fe62eff7ce9;hp=4d8686798c0aa12040defb489cd28ebc4d7acd1b;hb=HEAD;hpb=051db34fb275491d4d5dfa5bf7970e8e525766d8 diff --git a/tools/ccanlint/tests/tests_compile.c b/tools/ccanlint/tests/tests_compile.c index 4d868679..0bafcc64 100644 --- a/tools/ccanlint/tests/tests_compile.c +++ b/tools/ccanlint/tests/tests_compile.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -14,48 +13,67 @@ #include #include #include +#include "reduce_features.h" +#include "tests_compile.h" -static const char *can_build(struct manifest *m) +static const char *can_build(struct manifest *m UNNEEDED) { if (safe_mode) return "Safe mode enabled"; 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, ""); + char *list = tal_strdup(m, ""); struct ccan_file *i; struct manifest *subm; /* Objects from any other C files. */ list_for_each(&m->other_test_c_files, i, list) - list = talloc_asprintf_append(list, " %s", i->compiled); + tal_append_fmt(&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); + tal_append_fmt(&list, " %s", i->compiled[own_ctype]); - /* Other ccan modules. */ + /* Other ccan modules (normal depends). */ list_for_each(&m->deps, subm, list) { - if (subm->compiled) - list = talloc_asprintf_append(list, " %s", - subm->compiled); + if (subm->compiled[ctype]) + tal_append_fmt(&list, " %s", subm->compiled[ctype]); + } + + /* Other ccan modules (test depends). */ + list_for_each(&m->test_deps, subm, list) { + if (subm->compiled[ctype]) + tal_append_fmt(&list, " %s", subm->compiled[ctype]); } return list; } -static char *lib_list(const struct manifest *m) +char *test_lib_list(const struct manifest *m, enum compile_type ctype UNNEEDED) +{ + unsigned int i; + char **libs; + char *ret = tal_strdup(m, ""); + + libs = get_libs(m, m->dir, "testdepends", get_or_compile_info); + for (i = 0; libs[i]; i++) + tal_append_fmt(&ret, "-l%s ", libs[i]); + return ret; +} + +static char *cflags_list(const struct manifest *m, const char *iflags) { - unsigned int i, num; - char **libs = get_libs(m, m->dir, &num, &m->info_file->compiled); - char *ret = talloc_strdup(m, ""); + unsigned int i; + char *ret = tal_strdup(m, iflags); - for (i = 0; i < num; i++) - ret = talloc_asprintf_append(ret, "-l%s ", libs[i]); + char **flags = get_cflags(m, m->dir, get_or_compile_info); + for (i = 0; flags[i]; i++) + tal_append_fmt(&ret, " %s", flags[i]); return ret; } @@ -64,40 +82,83 @@ static bool compile(const void *ctx, struct ccan_file *file, bool fail, bool link_with_module, - bool keep, char **output) + enum compile_type ctype, + char **output) { - file->compiled = maybe_temp_file(ctx, "", keep, file->fullname); + char *fname, *flags; + + flags = tal_fmt(ctx, "%s%s%s", + fail ? "-DFAIL " : "", + cflags, + ctype == COMPILE_NOFEAT + ? " "REDUCE_FEATURES_FLAGS : ""); + flags = cflags_list(m, flags); + + fname = temp_file(ctx, "", file->fullname); if (!compile_and_link(ctx, file->fullname, ccan_dir, - obj_list(m, link_with_module), - fail ? "-DFAIL" : "", - lib_list(m), file->compiled, output)) { - talloc_free(file->compiled); + test_obj_list(m, link_with_module, + ctype, ctype), + compiler, flags, test_lib_list(m, ctype), fname, + output)) { + tal_free(fname); return false; } + + file->compiled[ctype] = fname; return true; } -static void do_compile_tests(struct manifest *m, - bool keep, - unsigned int *timeleft, struct score *score) +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 = tal_fmt(ctx, "%s%s", + cflags, + ctype == COMPILE_NOFEAT + ? " "REDUCE_FEATURES_FLAGS : ""); + flags = cflags_list(m, flags); + + compile_and_link_async(file, time_ms, file->fullname, ccan_dir, + test_obj_list(m, link_with_module, ctype, ctype), + compiler, flags, test_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, false, list == &m->api_tests, - keep, &cmdout)) { - score->error = "Failed to compile tests"; - score_file_error(score, i, 0, cmdout); - errors = true; - } else if (!streq(cmdout, "")) { - score->error = "Test compiled with warnings"; - score_file_error(score, i, 0, 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; } } @@ -107,27 +168,37 @@ static void do_compile_tests(struct manifest *m, /* For historical reasons, "fail" often means "gives warnings" */ list_for_each(&m->compile_fail_tests, i, list) { - if (!compile(score, m, i, false, false, false, &cmdout)) { - score->error = "Failed to compile without -DFAIL"; - score_file_error(score, i, 0, cmdout); + if (!compile(score, m, i, false, false, ctype, &cmdout)) { + score_file_error(score, i, 0, + "Compile without -DFAIL failed:\n%s", + cmdout); return; } if (!streq(cmdout, "")) { - score->error = "Compile with warnigns without -DFAIL"; - score_file_error(score, i, 0, cmdout); + score_file_error(score, i, 0, + "Compile gave warnings" + " without -DFAIL:\n%s", + cmdout); return; } - if (compile(score, m, i, true, false, false, &cmdout) + if (compile(score, m, i, true, false, ctype, &cmdout) && streq(cmdout, "")) { - score->error = "Compiled successfully with -DFAIL?"; - score_file_error(score, i, 0, NULL); + 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, + unsigned int *timeleft, struct score *score) +{ + compile_tests(m, score, COMPILE_NORMAL, *timeleft); } struct ccanlint tests_compile = { @@ -139,3 +210,26 @@ struct ccanlint tests_compile = { }; REGISTER_TEST(tests_compile); + +static const char *features_reduced(struct manifest *m UNNEEDED) +{ + if (features_were_reduced) + return NULL; + return "No features to turn off"; +} + +static void do_compile_tests_without_features(struct manifest *m, + unsigned int *timeleft, + struct score *score) +{ + compile_tests(m, score, COMPILE_NOFEAT, *timeleft); +} + +struct ccanlint tests_compile_without_features = { + .key = "tests_compile_without_features", + .name = "Module tests compile (without features)", + .check = do_compile_tests_without_features, + .can_run = features_reduced, + .needs = "module_builds tests_helpers_compile_without_features objects_build_without_features" +}; +REGISTER_TEST(tests_compile_without_features);