[LTP] [PATCH v2] Rewrite eventfd01 using new LTP API
Andrea Cervesato
andrea.cervesato@suse.com
Wed Mar 15 10:27:49 CET 2023
Hi,
On 3/14/23 17:56, Cyril Hrubis wrote:
> Hi!
>> Splitted eventfd01 test into multiple test files using new LTP API.
> ^
> Split
>
>> Now we have 5 more tests.
>>
>> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>> ---
>> Use TST_EXP_FD for fd check
>> Check CONFIG_EVENTFD for each test
>> Description adjustments
>>
>> runtest/syscalls | 5 +
>> testcases/kernel/syscalls/eventfd/.gitignore | 5 +
>> testcases/kernel/syscalls/eventfd/eventfd01.c | 745 +-----------------
>> testcases/kernel/syscalls/eventfd/eventfd02.c | 50 ++
>> testcases/kernel/syscalls/eventfd/eventfd03.c | 54 ++
>> testcases/kernel/syscalls/eventfd/eventfd04.c | 57 ++
>> testcases/kernel/syscalls/eventfd/eventfd05.c | 44 ++
>> testcases/kernel/syscalls/eventfd/eventfd06.c | 171 ++++
>> 8 files changed, 412 insertions(+), 719 deletions(-)
>> create mode 100644 testcases/kernel/syscalls/eventfd/eventfd02.c
>> create mode 100644 testcases/kernel/syscalls/eventfd/eventfd03.c
>> create mode 100644 testcases/kernel/syscalls/eventfd/eventfd04.c
>> create mode 100644 testcases/kernel/syscalls/eventfd/eventfd05.c
>> create mode 100644 testcases/kernel/syscalls/eventfd/eventfd06.c
>>
>> diff --git a/runtest/syscalls b/runtest/syscalls
>> index 9c76d7fe3..2179f8d5b 100644
>> --- a/runtest/syscalls
>> +++ b/runtest/syscalls
>> @@ -182,6 +182,11 @@ epoll_pwait04 epoll_pwait04
>> epoll_pwait05 epoll_pwait05
>>
>> eventfd01 eventfd01
>> +eventfd02 eventfd02
>> +eventfd03 eventfd03
>> +eventfd04 eventfd04
>> +eventfd05 eventfd05
>> +eventfd06 eventfd06
>>
>> eventfd2_01 eventfd2_01
>> eventfd2_02 eventfd2_02
>> diff --git a/testcases/kernel/syscalls/eventfd/.gitignore b/testcases/kernel/syscalls/eventfd/.gitignore
>> index db45c67cf..4f577370c 100644
>> --- a/testcases/kernel/syscalls/eventfd/.gitignore
>> +++ b/testcases/kernel/syscalls/eventfd/.gitignore
>> @@ -1 +1,6 @@
>> /eventfd01
>> +/eventfd02
>> +/eventfd03
>> +/eventfd04
>> +/eventfd05
>> +/eventfd06
>> diff --git a/testcases/kernel/syscalls/eventfd/eventfd01.c b/testcases/kernel/syscalls/eventfd/eventfd01.c
>> index 9b60434a2..8f83378da 100644
>> --- a/testcases/kernel/syscalls/eventfd/eventfd01.c
>> +++ b/testcases/kernel/syscalls/eventfd/eventfd01.c
>> @@ -1,738 +1,45 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> /*
>> - * Copyright (c) 2008 Vijay Kumar B. <vijaykumar@bravegnu.org>
>> - * Copyright (c) Linux Test Project, 2008-2022
>> - *
>> - * Based on testcases/kernel/syscalls/waitpid/waitpid01.c
>> - * Original copyright message:
>> - *
>> - * Copyright (c) International Business Machines Corp., 2001
> I suppose that we should retain these copyrights as well, since the new
> tests are mostly cleaned up code from the original test.
>
>> - * This program is free software; you can redistribute it and/or modify
>> - * it under the terms of the GNU General Public License as published by
>> - * the Free Software Foundation; either version 2 of the License, or
>> - * (at your option) any later version.
>> - *
>> - * This program is distributed in the hope that it will be useful,
>> - * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
>> - * the GNU General Public License for more details.
>> - *
>> - * You should have received a copy of the GNU General Public License
>> - * along with this program; if not, write to the Free Software
>> - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>> + * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>> */
>>
>> /*
> ^
> Should be /*\
>
>> - * NAME
>> - * eventfd01.c
>> - *
>> - * DESCRIPTION
>> - * Test cases for eventfd syscall.
>> - *
>> - * USAGE: <for command-line>
>> - * eventfd01 [-c n] [-i n] [-I x] [-P x] [-t]
>> - * where, -c n : Run n copies concurrently.
>> - * -i n : Execute test n times.
>> - * -I x : Execute test for x seconds.
>> - * -P x : Pause for x seconds between iterations.
>> + * [Description]
>> *
>> - * History
>> - * 07/2008 Vijay Kumar
>> - * Initial Version.
>> - *
>> - * Restrictions
>> - * None
>> - */
> ...
>
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/eventfd/eventfd02.c
>> @@ -0,0 +1,50 @@
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>> + */
>> +/*\
>> + * [Description]
>> + *
>> + * Verify write operation for eventfd fail with:
>> + *
>> + * - EAGAIN when counter is zero on non blocking fd
>> + * - EINVAL when buffer size is less than 8 bytes, or if an attempt is made to
>> + * write the value 0xffffffffffffffff
>> + */
>> +
>> +#include <stdlib.h>
>> +#include <sys/eventfd.h>
>> +#include "tst_test.h"
>> +
>> +static void run(void)
>> +{
>> + int fd;
>> + uint64_t val = 12;
>> + uint64_t buf;
>> + uint32_t invalid;
>> +
>> + fd = eventfd(0, EFD_NONBLOCK);
>> + TST_EXP_FD(fd);
> This produces rather cryptic message:
>
> eventfd02.c:27: TPASS: fd returned fd 3
>
> You are supposed to pass the syscall to the TST_EXP_FD() as:
>
> TST_EXP_FD(eventfd(0, EFD_NONBLOCK));
> fd = TST_RET;
>
> I suppose that we can as well redesing subset of the TST_EXP_*() macros
> so that they return a value with:
>
> diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
> index 231c04951..091209558 100644
> --- a/include/tst_test_macros.h
> +++ b/include/tst_test_macros.h
> @@ -86,13 +86,14 @@ extern void *TST_RET_PTR;
> #define TST_EXP_FD_SILENT(SCALL, ...) TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__)
>
> #define TST_EXP_FD(SCALL, ...) \
> - do { \
> + ({ \
> TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__); \
> \
> if (TST_PASS) \
> TST_MSGP_(TPASS, " returned fd %ld", TST_RET, \
> #SCALL, ##__VA_ARGS__); \
> - } while (0)
> + TST_RET; \
> + })
>
>
> Then we can write more simple:
>
> fd = TST_EXP_FD(eventfd(0, EFD_NONBLOCK));
I agree with this. Should we send this patch?
>
>> + SAFE_WRITE(0, fd, &val, sizeof(val));
>> + SAFE_READ(0, fd, &buf, sizeof(buf));
>> + TST_EXP_EQ_LI(buf, val);
>> +
>> + val = UINT64_MAX - 1;
>> + SAFE_WRITE(0, fd, &val, sizeof(val));
>> + TST_EXP_FAIL(write(fd, &val, sizeof(val)), EAGAIN);
>> + TST_EXP_FAIL(write(fd, &invalid, sizeof(invalid)), EINVAL);
>> +
>> + val = 0xffffffffffffffffLL;
>> + TST_EXP_FAIL(write(fd, &val, sizeof(val)), EINVAL);
>> +
>> + SAFE_CLOSE(fd);
>> +}
>> +
>> +static struct tst_test test = {
>> + .test_all = run,
>> + .needs_kconfigs = (const char *[]) {
>> + "CONFIG_EVENTFD",
>> + NULL
>> + },
>> +};
> ...
>
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
>> + */
>> +/*\
>> + * [Description]
>> + *
>> + * Test whether counter overflow is detected and handled correctly.
>> + *
>> + * It is not possible to directly overflow the counter using the
>> + * write() syscall. Overflows occur when the counter is incremented
>> + * from kernel space, in an irq context, when it is not possible to
>> + * block the calling thread of execution.
>> + *
>> + * The AIO subsystem internally uses eventfd mechanism for
>> + * notification of completion of read or write requests. In this test
>> + * we trigger a counter overflow, by setting the counter value to the
>> + * max possible value initially. When the AIO subsystem notifies
>> + * through the eventfd counter, the counter overflows.
>> + *
>> + * NOTE: If the counter starts from an initial value of 0, it will
>> + * take decades for an overflow to occur. But since we set the initial
>> + * value to the max possible counter value, we are able to cause it to
>> + * overflow with a single increment.
>> + *
>> + * When the counter overflows, the following are tested
>> + * 1. Check whether POLLERR event occurs in poll() for the eventfd.
>> + * 2. Check whether readfd_set/writefd_set is set in select() for the
>> + * eventfd.
>> + * 3. The counter value is UINT64_MAX.
>> + */
> This does not render reasonably, the list does not render as a list at
> all, and I would drop the NOTE: as well.
>
> The list should look like:
>
> * When the counter overflows, the following is tested:
> *
> * - POLLERR event occurs in poll() for the eventfd
> * - readfd_set/writefd_set is set in select() for the eventfd
> * - the counter value is UINT64_MAX
> */
>
>> + TEST(io_setup(MAXEVENTS, &ctx));
>> + if (TST_RET < 0)
>> + tst_brk(TBROK, "io_setup() failed: %s", tst_strerrno(-TST_RET));
>> +
>> + fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0644);
>> + evfd = eventfd(0, EFD_NONBLOCK);
>> + TST_EXP_FD(evfd);
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> + SAFE_CLOSE(evfd);
>> + io_destroy(ctx);
>> +}
>> +
>> +static void run(void)
>> +{
>> + test_select();
>> + test_poll();
>> +}
>> +
>> +static struct tst_test test = {
>> + .test_all = run,
>> + .setup = setup,
>> + .cleanup = cleanup,
>> + .needs_tmpdir = 1,
>> + .needs_kconfigs = (const char *[]) {
>> + "CONFIG_EVENTFD",
>> + NULL
>> + },
>> +};
>> +
>> +#else /* HAVE_IO_SET_EVENTFD */
>> +TST_TEST_TCONF("eventfd support is not available in AIO subsystem");
>> +#endif
>> +#else /* HAVE_LIBAIO */
>> +TST_TEST_TCONF("libaio is not available");
>> +#endif
More information about the ltp
mailing list