Skip to content

Commit

Permalink
test: strdup the suite and test name
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
whot committed Jun 26, 2017
1 parent d1b7b62 commit 3b2c47a
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions test/litest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 3b2c47a

Please sign in to comment.