public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH V2 1/2] Add Syscall numbers for io_pgetevents
@ 2020-01-24  9:53 Viresh Kumar
  2020-01-24  9:53 ` [LTP] [PATCH V2 2/2] syscalls/io_pgetevents Viresh Kumar
  2020-01-28 13:42 ` [LTP] [PATCH V2 1/2] Add Syscall numbers for io_pgetevents Cyril Hrubis
  0 siblings, 2 replies; 9+ messages in thread
From: Viresh Kumar @ 2020-01-24  9:53 UTC (permalink / raw)
  To: ltp

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
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(+)

diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in
index 19f3aa4475bd..25e1b27e9867 100644
--- a/include/lapi/syscalls/aarch64.in
+++ b/include/lapi/syscalls/aarch64.in
@@ -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
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 979a0183d4f5..c4e162662c3e 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -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)
diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in
index b0807ca6b69f..71486f30d8ca 100644
--- a/include/lapi/syscalls/hppa.in
+++ b/include/lapi/syscalls/hppa.in
@@ -26,5 +26,6 @@ mlock2 345
 copy_file_range 346
 preadv2 347
 pwritev2 348
+io_pgetevents 350
 pidfd_send_signal 424
 pidfd_open 434
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index f19e24bd63c9..ec47ca123a1f 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -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
diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in
index 92cc881d933b..e9ae3f0093bf 100644
--- a/include/lapi/syscalls/ia64.in
+++ b/include/lapi/syscalls/ia64.in
@@ -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
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index f83f7d233e61..3d27d2f2d0f6 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -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
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index f83f7d233e61..3d27d2f2d0f6 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -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
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index f99aceb71a81..460a17884735 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -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
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index 9666095b6bea..00236356df73 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -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
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index 6c610ba67308..b56b1ae5c748 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -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
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index d20e87926913..8f04d730a5d5 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -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
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index cba0080dd27a..8656a84d9b93 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -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
-- 
2.21.0.rc0.269.g1a574e7a288b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH V2 2/2] syscalls/io_pgetevents
  2020-01-24  9:53 [LTP] [PATCH V2 1/2] Add Syscall numbers for io_pgetevents Viresh Kumar
@ 2020-01-24  9:53 ` Viresh Kumar
  2020-01-27 10:50   ` [LTP] [PATCH V3 " Viresh Kumar
  2020-01-28  3:01   ` [LTP] [PATCH V4 2/2] syscalls/io_pgetevents: New tests Viresh Kumar
  2020-01-28 13:42 ` [LTP] [PATCH V2 1/2] Add Syscall numbers for io_pgetevents Cyril Hrubis
  1 sibling, 2 replies; 9+ messages in thread
From: Viresh Kumar @ 2020-01-24  9:53 UTC (permalink / raw)
  To: ltp

Add tests to check working of io_pgetevents() syscall.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
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

diff --git a/configure.ac b/configure.ac
index 1bf0911d88ad..c7cdff1c422c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,7 @@ AC_CHECK_FUNCS([ \
     getdents \
     getdents64 \
     kcmp \
+    io_pgetevents \
     mkdirat \
     mknodat \
     name_to_handle_at \
diff --git a/include/lapi/io_pgetevents.h b/include/lapi/io_pgetevents.h
new file mode 100644
index 000000000000..c498db83e7d0
--- /dev/null
+++ b/include/lapi/io_pgetevents.h
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef IO_PGETEVENTS_H
+#define IO_PGETEVENTS_H
+
+#include <sys/types.h>
+
+#include "config.h"
+#include "lapi/syscalls.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)
+{
+	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 */
+
+#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 */
diff --git a/runtest/syscalls b/runtest/syscalls
index f083758bc637..33ec1e59e51d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -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
 
diff --git a/testcases/kernel/syscalls/io_pgetevents/.gitignore b/testcases/kernel/syscalls/io_pgetevents/.gitignore
new file mode 100644
index 000000000000..ae02077ba44b
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/.gitignore
@@ -0,0 +1,2 @@
+io_pgetevents01
+io_pgetevents02
diff --git a/testcases/kernel/syscalls/io_pgetevents/Makefile b/testcases/kernel/syscalls/io_pgetevents/Makefile
new file mode 100644
index 000000000000..5ea7d67db123
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
new file mode 100644
index 000000000000..9b34f973c424
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Description:
+ * Basic io_pgetevents() test to receive 1 event successfully.
+ */
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <fcntl.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "tst_test.h"
+#include "lapi/io_pgetevents.h"
+#include "lapi/syscalls.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() worked 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
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
new file mode 100644
index 000000000000..35722c4b21d6
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Description:
+ * Basic io_pgetevents() test to check various failures.
+ */
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <fcntl.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "tst_test.h"
+#include "lapi/io_pgetevents.h"
+#include "lapi/syscalls.h"
+
+#ifdef HAVE_LIBAIO
+static struct tcase {
+	char *name;
+	int invalid_ctx;
+	long min_nr;
+	long max_nr;
+	int invalid_events;
+	int invalid_timeout;
+	int invalid_sigmask;
+	int exp_errno;
+} tcases[] = {
+	{"test-invalid-ctx", 1, 1, 1, 0, 0, 0, EINVAL},
+	{"test-invalid-min_nr", 0, -1, 1, 0, 0, 0, EINVAL},
+	{"test-invalid-max_nr", 0, 1, -1, 0, 0, 0, EINVAL},
+	{"test-invalid-events", 0, 1, 1, 1, 0, 0, EFAULT},
+	{"test-invalid-timeout", 0, 1, 1, 0, 1, 0, EFAULT},
+	{"test-invalid-sigmask", 0, 1, 1, 0, 0, 1, EFAULT},
+};
+
+static void run(unsigned int n)
+{
+	struct io_event events[1], *events_ptr = NULL;
+	sigset_t sigmask, *psigmask = (void *)(0xDEAD);
+	struct timespec *timeout = (void *)(0xDEAD);
+	struct tcase *tc = &tcases[n];
+	struct iocb cb, *cbs[1];
+	io_context_t ctx = 0;
+	char data[4096];
+	int ret, fd;
+
+	cbs[0] = &cb;
+
+	if (!tc->invalid_timeout)
+		timeout = NULL;
+
+	if (!tc->invalid_sigmask) {
+		psigmask = &sigmask;
+		sigemptyset(psigmask);
+	}
+
+	if (!tc->invalid_events)
+		events_ptr = events;
+
+	fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT);
+	io_prep_pwrite(&cb, fd, data, 4096, 0);
+
+	if (!tc->invalid_ctx) {
+		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;
+		}
+	}
+
+	/* Invalid Max event count */
+	TEST(io_pgetevents(ctx, tc->min_nr, tc->max_nr, events_ptr, timeout,
+			   psigmask));
+
+	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);
+	}
+
+	if (!tc->invalid_ctx) {
+		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",
+	.needs_tmpdir = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+};
+
+#else
+TST_TEST_TCONF("test requires libaio and it's development packages");
+#endif
-- 
2.21.0.rc0.269.g1a574e7a288b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH V3 2/2] syscalls/io_pgetevents
  2020-01-24  9:53 ` [LTP] [PATCH V2 2/2] syscalls/io_pgetevents Viresh Kumar
@ 2020-01-27 10:50   ` Viresh Kumar
  2020-01-27 14:32     ` Cyril Hrubis
  2020-01-28  3:01   ` [LTP] [PATCH V4 2/2] syscalls/io_pgetevents: New tests Viresh Kumar
  1 sibling, 1 reply; 9+ messages in thread
From: Viresh Kumar @ 2020-01-27 10:50 UTC (permalink / raw)
  To: ltp

Add tests to check working of io_pgetevents() syscall.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
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

diff --git a/configure.ac b/configure.ac
index 1bf0911d88ad..c7cdff1c422c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,7 @@ AC_CHECK_FUNCS([ \
     getdents \
     getdents64 \
     kcmp \
+    io_pgetevents \
     mkdirat \
     mknodat \
     name_to_handle_at \
diff --git a/include/lapi/io_pgetevents.h b/include/lapi/io_pgetevents.h
new file mode 100644
index 000000000000..6ee38c44d419
--- /dev/null
+++ b/include/lapi/io_pgetevents.h
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#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)
+{
+	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 */
+
+#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 */
diff --git a/runtest/syscalls b/runtest/syscalls
index a28a1f2ecd45..0743cf4e3f74 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -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
 
diff --git a/testcases/kernel/syscalls/io_pgetevents/.gitignore b/testcases/kernel/syscalls/io_pgetevents/.gitignore
new file mode 100644
index 000000000000..ae02077ba44b
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/.gitignore
@@ -0,0 +1,2 @@
+io_pgetevents01
+io_pgetevents02
diff --git a/testcases/kernel/syscalls/io_pgetevents/Makefile b/testcases/kernel/syscalls/io_pgetevents/Makefile
new file mode 100644
index 000000000000..5ea7d67db123
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
new file mode 100644
index 000000000000..d685adb48759
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * 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
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
new file mode 100644
index 000000000000..c612c3f0a2b2
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * 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;
+	}
+
+	ret = io_submit(ctx, 1, cbs);
+	if (ret != 1) {
+		tst_res(TBROK | TERRNO, "io_submit() failed");
+		goto exit;
+	}
+
+	return;
+
+exit:
+	SAFE_CLOSE(fd);
+}
+
+static void cleanup(void)
+{
+	if (io_destroy(ctx) < 0)
+		tst_res(TBROK | TERRNO, "io_destroy() failed");
+
+	SAFE_CLOSE(fd);
+}
+
+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));
+
+	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);
+	}
+}
+
+static struct tst_test test = {
+	.min_kver = "4.18",
+	.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
-- 
2.21.0.rc0.269.g1a574e7a288b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH V3 2/2] syscalls/io_pgetevents
  2020-01-27 10:50   ` [LTP] [PATCH V3 " Viresh Kumar
@ 2020-01-27 14:32     ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2020-01-27 14:32 UTC (permalink / raw)
  To: ltp

Hi!
> Add tests to check working of io_pgetevents() syscall.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
> 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
> 
> diff --git a/configure.ac b/configure.ac
> index 1bf0911d88ad..c7cdff1c422c 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -75,6 +75,7 @@ AC_CHECK_FUNCS([ \
>      getdents \
>      getdents64 \
>      kcmp \
> +    io_pgetevents \
>      mkdirat \
>      mknodat \
>      name_to_handle_at \
> diff --git a/include/lapi/io_pgetevents.h b/include/lapi/io_pgetevents.h
> new file mode 100644
> index 000000000000..6ee38c44d419
> --- /dev/null
> +++ b/include/lapi/io_pgetevents.h
> @@ -0,0 +1,51 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Linaro Limited. All rights reserved.
> + * Author: Viresh Kumar <viresh.kumar@linaro.org>
> + */
> +
> +#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)
> +{
> +	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.

> +#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.

> +#endif /* HAVE_LIBAIO */
> +
> +#endif /* IO_PGETEVENTS_H */
> diff --git a/runtest/syscalls b/runtest/syscalls
> index a28a1f2ecd45..0743cf4e3f74 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -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
>  
> diff --git a/testcases/kernel/syscalls/io_pgetevents/.gitignore b/testcases/kernel/syscalls/io_pgetevents/.gitignore
> new file mode 100644
> index 000000000000..ae02077ba44b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/io_pgetevents/.gitignore
> @@ -0,0 +1,2 @@
> +io_pgetevents01
> +io_pgetevents02
> diff --git a/testcases/kernel/syscalls/io_pgetevents/Makefile b/testcases/kernel/syscalls/io_pgetevents/Makefile
> new file mode 100644
> index 000000000000..5ea7d67db123
> --- /dev/null
> +++ b/testcases/kernel/syscalls/io_pgetevents/Makefile
> @@ -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
> diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
> new file mode 100644
> index 000000000000..d685adb48759
> --- /dev/null
> +++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
> @@ -0,0 +1,61 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
> + *
> + * 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
> diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
> new file mode 100644
> index 000000000000..c612c3f0a2b2
> --- /dev/null
> +++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
> @@ -0,0 +1,103 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
> + *
> + * 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;
> +	}
> +
> +	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.

> +}
> +
> +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)
			...
	}

> +}
> +
> +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));
> +
> +	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.

> +}
> +
> +static struct tst_test test = {
> +	.min_kver = "4.18",
> +	.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.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH V4 2/2] syscalls/io_pgetevents: New tests
  2020-01-24  9:53 ` [LTP] [PATCH V2 2/2] syscalls/io_pgetevents Viresh Kumar
  2020-01-27 10:50   ` [LTP] [PATCH V3 " Viresh Kumar
@ 2020-01-28  3:01   ` Viresh Kumar
  2020-01-28 13:40     ` Cyril Hrubis
  1 sibling, 1 reply; 9+ messages in thread
From: Viresh Kumar @ 2020-01-28  3:01 UTC (permalink / raw)
  To: ltp

Add tests to check working of io_pgetevents() syscall.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
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

diff --git a/configure.ac b/configure.ac
index 1bf0911d88ad..c7cdff1c422c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,7 @@ AC_CHECK_FUNCS([ \
     getdents \
     getdents64 \
     kcmp \
+    io_pgetevents \
     mkdirat \
     mknodat \
     name_to_handle_at \
diff --git a/include/lapi/io_pgetevents.h b/include/lapi/io_pgetevents.h
new file mode 100644
index 000000000000..5cdaffb6b15d
--- /dev/null
+++ b/include/lapi/io_pgetevents.h
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#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 */
diff --git a/runtest/syscalls b/runtest/syscalls
index a28a1f2ecd45..0743cf4e3f74 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -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
 
diff --git a/testcases/kernel/syscalls/io_pgetevents/.gitignore b/testcases/kernel/syscalls/io_pgetevents/.gitignore
new file mode 100644
index 000000000000..ae02077ba44b
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/.gitignore
@@ -0,0 +1,2 @@
+io_pgetevents01
+io_pgetevents02
diff --git a/testcases/kernel/syscalls/io_pgetevents/Makefile b/testcases/kernel/syscalls/io_pgetevents/Makefile
new file mode 100644
index 000000000000..c26cffd37f39
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
new file mode 100644
index 000000000000..d685adb48759
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * 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
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
new file mode 100644
index 000000000000..0c7fc59024df
--- /dev/null
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * 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, ctx_initialized;
+
+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_brk(TBROK | TERRNO, "io_setup() failed");
+
+	ctx_initialized = 1;
+
+	ret = io_submit(ctx, 1, cbs);
+	if (ret != 1)
+		tst_brk(TBROK | TERRNO, "io_submit() failed");
+}
+
+static void cleanup(void)
+{
+	if (ctx_initialized) {
+		if (io_destroy(ctx) < 0)
+			tst_res(TBROK | TERRNO, "io_destroy() failed");
+	}
+
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+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));
+
+	if (TST_RET == 1) {
+		tst_res(TFAIL, "%s: io_pgetevents() passed unexpectedly",
+			tc->name);
+		return;
+	}
+
+	if (tc->exp_errno != TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "%s: io_pgetevents() should fail with %s",
+			tc->name, tst_strerrno(tc->exp_errno));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "%s: io_pgetevents() failed as expected",
+		tc->name);
+}
+
+static struct tst_test test = {
+	.min_kver = "4.18",
+	.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
-- 
2.21.0.rc0.269.g1a574e7a288b


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH V4 2/2] syscalls/io_pgetevents: New tests
  2020-01-28  3:01   ` [LTP] [PATCH V4 2/2] syscalls/io_pgetevents: New tests Viresh Kumar
@ 2020-01-28 13:40     ` Cyril Hrubis
  2020-01-29  0:46       ` Viresh Kumar
  0 siblings, 1 reply; 9+ messages in thread
From: Cyril Hrubis @ 2020-01-28 13:40 UTC (permalink / raw)
  To: ltp

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.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH V2 1/2] Add Syscall numbers for io_pgetevents
  2020-01-24  9:53 [LTP] [PATCH V2 1/2] Add Syscall numbers for io_pgetevents Viresh Kumar
  2020-01-24  9:53 ` [LTP] [PATCH V2 2/2] syscalls/io_pgetevents Viresh Kumar
@ 2020-01-28 13:42 ` Cyril Hrubis
  1 sibling, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2020-01-28 13:42 UTC (permalink / raw)
  To: ltp

Hi!
Pushed as well, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH V4 2/2] syscalls/io_pgetevents: New tests
  2020-01-28 13:40     ` Cyril Hrubis
@ 2020-01-29  0:46       ` Viresh Kumar
  2020-01-29  9:50         ` Cyril Hrubis
  0 siblings, 1 reply; 9+ messages in thread
From: Viresh Kumar @ 2020-01-29  0:46 UTC (permalink / raw)
  To: ltp

On 28-01-20, 14:40, Cyril Hrubis wrote:
> 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.

-- 
viresh

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH V4 2/2] syscalls/io_pgetevents: New tests
  2020-01-29  0:46       ` Viresh Kumar
@ 2020-01-29  9:50         ` Cyril Hrubis
  0 siblings, 0 replies; 9+ messages in thread
From: Cyril Hrubis @ 2020-01-29  9:50 UTC (permalink / raw)
  To: ltp

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.

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.

> 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.

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.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-01-29  9:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-24  9:53 [LTP] [PATCH V2 1/2] Add Syscall numbers for io_pgetevents Viresh Kumar
2020-01-24  9:53 ` [LTP] [PATCH V2 2/2] syscalls/io_pgetevents Viresh Kumar
2020-01-27 10:50   ` [LTP] [PATCH V3 " Viresh Kumar
2020-01-27 14:32     ` Cyril Hrubis
2020-01-28  3:01   ` [LTP] [PATCH V4 2/2] syscalls/io_pgetevents: New tests Viresh Kumar
2020-01-28 13:40     ` Cyril Hrubis
2020-01-29  0:46       ` Viresh Kumar
2020-01-29  9:50         ` Cyril Hrubis
2020-01-28 13:42 ` [LTP] [PATCH V2 1/2] Add Syscall numbers for io_pgetevents Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox