X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Ftests%2Fcompile_tests.c;h=80ebe913da7b227945d15e227225e16d609773c8;hp=3d6d3881883d5494bffa504050faea9172ab0ca6;hb=1e7c49e054bf3838d0bc4370df98b7439f358b46;hpb=374d3d2eaa1b29dd3f3a940ca472bb209e95155d diff --git a/tools/ccanlint/tests/compile_tests.c b/tools/ccanlint/tests/compile_tests.c index 3d6d3881..80ebe913 100644 --- a/tools/ccanlint/tests/compile_tests.c +++ b/tools/ccanlint/tests/compile_tests.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -21,16 +22,12 @@ 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 *list; + char *list = talloc_strdup(m, ""); struct ccan_file *i; - - /* We expect to be linked with tap, unless that's us. */ - if (!streq(m->basename, "tap")) - list = talloc_asprintf(m, "%s/ccan/tap.o", ccan_dir); - else - list = talloc_strdup(m, ""); + struct manifest *subm; /* Objects from any other C files. */ list_for_each(&m->other_test_c_files, i, list) @@ -42,9 +39,10 @@ static char *obj_list(const struct manifest *m, bool link_with_module) list = talloc_asprintf_append(list, " %s", i->compiled); /* Other ccan modules. */ - list_for_each(&m->dep_dirs, i, list) { - if (i->compiled) - list = talloc_asprintf_append(list, " %s", i->compiled); + list_for_each(&m->deps, subm, list) { + if (subm->compiled) + list = talloc_asprintf_append(list, " %s", + subm->compiled); } return list; @@ -53,7 +51,7 @@ static char *obj_list(const struct manifest *m, bool link_with_module) static char *lib_list(const struct manifest *m) { unsigned int i, num; - char **libs = get_libs(m, ".", &num, &m->info_file->compiled); + char **libs = get_libs(m, m->dir, &num, &m->info_file->compiled); char *ret = talloc_strdup(m, ""); for (i = 0; i < num; i++) @@ -61,145 +59,81 @@ static char *lib_list(const struct manifest *m) return ret; } -static char *compile(const void *ctx, - struct manifest *m, - struct ccan_file *file, - bool fail, - bool link_with_module, - bool keep) +static bool compile(const void *ctx, + struct manifest *m, + struct ccan_file *file, + bool fail, + bool link_with_module, + bool keep, char **output) { - char *errmsg; - file->compiled = maybe_temp_file(ctx, "", keep, file->fullname); - errmsg = compile_and_link(ctx, file->fullname, ccan_dir, - obj_list(m, link_with_module), - fail ? "-DFAIL" : "", - lib_list(m), file->compiled); - if (errmsg) { + 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); - return errmsg; + return false; } - return NULL; + return true; } -struct compile_tests_result { - struct list_node list; - const char *filename; - const char *description; - const char *output; -}; - -static void *do_compile_tests(struct manifest *m, - bool keep, - unsigned int *timeleft) +static void do_compile_tests(struct manifest *m, + bool keep, + unsigned int *timeleft, struct score *score) { - struct list_head *list = talloc(m, struct list_head); char *cmdout; struct ccan_file *i; - struct compile_tests_result *res; - - list_head_init(list); - - compile_tests.total_score = 0; - list_for_each(&m->compile_ok_tests, i, list) { - compile_tests.total_score++; - cmdout = compile(list, m, i, false, false, keep); - if (cmdout) { - res = talloc(list, struct compile_tests_result); - res->filename = i->name; - res->description = "failed to compile"; - res->output = talloc_steal(res, cmdout); - list_add_tail(list, &res->list); - } - } - - list_for_each(&m->run_tests, i, list) { - compile_tests.total_score++; - cmdout = compile(m, m, i, false, false, keep); - if (cmdout) { - res = talloc(list, struct compile_tests_result); - res->filename = i->name; - res->description = "failed to compile"; - res->output = talloc_steal(res, cmdout); - list_add_tail(list, &res->list); + struct list_head *list; + bool errors = false, warnings = false; + + 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; + } } } - list_for_each(&m->api_tests, i, list) { - compile_tests.total_score++; - cmdout = compile(m, m, i, false, true, keep); - if (cmdout) { - res = talloc(list, struct compile_tests_result); - res->filename = i->name; - res->description = "failed to compile"; - res->output = talloc_steal(res, cmdout); - list_add_tail(list, &res->list); - } - } + /* The compile fail tests are a bit weird, handle them separately */ + if (errors) + return; + /* For historical reasons, "fail" often means "gives warnings" */ list_for_each(&m->compile_fail_tests, i, list) { - compile_tests.total_score++; - cmdout = compile(list, m, i, false, false, false); - if (cmdout) { - res = talloc(list, struct compile_tests_result); - res->filename = i->name; - res->description = "failed to compile without -DFAIL"; - res->output = talloc_steal(res, cmdout); - list_add_tail(list, &res->list); - } else { - cmdout = compile(list, m, i, true, false, false); - if (!cmdout) { - res = talloc(list, struct compile_tests_result); - res->filename = i->name; - res->description = "compiled successfully" - " with -DFAIL"; - res->output = ""; - list_add_tail(list, &res->list); - } + if (!compile(score, m, i, false, false, false, &cmdout)) { + score->error = "Failed to compile without -DFAIL"; + score_file_error(score, i, 0, cmdout); + return; + } + if (!streq(cmdout, "")) { + score->error = "Compile with warnigns without -DFAIL"; + score_file_error(score, i, 0, cmdout); + return; + } + if (compile(score, m, i, true, false, false, &cmdout) + && streq(cmdout, "")) { + score->error = "Compiled successfully with -DFAIL?"; + score_file_error(score, i, 0, NULL); + return; } } - if (list_empty(list)) { - talloc_free(list); - list = NULL; - } - - return list; -} - -static unsigned int score_compile_tests(struct manifest *m, - void *check_result) -{ - struct list_head *list = check_result; - struct compile_tests_result *i; - unsigned int score = compile_tests.total_score; - - list_for_each(list, i, list) - score--; - return score; -} - -static const char *describe_compile_tests(struct manifest *m, - void *check_result) -{ - struct list_head *list = check_result; - struct compile_tests_result *i; - char *descrip = talloc_strdup(list, "Compilation tests failed:\n"); - - list_for_each(list, i, list) - descrip = talloc_asprintf_append(descrip, "%s %s\n%s", - i->filename, i->description, - i->output); - return descrip; + score->pass = true; + score->total = 2; + score->score = 1 + !warnings; } struct ccanlint compile_tests = { .key = "compile-tests", .name = "Module tests compile", - .score = score_compile_tests, - .total_score = 1, .check = do_compile_tests, - .describe = describe_compile_tests, .can_run = can_build, };