• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Crackerjack Project., 2007
4  * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
5  * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
6  * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
7  */
8 
9 /*\
10  * [Description]
11  *
12  * Test io_getevents invoked via libaio with invalid ctx and expects it to
13  * return -EINVAL.
14  */
15 
16 #include "config.h"
17 #include "tst_test.h"
18 
19 #ifdef HAVE_LIBAIO
20 #include <libaio.h>
21 
run(void)22 static void run(void)
23 {
24 	io_context_t ctx;
25 
26 	memset(&ctx, 0, sizeof(ctx));
27 	TEST(io_getevents(ctx, 0, 0, NULL, NULL));
28 
29 	if (TST_RET == 0) {
30 		tst_res(TFAIL, "io_getevents() succeeded unexpectedly");
31 		return;
32 	}
33 
34 	if (TST_RET == -EINVAL) {
35 		tst_res(TPASS, "io_getevents() failed with EINVAL");
36 		return;
37 	}
38 
39 	tst_res(TFAIL, "io_getevents() failed unexpectedly %s (%ld) expected EINVAL",
40 		tst_strerrno(-TST_RET), -TST_RET);
41 }
42 
43 static struct tst_test test = {
44 	.needs_kconfigs = (const char *[]) {
45 		"CONFIG_AIO=y",
46 		NULL
47 	},
48 	.test_all = run,
49 };
50 
51 #else
52 TST_TEST_TCONF("test requires libaio and it's development packages");
53 #endif
54