Skip to contentSkip to conversation

Add Syscall numbers for io_pgetevents

PATCH New Viresh Kumar 2 participants 9 messages Jan 24, 2020 – Jan 29, 2020

v2 of 3 New Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 Add Syscall numbers for io_pgetevents

---
V1->V2:
- No changes

 include/lapi/syscalls/aarch64.in   | 1 +
 include/lapi/syscalls/arm.in       | 1 +
 include/lapi/syscalls/hppa.in      | 1 +
 include/lapi/syscalls/i386.in      | 1 +
 include/lapi/syscalls/ia64.in      | 1 +
 include/lapi/syscalls/powerpc.in   | 1 +
 include/lapi/syscalls/powerpc64.in | 1 +
 include/lapi/syscalls/s390.in      | 1 +
 include/lapi/syscalls/s390x.in     | 1 +
 include/lapi/syscalls/sparc.in     | 1 +
 include/lapi/syscalls/sparc64.in   | 1 +
 include/lapi/syscalls/x86_64.in    | 1 +
 12 files changed, 12 insertions(+)
include/lapi/syscalls/aarch64.in +1 -0
index 19f3aa4475bd..25e1b27e9867 100644
@@ -269,6 +269,7 @@ pwritev2 287
 pkey_mprotect 288
 pkey_alloc 289
 pkey_free 290
+io_pgetevents 292
 pidfd_send_signal 424
 pidfd_open 434
 _sysctl 1078
include/lapi/syscalls/arm.in +1 -0
index 979a0183d4f5..c4e162662c3e 100644
@@ -354,5 +354,6 @@ pkey_mprotect (__NR_SYSCALL_BASE+394)
 pkey_alloc (__NR_SYSCALL_BASE+395)
 pkey_free (__NR_SYSCALL_BASE+396)
 statx (__NR_SYSCALL_BASE+397)
+io_pgetevents (__NR_SYSCALL_BASE+399)
 pidfd_send_signal (__NR_SYSCALL_BASE+424)
 pidfd_open (__NR_SYSCALL_BASE+434)
include/lapi/syscalls/hppa.in +1 -0
index b0807ca6b69f..71486f30d8ca 100644
@@ -26,5 +26,6 @@ mlock2 345
 copy_file_range 346
 preadv2 347
 pwritev2 348
+io_pgetevents 350
 pidfd_send_signal 424
 pidfd_open 434
include/lapi/syscalls/i386.in +1 -0
index f19e24bd63c9..ec47ca123a1f 100644
@@ -353,5 +353,6 @@ pkey_mprotect 380
 pkey_alloc 381
 pkey_free 382
 statx 383
+io_pgetevents 385
 pidfd_send_signal 424
 pidfd_open 434
include/lapi/syscalls/ia64.in +1 -0
index 92cc881d933b..e9ae3f0093bf 100644
@@ -306,6 +306,7 @@ mlock2 1346
 copy_file_range 1347
 preadv2 1348
 pwritev2 1349
+io_pgetevents 1351
 pkey_mprotect 1354
 pkey_alloc 1355
 pkey_free 1356
include/lapi/syscalls/powerpc.in +1 -0
index f83f7d233e61..3d27d2f2d0f6 100644
@@ -356,6 +356,7 @@ copy_file_range 379
 preadv2 380
 pwritev2 381
 statx 383
+io_pgetevents 388
 pidfd_send_signal 424
 pidfd_open 434
 pkey_mprotect 386
include/lapi/syscalls/powerpc64.in +1 -0
index f83f7d233e61..3d27d2f2d0f6 100644
@@ -356,6 +356,7 @@ copy_file_range 379
 preadv2 380
 pwritev2 381
 statx 383
+io_pgetevents 388
 pidfd_send_signal 424
 pidfd_open 434
 pkey_mprotect 386
include/lapi/syscalls/s390.in +1 -0
index f99aceb71a81..460a17884735 100644
@@ -340,6 +340,7 @@ mlock2 374
 copy_file_range 375
 preadv2 376
 pwritev2 377
+io_pgetevents 382
 pkey_mprotect 384
 pkey_alloc 385
 pkey_free 386
include/lapi/syscalls/s390x.in +1 -0
index 9666095b6bea..00236356df73 100644
@@ -338,6 +338,7 @@ mlock2 374
 copy_file_range 375
 preadv2 376
 pwritev2 377
+io_pgetevents 382
 pkey_mprotect 384
 pkey_alloc 385
 pkey_free 386
include/lapi/syscalls/sparc.in +1 -0
index 6c610ba67308..b56b1ae5c748 100644
@@ -345,6 +345,7 @@ mlock2 356
 copy_file_range 357
 preadv2 358
 pwritev2 359
+io_pgetevents 361
 pkey_mprotect 362
 pkey_alloc 363
 pkey_free 364
include/lapi/syscalls/sparc64.in +1 -0
index d20e87926913..8f04d730a5d5 100644
@@ -320,6 +320,7 @@ mlock2 356
 copy_file_range 357
 preadv2 358
 pwritev2 359
+io_pgetevents 361
 pkey_mprotect 362
 pkey_alloc 363
 pkey_free 364
include/lapi/syscalls/x86_64.in +1 -0
index cba0080dd27a..8656a84d9b93 100644
@@ -320,5 +320,6 @@ pkey_mprotect 329
 pkey_alloc 330
 pkey_free 331
 statx 332
+io_pgetevents 333
 pidfd_send_signal 424
 pidfd_open 434
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
#1 lore raw

PATCH v2 2/2 syscalls/io_pgetevents

Add tests to check working of io_pgetevents() syscall.

---
V1->V2:
- Do the failure testing with help of array and .tcnt.
- Use tst_syscall().
- Removed cleanup() routines.
- Improved print messages and few more minor changes.

 configure.ac                                  |   1 +
 include/lapi/io_pgetevents.h                  |  49 ++++++++
 runtest/syscalls                              |   4 +
 .../kernel/syscalls/io_pgetevents/.gitignore  |   2 +
 .../kernel/syscalls/io_pgetevents/Makefile    |   6 +
 .../syscalls/io_pgetevents/io_pgetevents01.c  |  69 +++++++++++
 .../syscalls/io_pgetevents/io_pgetevents02.c  | 111 ++++++++++++++++++
 7 files changed, 242 insertions(+)
 create mode 100644 include/lapi/io_pgetevents.h
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/.gitignore
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/Makefile
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
configure.ac +1 -0
index 1bf0911d88ad..c7cdff1c422c 100644
@@ -75,6 +75,7 @@ AC_CHECK_FUNCS([ \
     getdents \
     getdents64 \
     kcmp \
+    io_pgetevents \
     mkdirat \
     mknodat \
     name_to_handle_at \
include/lapi/io_pgetevents.h new file +49 -0

49 lines not on this page · raw message

runtest/syscalls +4 -0
index f083758bc637..33ec1e59e51d 100644
@@ -556,6 +556,10 @@ ioprio_set03 ioprio_set03
 io_cancel01 io_cancel01
 io_destroy01 io_destroy01
 io_getevents01 io_getevents01
+
+io_pgetevents01 io_pgetevents01
+io_pgetevents02 io_pgetevents02
+
 io_setup01 io_setup01
 io_submit01 io_submit01
 
testcases/kernel/syscalls/io_pgetevents/.gitignore new file +2 -0
new file mode 100644
index 000000000000..ae02077ba44b
@@ -0,0 +1,2 @@
+io_pgetevents01
+io_pgetevents02
testcases/kernel/syscalls/io_pgetevents/Makefile new file +6 -0
new file mode 100644
index 000000000000..5ea7d67db123
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c new file +69 -0

69 lines not on this page · raw message

testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +111 -0

111 lines not on this page · raw message

Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
#2 lore raw

PATCH v3 2/2 syscalls/io_pgetevents

Add tests to check working of io_pgetevents() syscall.

---
V2->V3:
- Dropped duplicate headers
- Handle failure tests with global variable
- All changes were inspired from the reviews of pidfd_open() patchset.

V1->V2:
- Do the failure testing with help of array and .tcnt.
- Use tst_syscall().
- Removed cleanup() routines.
- Improved print messages and few more minor changes.

 configure.ac                                  |   1 +
 include/lapi/io_pgetevents.h                  |  51 +++++++++
 runtest/syscalls                              |   4 +
 .../kernel/syscalls/io_pgetevents/.gitignore  |   2 +
 .../kernel/syscalls/io_pgetevents/Makefile    |   6 +
 .../syscalls/io_pgetevents/io_pgetevents01.c  |  61 +++++++++++
 .../syscalls/io_pgetevents/io_pgetevents02.c  | 103 ++++++++++++++++++
 7 files changed, 228 insertions(+)
 create mode 100644 include/lapi/io_pgetevents.h
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/.gitignore
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/Makefile
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
configure.ac +1 -0
index 1bf0911d88ad..c7cdff1c422c 100644
@@ -75,6 +75,7 @@ AC_CHECK_FUNCS([ \
     getdents \
     getdents64 \
     kcmp \
+    io_pgetevents \
     mkdirat \
     mknodat \
     name_to_handle_at \
include/lapi/io_pgetevents.h new file +51 -0

51 lines not on this page · raw message

runtest/syscalls +4 -0
index a28a1f2ecd45..0743cf4e3f74 100644
@@ -556,6 +556,10 @@ ioprio_set03 ioprio_set03
 io_cancel01 io_cancel01
 io_destroy01 io_destroy01
 io_getevents01 io_getevents01
+
+io_pgetevents01 io_pgetevents01
+io_pgetevents02 io_pgetevents02
+
 io_setup01 io_setup01
 io_submit01 io_submit01
 
testcases/kernel/syscalls/io_pgetevents/.gitignore new file +2 -0
new file mode 100644
index 000000000000..ae02077ba44b
@@ -0,0 +1,2 @@
+io_pgetevents01
+io_pgetevents02
testcases/kernel/syscalls/io_pgetevents/Makefile new file +6 -0
new file mode 100644
index 000000000000..5ea7d67db123
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c new file +61 -0

61 lines not on this page · raw message

testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
#3 lore raw

PATCH v3 2/2 syscalls/io_pgetevents

Hi!

Quoted 76 lines

Add tests to check working of io_pgetevents() syscall.

---
V2->V3:
- Dropped duplicate headers
- Handle failure tests with global variable
- All changes were inspired from the reviews of pidfd_open() patchset.

V1->V2:
- Do the failure testing with help of array and .tcnt.
- Use tst_syscall().
- Removed cleanup() routines.
- Improved print messages and few more minor changes.

 configure.ac                                  |   1 +
 include/lapi/io_pgetevents.h                  |  51 +++++++++
 runtest/syscalls                              |   4 +
 .../kernel/syscalls/io_pgetevents/.gitignore  |   2 +
 .../kernel/syscalls/io_pgetevents/Makefile    |   6 +
 .../syscalls/io_pgetevents/io_pgetevents01.c  |  61 +++++++++++
 .../syscalls/io_pgetevents/io_pgetevents02.c  | 103 ++++++++++++++++++
 7 files changed, 228 insertions(+)
 create mode 100644 include/lapi/io_pgetevents.h
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/.gitignore
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/Makefile
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
configure.ac +1 -0
index 1bf0911d88ad..c7cdff1c422c 100644
@@ -75,6 +75,7 @@ AC_CHECK_FUNCS([ \
     getdents \
     getdents64 \
     kcmp \
+    io_pgetevents \
     mkdirat \
     mknodat \
     name_to_handle_at \
include/lapi/io_pgetevents.h new file +29 -0
new file mode 100644
index 000000000000..6ee38c44d419
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <[email protected]>
+ */
+
+#ifndef IO_PGETEVENTS_H
+#define IO_PGETEVENTS_H
+
+#include <sys/syscall.h>
+#include <sys/types.h>
+
+#include "config.h"
+#include "lapi/syscalls.h"
+#include "tst_test.h"
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
+#ifndef HAVE_IO_SETUP
+int io_setup(int nr, io_context_t *ctxp)
+{
+	return tst_syscall(__NR_io_setup, nr, ctxp);
+}
+#endif /* HAVE_IO_SETUP */
+
+#ifndef HAVE_IO_DESTROY
+int io_destroy(io_context_t ctx)
+{

include/lapi/io_pgetevents.h line 39

Quoted 10 lines
include/lapi/io_pgetevents.h new file +10 -0
+	return tst_syscall(__NR_io_destroy, ctx);
+}
+#endif /* HAVE_IO_DESTROY */
+
+#ifndef HAVE_IO_SUBMIT
+int io_submit(io_context_t ctx, long nr, struct iocb **iocbpp)
+{
+	return tst_syscall(__NR_io_submit, ctx, nr, iocbpp);
+}
+#endif /* HAVE_IO_SUBMIT */

I'm not sure this is correct, the libaio.h does define these wrappers and the rest of LTP seems to use these syscalls only guarded by HAVE_LIBAIO, so I guess these cannot be missing if libaio.h is present.

Furthermore there are no checks for io_setup, io_destroy and io_submit calls in the configure.ac so presumbly this macros are never used anyway.

include/lapi/io_pgetevents.h line 48

Quoted 8 lines
include/lapi/io_pgetevents.h new file +8 -0
+#ifndef HAVE_IO_PGETEVENTS
+int io_pgetevents(io_context_t ctx, long min_nr, long max_nr,
+		 struct io_event *events, struct timespec *timeout,
+		 sigset_t *sigmask)
+{
+	return syscall(__NR_io_pgetevents, ctx, min_nr, max_nr, events, timeout, sigmask);
+}
+#endif /* HAVE_IO_PGETEVENTS */

This is the only function that seems to be missing from the libaio.h header, so I guess that all we have to do here is to define it if it's not defined.

Quoted 163 lines
include/lapi/io_pgetevents.h new file +3 -0
+#endif /* HAVE_LIBAIO */
+
+#endif /* IO_PGETEVENTS_H */
runtest/syscalls +4 -0
index a28a1f2ecd45..0743cf4e3f74 100644
@@ -556,6 +556,10 @@ ioprio_set03 ioprio_set03
 io_cancel01 io_cancel01
 io_destroy01 io_destroy01
 io_getevents01 io_getevents01
+
+io_pgetevents01 io_pgetevents01
+io_pgetevents02 io_pgetevents02
+
 io_setup01 io_setup01
 io_submit01 io_submit01
 
testcases/kernel/syscalls/io_pgetevents/.gitignore new file +2 -0
new file mode 100644
index 000000000000..ae02077ba44b
@@ -0,0 +1,2 @@
+io_pgetevents01
+io_pgetevents02
testcases/kernel/syscalls/io_pgetevents/Makefile new file +6 -0
new file mode 100644
index 000000000000..5ea7d67db123
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c new file +61 -0
new file mode 100644
index 000000000000..d685adb48759
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <[email protected]>
+ *
+ * Description:
+ * Basic io_pgetevents() test to receive 1 event successfully.
+ */
+#include "lapi/io_pgetevents.h"
+
+#ifdef HAVE_LIBAIO
+static void run(void)
+{
+	struct io_event events[1];
+	struct iocb cb, *cbs[1];
+	io_context_t ctx = 0;
+	sigset_t sigmask;
+	char data[4096];
+	int ret, fd;
+
+	cbs[0] = &cb;
+	sigemptyset(&sigmask);
+
+	fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT);
+	io_prep_pwrite(&cb, fd, data, 4096, 0);
+
+	ret = io_setup(1, &ctx);
+	if (ret < 0) {
+		tst_res(TBROK | TERRNO, "io_setup() failed");
+		goto exit;
+	}
+
+	ret = io_submit(ctx, 1, cbs);
+	if (ret != 1) {
+		tst_res(TBROK | TERRNO, "io_submit() failed");
+		goto exit;
+	}
+
+	/* get the reply */
+	ret = io_pgetevents(ctx, 1, 1, events, NULL, &sigmask);
+
+	if (ret == 1)
+		tst_res(TPASS, "io_pgetevents() works as expected");
+	else
+		tst_res(TFAIL | TERRNO, "io_pgetevents() failed");
+
+	if (io_destroy(ctx) < 0)
+		tst_res(TBROK | TERRNO, "io_destroy() failed");
+
+exit:
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.min_kver = "4.18",
+	.test_all = run,
+	.needs_tmpdir = 1,
+};
+
+#else
+TST_TEST_TCONF("test requires libaio and it's development packages");
+#endif
testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +52 -0
new file mode 100644
index 000000000000..c612c3f0a2b2
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <[email protected]>
+ *
+ * Description:
+ * Basic io_pgetevents() test to check various failures.
+ */
+#include "lapi/io_pgetevents.h"
+
+#ifdef HAVE_LIBAIO
+static sigset_t sigmask;
+static struct io_event events[1];
+static io_context_t ctx, invalid_ctx = 0;
+static int fd;
+
+static struct tcase {
+	char *name;
+	io_context_t *ctx;
+	long min_nr;
+	long max_nr;
+	struct io_event *events;
+	struct timespec *timeout;
+	sigset_t *sigmask;
+	int exp_errno;
+} tcases[] = {
+	{"invalid ctx", &invalid_ctx, 1, 1, events, NULL, &sigmask, EINVAL},
+	{"invalid min_nr", &ctx, -1, 1, events, NULL, &sigmask, EINVAL},
+	{"invalid max_nr", &ctx, 1, -1, events, NULL, &sigmask, EINVAL},
+	{"invalid events", &ctx, 1, 1, NULL, NULL, &sigmask, EFAULT},
+	{"invalid timeout", &ctx, 1, 1, events, (void *)(0xDEAD), &sigmask, EFAULT},
+	{"invalid sigmask", &ctx, 1, 1, events, NULL, (void *)(0xDEAD), EFAULT},
+};
+
+static void setup(void)
+{
+	struct iocb cb, *cbs[1];
+	char data[4096];
+	int ret;
+
+	cbs[0] = &cb;
+
+	sigemptyset(&sigmask);
+
+	fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT);
+	io_prep_pwrite(&cb, fd, data, 4096, 0);
+
+	ret = io_setup(1, &ctx);
+	if (ret < 0) {
+		tst_res(TBROK | TERRNO, "io_setup() failed");
+		goto exit;
+	}
+

testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c line 62

Quoted 10 lines
testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +10 -0
+	ret = io_submit(ctx, 1, cbs);
+	if (ret != 1) {
+		tst_res(TBROK | TERRNO, "io_submit() failed");
+		goto exit;
+	}
+
+	return;
+
+exit:
+	SAFE_CLOSE(fd);

We do close the fd in test cleanup() so this should be removed.

Also we will attempt to continue the test here even when the io_setup() or io_submit() have failed.

What we should do here instead is to call tst_brk() in the checks for io_setup() and io_submit() failures. The fd will be closed in the cleanup that way.

testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c line 70

Quoted 8 lines
testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +8 -0
+}
+
+static void cleanup(void)
+{
+	if (io_destroy(ctx) < 0)
+		tst_res(TBROK | TERRNO, "io_destroy() failed");
+
+	SAFE_CLOSE(fd);

The cleanup could be called when any of the SAFE_ calls fails, which especially means that if SAFE_OPEN() fails we will attempt to destroy uninitialized context and close fd -1.

What we do in cleanups to cope with this is to check if the fd is valid fist, i.e.

	if (fd > 0)
		SAFE_CLOSE(fd);

For the io_destroy(ctx) it's probably easiest to create a global flag ctx_initalized and set it to 1 right after the io_setup(). Then we can do:

	if (ctx_initialized) {
		if (io_destroy(ctx) < 0)
			...
	}
Quoted 9 lines
testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +9 -0
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(io_pgetevents(*tc->ctx, tc->min_nr, tc->max_nr, tc->events,
+			   tc->timeout, tc->sigmask));
+

testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c line 89

Quoted 10 lines
testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +10 -0
+	if (TST_RET == 1) {
+		tst_res(TFAIL, "%s: io_pgetevents() passed unexpectedly",
+			tc->name);
+	} else if (tc->exp_errno != TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "%s: io_pgetevents() should fail with %s",
+			tc->name, tst_strerrno(tc->exp_errno));
+	} else {
+		tst_res(TPASS | TTERRNO, "%s: io_pgetevents() failed as expected",
+			tc->name);
+	}

We usually use return to avoid if-else mazes like this one, i.e.

	if (TST_RET == 1) {
		tst_res(TFAIL, ...);
		return;
	}

	if (tc->exp_errno != TST_ERR) {
		tst_res(TFAIL ...);
		return;
	}

	tst_res(TPASS, ...);

I find this a bit more readable.

Quoted 4 lines
testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +4 -0
+}
+
+static struct tst_test test = {
+	.min_kver = "4.18",

testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c line 103

Quoted 10 lines
testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +10 -0
+	.needs_tmpdir = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};
+
+#else
+TST_TEST_TCONF("test requires libaio and it's development packages");
+#endif

Other than the minor issues the rest looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
#4 lore raw

PATCH v4 2/2 syscalls/io_pgetevents: New tests

In reply to Viresh Kumar

Add tests to check working of io_pgetevents() syscall.

---
V3->V4:
- Dropped few helpers from io_pgetevents.h as loading the AIO_LIBS from Makefile made the warnings go away.
- Better handling of the failure in setup() path.
- Use "return" to avoid using if/else maze.

V2->V3:
- Dropped duplicate headers
- Handle failure tests with global variable
- All changes were inspired from the reviews of pidfd_open() patchset.

V1->V2:
- Do the failure testing with help of array and .tcnt.
- Use tst_syscall().
- Removed cleanup() routines.
- Improved print messages and few more minor changes.

 configure.ac                                  |   1 +
 include/lapi/io_pgetevents.h                  |  30 +++++
 runtest/syscalls                              |   4 +
 .../kernel/syscalls/io_pgetevents/.gitignore  |   2 +
 .../kernel/syscalls/io_pgetevents/Makefile    |   9 ++
 .../syscalls/io_pgetevents/io_pgetevents01.c  |  61 +++++++++++
 .../syscalls/io_pgetevents/io_pgetevents02.c  | 103 ++++++++++++++++++
 7 files changed, 210 insertions(+)
 create mode 100644 include/lapi/io_pgetevents.h
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/.gitignore
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/Makefile
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
 create mode 100644 testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
configure.ac +1 -0
index 1bf0911d88ad..c7cdff1c422c 100644
@@ -75,6 +75,7 @@ AC_CHECK_FUNCS([ \
     getdents \
     getdents64 \
     kcmp \
+    io_pgetevents \
     mkdirat \
     mknodat \
     name_to_handle_at \
include/lapi/io_pgetevents.h new file +30 -0
new file mode 100644
index 000000000000..5cdaffb6b15d
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <[email protected]>
+ */
+
+#ifndef IO_PGETEVENTS_H
+#define IO_PGETEVENTS_H
+
+#include <sys/syscall.h>
+#include <sys/types.h>
+
+#include "config.h"
+#include "lapi/syscalls.h"
+#include "tst_test.h"
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
+#ifndef HAVE_IO_PGETEVENTS
+int io_pgetevents(io_context_t ctx, long min_nr, long max_nr,
+		 struct io_event *events, struct timespec *timeout,
+		 sigset_t *sigmask)
+{
+	return syscall(__NR_io_pgetevents, ctx, min_nr, max_nr, events, timeout, sigmask);
+}
+#endif /* HAVE_IO_PGETEVENTS */
+#endif /* HAVE_LIBAIO */
+
+#endif /* IO_PGETEVENTS_H */
runtest/syscalls +4 -0
index a28a1f2ecd45..0743cf4e3f74 100644
@@ -556,6 +556,10 @@ ioprio_set03 ioprio_set03
 io_cancel01 io_cancel01
 io_destroy01 io_destroy01
 io_getevents01 io_getevents01
+
+io_pgetevents01 io_pgetevents01
+io_pgetevents02 io_pgetevents02
+
 io_setup01 io_setup01
 io_submit01 io_submit01
 
testcases/kernel/syscalls/io_pgetevents/.gitignore new file +2 -0
new file mode 100644
index 000000000000..ae02077ba44b
@@ -0,0 +1,2 @@
+io_pgetevents01
+io_pgetevents02
testcases/kernel/syscalls/io_pgetevents/Makefile new file +9 -0
new file mode 100644
index 000000000000..c26cffd37f39
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+LDLIBS			+= $(AIO_LIBS)
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c new file +61 -0

61 lines not on this page · raw message

testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
#5 lore raw

PATCH v4 2/2 syscalls/io_pgetevents: New tests

Hi!
Pushed with one minor adjustement, thanks.

I've removed the tst_test.h include from the lapi header and put it into the two test sources. Since that is the main header the tests should include it's better when they include it explicitely.

Signature · 2 lines
Cyril Hrubis
[email protected]
#6 lore raw

PATCH v4 2/2 syscalls/io_pgetevents: New tests

Quoted 6 lines · Cyril Hrubis

Hi!
Pushed with one minor adjustement, thanks.

I've removed the tst_test.h include from the lapi header and put it into the two test sources. Since that is the main header the tests should include it's better when they include it explicitely.

That was a very intentional change I kept because the header should also take care of its dependencies. An earlier version was using few tst_syscall() calls in lapi header and so it should have directly included tst_test.h file, which I did.

But the same got removed in the latest version and so the same isn't required. Though changing the order of lapi header and tst_test.h in the io_pgetevents0*.c files still generate compilation errors as definition of syscall() isn't found as well and the header should now explicitly include <unistd.h>.

I have a question now :)

In the pidfd_open() lapi header I used tst_syscall() and in io_pgetevents() lapi header I used syscall(). Should I use tst_syscall() in both of them ? If yes, then I will include tst_test.h as well in both of them and send you a patch.

Signature · 1 line
viresh
#7 lore raw

PATCH v4 2/2 syscalls/io_pgetevents: New tests

Hi!

Quoted 10 lines
Quoted 5 lines

Pushed with one minor adjustement, thanks.

I've removed the tst_test.h include from the lapi header and put it into the two test sources. Since that is the main header the tests should include it's better when they include it explicitely.

That was a very intentional change I kept because the header should also take care of its dependencies. An earlier version was using few tst_syscall() calls in lapi header and so it should have directly included tst_test.h file, which I did.

The tst_syscall() is defined in lapi/syscalls.h and I doubt that this header is incldued from tst_test.h and even if it is we should include the lapi/syscall.h instead.

Quoted 6 lines

But the same got removed in the latest version and so the same isn't required. Though changing the order of lapi header and tst_test.h in the io_pgetevents0*.c files still generate compilation errors as definition of syscall() isn't found as well and the header should now explicitly include <unistd.h>.

Quoted 6 lines

I have a question now :)

In the pidfd_open() lapi header I used tst_syscall() and in io_pgetevents() lapi header I used syscall(). Should I use tst_syscall() in both of them ? If yes, then I will include tst_test.h as well in both of them and send you a patch.

The difference between plain syscall() and tst_syscall() is twofold, it takes care of undefined __NR_foo as well as of ENOSYS return from kernel, so generally tst_syscall() should be used instead.

Signature · 2 lines
Cyril Hrubis
[email protected]