[LTP] [PATCH 2/3] syscalls/io_setup: Add io_setup02 test for native AIO

Xie Ziyao xieziyao@huawei.com
Fri May 7 10:33:20 CEST 2021


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



More information about the ltp mailing list