test: detach the suite handling from the file names
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 17 Oct 2024 09:55:25 +0000 (19:55 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Fri, 18 Oct 2024 00:49:47 +0000 (10:49 +1000)
Instead of extracting the suite name from the test's file name use the
current suite that is being parsed. This way we pave the way for
multiple suites in the same file.

This uses a global because otherwise we'd have to redo all the
litest_add() functions but it does the job here.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1065>

.gitlab-ci.yml
.gitlab-ci/config.yml
meson.build
test/litest.c

index 18dc1900a3637407619209d5d3b784520303f5f0..5e90da3a60cdab3ef7206cceaff732c690bd927c 100644 (file)
@@ -559,7 +559,7 @@ vm-tap:
   extends:
     - .fedora:40@test-suite-vm
   variables:
-    SUITE_NAMES: 'touchpad-tap'
+    SUITE_NAMES: 'touchpad_tap'
 
 vm-tap-no-libwacom:
   extends:
@@ -572,7 +572,7 @@ vm-touchpad-buttons:
   extends:
     - .fedora:40@test-suite-vm
   variables:
-    SUITE_NAMES: 'touchpad-buttons'
+    SUITE_NAMES: 'touchpad_buttons'
 
 vm-touchpad-buttons-no-libwacom:
   extends:
@@ -895,8 +895,8 @@ check-test-suites:
     - |
       cat <<EOF > ci-testsuites ;
         libinput-test-suite-touchpad
-        libinput-test-suite-touchpad-tap
-        libinput-test-suite-touchpad-buttons
+        libinput-test-suite-touchpad_tap
+        libinput-test-suite-touchpad_buttons
         libinput-test-suite-tablet
         libinput-test-suite-gestures
         libinput-test-suite-device
index 004f503bdcd1db6ad57de7f33c218014b14b4192..f8cbc3743b8b43a6479c2f25ca298b8d3779d6ba 100644 (file)
@@ -174,10 +174,10 @@ test_suites:
       - touchpad
   - name: tap
     suites:
-      - touchpad-tap
+      - touchpad_tap
   - name: touchpad-buttons
     suites:
-      - touchpad-buttons
+      - touchpad_buttons
   - name: tablet
     suites:
       - tablet
index dccc32c2ad9db8df911e841afe26c3d179b91b94..23947b4efb44dc6566aa04a8182cedb7b987b08d 100644 (file)
@@ -938,6 +938,7 @@ if get_option('tests')
        foreach testfile : tests_sources
                tfile = testfile.split('test/test-')[1]
                group = tfile.split('.c')[0]
+               group = group.replace('-', '_')
                test('libinput-test-suite-@0@'.format(group),
                     libinput_test_runner,
                     suite : ['all', 'valgrind', 'root', 'hardware'],
index 958ae8db7dc935573f23a694e740621699ec330e..bb649569ab93b301249ae03aadea6f369f14771e 100644 (file)
@@ -108,6 +108,7 @@ created_file_unlink(struct created_file *f)
 
 static struct list created_files_list; /* list of all files to remove at the end
                                          of the test run */
+static struct suite *current_suite = NULL;
 
 static void litest_init_udev_rules(struct list *created_files_list);
 static void litest_remove_udev_rules(struct list *created_files_list);
@@ -499,39 +500,6 @@ litest_add_tcase_deviceless(struct suite *suite,
        list_insert(&suite->tests, &t->node);
 }
 
-static struct suite *
-get_suite(const char *name)
-{
-       struct suite *s;
-
-       list_for_each(s, &all_test_suites, node) {
-               if (streq(s->name, name))
-                       return s;
-       }
-
-       s = zalloc(sizeof(*s));
-       s->name = safe_strdup(name);
-
-       list_init(&s->tests);
-       list_insert(&all_test_suites, &s->node);
-
-       return s;
-}
-
-static void
-create_suite_name(const char *filename, char suitename[64])
-{
-       char *trunk = trunkname(filename);
-       char *p = trunk;
-
-       /* strip the test- prefix */
-       if (strstartswith(trunk, "test-"))
-               p += 5;
-
-       snprintf(suitename, 64, "%s", p);
-       free(trunk);
-}
-
 static void
 litest_add_tcase(const char *filename,
                 const char *funcname,
@@ -540,8 +508,6 @@ litest_add_tcase(const char *filename,
                 int64_t excluded,
                 const struct range *range)
 {
-       char suite_name[65];
-       struct suite *suite;
        bool added = false;
 
        litest_assert(required >= LITEST_DEVICELESS);
@@ -551,13 +517,11 @@ litest_add_tcase(const char *filename,
            fnmatch(filter_test, funcname, 0) != 0)
                return;
 
-       create_suite_name(filename, suite_name);
+       struct suite *suite = current_suite;
 
-       if (filter_group && fnmatch(filter_group, suite_name, 0) != 0)
+       if (filter_group && fnmatch(filter_group, suite->name, 0) != 0)
                return;
 
-       suite = get_suite(suite_name);
-
        if (required == LITEST_DEVICELESS &&
            excluded == LITEST_DEVICELESS) {
                litest_add_tcase_deviceless(suite, func, funcname, range);
@@ -691,10 +655,8 @@ _litest_add_ranged_for_device(const char *filename,
                              enum litest_device_type type,
                              const struct range *range)
 {
-       struct suite *s;
        struct litest_test_device *dev;
        bool device_filtered = false;
-       char suite_name[64];
 
        litest_assert(type < LITEST_NO_DEVICE);
 
@@ -702,12 +664,11 @@ _litest_add_ranged_for_device(const char *filename,
            fnmatch(filter_test, funcname, 0) != 0)
                return;
 
-       create_suite_name(filename, suite_name);
+       struct suite *s = current_suite;
 
-       if (filter_group && fnmatch(filter_group, suite_name, 0) != 0)
+       if (filter_group && fnmatch(filter_group, s->name, 0) != 0)
                return;
 
-       s = get_suite(suite_name);
        list_for_each(dev, &devices, node) {
                if (filter_device &&
                    fnmatch(filter_device, dev->shortname, 0) != 0) {
@@ -4927,7 +4888,16 @@ setup_tests(void)
        for (c = &__start_test_collection_section;
             c < &__stop_test_collection_section;
             c++) {
+               struct suite *s;
+               s = zalloc(sizeof(*s));
+               s->name = safe_strdup(c->name);
+
+               list_init(&s->tests);
+               list_insert(&all_test_suites, &s->node);
+
+               current_suite = s;
                c->setup();
+               current_suite = NULL;
        }
 }