X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Frun_tests.c;h=105a3e4b10b688c8466174414101b0ee1996aaaf;hp=1a8d75ea4548ecc28836cd2b9d813108103a35d5;hb=be74c29bc91273ce585139b2b1f7305512ae941b;hpb=650c775ff00cccd03fc84e7789a03c51d9839004 diff --git a/tools/run_tests.c b/tools/run_tests.c index 1a8d75ea..105a3e4b 100644 --- a/tools/run_tests.c +++ b/tools/run_tests.c @@ -4,11 +4,12 @@ #include #include #include +#include +#include #include "ccan/tap/tap.h" #include "ccan/talloc/talloc.h" -#include "ccan/string/string.h" - -#define CFLAGS "-O3 -Wall -Wundef -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Werror -Iccan -I." +#include "ccan/str/str.h" +#include "tools.h" /* FIXME: Use build bug later. */ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -20,7 +21,8 @@ static int verbose; struct test_type { const char *name; - void (*testfn)(struct test_type *t, const char *name); + void (*buildfn)(const char *dir, struct test_type *t, const char *name); + void (*runfn)(const char *name); }; struct test @@ -99,14 +101,32 @@ static void add_obj(const char *testdir, const char *name) objs = obj; } -static int build(const char *name, int fail) +static int build(const char *dir, const char *name, int fail) { const char *cmd; int ret; + char *externals = talloc_strdup(name, ""); + char **deps; + + for (deps = get_deps(talloc_autofree_context(), dir, true); *deps; deps++) { + char *newobj; + struct stat st; + + if (!strstarts(*deps, "ccan/")) + continue; + + /* ccan/foo -> ccan/foo.o */ + newobj = talloc_asprintf(name, "%s.o", *deps); - cmd = talloc_asprintf(name, "gcc " CFLAGS " %s -o %s %s %s%s", + /* Only if it exists. Makefile sorts this out. */ + if (stat(newobj, &st) == 0 || errno != ENOENT) + externals = talloc_asprintf_append(externals, + " %s", newobj); + } + + cmd = talloc_asprintf(name, "gcc " CFLAGS " %s -o %s %s %s%s%s", fail ? "-DFAIL" : "", - output_name(name), name, obj_list(), + output_name(name), name, obj_list(), externals, verbose ? "" : "> /dev/null 2>&1"); if (verbose) @@ -119,17 +139,21 @@ static int build(const char *name, int fail) return ret; } -static void compile_ok(struct test_type *t, const char *name) +static void compile_ok(const char *dir, struct test_type *t, const char *name) { - ok(build(name, 0) == 0, "%s %s", t->name, name); + ok(build(dir, name, 0) == 0, "%s %s", t->name, name); } -static void compile_fail(struct test_type *t, const char *name) +static void compile_fail(const char *dir, struct test_type *t, const char *name) { - if (build(name, 0) != 0) + if (build(dir, name, 0) != 0) fail("non-FAIL build %s", name); else - ok(build(name, 1) > 0, "%s %s", t->name, name); + ok(build(dir, name, 1) > 0, "%s %s", t->name, name); +} + +static void no_run(const char *name) +{ } static void run(const char *name) @@ -144,9 +168,10 @@ static void cleanup(const char *name) } static struct test_type test_types[] = { - { "compile_ok", compile_ok }, - { "compile_fail", compile_fail }, - { "run", compile_ok }, + { "compile_ok", compile_ok, no_run }, + { "compile_fail", compile_fail, no_run }, + { "run", compile_ok, run }, + { "api", compile_ok, run }, }; int main(int argc, char *argv[]) @@ -189,20 +214,19 @@ int main(int argc, char *argv[]) } } - plan_tests(num_tests + num_objs); + plan_tests(num_tests + num_objs + (num_objs ? 1 : 0)); /* First all the extra object compilations. */ compile_objs(); /* Do all the test compilations. */ for (test = tests; test; test = test->next) - test->type->testfn(test->type, test->name); + test->type->buildfn(argv[1], test->type, test->name); cleanup_objs(); /* Now run all the ones which wanted to run. */ for (test = tests; test; test = test->next) { - if (streq(test->type->name, "run")) - run(test->name); + test->type->runfn(test->name); cleanup(test->name); }