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 <[email protected]>
5 * Copyright (c) 2011 Cyril Hrubis <[email protected]>
6 * Copyright (c) 2017 Xiao Yang <[email protected]>
7 */
8
9 /*\
10 * [Description]
11 *
12 * Test io_destroy invoked via libaio with invalid ctx and expects it to
13 * return -EINVAL.
14 */
15
16 #include <errno.h>
17 #include <string.h>
18 #include "config.h"
19 #include "tst_test.h"
20
21 #ifdef HAVE_LIBAIO
22 #include <libaio.h>
23
verify_io_destroy(void)24 static void verify_io_destroy(void)
25 {
26 io_context_t ctx;
27
28 memset(&ctx, 0xff, sizeof(ctx));
29 TEST(io_destroy(ctx));
30
31 if (TST_RET == 0) {
32 tst_res(TFAIL, "io_destroy() succeeded unexpectedly");
33 return;
34 }
35
36 if (TST_RET == -ENOSYS) {
37 tst_res(TCONF, "io_destroy() not supported");
38 return;
39 }
40
41 if (TST_RET == -EINVAL) {
42 tst_res(TPASS, "io_destroy() failed as expected, returned -EINVAL");
43 return;
44 }
45
46 tst_res(TFAIL, "io_destroy() failed unexpectedly, returned -%s expected -EINVAL",
47 tst_strerrno(-TST_RET));
48 }
49
50 static struct tst_test test = {
51 .test_all = verify_io_destroy,
52 };
53
54 #else
55 TST_TEST_TCONF("test requires libaio and it's development packages");
56 #endif
57