[PATCH libevdev 5/6] test: add test for sending uinput events

David Herrmann dh.herrmann at gmail.com
Wed Aug 14 06:45:23 PDT 2013


Hi

On Wed, Aug 14, 2013 at 3:40 PM, Benjamin Tissoires
<benjamin.tissoires at gmail.com> wrote:
> On Wed, Aug 14, 2013 at 3:28 PM, David Herrmann <dh.herrmann at gmail.com> wrote:
>> Hi
>>
>> On Wed, Aug 14, 2013 at 3:21 PM, Benjamin Tissoires
>> <benjamin.tissoires at gmail.com> 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/test-uinput.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>>>  1 file changed, 64 insertions(+)
>>>>
>>>> diff --git a/test/test-uinput.c b/test/test-uinput.c
>>>> index de5f3f8..c1ffc3a 100644
>>>> --- a/test/test-uinput.c
>>>> +++ b/test/test-uinput.c
>>>> @@ -25,6 +25,7 @@
>>>>  #include <linux/input.h>
>>>>  #include <errno.h>
>>>>  #include <unistd.h>
>>>> +#include <stdlib.h>
>>>>  #include <fcntl.h>
>>>>  #include <libevdev/libevdev-uinput.h>
>>>>
>>>> @@ -161,6 +162,65 @@ START_TEST(test_uinput_check_syspath_name)
>>>>  }
>>>>  END_TEST
>>>>
>>>> +START_TEST(test_uinput_events)
>>>> +{
>>>> +       struct libevdev *dev;
>>>> +       struct libevdev_uinput *uidev;
>>>> +       int fd, fd2;
>>>> +       int rc;
>>>> +       char *devnode;
>>>> +       int i;
>>>> +       const int nevents = 5;
>>>> +       struct input_event events[] = { {{0, 0}, EV_REL, REL_X, 1},
>>>> +                                       {{0, 0}, EV_REL, REL_Y, -1},
>>>> +                                       {{0, 0}, EV_SYN, SYN_REPORT, 0},
>>>> +                                       {{0, 0}, EV_KEY, BTN_LEFT, 1},
>>>> +                                       {{0, 0}, EV_SYN, SYN_REPORT, 0}};
>>>> +       struct input_event events_read[nevents];
>>>> +
>>>> +       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_type(dev, EV_KEY);
>>>> +       libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
>>>> +       libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
>>>> +       libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
>>>> +
>>>> +       fd = open(UINPUT_NODE, O_RDWR);
>>>> +       ck_assert_int_gt(fd, -1);
>>>> +
>>>> +       rc = libevdev_uinput_create_from_device(dev, fd, &uidev);
>>>> +       ck_assert_int_eq(rc, 0);
>>>> +       ck_assert(uidev != NULL);
>>>> +
>>>> +       devnode = uinput_devnode_from_syspath(libevdev_uinput_get_syspath(uidev));
>>>
>>> this makes me think that this function (retrieve the devnode of a
>>> uinput device, should be in the libevdev_uinput API, rather than in
>>> test-commons).
>>
>> This would add a udev dependency. I think we don't have that yet, do
>
> no, we don't :) But I think we could bypass this dependency because
> uinput_devnode_from_syspath will just transform
> "/sys/devices/virtual/input/input235/event21" into
> "/dev/input/event21" for instance. And I can not recall any evdev
> device which is not in /dev/input/eventX, so, maybe we could just drop
> the elegant way and hardcode this path in the lib.

That conversion is actually fine. The kernel guarantees that both are
the same (as long as you use devtmpfs). udev maintainers also strongly
advise people to rely on such facts. udev never removes/renames nodes,
it only adds symlinks. Everything else would be racy.

>> we? Besides, it's a pretty small helper and as mentioned on github,
>> real uinput drivers don't need it. It's only useful for uinput tests
>> as they need access to both, uinput and /dev/input/eventX.
>>
>
> I'm pretty sure we will need this at some point:
> - for instance, evemu-play relies on the created devnode, instead of
> the uinput fd. I know it's bad, but this is how it works, and it
> allows cross-process accessing the same virtual input device (which is
> bad too :-P ).
> - also, I can easily imagine this devnode to be used as a debug
> information in XIT, to compare if the new device appears in the X.org
> logs...

Sure, without the udev dependency we should definitely add that. I
remember Peter had it in there in the first draft but removed it after
I commented on it.

Regards
David


More information about the Input-tools mailing list