• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "tst_test.h"
9 #include "lapi/io_pgetevents.h"
10 
11 #ifdef HAVE_LIBAIO
12 static int fd;
13 
cleanup(void)14 static void cleanup(void)
15 {
16 	if (fd > 0)
17 		SAFE_CLOSE(fd);
18 }
19 
run(void)20 static void run(void)
21 {
22 	struct io_event events[1];
23 	struct iocb cb, *cbs[1];
24 	io_context_t ctx = 0;
25 	sigset_t sigmask;
26 	char data[4096];
27 	int ret, fd;
28 
29 	cbs[0] = &cb;
30 	sigemptyset(&sigmask);
31 
32 	fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT, 0644);
33 	io_prep_pwrite(&cb, fd, data, 4096, 0);
34 
35 	ret = io_setup(1, &ctx);
36 	if (ret < 0)
37 		tst_brk(TBROK | TERRNO, "io_setup() failed");
38 
39 	ret = io_submit(ctx, 1, cbs);
40 	if (ret != 1)
41 		tst_brk(TBROK | TERRNO, "io_submit() failed");
42 
43 	/* get the reply */
44 	ret = io_pgetevents(ctx, 1, 1, events, NULL, &sigmask);
45 
46 	if (ret == 1)
47 		tst_res(TPASS, "io_pgetevents() works as expected");
48 	else
49 		tst_res(TFAIL | TERRNO, "io_pgetevents() failed");
50 
51 	if (io_destroy(ctx) < 0)
52 		tst_brk(TBROK | TERRNO, "io_destroy() failed");
53 }
54 
55 static struct tst_test test = {
56 	.min_kver = "4.18",
57 	.test_all = run,
58 	.needs_tmpdir = 1,
59 	.cleanup = cleanup,
60 };
61 
62 #else
63 TST_TEST_TCONF("test requires libaio and it's development packages");
64 #endif
65