[PATCH libevdev 2/6] test: add uinput creation tests

Benjamin Tissoires benjamin.tissoires at gmail.com
Wed Aug 28 02:28:15 PDT 2013


Hi Peter,

I'm cleaning my inbox from input-tools patches, and I hope that I did
not blocked the uinput branch from my lack of answers... :(
If so, really sorry.

On Thu, Aug 15, 2013 at 12:03 AM, Peter Hutterer
<peter.hutterer at who-t.net> wrote:
> On Wed, Aug 14, 2013 at 02:52:52PM +0200, Benjamin Tissoires wrote:
>> On Tue, Aug 13, 2013 at 12:39 PM, Peter Hutterer
>> <peter.hutterer at who-t.net> wrote:
>> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
>> > ---
>> >  test/Makefile.am   |   1 +
>> >  test/test-main.c   |   2 +
>> >  test/test-uinput.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>> >  3 files changed, 179 insertions(+)
>> >  create mode 100644 test/test-uinput.c
>> >
>> > diff --git a/test/Makefile.am b/test/Makefile.am
>> > index 8cad6c7..cabd1bf 100644
>
> [...]
>
>> > +START_TEST(test_uinput_check_syspath_time)
>> > +{
>> > +       struct libevdev *dev;
>> > +       struct libevdev_uinput *uidev, *uidev2;
>> > +       const char *syspath, *syspath2;
>> > +       int fd, fd2;
>> > +       int rc;
>> > +
>> > +       dev = libevdev_new();
>> > +       ck_assert(dev != NULL);
>> > +       libevdev_set_name(dev, TEST_DEVICE_NAME);
>> > +       libevdev_enable_event_type(dev, EV_SYN);
>> > +       libevdev_enable_event_type(dev, EV_REL);
>> > +       libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
>> > +       libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
>> > +
>> > +       fd = open(UINPUT_NODE, O_RDWR);
>> > +       ck_assert_int_gt(fd, -1);
>> > +       fd2 = open(UINPUT_NODE, O_RDWR);
>> > +       ck_assert_int_gt(fd2, -1);
>> > +
>> > +       rc = libevdev_uinput_create_from_device(dev, fd, &uidev);
>> > +       ck_assert_int_eq(rc, 0);
>> > +
>> > +       /* sleep for 1.5 seconds so syspath gives us something useful */
>>
>> I would have said that the function
>> libevdev_uinput_create_from_device() blocks until the input device is
>> registered. So either the usleep is not required, either the comment
>> is not very helpful (I can understand that this will help having
>> different file stats for different calls, but this should be explicit
>> IMO)
>>
>> > +       usleep(1500000);
>> > +
>> > +       /* create a second one to stress the syspath filtering code */
>>
>> waiting for 1.5 sec between the two call will not stress the syspath
>> filtering code :)
>
> well, in this case it does though 'stress' is probably the wrong word.
> ctime is taken before and after UI_DEV_CREATE, but since it's in seconds the
> two will almost always be the same. The first check the syspath filtering
> code does is check for time less/greater than the two ctimes.
>
> that low resolution also means if we start up two devices with the same
> name within the same second, we can't differentiate between the two. that's
> what the wait is for, it's between two libevdev_uinput_create_from_device()
> calls. that way the ctime of the second device is definitely higher than the
> ctime of the first device.
>
> how about this diff then:
>
> diff --git a/test/test-uinput.c b/test/test-uinput.c
> index 449099f..9d7fa85 100644
> --- a/test/test-uinput.c
> +++ b/test/test-uinput.c
> @@ -110,10 +110,15 @@ START_TEST(test_uinput_check_syspath_time)
>         rc = libevdev_uinput_create_from_device(dev, fd, &uidev);
>         ck_assert_int_eq(rc, 0);
>
> -       /* sleep for 1.5 seconds so syspath gives us something useful */
> +       /* sleep for 1.5 seconds. sysfs resolution is 1 second, so
> +          creating both devices without delay means
> +          libevdev_uinput_get_syspath can't actually differ between
> +          them. By waiting, we get different ctime for uidev and uidev2,
> +          and exercise that part of the code.
> +        */
>         usleep(1500000);
>
> -       /* create a second one to stress the syspath filtering code */
> +       /* create a second one to test the syspath time filtering code */
>         rc = libevdev_uinput_create_from_device(dev, fd2, &uidev2);
>         ck_assert_int_eq(rc, 0);
>
>
>

Yep, that's much better.

With the modification above:

Reviewed-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>

Cheers,
Benjamin


>> > +       rc = libevdev_uinput_create_from_device(dev, fd2, &uidev2);
>> > +       ck_assert_int_eq(rc, 0);
>> > +
>> > +       syspath = libevdev_uinput_get_syspath(uidev);
>> > +       ck_assert(syspath != NULL);
>> > +
>> > +       /* get syspath twice returns same pointer */
>> > +       syspath2 = libevdev_uinput_get_syspath(uidev);
>> > +       ck_assert(syspath == syspath2);
>> > +
>> > +       /* second dev has different syspath */
>> > +       syspath2 = libevdev_uinput_get_syspath(uidev2);
>> > +       ck_assert(strcmp(syspath, syspath2) != 0);
>> > +
>> > +       libevdev_free(dev);
>> > +       libevdev_uinput_destroy(uidev);
>> > +       libevdev_uinput_destroy(uidev2);
>> > +
>> > +       close(fd);
>> > +       close(fd2);
>> > +}
>> > +END_TEST
>> > +
>> > +START_TEST(test_uinput_check_syspath_name)
>> > +{
>> > +       struct libevdev *dev;
>> > +       struct libevdev_uinput *uidev, *uidev2;
>> > +       const char *syspath, *syspath2;
>> > +       int fd, fd2;
>> > +       int rc;
>> > +
>> > +       dev = libevdev_new();
>> > +       ck_assert(dev != NULL);
>> > +       libevdev_set_name(dev, TEST_DEVICE_NAME);
>> > +       libevdev_enable_event_type(dev, EV_SYN);
>> > +       libevdev_enable_event_type(dev, EV_REL);
>> > +       libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
>> > +       libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
>> > +
>> > +       fd = open(UINPUT_NODE, O_RDWR);
>> > +       ck_assert_int_gt(fd, -1);
>> > +       fd2 = open(UINPUT_NODE, O_RDWR);
>> > +       ck_assert_int_gt(fd2, -1);
>> > +
>> > +       rc = libevdev_uinput_create_from_device(dev, fd, &uidev);
>> > +       ck_assert_int_eq(rc, 0);
>> > +
>> > +       /* create a second one to stress the syspath filtering code */
>> > +       libevdev_set_name(dev, TEST_DEVICE_NAME " 2");
>> > +       rc = libevdev_uinput_create_from_device(dev, fd2, &uidev2);
>> > +       ck_assert_int_eq(rc, 0);
>> > +
>> > +       syspath = libevdev_uinput_get_syspath(uidev);
>> > +       ck_assert(syspath != NULL);
>> > +
>> > +       /* get syspath twice returns same pointer */
>> > +       syspath2 = libevdev_uinput_get_syspath(uidev);
>> > +       ck_assert(syspath == syspath2);
>> > +
>> > +       /* second dev has different syspath */
>> > +       syspath2 = libevdev_uinput_get_syspath(uidev2);
>> > +       ck_assert(strcmp(syspath, syspath2) != 0);
>> > +
>> > +       libevdev_free(dev);
>> > +       libevdev_uinput_destroy(uidev);
>> > +       libevdev_uinput_destroy(uidev2);
>> > +
>> > +       close(fd);
>> > +       close(fd2);
>> > +}
>> > +END_TEST
>> > +
>> > +Suite *
>> > +uinput_suite(void)
>> > +{
>> > +       Suite *s = suite_create("libevdev uinput device tests");
>> > +
>> > +       TCase *tc = tcase_create("device creation");
>> > +       tcase_add_test(tc, test_uinput_create_device);
>> > +       tcase_add_test(tc, test_uinput_check_syspath_time);
>> > +       tcase_add_test(tc, test_uinput_check_syspath_name);
>> > +       suite_add_tcase(s, tc);
>> > +
>> > +       return s;
>> > +}
>> > --
>> > 1.8.2.1
>> >
>> > _______________________________________________
>> > Input-tools mailing list
>> > Input-tools at lists.freedesktop.org
>> > http://lists.freedesktop.org/mailman/listinfo/input-tools
>>


More information about the Input-tools mailing list