test: add --filter-device argument
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 20 May 2015 00:49:13 +0000 (10:49 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 21 May 2015 22:45:35 +0000 (08:45 +1000)
Similar to the CK_RUN_CASE environment variable, but it does support
fnmatch()-style wildcards, e.g.

./test/test-touchpad --filter-device="synaptics*"

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
doc/test-suite.dox
test/litest.c

index 079018c0fc9992d6b474c5c9f05709a32d970443..757dc86e26a1e7f7b4d3a7a1888592784b42ec38 100644 (file)
@@ -69,6 +69,17 @@ basic shell-style function name matching. For example:
 $ ./test/test-touchpad --filter-test="*1fg_tap*"
 @endcode
 
+The `--filter-device` argument enables selective running of tests through
+basic shell-style device name matching. The device names matched are the
+litest-specific shortnames, see the output of `--list`. For example:
+
+@code
+$ ./test/test-touchpad --filter-device="synaptics*"
+@endcode
+
+The `--filter-device` argument can be combined with `--list` to show
+which devices will be affected.
+
 @section test-verbosity Controlling test output
 
 Each test supports the `--verbose` commandline option to enable debugging
index fb0403db98c75c0d772b37047efa04ec3447fda0..fb4e1b938261a06ca696867c3679f60656dfd1f4 100644 (file)
@@ -52,6 +52,7 @@
 static int in_debugger = -1;
 static int verbose = 0;
 const char *filter_test = NULL;
+const char *filter_device = NULL;
 
 struct test {
        struct list node;
@@ -237,6 +238,10 @@ litest_add_tcase_no_device(struct suite *suite,
        struct test *t;
        const char *test_name = "no device";
 
+       if (filter_device &&
+           fnmatch(filter_device, test_name, 0) != 0)
+               return;
+
        list_for_each(t, &suite->tests, node) {
                if (strcmp(t->name, test_name) != 0)
                        continue;
@@ -305,24 +310,31 @@ litest_add_tcase(const char *suite_name,
            excluded == LITEST_DISABLE_DEVICE) {
                litest_add_tcase_no_device(suite, func, range);
        } else if (required != LITEST_ANY || excluded != LITEST_ANY) {
-               while (*dev) {
-                       if (((*dev)->features & required) == required &&
-                           ((*dev)->features & excluded) == 0)
-                               litest_add_tcase_for_device(suite,
-                                                           funcname,
-                                                           func,
-                                                           *dev,
-                                                           range);
-                       dev++;
+               for (; *dev; dev++) {
+                       if (filter_device &&
+                           fnmatch(filter_device, (*dev)->shortname, 0) != 0)
+                               continue;
+                       if (((*dev)->features & required) != required ||
+                           ((*dev)->features & excluded) != 0)
+                               continue;
+
+                       litest_add_tcase_for_device(suite,
+                                                   funcname,
+                                                   func,
+                                                   *dev,
+                                                   range);
                }
        } else {
-               while (*dev) {
+               for (; *dev; dev++) {
+                       if (filter_device &&
+                           fnmatch(filter_device, (*dev)->shortname, 0) != 0)
+                               continue;
+
                        litest_add_tcase_for_device(suite,
                                                    funcname,
                                                    func,
                                                    *dev,
                                                    range);
-                       dev++;
                }
        }
 }
@@ -395,7 +407,11 @@ _litest_add_ranged_for_device(const char *name,
        assert(type < LITEST_NO_DEVICE);
 
        s = get_suite(name);
-       while (*dev) {
+       for (; *dev; dev++) {
+               if (filter_device &&
+                   fnmatch(filter_device, (*dev)->shortname, 0) != 0)
+                       continue;
+
                if ((*dev)->type == type) {
                        litest_add_tcase_for_device(s,
                                                    funcname,
@@ -404,7 +420,6 @@ _litest_add_ranged_for_device(const char *name,
                                                    range);
                        return;
                }
-               dev++;
        }
 
        ck_abort_msg("Invalid test device type");
@@ -1900,11 +1915,13 @@ litest_parse_argv(int argc, char **argv)
 {
        enum {
                OPT_FILTER_TEST,
+               OPT_FILTER_DEVICE,
                OPT_LIST,
                OPT_VERBOSE,
        };
        static const struct option opts[] = {
                { "filter-test", 1, 0, OPT_FILTER_TEST },
+               { "filter-device", 1, 0, OPT_FILTER_DEVICE },
                { "list", 0, 0, OPT_LIST },
                { "verbose", 0, 0, OPT_VERBOSE },
                { 0, 0, 0, 0}
@@ -1921,6 +1938,9 @@ litest_parse_argv(int argc, char **argv)
                case OPT_FILTER_TEST:
                        filter_test = optarg;
                        break;
+               case OPT_FILTER_DEVICE:
+                       filter_device = optarg;
+                       break;
                case OPT_LIST:
                        litest_list_tests(&all_tests);
                        exit(0);