diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2017-06-22 14:04:47 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2017-06-26 18:43:59 +1000 |
commit | 3b2c47a86d21a33c39c72e7a2938f8651f3c00d6 (patch) | |
tree | e779a879072978a494b52f17152295c1ceaef846 /test | |
parent | d1b7b6267c0689c44dab2e73a0e5ac7da611e377 (diff) |
test: strdup the suite and test name
The check framework takes and stores the pointer and expects it to be live for
the livetime of the test but it doesn't strdup it. We have to keep those
pointers around ourselves.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rw-r--r-- | test/litest.c | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/test/litest.c b/test/litest.c index 631a408..3cb3f38 100644 --- a/test/litest.c +++ b/test/litest.c @@ -924,10 +924,20 @@ litest_run_suite(char *argv0, struct list *tests, int which, int max) struct test *t; int argvlen = strlen(argv0); int count = -1; + struct name { + struct list node; + char *name; + }; + struct name *n, *tmp; + struct list testnames; if (max > 1) snprintf(argv0, argvlen, "libinput-test-%-50d", which); + /* Check just takes the suite/test name pointers but doesn't strdup + * them - we have to keep them around */ + list_init(&testnames); + /* For each test, create one test suite with one test case, then add it to the test runner. The only benefit suites give us in check is that we can filter them, but our test runner has a @@ -936,20 +946,34 @@ litest_run_suite(char *argv0, struct list *tests, int which, int max) list_for_each(t, &s->tests, node) { Suite *suite; TCase *tc; - char sname[128]; + char *sname, *tname; count = (count + 1) % max; if (max != 1 && (count % max) != which) continue; - snprintf(sname, - sizeof(sname), - "%s:%s:%s", - s->name, - t->name, - t->devname); - - tc = tcase_create(t->name); + xasprintf(&sname, + "%s:%s:%s", + s->name, + t->name, + t->devname); + litest_assert(sname != NULL); + n = zalloc(sizeof(*n)); + litest_assert_notnull(n); + n->name = sname; + list_insert(&testnames, &n->node); + + xasprintf(&tname, + "%s:%s", + t->name, + t->devname); + litest_assert(tname != NULL); + n = zalloc(sizeof(*n)); + litest_assert_notnull(n); + n->name = tname; + list_insert(&testnames, &n->node); + + tc = tcase_create(tname); tcase_add_checked_fixture(tc, t->setup, t->teardown); @@ -972,11 +996,17 @@ litest_run_suite(char *argv0, struct list *tests, int which, int max) } if (!sr) - return 0; + goto out; srunner_run_all(sr, CK_ENV); failed = srunner_ntests_failed(sr); srunner_free(sr); +out: + list_for_each_safe(n, tmp, &testnames, node) { + free(n->name); + free(n); + } + return failed; } |