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

Peter Hutterer peter.hutterer at who-t.net
Sun Aug 3 19:43:32 PDT 2014


On Sun, Jul 27, 2014 at 11:28:26PM +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);
> > 
> 
> Sure, works for me. Updated version of the patch:

replace all LITEST_CLICKPAD with LITEST_SYNAPTICS_CLICKPAD and then it's
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
the former is a feature flag, the latter is the actual device.

Cheers,
   Peter

> 
> 
>  test/litest.c | 45 +++++++++++++++++++++++++++++++++++----------
>  test/litest.h |  4 ++++
>  test/path.c   | 13 +++++++------
>  test/udev.c   | 15 ++++++++-------
>  4 files changed, 54 insertions(+), 23 deletions(-)
> 
> diff --git a/test/litest.c b/test/litest.c
> index deab0cf..946a0d7 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -179,11 +179,8 @@ 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 struct suite *
> +get_suite(const char *name)
>  {
>  	struct suite *s;
>  
> @@ -191,10 +188,8 @@ litest_add(const char *name,
>  		list_init(&all_tests);
>  
>  	list_for_each(s, &all_tests, node) {
> -		if (strcmp(s->name, name) == 0) {
> -			litest_add_tcase(s, func, required, excluded);
> -			return;
> -		}
> +		if (strcmp(s->name, name) == 0)
> +			return s;
>  	}
>  
>  	s = zalloc(sizeof(*s));
> @@ -203,7 +198,37 @@ litest_add(const char *name,
>  
>  	list_init(&s->tests);
>  	list_insert(&all_tests, &s->node);
> -	litest_add_tcase(s, func, required, excluded);
> +
> +	return s;
> +}
> +
> +void
> +litest_add(const char *name,
> +	   void *func,
> +	   enum litest_device_feature required,
> +	   enum litest_device_feature excluded)
> +{
> +	litest_add_tcase(get_suite(name), func, required, excluded);
> +}
> +
> +void
> +litest_add_for_device(const char *name,
> +		      void *func,
> +		      enum litest_device_type type)
> +{
> +	struct suite *s;
> +	struct litest_test_device **dev = devices;
> +
> +	s = get_suite(name);
> +	while (*dev) {
> +		if ((*dev)->type == type) {
> +			litest_add_tcase_for_device(s, func, *dev);
> +			return;
> +		}
> +		dev++;
> +	}
> +
> +	ck_abort_msg("Invalid test device type");
>  }
>  
>  static int
> diff --git a/test/litest.h b/test/litest.h
> index 9a9d10a..c0035d3 100644
> --- a/test/litest.h
> +++ b/test/litest.h
> @@ -76,6 +76,10 @@ 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_for_device(const char *name,
> +		      void *func,
> +		      enum litest_device_type type);
>  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 475e125..f6f6b84 100644
> --- a/test/path.c
> +++ b/test/path.c
> @@ -793,8 +793,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);
> @@ -804,13 +805,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_for_device("path:seat events", path_added_seat, LITEST_CLICKPAD);
>  	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_for_device("path:device events", path_add_device, LITEST_CLICKPAD);
>  	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_for_device("path:device events", path_remove_device, LITEST_CLICKPAD);
> +	litest_add_for_device("path:device events", path_double_remove_device, LITEST_CLICKPAD);
>  	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 9a59eb5..f5067c9 100644
> --- a/test/udev.c
> +++ b/test/udev.c
> @@ -407,19 +407,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_for_device("udev:suspend", udev_double_suspend, LITEST_CLICKPAD);
> +	litest_add_for_device("udev:suspend", udev_double_resume, LITEST_CLICKPAD);
> +	litest_add_for_device("udev:suspend", udev_suspend_resume, LITEST_CLICKPAD);
> +	litest_add_for_device("udev:device events", udev_device_sysname, LITEST_CLICKPAD);
> +	litest_add_for_device("udev:seat", udev_seat_recycle, LITEST_CLICKPAD);
>  
>  	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