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_cancel invoked via libaio with one of the data structures points
13 * to invalid data and expects it to return -EFAULT.
14 */
15
16 #include "config.h"
17 #include "tst_test.h"
18
19 #ifdef HAVE_LIBAIO
20
21 #include <libaio.h>
22
run(void)23 static void run(void)
24 {
25 io_context_t ctx;
26
27 memset(&ctx, 0, sizeof(ctx));
28 TEST(io_cancel(ctx, NULL, NULL));
29
30 if (TST_RET == 0) {
31 tst_res(TFAIL, "io_cancel() succeeded unexpectedly");
32 return;
33 }
34
35 if (TST_RET == -EFAULT) {
36 tst_res(TPASS, "io_cancel() failed with EFAULT");
37 return;
38 }
39
40 tst_res(TFAIL, "io_cancel() failed unexpectedly %s (%ld) expected EFAULT",
41 tst_strerrno(-TST_RET), -TST_RET);
42 }
43
44 static struct tst_test test = {
45 .needs_kconfigs = (const char *[]) {
46 "CONFIG_AIO=y",
47 NULL
48 },
49 .test_all = run,
50 };
51
52 #else
53 TST_TEST_TCONF("test requires libaio and it's development packages");
54 #endif
55