From: Peter Hutterer <peter.hutterer@who-t.net>
To: Benjamin Tissoires <bentiss@kernel.org>
Cc: Jiri Kosina <jikos@kernel.org>, Shuah Khan <shuah@kernel.org>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v4 3/3] selftests/hid: Add HIDIOCREVOKE tests
Date: Tue, 27 Aug 2024 15:16:44 +1000 [thread overview]
Message-ID: <20240827051644.GA1580781@quokka> (raw)
In-Reply-To: <20240827-hidraw-revoke-v4-3-88c6795bf867@kernel.org>
Thanks for picking this up and adding the tests, much appreciated
On Tue, Aug 27, 2024 at 12:47:53AM +0900, Benjamin Tissoires wrote:
> Add 4 tests for the new revoke ioctl, for read/write/ioctl and poll.
>
> Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
>
> ---
>
> new in v4
> ---
> tools/testing/selftests/hid/hidraw.c | 143 +++++++++++++++++++++++++++++++++++
> 1 file changed, 143 insertions(+)
>
> diff --git a/tools/testing/selftests/hid/hidraw.c b/tools/testing/selftests/hid/hidraw.c
> index f8c933476dcd..669eada8886b 100644
> --- a/tools/testing/selftests/hid/hidraw.c
> +++ b/tools/testing/selftests/hid/hidraw.c
> @@ -19,6 +19,11 @@
> __typeof__(b) _b = (b); \
> _a < _b ? _a : _b; })
>
> +/* for older kernels */
> +#ifndef HIDIOCREVOKE
> +#define HIDIOCREVOKE _IOW('H', 0x0D, int) /* Revoke device access */
> +#endif /* HIDIOCREVOKE */
> +
> static unsigned char rdesc[] = {
> 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */
> 0x09, 0x21, /* Usage (Vendor Usage 0x21) */
> @@ -516,6 +521,144 @@ TEST_F(hidraw, raw_event)
> ASSERT_EQ(buf[1], 42);
> }
>
> +/*
> + * After initial opening/checks of hidraw, revoke the hidraw
> + * node and check that we can not read any more data.
> + */
> +TEST_F(hidraw, raw_event_revoked)
> +{
> + __u8 buf[10] = {0};
> + int err;
> +
> + /* inject one event */
> + buf[0] = 1;
> + buf[1] = 42;
> + uhid_send_event(_metadata, self->uhid_fd, buf, 6);
> +
> + /* read the data from hidraw */
> + memset(buf, 0, sizeof(buf));
> + err = read(self->hidraw_fd, buf, sizeof(buf));
> + ASSERT_EQ(err, 6) TH_LOG("read_hidraw");
> + ASSERT_EQ(buf[0], 1);
> + ASSERT_EQ(buf[1], 42);
> +
> + /* call the revoke ioctl */
> + err = ioctl(self->hidraw_fd, HIDIOCREVOKE, NULL);
> + ASSERT_OK(err) TH_LOG("couldn't revoke the hidraw fd");
> +
> + /* inject one other event */
> + buf[0] = 1;
> + buf[1] = 43;
> + uhid_send_event(_metadata, self->uhid_fd, buf, 6);
> +
> + /* read the data from hidraw */
> + memset(buf, 0, sizeof(buf));
> + err = read(self->hidraw_fd, buf, sizeof(buf));
> + ASSERT_EQ(err, -1) TH_LOG("read_hidraw");
do you want to check for errno == ENODEV here to avoid false positives?
Shouldn't really happen in this test suite but it costs very little.
Same for the various cases below.
With or without - series:
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Cheers,
Peter
prev parent reply other threads:[~2024-08-27 5:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-26 15:47 [PATCH v4 0/3] HID: hidraw: HIDIOCREVOKE introduction bentiss
2024-08-26 15:47 ` [PATCH v4 1/3] HID: hidraw: add HIDIOCREVOKE ioctl bentiss
2024-08-26 15:47 ` [PATCH v4 2/3] selftests/hid: Add initial hidraw tests skeleton Benjamin Tissoires
2024-08-26 15:47 ` [PATCH v4 3/3] selftests/hid: Add HIDIOCREVOKE tests Benjamin Tissoires
2024-08-27 5:16 ` Peter Hutterer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240827051644.GA1580781@quokka \
--to=peter.hutterer@who-t.net \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox