test: detach the suite handling from the file names

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>
This commit is contained in:
Peter Hutterer 2024-10-17 19:55:25 +10:00
parent dba296d290
commit 0135b0b41c
4 changed files with 21 additions and 50 deletions

View 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

View 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

View 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'],

View 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;
}
}