test: strdup the suite and test name
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 22 Jun 2017 04:04:47 +0000 (14:04 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 26 Jun 2017 08:43:59 +0000 (18:43 +1000)
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>
test/litest.c

index 631a408fa1fa2a8525c4669fd90781f0aa585082..3cb3f3865d2336ccf6223229e58da1aa0427f687 100644 (file)
@@ -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;
 }