1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
4 *
5 * Description:
6 * Basic io_pgetevents() test to receive 1 event successfully.
7 */
8 #include "time64_variants.h"
9 #include "tst_test.h"
10 #include "tst_timer.h"
11 #include "lapi/io_pgetevents.h"
12
13 #ifdef HAVE_LIBAIO
14 static int fd;
15
16 static struct time64_variants variants[] = {
17 #if (__NR_io_pgetevents != __LTP__NR_INVALID_SYSCALL)
18 { .io_pgetevents = sys_io_pgetevents, .ts_type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
19 #endif
20
21 #if (__NR_io_pgetevents_time64 != __LTP__NR_INVALID_SYSCALL)
22 { .io_pgetevents = sys_io_pgetevents_time64, .ts_type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
23 #endif
24 };
25
setup(void)26 static void setup(void)
27 {
28 tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
29 }
30
cleanup(void)31 static void cleanup(void)
32 {
33 if (fd > 0)
34 SAFE_CLOSE(fd);
35 }
36
run(void)37 static void run(void)
38 {
39 struct time64_variants *tv = &variants[tst_variant];
40 struct io_event events[1];
41 struct iocb cb, *cbs[1];
42 io_context_t ctx = 0;
43 struct tst_ts to = tst_ts_from_ns(tv->ts_type, 10000);
44 sigset_t sigmask;
45 char data[4096];
46 int ret;
47
48 cbs[0] = &cb;
49 sigemptyset(&sigmask);
50
51 fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT, 0644);
52 io_prep_pwrite(&cb, fd, data, 4096, 0);
53
54 TEST(io_setup(1, &ctx));
55 if (TST_RET == -ENOSYS)
56 tst_brk(TCONF | TRERRNO, "io_setup(): AIO not supported by kernel");
57 if (TST_RET < 0)
58 tst_brk(TBROK | TRERRNO, "io_setup() failed");
59
60 ret = io_submit(ctx, 1, cbs);
61 if (ret != 1)
62 tst_brk(TBROK | TERRNO, "io_submit() failed");
63
64 /* get the reply */
65 ret = tv->io_pgetevents(ctx, 1, 1, events, tst_ts_get(&to), &sigmask);
66
67 if (ret == 1)
68 tst_res(TPASS, "io_pgetevents() works as expected");
69 else
70 tst_res(TFAIL | TERRNO, "io_pgetevents() failed");
71
72 if (io_destroy(ctx) < 0)
73 tst_brk(TBROK | TERRNO, "io_destroy() failed");
74 }
75
76 static struct tst_test test = {
77 .min_kver = "4.18",
78 .test_all = run,
79 .test_variants = ARRAY_SIZE(variants),
80 .needs_tmpdir = 1,
81 .cleanup = cleanup,
82 .setup = setup,
83 };
84
85 #else
86 TST_TEST_TCONF("test requires libaio and it's development packages");
87 #endif
88