[LTP] [PATCH 5/7] io_getevents02: Add io_getevents02 test for libaio

Xie Ziyao xieziyao@huawei.com
Fri Jun 18 11:42:08 CEST 2021


Test io_getevents invoked via libaio with invalid ctx and expects it to
return -EINVAL.

Signed-off-by: Xie Ziyao <xieziyao@huawei.com>
---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/io_getevents/.gitignore   |  1 +
 .../syscalls/io_getevents/io_getevents02.c    | 51 +++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 testcases/kernel/syscalls/io_getevents/io_getevents02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 28ffa1286..bf5a42b1f 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -610,6 +610,7 @@ io_cancel02 io_cancel02
 io_destroy01 io_destroy01
 io_destroy02 io_destroy02
 io_getevents01 io_getevents01
+io_getevents02 io_getevents02

 io_pgetevents01 io_pgetevents01
 io_pgetevents02 io_pgetevents02
diff --git a/testcases/kernel/syscalls/io_getevents/.gitignore b/testcases/kernel/syscalls/io_getevents/.gitignore
index b3a5f4df1..b57022f73 100644
--- a/testcases/kernel/syscalls/io_getevents/.gitignore
+++ b/testcases/kernel/syscalls/io_getevents/.gitignore
@@ -1 +1,2 @@
 /io_getevents01
+/io_getevents02
diff --git a/testcases/kernel/syscalls/io_getevents/io_getevents02.c b/testcases/kernel/syscalls/io_getevents/io_getevents02.c
new file mode 100644
index 000000000..d91319151
--- /dev/null
+++ b/testcases/kernel/syscalls/io_getevents/io_getevents02.c
@@ -0,0 +1,51 @@
+// 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) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_getevents invoked via libaio with invalid ctx and expects it to
+ * return -EINVAL.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
+#define EXP_RET (-EINVAL)
+
+static void run(void)
+{
+	io_context_t ctx;
+
+	memset(&ctx, 0, sizeof(ctx));
+	TEST(io_getevents(ctx, 0, 0, NULL, NULL));
+
+	if (TST_RET == 0)
+		tst_res(TFAIL, "call succeeded unexpectedly");
+	else if (TST_RET == EXP_RET)
+		tst_res(TPASS, "io_cancel(ctx, NULL, NULL) returns %ld : %s",
+			TST_RET, strerror(-TST_RET));
+	else
+		tst_res(TFAIL, "io_cancel(ctx, NULL, NULL) returns %ld : %s, expected %d : %s",
+			TST_RET, strerror(-TST_RET), EXP_RET, strerror(-EXP_RET));
+}
+
+static struct tst_test test = {
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.test_all = run,
+};
+
+#else
+TST_TEST_TCONF("test requires libaio and it's development packages");
+#endif
--
2.17.1



More information about the ltp mailing list