[PATCH libinput 3/6] test: add filtering to litest framework
Peter Hutterer
peter.hutterer at who-t.net
Tue May 19 20:24:59 PDT 2015
Complementary to CK_RUN_SUITE and CK_RUN_CASE, this filters on actual test
function names with a simple fnmatch.
./test/test-touchpad --filter-test="*1fg_tap*"
Most of this patch is renaming litest_add_* to _litest_add_* so we can use the
macros to get at the function names.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
doc/test-suite.dox | 8 ++-
test/litest.c | 190 +++++++++++++++++++++++++++++++++--------------------
test/litest.h | 55 +++++++++++-----
3 files changed, 160 insertions(+), 93 deletions(-)
diff --git a/doc/test-suite.dox b/doc/test-suite.dox
index 5bcaee0..079018c 100644
--- a/doc/test-suite.dox
+++ b/doc/test-suite.dox
@@ -62,8 +62,12 @@ $ CK_RUN_CASE="wheel only" ./test/test-device
$ CK_RUN_SUITE="device:wheel" CK_RUN_CASE="wheel only" ./test/test-device
@endcode
-Check and litest currently do not provide a way to run a specific test
-function only.
+The `--filter-test` argument enables selective running of tests through
+basic shell-style function name matching. For example:
+
+ at code
+$ ./test/test-touchpad --filter-test="*1fg_tap*"
+ at endcode
@section test-verbosity Controlling test output
diff --git a/test/litest.c b/test/litest.c
index d581018..fb0403d 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -29,6 +29,7 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <fnmatch.h>
#include <getopt.h>
#include <poll.h>
#include <stdint.h>
@@ -50,6 +51,7 @@
static int in_debugger = -1;
static int verbose = 0;
+const char *filter_test = NULL;
struct test {
struct list node;
@@ -187,6 +189,7 @@ litest_drop_udev_rules(void)
static void
litest_add_tcase_for_device(struct suite *suite,
+ const char *funcname,
void *func,
const struct litest_test_device *dev,
const struct range *range)
@@ -254,53 +257,6 @@ litest_add_tcase_no_device(struct suite *suite,
suite_add_tcase(suite->suite, t->tc);
}
-static void
-litest_add_tcase(struct suite *suite, void *func,
- enum litest_device_feature required,
- enum litest_device_feature excluded,
- const struct range *range)
-{
- struct litest_test_device **dev = devices;
-
- assert(required >= LITEST_DISABLE_DEVICE);
- assert(excluded >= LITEST_DISABLE_DEVICE);
-
- if (required == LITEST_DISABLE_DEVICE &&
- 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, func, *dev, range);
- dev++;
- }
- } else {
- while (*dev) {
- litest_add_tcase_for_device(suite, func, *dev, range);
- dev++;
- }
- }
-}
-
-void
-litest_add_no_device(const char *name, void *func)
-{
- litest_add(name, func, LITEST_DISABLE_DEVICE, LITEST_DISABLE_DEVICE);
-}
-
-void
-litest_add_ranged_no_device(const char *name,
- void *func,
- const struct range *range)
-{
- litest_add_ranged(name,
- func,
- LITEST_DISABLE_DEVICE,
- LITEST_DISABLE_DEVICE,
- range);
-}
-
static struct suite *
get_suite(const char *name)
{
@@ -325,39 +281,114 @@ get_suite(const char *name)
return s;
}
-void
-litest_add(const char *name,
- void *func,
- enum litest_device_feature required,
- enum litest_device_feature excluded)
+static void
+litest_add_tcase(const char *suite_name,
+ const char *funcname,
+ void *func,
+ enum litest_device_feature required,
+ enum litest_device_feature excluded,
+ const struct range *range)
{
- litest_add_ranged(name, func, required, excluded, NULL);
-}
+ struct litest_test_device **dev = devices;
+ struct suite *suite;
-void
-litest_add_ranged(const char *name,
- void *func,
- enum litest_device_feature required,
- enum litest_device_feature excluded,
- const struct range *range)
-{
- litest_add_tcase(get_suite(name), func, required, excluded, range);
+ assert(required >= LITEST_DISABLE_DEVICE);
+ assert(excluded >= LITEST_DISABLE_DEVICE);
+
+ if (filter_test &&
+ fnmatch(filter_test, funcname, 0) != 0)
+ return;
+
+ suite = get_suite(suite_name);
+
+ if (required == LITEST_DISABLE_DEVICE &&
+ 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++;
+ }
+ } else {
+ while (*dev) {
+ litest_add_tcase_for_device(suite,
+ funcname,
+ func,
+ *dev,
+ range);
+ dev++;
+ }
+ }
}
void
-litest_add_for_device(const char *name,
- void *func,
- enum litest_device_type type)
+_litest_add_no_device(const char *name, const char *funcname, void *func)
{
- litest_add_ranged_for_device(name, func, type, NULL);
+ _litest_add(name, funcname, func, LITEST_DISABLE_DEVICE, LITEST_DISABLE_DEVICE);
}
void
-litest_add_ranged_for_device(const char *name,
+_litest_add_ranged_no_device(const char *name,
+ const char *funcname,
void *func,
- enum litest_device_type type,
const struct range *range)
{
+ _litest_add_ranged(name,
+ funcname,
+ func,
+ LITEST_DISABLE_DEVICE,
+ LITEST_DISABLE_DEVICE,
+ range);
+}
+
+void
+_litest_add(const char *name,
+ const char *funcname,
+ void *func,
+ enum litest_device_feature required,
+ enum litest_device_feature excluded)
+{
+ _litest_add_ranged(name,
+ funcname,
+ func,
+ required,
+ excluded,
+ NULL);
+}
+
+void
+_litest_add_ranged(const char *name,
+ const char *funcname,
+ void *func,
+ enum litest_device_feature required,
+ enum litest_device_feature excluded,
+ const struct range *range)
+{
+ litest_add_tcase(name, funcname, func, required, excluded, range);
+}
+
+void
+_litest_add_for_device(const char *name,
+ const char *funcname,
+ void *func,
+ enum litest_device_type type)
+{
+ _litest_add_ranged_for_device(name, funcname, func, type, NULL);
+}
+
+void
+_litest_add_ranged_for_device(const char *name,
+ const char *funcname,
+ void *func,
+ enum litest_device_type type,
+ const struct range *range)
+{
struct suite *s;
struct litest_test_device **dev = devices;
@@ -366,7 +397,11 @@ litest_add_ranged_for_device(const char *name,
s = get_suite(name);
while (*dev) {
if ((*dev)->type == type) {
- litest_add_tcase_for_device(s, func, *dev, range);
+ litest_add_tcase_for_device(s,
+ funcname,
+ func,
+ *dev,
+ range);
return;
}
dev++;
@@ -1863,9 +1898,15 @@ litest_semi_mt_touch_up(struct litest_device *d,
static int
litest_parse_argv(int argc, char **argv)
{
+ enum {
+ OPT_FILTER_TEST,
+ OPT_LIST,
+ OPT_VERBOSE,
+ };
static const struct option opts[] = {
- { "list", 0, 0, 'l' },
- { "verbose", 0, 0, 'v' },
+ { "filter-test", 1, 0, OPT_FILTER_TEST },
+ { "list", 0, 0, OPT_LIST },
+ { "verbose", 0, 0, OPT_VERBOSE },
{ 0, 0, 0, 0}
};
@@ -1877,10 +1918,13 @@ litest_parse_argv(int argc, char **argv)
if (c == -1)
break;
switch(c) {
- case 'l':
+ case OPT_FILTER_TEST:
+ filter_test = optarg;
+ break;
+ case OPT_LIST:
litest_list_tests(&all_tests);
exit(0);
- case 'v':
+ case OPT_VERBOSE:
verbose = 1;
break;
default:
diff --git a/test/litest.h b/test/litest.h
index b6aaa6f..47bbe54 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -109,26 +109,45 @@ struct libinput *litest_create_context(void);
void litest_disable_log_handler(struct libinput *libinput);
void litest_restore_log_handler(struct libinput *libinput);
-void litest_add(const char *name, void *func,
- enum litest_device_feature required_feature,
- enum litest_device_feature excluded_feature);
-void litest_add_ranged(const char *name,
- void *func,
- enum litest_device_feature required,
- enum litest_device_feature excluded,
- const struct range *range);
-void
-litest_add_for_device(const char *name,
- void *func,
- enum litest_device_type type);
-void litest_add_ranged_for_device(const char *name,
+#define litest_add(name_, func_, ...) \
+ _litest_add(name_, #func_, func_, __VA_ARGS__)
+#define litest_add_ranged(name_, func_, ...) \
+ _litest_add_ranged(name_, #func_, func_, __VA_ARGS__)
+#define litest_add_for_device(name_, func_, ...) \
+ _litest_add_for_device(name_, #func_, func_, __VA_ARGS__)
+#define litest_add_ranged_for_device(name_, func_, ...) \
+ _litest_add_ranged_for_device(name_, #func_, func_, __VA_ARGS__)
+#define litest_add_no_device(name_, func_) \
+ _litest_add_no_device(name_, #func_, func_)
+#define litest_add_ranged_no_device(name_, func_, ...) \
+ _litest_add_ranged_no_device(name_, #func_, func_, __VA_ARGS__)
+void _litest_add(const char *name,
+ const char *funcname,
+ void *func,
+ enum litest_device_feature required_feature,
+ enum litest_device_feature excluded_feature);
+void _litest_add_ranged(const char *name,
+ const char *funcname,
+ void *func,
+ enum litest_device_feature required,
+ enum litest_device_feature excluded,
+ const struct range *range);
+void _litest_add_for_device(const char *name,
+ const char *funcname,
+ void *func,
+ enum litest_device_type type);
+void _litest_add_ranged_for_device(const char *name,
+ const char *funcname,
+ void *func,
+ enum litest_device_type type,
+ const struct range *range);
+void _litest_add_no_device(const char *name,
+ const char *funcname,
+ void *func);
+void _litest_add_ranged_no_device(const char *name,
+ const char *funcname,
void *func,
- enum litest_device_type type,
const struct range *range);
-void litest_add_no_device(const char *name, void *func);
-void litest_add_ranged_no_device(const char *name,
- void *func,
- const struct range *range);
extern void litest_setup_tests(void);
struct litest_device * litest_create_device(enum litest_device_type which);
--
2.3.5
More information about the wayland-devel
mailing list