1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Crackerjack Project., 2007
4 * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
5 * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
6 */
7
8 /* Porting from Crackerjack to LTP is done
9 * by Masatake YAMATO <yamato@redhat.com>
10 *
11 * Description:
12 * io_destroy(2) fails and returns -EINVAL if ctx is invalid.
13 */
14
15 #include <errno.h>
16 #include <string.h>
17 #include "config.h"
18 #include "tst_test.h"
19
20 #ifdef HAVE_LIBAIO
21 #include <libaio.h>
22
verify_io_destroy(void)23 static void verify_io_destroy(void)
24 {
25 io_context_t ctx;
26
27 memset(&ctx, 0xff, sizeof(ctx));
28 TEST(io_destroy(ctx));
29
30 if (TST_RET == 0) {
31 tst_res(TFAIL, "io_destroy() succeeded unexpectedly");
32 return;
33 }
34
35 if (TST_RET == -ENOSYS) {
36 tst_res(TCONF, "io_destroy() not supported");
37 return;
38 }
39
40 if (TST_RET == -EINVAL) {
41 tst_res(TPASS, "io_destroy() failed as expected, returned -EINVAL");
42 return;
43 }
44
45 tst_res(TFAIL, "io_destroy() failed unexpectedly, returned -%s expected -EINVAL",
46 tst_strerrno(-TST_RET));
47 }
48
49 static struct tst_test test = {
50 .test_all = verify_io_destroy,
51 };
52
53 #else
54 TST_TEST_TCONF("test requires libaio and it's development packages");
55 #endif
56