Re: [PATCH 2/2] selftests/liveupdate: Test ENOTTY for unknown ioctl numbers
From: Pratyush Yadav
Date: Wed Dec 02 2026 - 05:45:46 EST
On Tue, Dec 01 2026, Chris Down wrote:
> Check that command numbers outside the ioctl tables of /dev/liveupdate
> and of a session fd fail with ENOTTY, not EINVAL.
>
> Signed-off-by: Chris Down <chris@xxxxxxxxxxxxxx>
> ---
> .../testing/selftests/liveupdate/liveupdate.c | 35 +++++++++++++++++++
> 1 file changed, 35 insertions(+)
>
> diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c
> index 2dedd5fc2534..8df62fda4710 100644
> --- a/tools/testing/selftests/liveupdate/liveupdate.c
> +++ b/tools/testing/selftests/liveupdate/liveupdate.c
> @@ -530,4 +530,39 @@ TEST_F(liveupdate_device, preserve_many_files)
> ASSERT_EQ(close(session_fd), 0);
> }
>
> +/*
> + * Test Case: Unknown IOCTL Numbers
> + *
> + * Verifies that command numbers outside the ioctl tables of /dev/liveupdate
> + * and of a session fd fail with ENOTTY, not EINVAL, which is reserved for a
> + * known command with a bad argument.
> + */
> +TEST_F(liveupdate_device, unknown_ioctl_number)
> +{
> + char buf[64] = {};
> + int session_fd;
> +
> + self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
> + if (self->fd1 < 0 && errno == ENOENT)
> + SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
> + ASSERT_GE(self->fd1, 0);
> +
> + session_fd = luo_create_session(self->fd1, "unknown-ioctl-test");
> + ASSERT_GE(session_fd, 0);
> +
> + EXPECT_LT(ioctl(self->fd1, _IO(LIVEUPDATE_IOCTL_TYPE, 0x3f), buf), 0);
> + EXPECT_EQ(errno, ENOTTY);
> + EXPECT_LT(ioctl(self->fd1, _IO(LIVEUPDATE_IOCTL_TYPE, 0xff), buf), 0);
> + EXPECT_EQ(errno, ENOTTY);
Why 0x3f and 0xff? I assume you use this because
LIVEUPDATE_CMD_SESSION_BASE is 0x40, so you want to test for a command
before and after the base. This makes sense for a session FD, but for
/dev/liveupdate, LIVEUPDATE_CMD_BASE is 0x00, so both 0x3f and 0xff
would test for the same condition, right?
Also, please give these numbers a name. Otherwise we will forget why
these were used in the first place.
> +
> + EXPECT_LT(ioctl(session_fd, TCGETS, buf), 0);
> + EXPECT_EQ(errno, ENOTTY);
> + EXPECT_LT(ioctl(session_fd, _IO(LIVEUPDATE_IOCTL_TYPE, 0x3f), buf), 0);
> + EXPECT_EQ(errno, ENOTTY);
> + EXPECT_LT(ioctl(session_fd, _IO(LIVEUPDATE_IOCTL_TYPE, 0xff), buf), 0);
> + EXPECT_EQ(errno, ENOTTY);
> +
> + ASSERT_EQ(close(session_fd), 0);
> +}
> +
> TEST_HARNESS_MAIN
--
Regards,
Pratyush Yadav