[PATCH libinput 2/8] test: Use only one test device for some udev and path tests

Peter Hutterer peter.hutterer at who-t.net
Wed Jul 16 21:25:13 PDT 2014


On Wed, Jul 16, 2014 at 10:39:07PM +0200, Jonas Ådahl wrote:
> 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 at gmail.com>

hmm, I think instead of litest_add_once which is pretty much unpredictable
maybe just add a litest_add_for_device() call where you can pass the enum
litest_device_type in. That way you get the same benefits as your patch
here, with the benefit of knowing which device the test runs for on any
given system.

so instad of 
    litest_add_once("udev:suspend", udev_double_suspend, LITEST_ANY, LITEST_ANY);
you have
    litest_add_for_device("udev:suspend", udev_double_suspend, LITEST_SYNAPTICS_CLICKPAD);

Cheers,
   Peter

> ---
>  test/litest.c | 65 ++++++++++++++++++++++++++++++++++++++++++-----------------
>  test/litest.h |  3 +++
>  test/path.c   | 13 ++++++------
>  test/udev.c   | 15 +++++++-------
>  4 files changed, 65 insertions(+), 31 deletions(-)
> 
> diff --git a/test/litest.c b/test/litest.c
> index adcbf3e..b64c7e3 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -151,25 +151,33 @@ 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,
> +		 int num)
>  {
>  	struct litest_test_device **dev = devices;
>  
> +	if (num == 0)
> +		return;
> +
>  	if (required == LITEST_DISABLE_DEVICE &&
>  	    excluded == LITEST_DISABLE_DEVICE) {
>  		litest_add_tcase_no_device(suite, func);
> -	} 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);
> -			dev++;
> -		}
> -	} else {
> -		while (*dev) {
> +		return;
> +	}
> +
> +	while (*dev) {
> +		if ((required == LITEST_ANY && excluded == LITEST_ANY) ||
> +		    (((*dev)->features & required) == required &&
> +		     ((*dev)->features & excluded) == 0)) {
>  			litest_add_tcase_for_device(suite, func, *dev);
> -			dev++;
> +
> +			if (num != -1) {
> +				num--;
> +				if (num == 0)
> +					break;
> +			}
>  		}
> +		dev++;
>  	}
>  }
>  
> @@ -179,11 +187,12 @@ 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 void
> +litest_add_common(const char *name,
> +		  void *func,
> +		  enum litest_device_feature required,
> +		  enum litest_device_feature excluded,
> +		  int num_devices)
>  {
>  	struct suite *s;
>  
> @@ -192,7 +201,9 @@ litest_add(const char *name,
>  
>  	list_for_each(s, &all_tests, node) {
>  		if (strcmp(s->name, name) == 0) {
> -			litest_add_tcase(s, func, required, excluded);
> +			litest_add_tcase(s, func,
> +					 required, excluded,
> +					 num_devices);
>  			return;
>  		}
>  	}
> @@ -203,7 +214,25 @@ litest_add(const char *name,
>  
>  	list_init(&s->tests);
>  	list_insert(&all_tests, &s->node);
> -	litest_add_tcase(s, func, required, excluded);
> +	litest_add_tcase(s, func, required, excluded, num_devices);
> +}
> +
> +void
> +litest_add(const char *name,
> +	   void *func,
> +	   enum litest_device_feature required,
> +	   enum litest_device_feature excluded)
> +{
> +	litest_add_common(name, func, required, excluded, -1);
> +}
> +
> +void
> +litest_add_once(const char *name,
> +		void *func,
> +		enum litest_device_feature required,
> +		enum litest_device_feature excluded)
> +{
> +	litest_add_common(name, func, required, excluded, 1);
>  }
>  
>  static int
> diff --git a/test/litest.h b/test/litest.h
> index 3e75dd5..b66a74f 100644
> --- a/test/litest.h
> +++ b/test/litest.h
> @@ -74,6 +74,9 @@ 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_once(const char *name, void *func,
> +		     enum litest_device_feature required_feature,
> +		     enum litest_device_feature excluded_feature);
>  void litest_add_no_device(const char *name, void *func);
>  
>  int litest_run(int argc, char **argv);
> diff --git a/test/path.c b/test/path.c
> index 9cc5b04..8bfe329 100644
> --- a/test/path.c
> +++ b/test/path.c
> @@ -797,8 +797,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);
> @@ -808,13 +809,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_once("path:seat events", path_added_seat, LITEST_ANY, LITEST_ANY);
>  	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_once("path:device events", path_add_device, LITEST_ANY, LITEST_ANY);
>  	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_once("path:device events", path_remove_device, LITEST_ANY, LITEST_ANY);
> +	litest_add_once("path:device events", path_double_remove_device, LITEST_ANY, LITEST_ANY);
>  	litest_add_no_device("path:seat", path_seat_recycle);
>  
>  	return litest_run(argc, argv);
> diff --git a/test/udev.c b/test/udev.c
> index f07decb..f6930b4 100644
> --- a/test/udev.c
> +++ b/test/udev.c
> @@ -408,19 +408,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_once("udev:suspend", udev_double_suspend, LITEST_ANY, LITEST_ANY);
> +	litest_add_once("udev:suspend", udev_double_resume, LITEST_ANY, LITEST_ANY);
> +	litest_add_once("udev:suspend", udev_suspend_resume, LITEST_ANY, LITEST_ANY);
> +	litest_add_once("udev:device events", udev_device_sysname, LITEST_ANY, LITEST_ANY);
> +	litest_add_once("udev:seat", udev_seat_recycle, LITEST_ANY, LITEST_ANY);
>  
>  	return litest_run(argc, argv);
>  }
> -- 
> 1.8.5.1
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> 


More information about the wayland-devel mailing list