diff mbox series

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

Message ID 20210507083321.167998-3-xieziyao@huawei.com
State Changes Requested
Headers show
Series syscalls/aio: Add testcases for native AIO | expand

Commit Message

xieziyao May 7, 2021, 8:33 a.m. UTC
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

--
2.17.1

Comments

Cyril Hrubis June 7, 2021, 1:18 p.m. UTC | #1
Hi!
Here as well, we need the needs_kconfig array.
diff mbox series

Patch

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,
+};