1 /*
2 *
3 * Copyright (c) Crackerjack Project., 2007
4 * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /* Porting from Crackerjack to LTP is done
22 by Masatake YAMATO <yamato@redhat.com> */
23
24 #include "config.h"
25 #include "test.h"
26
27 char *TCID = "io_destroy01";
28
29 int TST_TOTAL = 1;
30
31 #ifdef HAVE_LIBAIO_H
32 #include <libaio.h>
33 #include <errno.h>
34 #include <string.h>
35
cleanup(void)36 static void cleanup(void)
37 {
38 }
39
setup(void)40 static void setup(void)
41 {
42 tst_sig(NOFORK, DEF_HANDLER, cleanup);
43
44 TEST_PAUSE;
45 }
46
47 /*
48 DESCRIPTION
49 io_destroy removes the asynchronous I/O context from the list of I/O
50 contexts and then destroys it. io_destroy can also cancel any out-
51 standing asynchronous I/O actions on ctx and block on completion.
52
53 RETURN VALUE
54 io_destroy returns 0 on success.
55
56 ERRORS
57 EINVAL The AIO context specified by ctx is invalid.
58 */
59
60 #define EXP_RET (-EINVAL)
61
main(int argc,char * argv[])62 int main(int argc, char *argv[])
63 {
64 int lc;
65
66 io_context_t ctx;
67
68 memset(&ctx, 0xff, sizeof(ctx));
69
70 tst_parse_opts(argc, argv, NULL, NULL);
71
72 setup();
73
74 for (lc = 0; TEST_LOOPING(lc); lc++) {
75 tst_count = 0;
76
77 TEST(io_destroy(ctx));
78
79 switch (TEST_RETURN) {
80 case 0:
81 tst_resm(TFAIL, "call succeeded unexpectedly");
82 break;
83 case EXP_RET:
84 tst_resm(TPASS, "expected failure - "
85 "returned value = %ld : %s", TEST_RETURN,
86 strerror(-TEST_RETURN));
87 break;
88 case -ENOSYS:
89 tst_resm(TCONF, "io_cancel returned ENOSYS");
90 break;
91 default:
92 tst_resm(TFAIL, "unexpected returned value - %s (%i) - "
93 "expected %s (%i)", strerror(-TEST_RETURN),
94 (int)TEST_RETURN, strerror(-EXP_RET), EXP_RET);
95 break;
96 }
97 }
98
99 cleanup();
100 tst_exit();
101 }
102 #else
main(int argc,char * argv[])103 int main(int argc, char *argv[])
104 {
105 tst_brkm(TCONF, NULL, "System doesn't support execution of the test");
106 }
107 #endif
108