X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Frun_tests.c;h=5ba276fe4dbf7fdf517e0cb7859e9e1061218af3;hb=b7f7224b320e4659d0e2d9eba503a1713ede3b48;hp=d9696081f753654dd457b8b8c2a413af6132a1de;hpb=914fa0bf6ec0bbe165ddf917e73a1e207743ba1d;p=ccan diff --git a/tools/run_tests.c b/tools/run_tests.c index d9696081..5ba276fe 100644 --- a/tools/run_tests.c +++ b/tools/run_tests.c @@ -19,7 +19,7 @@ static int verbose; struct test_type { const char *name; void (*buildfn)(const char *dir, struct test_type *t, const char *name, - const char *apiobj); + const char *apiobj, const char *libs); void (*runfn)(const char *name); }; @@ -46,7 +46,7 @@ static char *output_name(const char *name) return ret; } -static char *obj_list(void) +static char *obj_list(const char *dir) { char *list = talloc_strdup(objs, ""); struct obj *i; @@ -55,7 +55,8 @@ static char *obj_list(void) list = talloc_asprintf_append(list, "%s ", i->name); /* FIXME */ - list = talloc_asprintf_append(list, "ccan/tap/tap.o"); + if (!streq(dir, "tap") && !strends(dir, "/tap")) + list = talloc_asprintf_append(list, "ccan/tap/tap.o"); return list; } @@ -103,15 +104,15 @@ static void add_obj(const char *testdir, const char *name, bool generate) } static int build(const char *dir, const char *name, const char *apiobj, - int fail) + const char *libs, int fail) { const char *cmd; int ret; - cmd = talloc_asprintf(name, "gcc " CFLAGS " %s -o %s %s %s %s %s", + cmd = talloc_asprintf(name, "gcc " CFLAGS " %s -o %s %s %s %s%s %s", fail ? "-DFAIL" : "", - output_name(name), name, apiobj, obj_list(), - verbose ? "" : "> /dev/null 2>&1"); + output_name(name), name, apiobj, obj_list(dir), + libs, verbose ? "" : "> /dev/null 2>&1"); if (verbose) fprintf(stderr, "Running %s\n", cmd); @@ -124,25 +125,26 @@ static int build(const char *dir, const char *name, const char *apiobj, } static void compile_ok(const char *dir, struct test_type *t, const char *name, - const char *apiobj) + const char *apiobj, const char *libs) { - ok(build(dir, name, "", 0) == 0, "%s %s", t->name, name); + ok(build(dir, name, "", libs, 0) == 0, "%s %s", t->name, name); } /* api tests get the API obj linked in as well. */ static void compile_api_ok(const char *dir, struct test_type *t, - const char *name, const char *apiobj) + const char *name, const char *apiobj, + const char *libs) { - ok(build(dir, name, apiobj, 0) == 0, "%s %s", t->name, name); + ok(build(dir, name, apiobj, libs, 0) == 0, "%s %s", t->name, name); } static void compile_fail(const char *dir, struct test_type *t, const char *name, - const char *apiobj) + const char *apiobj, const char *libs) { - if (build(dir, name, "", 0) != 0) + if (build(dir, name, "", libs, 0) != 0) fail("non-FAIL build %s", name); else - ok(build(dir, name, "", 1) > 0, "%s %s", t->name, name); + ok(build(dir, name, "", libs, 1) > 0, "%s %s", t->name, name); } static void no_run(const char *name) @@ -173,6 +175,7 @@ int main(int argc, char *argv[]) struct dirent *d; char *testdir, *cwd; const char *apiobj = ""; + char *libs = talloc_strdup(NULL, ""); struct test *test; unsigned int num_tests = 0, num_objs = 0, i; @@ -182,6 +185,13 @@ int main(int argc, char *argv[]) argv++; } + while (argc > 1 && strstarts(argv[1], "--lib=")) { + libs = talloc_asprintf_append(libs, " -l%s", + argv[1] + strlen("--lib=")); + argc--; + argv++; + } + if (argc > 1 && strstarts(argv[1], "--apiobj=")) { apiobj = argv[1] + strlen("--apiobj="); argc--; @@ -224,7 +234,8 @@ int main(int argc, char *argv[]) /* Do all the test compilations. */ for (test = tests; test; test = test->next) - test->type->buildfn(argv[1], test->type, test->name, apiobj); + test->type->buildfn(argv[1], test->type, test->name, + apiobj, libs); cleanup_objs();