From 4be59a972a89ea013b21ccdca19afe8456267520 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20=C3=85dahl?= Date: Mon, 14 Jul 2014 00:01:10 +0200 Subject: [PATCH] test: Use only one test device for some udev and path tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some tests in test/path.c and test/udev.c are not dependent on device behaviour but rather managing of device lifetime etc. Run those tests only once with only one device, resulting more or less the same code coverage but shorter run time. Signed-off-by: Jonas Ådahl Reviewed-by: Peter Hutterer --- test/litest.c | 45 +++++++++++++++++++++++++++++++++++---------- test/litest.h | 4 ++++ test/path.c | 13 +++++++------ test/udev.c | 15 ++++++++------- 4 files changed, 54 insertions(+), 23 deletions(-) diff --git a/test/litest.c b/test/litest.c index 18e2e32d..524b5456 100644 --- a/test/litest.c +++ b/test/litest.c @@ -181,11 +181,8 @@ litest_add_no_device(const char *name, void *func) litest_add(name, func, LITEST_DISABLE_DEVICE, LITEST_DISABLE_DEVICE); } -void -litest_add(const char *name, - void *func, - enum litest_device_feature required, - enum litest_device_feature excluded) +static struct suite * +get_suite(const char *name) { struct suite *s; @@ -193,10 +190,8 @@ litest_add(const char *name, list_init(&all_tests); list_for_each(s, &all_tests, node) { - if (strcmp(s->name, name) == 0) { - litest_add_tcase(s, func, required, excluded); - return; - } + if (strcmp(s->name, name) == 0) + return s; } s = zalloc(sizeof(*s)); @@ -205,7 +200,37 @@ litest_add(const char *name, list_init(&s->tests); list_insert(&all_tests, &s->node); - litest_add_tcase(s, func, required, excluded); + + return s; +} + +void +litest_add(const char *name, + void *func, + enum litest_device_feature required, + enum litest_device_feature excluded) +{ + litest_add_tcase(get_suite(name), func, required, excluded); +} + +void +litest_add_for_device(const char *name, + void *func, + enum litest_device_type type) +{ + struct suite *s; + struct litest_test_device **dev = devices; + + s = get_suite(name); + while (*dev) { + if ((*dev)->type == type) { + litest_add_tcase_for_device(s, func, *dev); + return; + } + dev++; + } + + ck_abort_msg("Invalid test device type"); } static int diff --git a/test/litest.h b/test/litest.h index bb3fd7d1..2dcb7b20 100644 --- a/test/litest.h +++ b/test/litest.h @@ -79,6 +79,10 @@ struct libinput *litest_create_context(void); void litest_add(const char *name, void *func, enum litest_device_feature required_feature, enum litest_device_feature excluded_feature); +void +litest_add_for_device(const char *name, + void *func, + enum litest_device_type type); void litest_add_no_device(const char *name, void *func); int litest_run(int argc, char **argv); diff --git a/test/path.c b/test/path.c index 475e125f..ecb78397 100644 --- a/test/path.c +++ b/test/path.c @@ -793,8 +793,9 @@ START_TEST(path_seat_recycle) } END_TEST -int main (int argc, char **argv) { - +int +main(int argc, char **argv) +{ litest_add_no_device("path:create", path_create_NULL); litest_add_no_device("path:create", path_create_invalid); litest_add_no_device("path:create", path_create_destroy); @@ -804,13 +805,13 @@ int main (int argc, char **argv) { litest_add_no_device("path:suspend", path_add_device_suspend_resume); litest_add_no_device("path:suspend", path_add_device_suspend_resume_fail); litest_add_no_device("path:suspend", path_add_device_suspend_resume_remove_device); - litest_add("path:seat events", path_added_seat, LITEST_ANY, LITEST_ANY); + litest_add_for_device("path:seat events", path_added_seat, LITEST_SYNAPTICS_CLICKPAD); litest_add("path:device events", path_added_device, LITEST_ANY, LITEST_ANY); litest_add("path:device events", path_device_sysname, LITEST_ANY, LITEST_ANY); - litest_add("path:device events", path_add_device, LITEST_ANY, LITEST_ANY); + litest_add_for_device("path:device events", path_add_device, LITEST_SYNAPTICS_CLICKPAD); litest_add_no_device("path:device events", path_add_invalid_path); - litest_add("path:device events", path_remove_device, LITEST_ANY, LITEST_ANY); - litest_add("path:device events", path_double_remove_device, LITEST_ANY, LITEST_ANY); + litest_add_for_device("path:device events", path_remove_device, LITEST_SYNAPTICS_CLICKPAD); + litest_add_for_device("path:device events", path_double_remove_device, LITEST_SYNAPTICS_CLICKPAD); litest_add_no_device("path:seat", path_seat_recycle); return litest_run(argc, argv); diff --git a/test/udev.c b/test/udev.c index 9a59eb58..95206635 100644 --- a/test/udev.c +++ b/test/udev.c @@ -407,19 +407,20 @@ START_TEST(udev_seat_recycle) } END_TEST -int main (int argc, char **argv) { - +int +main(int argc, char **argv) +{ litest_add_no_device("udev:create", udev_create_NULL); litest_add_no_device("udev:create", udev_create_seat0); litest_add_no_device("udev:create", udev_create_empty_seat); litest_add_no_device("udev:seat events", udev_added_seat_default); - litest_add("udev:suspend", udev_double_suspend, LITEST_ANY, LITEST_ANY); - litest_add("udev:suspend", udev_double_resume, LITEST_ANY, LITEST_ANY); - litest_add("udev:suspend", udev_suspend_resume, LITEST_ANY, LITEST_ANY); - litest_add("udev:device events", udev_device_sysname, LITEST_ANY, LITEST_ANY); - litest_add("udev:seat", udev_seat_recycle, LITEST_ANY, LITEST_ANY); + litest_add_for_device("udev:suspend", udev_double_suspend, LITEST_SYNAPTICS_CLICKPAD); + litest_add_for_device("udev:suspend", udev_double_resume, LITEST_SYNAPTICS_CLICKPAD); + litest_add_for_device("udev:suspend", udev_suspend_resume, LITEST_SYNAPTICS_CLICKPAD); + litest_add_for_device("udev:device events", udev_device_sysname, LITEST_SYNAPTICS_CLICKPAD); + litest_add_for_device("udev:seat", udev_seat_recycle, LITEST_SYNAPTICS_CLICKPAD); return litest_run(argc, argv); } -- 2.34.1