test: Use only one test device for some udev and path tests
authorJonas Ådahl <jadahl@gmail.com>
Sun, 13 Jul 2014 22:01:10 +0000 (00:01 +0200)
committerJonas Ådahl <jadahl@gmail.com>
Mon, 18 Aug 2014 20:35:19 +0000 (22:35 +0200)
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 <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
test/litest.c
test/litest.h
test/path.c
test/udev.c

index 18e2e32d05dbae5db79f3a7b2c4a007dd5b02b4f..524b545685fda69161de07e8cf0131cad1826473 100644 (file)
@@ -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
index bb3fd7d123b518ab15c95270e5a32b89816dbc73..2dcb7b206e8456419e9c3acd4d28354f23ceaebd 100644 (file)
@@ -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);
index 475e125fbb1db7eff816c249a25df07385a5665f..ecb78397e80a8fd7a6623136f820cde62d47e232 100644 (file)
@@ -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);
index 9a59eb58205dfd3ffeb6e5d707629c3e5dbaf259..952066359314c7ce554a1eaa08117abe15cf91c9 100644 (file)
@@ -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);
 }