From b97ad3c1741c484ccb1abac2cf27b8a1f11e354e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 6 May 2015 08:09:50 +1000 Subject: [PATCH] test: add litest_add_ranged* functionality litest_add_ranged* takes a range parameter that serves as the lower/upper boundary for a loop. This enables tests to be run multiple times, avoiding the timeouts we triggered by having the loops inside (e.g. see 2bf8d035c and 6dd02468). This just wraps the underlying check framework, the ranged variable is available as "_i" in the test. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/litest.c | 64 +++++++++++++++++++++++++++++++++++++++++++-------- test/litest.h | 20 ++++++++++++++++ 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/test/litest.c b/test/litest.c index c24a3061..2aac5a34 100644 --- a/test/litest.c +++ b/test/litest.c @@ -186,7 +186,8 @@ litest_drop_udev_rules(void) static void litest_add_tcase_for_device(struct suite *suite, void *func, - const struct litest_test_device *dev) + const struct litest_test_device *dev, + const struct range *range) { struct test *t; const char *test_name = dev->shortname; @@ -195,7 +196,13 @@ litest_add_tcase_for_device(struct suite *suite, if (strcmp(t->name, test_name) != 0) continue; - tcase_add_test(t->tc, func); + if (range) + tcase_add_loop_test(t->tc, + func, + range->lower, + range->upper); + else + tcase_add_test(t->tc, func); return; } @@ -218,7 +225,9 @@ litest_add_tcase_for_device(struct suite *suite, } static void -litest_add_tcase_no_device(struct suite *suite, void *func) +litest_add_tcase_no_device(struct suite *suite, + void *func, + const struct range *range) { struct test *t; const char *test_name = "no device"; @@ -227,7 +236,10 @@ litest_add_tcase_no_device(struct suite *suite, void *func) if (strcmp(t->name, test_name) != 0) continue; - tcase_add_test(t->tc, func); + if (range) + tcase_add_loop_test(t->tc, func, range->lower, range->upper); + else + tcase_add_test(t->tc, func); return; } @@ -243,7 +255,8 @@ litest_add_tcase_no_device(struct suite *suite, void *func) static void litest_add_tcase(struct suite *suite, void *func, enum litest_device_feature required, - enum litest_device_feature excluded) + enum litest_device_feature excluded, + const struct range *range) { struct litest_test_device **dev = devices; @@ -252,17 +265,17 @@ litest_add_tcase(struct suite *suite, void *func, if (required == LITEST_DISABLE_DEVICE && excluded == LITEST_DISABLE_DEVICE) { - litest_add_tcase_no_device(suite, func); + 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); + litest_add_tcase_for_device(suite, func, *dev, range); dev++; } } else { while (*dev) { - litest_add_tcase_for_device(suite, func, *dev); + litest_add_tcase_for_device(suite, func, *dev, range); dev++; } } @@ -274,6 +287,18 @@ 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) { @@ -304,13 +329,32 @@ litest_add(const char *name, enum litest_device_feature required, enum litest_device_feature excluded) { - litest_add_tcase(get_suite(name), func, required, excluded); + litest_add_ranged(name, func, required, excluded, NULL); +} + +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); } void litest_add_for_device(const char *name, void *func, enum litest_device_type type) +{ + litest_add_ranged_for_device(name, func, type, NULL); +} + +void +litest_add_ranged_for_device(const char *name, + void *func, + enum litest_device_type type, + const struct range *range) { struct suite *s; struct litest_test_device **dev = devices; @@ -320,7 +364,7 @@ litest_add_for_device(const char *name, s = get_suite(name); while (*dev) { if ((*dev)->type == type) { - litest_add_tcase_for_device(s, func, *dev); + litest_add_tcase_for_device(s, func, *dev, range); return; } dev++; diff --git a/test/litest.h b/test/litest.h index 664b49ac..38d3c1b6 100644 --- a/test/litest.h +++ b/test/litest.h @@ -97,6 +97,14 @@ struct litest_device { char *udev_rule_file; }; +/* A loop range, resolves to: + for (i = lower; i < upper; i++) + */ +struct range { + int lower; /* inclusive */ + int upper; /* exclusive */ +}; + struct libinput *litest_create_context(void); void litest_disable_log_handler(struct libinput *libinput); void litest_restore_log_handler(struct libinput *libinput); @@ -104,11 +112,23 @@ 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, + 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); int litest_run(int argc, char **argv); struct litest_device * litest_create_device(enum litest_device_type which);