[PATCH libinput 1/3] test: add litest_add_ranged* functionality

Peter Hutterer peter.hutterer at who-t.net
Tue May 5 17:17:06 PDT 2015


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 <peter.hutterer at who-t.net>
---
 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 91f2747..48d3ca4 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -184,7 +184,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;
@@ -193,7 +194,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;
 	}
 
@@ -216,7 +223,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";
@@ -225,7 +234,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;
 	}
 
@@ -241,7 +253,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;
 
@@ -250,17 +263,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++;
 		}
 	}
@@ -272,6 +285,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)
 {
@@ -302,7 +327,17 @@ 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
@@ -310,6 +345,15 @@ 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;
 
@@ -318,7 +362,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 f1a720c..451eac1 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -95,6 +95,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);
@@ -102,11 +110,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);
-- 
2.3.5



More information about the wayland-devel mailing list