* [LTP] [PATCH 0/3] syscalls/aio: Add testcases for native AIO
@ 2021-05-07 8:33 Xie Ziyao
2021-05-07 8:33 ` [LTP] [PATCH 1/3] syscalls/io_destroy: Add io_destroy02 test " Xie Ziyao
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Xie Ziyao @ 2021-05-07 8:33 UTC (permalink / raw)
To: ltp
Test io_destroy, io_setup, io_submit invoked via syscall(2).
Xie Ziyao (3):
syscalls/io_destroy: Add io_destroy02 test for native AIO
syscalls/io_setup: Add io_setup02 test for native AIO
syscalls/io_submit: Add io_submit02 test for native AIO
runtest/syscalls | 3 +
.../kernel/syscalls/io_destroy/.gitignore | 1 +
.../kernel/syscalls/io_destroy/io_destroy02.c | 32 +++++
testcases/kernel/syscalls/io_setup/.gitignore | 1 +
.../kernel/syscalls/io_setup/io_setup02.c | 52 ++++++++
.../kernel/syscalls/io_submit/.gitignore | 1 +
.../kernel/syscalls/io_submit/io_submit02.c | 119 ++++++++++++++++++
7 files changed, 209 insertions(+)
create mode 100644 testcases/kernel/syscalls/io_destroy/io_destroy02.c
create mode 100644 testcases/kernel/syscalls/io_setup/io_setup02.c
create mode 100644 testcases/kernel/syscalls/io_submit/io_submit02.c
--
2.17.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [PATCH 1/3] syscalls/io_destroy: Add io_destroy02 test for native AIO
2021-05-07 8:33 [LTP] [PATCH 0/3] syscalls/aio: Add testcases for native AIO Xie Ziyao
@ 2021-05-07 8:33 ` Xie Ziyao
2021-06-07 13:15 ` Cyril Hrubis
2021-05-07 8:33 ` [LTP] [PATCH 2/3] syscalls/io_setup: Add io_setup02 " Xie Ziyao
2021-05-07 8:33 ` [LTP] [PATCH 3/3] syscalls/io_submit: Add io_submit02 " Xie Ziyao
2 siblings, 1 reply; 7+ messages in thread
From: Xie Ziyao @ 2021-05-07 8:33 UTC (permalink / raw)
To: ltp
Test io_destroy invoked via syscall(2) with an invalid ctx and expects
it to return EINVAL.
Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
runtest/syscalls | 1 +
.../kernel/syscalls/io_destroy/.gitignore | 1 +
.../kernel/syscalls/io_destroy/io_destroy02.c | 32 +++++++++++++++++++
3 files changed, 34 insertions(+)
create mode 100644 testcases/kernel/syscalls/io_destroy/io_destroy02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index aa7fa24dd..bd6ec6a2e 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -607,6 +607,7 @@ ioprio_set03 ioprio_set03
io_cancel01 io_cancel01
io_destroy01 io_destroy01
+io_destroy02 io_destroy02
io_getevents01 io_getevents01
io_pgetevents01 io_pgetevents01
diff --git a/testcases/kernel/syscalls/io_destroy/.gitignore b/testcases/kernel/syscalls/io_destroy/.gitignore
index 025aa0f4a..48a16cd2f 100644
--- a/testcases/kernel/syscalls/io_destroy/.gitignore
+++ b/testcases/kernel/syscalls/io_destroy/.gitignore
@@ -1 +1,2 @@
/io_destroy01
+/io_destroy02
diff --git a/testcases/kernel/syscalls/io_destroy/io_destroy02.c b/testcases/kernel/syscalls/io_destroy/io_destroy02.c
new file mode 100644
index 000000000..357e61f10
--- /dev/null
+++ b/testcases/kernel/syscalls/io_destroy/io_destroy02.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_destroy invoked via syscall(2) with an invalid ctx and expects
+ * it to return EINVAL.
+ */
+
+#include <linux/aio_abi.h>
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+static void verify_io_destroy(void)
+{
+ aio_context_t ctx;
+ memset(&ctx, 0xff, sizeof(ctx));
+ TST_EXP_FAIL(tst_syscall(__NR_io_destroy, ctx), EINVAL);
+}
+
+static struct tst_test test = {
+ .test_all = verify_io_destroy,
+};
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [LTP] [PATCH 2/3] syscalls/io_setup: Add io_setup02 test for native AIO
2021-05-07 8:33 [LTP] [PATCH 0/3] syscalls/aio: Add testcases for native AIO Xie Ziyao
2021-05-07 8:33 ` [LTP] [PATCH 1/3] syscalls/io_destroy: Add io_destroy02 test " Xie Ziyao
@ 2021-05-07 8:33 ` Xie Ziyao
2021-06-07 13:18 ` Cyril Hrubis
2021-05-07 8:33 ` [LTP] [PATCH 3/3] syscalls/io_submit: Add io_submit02 " Xie Ziyao
2 siblings, 1 reply; 7+ messages in thread
From: Xie Ziyao @ 2021-05-07 8:33 UTC (permalink / raw)
To: ltp
Test io_setup invoked via syscall(2):
- io_setup fails and returns -EFAULT if ctxp is NULL;
- io_setup fails and returns -EINVAL if ctxp is not initialized to 0;
- io_setup fails and returns -EINVAL if nr_events is -1;
- io_setup fails and returns -EAGAIN if nr_events exceeds the limit
of available events;
- io_setup succeeds if both nr_events and ctxp are valid.
Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/io_setup/.gitignore | 1 +
.../kernel/syscalls/io_setup/io_setup02.c | 52 +++++++++++++++++++
3 files changed, 54 insertions(+)
create mode 100644 testcases/kernel/syscalls/io_setup/io_setup02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index bd6ec6a2e..b8f195891 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -614,6 +614,7 @@ io_pgetevents01 io_pgetevents01
io_pgetevents02 io_pgetevents02
io_setup01 io_setup01
+io_setup02 io_setup02
io_submit01 io_submit01
keyctl01 keyctl01
diff --git a/testcases/kernel/syscalls/io_setup/.gitignore b/testcases/kernel/syscalls/io_setup/.gitignore
index 4fd03960c..37a4b8321 100644
--- a/testcases/kernel/syscalls/io_setup/.gitignore
+++ b/testcases/kernel/syscalls/io_setup/.gitignore
@@ -1 +1,2 @@
/io_setup01
+/io_setup02
diff --git a/testcases/kernel/syscalls/io_setup/io_setup02.c b/testcases/kernel/syscalls/io_setup/io_setup02.c
new file mode 100644
index 000000000..1d657e14a
--- /dev/null
+++ b/testcases/kernel/syscalls/io_setup/io_setup02.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_setup invoked via syscall(2):
+ * - io_setup fails and returns -EFAULT if ctxp is NULL;
+ * - io_setup fails and returns -EINVAL if ctxp is not initialized to 0;
+ * - io_setup fails and returns -EINVAL if nr_events is -1;
+ * - io_setup fails and returns -EAGAIN if nr_events exceeds the limit
+ * of available events;
+ * - io_setup succeeds if both nr_events and ctxp are valid.
+ */
+
+#include <linux/aio_abi.h>
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+static void verify_io_setup(void)
+{
+ aio_context_t ctx;
+ TST_EXP_FAIL(tst_syscall(__NR_io_setup, 1, NULL), EFAULT);
+
+ memset(&ctx, 1, sizeof(ctx));
+ TST_EXP_FAIL(tst_syscall(__NR_io_setup, 1, &ctx), EINVAL);
+ memset(&ctx, 0, sizeof(ctx));
+ TST_EXP_FAIL(tst_syscall(__NR_io_setup, -1, &ctx), EINVAL);
+
+ unsigned aio_max = 0;
+ if (!access("/proc/sys/fs/aio-max-nr", F_OK)) {
+ SAFE_FILE_SCANF("/proc/sys/fs/aio-max-nr", "%u", &aio_max);
+ TST_EXP_FAIL(tst_syscall(__NR_io_setup, aio_max + 1, &ctx), EAGAIN);
+ } else {
+ tst_res(TCONF, "the aio-max-nr file did not exist");
+ }
+
+ TST_EXP_PASS(tst_syscall(__NR_io_setup, 1, &ctx));
+ TST_EXP_PASS(tst_syscall(__NR_io_destroy, ctx));
+}
+
+static struct tst_test test = {
+ .test_all = verify_io_setup,
+};
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [LTP] [PATCH 3/3] syscalls/io_submit: Add io_submit02 test for native AIO
2021-05-07 8:33 [LTP] [PATCH 0/3] syscalls/aio: Add testcases for native AIO Xie Ziyao
2021-05-07 8:33 ` [LTP] [PATCH 1/3] syscalls/io_destroy: Add io_destroy02 test " Xie Ziyao
2021-05-07 8:33 ` [LTP] [PATCH 2/3] syscalls/io_setup: Add io_setup02 " Xie Ziyao
@ 2021-05-07 8:33 ` Xie Ziyao
2021-06-07 13:22 ` Cyril Hrubis
2 siblings, 1 reply; 7+ messages in thread
From: Xie Ziyao @ 2021-05-07 8:33 UTC (permalink / raw)
To: ltp
Test io_submit invoked via syscall(2):
- io_submit fails and returns EINVAL if ctx is invalid;
- io_submit fails and returns EINVAL if nr is invalid;
- io_submit fails and returns EFAULT if iocbpp pointer is invalid;
- io_submit fails and returns EBADF if fd is invalid;
- io_submit should work fine if no-op.
Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
runtest/syscalls | 1 +
.../kernel/syscalls/io_submit/.gitignore | 1 +
.../kernel/syscalls/io_submit/io_submit02.c | 119 ++++++++++++++++++
3 files changed, 121 insertions(+)
create mode 100644 testcases/kernel/syscalls/io_submit/io_submit02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index b8f195891..a1c0f2de2 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -616,6 +616,7 @@ io_pgetevents02 io_pgetevents02
io_setup01 io_setup01
io_setup02 io_setup02
io_submit01 io_submit01
+io_submit02 io_submit02
keyctl01 keyctl01
keyctl02 keyctl02
diff --git a/testcases/kernel/syscalls/io_submit/.gitignore b/testcases/kernel/syscalls/io_submit/.gitignore
index cac043b6c..5f2a2cff2 100644
--- a/testcases/kernel/syscalls/io_submit/.gitignore
+++ b/testcases/kernel/syscalls/io_submit/.gitignore
@@ -1 +1,2 @@
/io_submit01
+/io_submit02
diff --git a/testcases/kernel/syscalls/io_submit/io_submit02.c b/testcases/kernel/syscalls/io_submit/io_submit02.c
new file mode 100644
index 000000000..e695bcb5d
--- /dev/null
+++ b/testcases/kernel/syscalls/io_submit/io_submit02.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011-2017 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_submit invoked via syscall(2):
+ * - io_submit fails and returns EINVAL if ctx is invalid;
+ * - io_submit fails and returns EINVAL if nr is invalid;
+ * - io_submit fails and returns EFAULT if iocbpp pointer is invalid;
+ * - io_submit fails and returns EBADF if fd is invalid;
+ * - io_submit should work fine if no-op.
+ */
+
+#include <linux/aio_abi.h>
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+static aio_context_t ctx;
+static aio_context_t invalid_ctx;
+static char buf[100];
+
+static struct iocb iocb;
+static struct iocb *iocbs[] = {&iocb};
+
+static struct iocb inv_fd_iocb;
+static struct iocb *inv_fd_iocbs[] = {&inv_fd_iocb};
+
+static int rdonly_fd;
+static struct iocb rdonly_fd_iocb;
+static struct iocb *rdonly_fd_iocbs[] = {&rdonly_fd_iocb};
+
+static int wronly_fd;
+static struct iocb wronly_fd_iocb;
+static struct iocb *wronly_fd_iocbs[] = {&wronly_fd_iocb};
+
+static struct iocb zero_buf_iocb;
+static struct iocb *zero_buf_iocbs[] = {&zero_buf_iocb};
+
+static struct iocb *zero_iocbs[1];
+
+static struct tcase {
+ aio_context_t *ctx;
+ long nr;
+ struct iocb **iocbs;
+ int exp_errno;
+ const char *desc;
+} tc[] = {
+ /* Invalid ctx */
+ {&invalid_ctx, 1, iocbs, EINVAL, "invalid ctx"},
+ /* Invalid nr */
+ {&ctx, -1, iocbs, EINVAL, "invalid nr"},
+ /* Invalid pointer */
+ {&ctx, 1, (void*)-1, EFAULT, "invalid iocbpp pointer"},
+ {&ctx, 1, zero_iocbs, EFAULT, "NULL iocb pointers"},
+ /* Invalid fd */
+ {&ctx, 1, inv_fd_iocbs, EBADF, "invalid fd"},
+ {&ctx, 1, rdonly_fd_iocbs, EBADF, "readonly fd for write"},
+ {&ctx, 1, wronly_fd_iocbs, EBADF, "writeonly fd for read"},
+ /* No-op but should work fine */
+ {&ctx, 1, zero_buf_iocbs, 0, "zero buf size"},
+ {&ctx, 0, NULL, 0, "zero nr"},
+};
+
+static inline void io_prep_option(struct iocb *cb, int fd, void *buf,
+ size_t count, long long offset, unsigned opcode)
+{
+ memset(cb, 0, sizeof(*cb));
+ cb->aio_fildes = fd;
+ cb->aio_lio_opcode = opcode;
+ cb->aio_buf = (uint64_t)buf;
+ cb->aio_offset = offset;
+ cb->aio_nbytes = count;
+}
+
+static void setup(void)
+{
+ TST_EXP_PASS(tst_syscall(__NR_io_setup, 1, &ctx));
+ io_prep_option(&inv_fd_iocb, -1, buf, sizeof(buf), 0, IOCB_CMD_PREAD);
+
+ rdonly_fd = SAFE_OPEN("rdonly_file", O_RDONLY | O_CREAT, 0777);
+ io_prep_option(&rdonly_fd_iocb, rdonly_fd, buf, sizeof(buf), 0, IOCB_CMD_PWRITE);
+
+ io_prep_option(&zero_buf_iocb, rdonly_fd, buf, 0, 0, IOCB_CMD_PREAD);
+
+ wronly_fd = SAFE_OPEN("wronly_file", O_WRONLY | O_CREAT, 0777);
+ io_prep_option(&wronly_fd_iocb, wronly_fd, buf, sizeof(buf), 0, IOCB_CMD_PREAD);
+}
+
+static void cleanup(void)
+{
+ if (rdonly_fd > 0)
+ SAFE_CLOSE(rdonly_fd);
+ if (wronly_fd > 0)
+ SAFE_CLOSE(wronly_fd);
+}
+
+static void run(unsigned int i)
+{
+ TEST(tst_syscall(__NR_io_submit, *tc[i].ctx, tc[i].nr, tc[i].iocbs));
+ tst_res(TST_ERR == tc[i].exp_errno ? TPASS : TFAIL,
+ "io_submit(2) with %s returns %s, expected %s",
+ tc[i].desc, tst_strerrno(TST_ERR), tst_strerrno(tc[i].exp_errno));
+}
+
+static struct tst_test test = {
+ .setup = setup,
+ .cleanup = cleanup,
+ .test = run,
+ .tcnt = ARRAY_SIZE(tc),
+ .needs_tmpdir = 1,
+};
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [LTP] [PATCH 1/3] syscalls/io_destroy: Add io_destroy02 test for native AIO
2021-05-07 8:33 ` [LTP] [PATCH 1/3] syscalls/io_destroy: Add io_destroy02 test " Xie Ziyao
@ 2021-06-07 13:15 ` Cyril Hrubis
0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2021-06-07 13:15 UTC (permalink / raw)
To: ltp
Hi!
Test looks good but there is one minor problem that has to be solwed,
see below.
> +/*
> + * Copyright (c) Crackerjack Project., 2007
> + * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
> + * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
> + * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
> + * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * Test io_destroy invoked via syscall(2) with an invalid ctx and expects
> + * it to return EINVAL.
> + */
> +
> +#include <linux/aio_abi.h>
> +
> +#include "config.h"
> +#include "tst_test.h"
> +#include "lapi/syscalls.h"
> +
> +static void verify_io_destroy(void)
> +{
> + aio_context_t ctx;
> + memset(&ctx, 0xff, sizeof(ctx));
> + TST_EXP_FAIL(tst_syscall(__NR_io_destroy, ctx), EINVAL);
This may fail the test if CONFIG_AIO has been disabled in kernel, which
I think is common for embedded tests.
Thinking of solution the easiest fix would probably be to add
.needs_kconfigs with "CONFIG_AIO" to the tst_test structure.
> +}
> +
> +static struct tst_test test = {
> + .test_all = verify_io_destroy,
> +};
> --
> 2.17.1
>
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [PATCH 2/3] syscalls/io_setup: Add io_setup02 test for native AIO
2021-05-07 8:33 ` [LTP] [PATCH 2/3] syscalls/io_setup: Add io_setup02 " Xie Ziyao
@ 2021-06-07 13:18 ` Cyril Hrubis
0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2021-06-07 13:18 UTC (permalink / raw)
To: ltp
Hi!
Here as well, we need the needs_kconfig array.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 7+ messages in thread
* [LTP] [PATCH 3/3] syscalls/io_submit: Add io_submit02 test for native AIO
2021-05-07 8:33 ` [LTP] [PATCH 3/3] syscalls/io_submit: Add io_submit02 " Xie Ziyao
@ 2021-06-07 13:22 ` Cyril Hrubis
0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2021-06-07 13:22 UTC (permalink / raw)
To: ltp
Hi!
> + TEST(tst_syscall(__NR_io_submit, *tc[i].ctx, tc[i].nr, tc[i].iocbs));
> + tst_res(TST_ERR == tc[i].exp_errno ? TPASS : TFAIL,
> + "io_submit(2) with %s returns %s, expected %s",
> + tc[i].desc, tst_strerrno(TST_ERR), tst_strerrno(tc[i].exp_errno));
I do not like this tst_res() that much. Can we rather do:
if (tc[i].exp_errno)
TST_EXP_FAIL(...);
else
TST_EXP_PASS(...);
Another possibility would be splitting the test into two one for
negative and one for positive cases.
And we need the .needs_kconfig in this test as well.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-06-07 13:22 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 8:33 [LTP] [PATCH 0/3] syscalls/aio: Add testcases for native AIO Xie Ziyao
2021-05-07 8:33 ` [LTP] [PATCH 1/3] syscalls/io_destroy: Add io_destroy02 test " Xie Ziyao
2021-06-07 13:15 ` Cyril Hrubis
2021-05-07 8:33 ` [LTP] [PATCH 2/3] syscalls/io_setup: Add io_setup02 " Xie Ziyao
2021-06-07 13:18 ` Cyril Hrubis
2021-05-07 8:33 ` [LTP] [PATCH 3/3] syscalls/io_submit: Add io_submit02 " Xie Ziyao
2021-06-07 13:22 ` Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.