Skip to contentSkip to conversation

syscall: Add io_uring related tests

PATCH Superseded Vikas Kumar 2 participants 2 messages May 26, 2020

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 syscall: Add io_uring related tests

Added asynchronous I/O API tests for io_uring_setup(), io_uring_register() and io_uring_enter(). These tests intend to validate io_uring operations.

1. io_uring_setup() creates submission queue and completion queue to perform subsequent operations on the io_uring instance.
2. io_uring_register() registers user buffers in kernel for long term usese.
3. io_uring_enter() initiates I/O operations using the shared SQ and CQ queue.

---
 include/lapi/io_uring.h                       |  42 ++++
 testcases/kernel/syscalls/io_uring/Makefile   |   7 +
 .../kernel/syscalls/io_uring/io_uring01.c     | 214 ++++++++++++++++++
 3 files changed, 263 insertions(+)
 create mode 100644 testcases/kernel/syscalls/io_uring/Makefile
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring01.c
include/lapi/io_uring.h +42 -0
index 5fde58e22..168cae14c 100644
@@ -280,4 +280,46 @@ int io_uring_enter(int fd, unsigned int to_submit, unsigned int min_complete,
 }
 #endif /* HAVE_IO_URING_ENTER */
 
+/*
+ * Check whether the ioring related system calls are supported on
+ * the current kernel. These system calls are enabled by default
+ * on kernel version 5.1.0 or higher. But they also might have
+ * been backported as well.
+ */
+void io_uring_setup_supported_by_kernel(void)
+{
+	if ((tst_kvercmp(5, 1, 0)) < 0) {
+		TEST(syscall(__NR_io_uring_setup, NULL, 0));
+		if (TST_RET != -1)
+			SAFE_CLOSE(TST_RET);
+		else if (TST_ERR == ENOSYS)
+			tst_brk(TCONF,
+				"Test not supported on kernel version < v5.1");
+	}
+}
+
+void io_uring_register_supported_by_kernel(void)
+{
+	if ((tst_kvercmp(5, 1, 0)) < 0) {
+		TEST(syscall(__NR_io_uring_register, NULL, 0));
+		if (TST_RET != -1)
+			SAFE_CLOSE(TST_RET);
+		else if (TST_ERR == ENOSYS)
+			tst_brk(TCONF,
+				"Test not supported on kernel version < v5.1");
+	}
+}
+
+void io_uring_enter_supported_by_kernel(void)
+{
+	if ((tst_kvercmp(5, 1, 0)) < 0) {
+		TEST(syscall(__NR_io_uring_enter, NULL, 0));
+		if (TST_RET != -1)
+			SAFE_CLOSE(TST_RET);
+		else if (TST_ERR == ENOSYS)
+			tst_brk(TCONF,
+				"Test not supported on kernel version < v5.1");
+	}
+}
+
 #endif /* IO_URING_H__ */
testcases/kernel/syscalls/io_uring/Makefile new file +7 -0
new file mode 100644
index 000000000..7c6797397
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2020 ARM, Ltd.  All rights reserved.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/io_uring/io_uring01.c new file +214 -0

214 lines not on this page · raw message

Signature · 1 line
2.17.1
#1 lore raw

PATCH v5 1/1 syscall: Add io_uring related tests

Hi Vikas,

not a complete review, just a few notes.

...

Quoted 6 lines

+/*
+ * Check whether the ioring related system calls are supported on
+ * the current kernel. These system calls are enabled by default
+ * on kernel version 5.1.0 or higher. But they also might have
+ * been backported as well.
+ */

IMHO the function name is obvious, so please shorten the comment :).

Quoted 25 lines
include/lapi/io_uring.h +25 -0
+void io_uring_setup_supported_by_kernel(void)
+{
+	if ((tst_kvercmp(5, 1, 0)) < 0) {
+		TEST(syscall(__NR_io_uring_setup, NULL, 0));
+		if (TST_RET != -1)
+			SAFE_CLOSE(TST_RET);
+		else if (TST_ERR == ENOSYS)
+			tst_brk(TCONF,
+				"Test not supported on kernel version < v5.1");
+	}
+}
+
+void io_uring_register_supported_by_kernel(void)
+{
+	if ((tst_kvercmp(5, 1, 0)) < 0) {
+		TEST(syscall(__NR_io_uring_register, NULL, 0));
+		if (TST_RET != -1)
+			SAFE_CLOSE(TST_RET);
+		else if (TST_ERR == ENOSYS)
+			tst_brk(TCONF,
+				"Test not supported on kernel version < v5.1");
+	}
+}
+
+void io_uring_enter_supported_by_kernel(void)

include/lapi/io_uring.h int io_uring_enter(int fd, unsigned int to_submit, unsigned int min_complete, · line 323

Quoted 10 lines
include/lapi/io_uring.h +10 -0
+{
+	if ((tst_kvercmp(5, 1, 0)) < 0) {
+		TEST(syscall(__NR_io_uring_enter, NULL, 0));
+		if (TST_RET != -1)
+			SAFE_CLOSE(TST_RET);
+		else if (TST_ERR == ENOSYS)
+			tst_brk(TCONF,
+				"Test not supported on kernel version < v5.1");
+	}
+}

IMHO It's unlikely that somebody would backport just some syscalls, not all 3. I'd be just for testing io_uring_setup().
Then no setup function is needed (use .setup = io_uring_setup_supported_by_kernel in struct tst_test).

And according to man pages only io_uring_setup() returns a file descriptor. The other two takes it as a parameter, so SAFE_CLOSE(TST_RET) is wrong.
https://www.mankier.com/2/io_uring_setup
https://www.mankier.com/2/io_uring_register
https://www.mankier.com/2/io_uring_enter

testcases/kernel/syscalls/io_uring/io_uring01.c line 195

Quoted 9 lines
testcases/kernel/syscalls/io_uring/io_uring01.c new file +9 -0
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int ret = 0;
+
+	s = SAFE_MALLOC(sizeof(*s));
+	if (!s)
+		return;

All SAFE_* macros (and safe_* functions which use them) are here to avoid these checks in the code. They exit executing via tst_brk(TCONF, "..."), therefore use just
s = SAFE_MALLOC(sizeof(*s));
(drop the check).

testcases/kernel/syscalls/io_uring/io_uring01.c line 206

Quoted 11 lines
testcases/kernel/syscalls/io_uring/io_uring01.c new file +11 -0
+
+	memset(s, 0, sizeof(*s));
+	ret = setup_io_uring_test(s, tc);
+	if (ret)
+		tst_res(TFAIL | TTERRNO, "io_uring_setup error");
+
+	ret = submit_to_uring_sq(s, tc);
+	if (ret)
+		tst_res(TFAIL | TTERRNO, "io_uring_submit error");
+	else
+		tst_res(TPASS, "functionality of io_uring API is correct");

nit: we prefer return in if instead of else:

if (submit_to_uring_sq(s, tc)) {
	tst_res(TFAIL | TTERRNO, "io_uring_submit error");
	return;
}

tst_res(TPASS, "functionality of io_uring API is correct");

Kind regards,
Petr