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 <errno.h>
25 #include <string.h>
26 
27 #include "config.h"
28 #include "test.h"
29 
30 char *TCID = "io_destroy01";
31 
32 int TST_TOTAL = 1;
33 
34 #ifdef HAVE_LIBAIO
35 #include <libaio.h>
36 
37 static void cleanup(void)
38 {
39 }
40 
41 static void setup(void)
42 {
43 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
44 
45 	TEST_PAUSE;
46 }
47 
48 /*
49   DESCRIPTION
50        io_destroy  removes  the asynchronous I/O context from the list of I/O
51        contexts and then destroys it.  io_destroy can also  cancel  any  out-
52        standing asynchronous I/O actions on ctx and block on completion.
53 
54  RETURN VALUE
55        io_destroy returns 0 on success.
56 
57  ERRORS
58        EINVAL The AIO context specified by ctx is invalid.
59 */
60 
61 #define EXP_RET (-EINVAL)
62 
63 int main(int argc, char *argv[])
64 {
65 	int lc;
66 
67 	io_context_t ctx;
68 
69 	memset(&ctx, 0xff, sizeof(ctx));
70 
71 	tst_parse_opts(argc, argv, NULL, NULL);
72 
73 	setup();
74 
75 	for (lc = 0; TEST_LOOPING(lc); lc++) {
76 		tst_count = 0;
77 
78 		TEST(io_destroy(ctx));
79 
80 		switch (TEST_RETURN) {
81 		case 0:
82 			tst_resm(TFAIL, "call succeeded unexpectedly");
83 			break;
84 		case EXP_RET:
85 			tst_resm(TPASS, "expected failure - "
86 				 "returned value = %ld : %s", TEST_RETURN,
87 				 strerror(-TEST_RETURN));
88 			break;
89 		case -ENOSYS:
90 			tst_resm(TCONF, "io_cancel returned ENOSYS");
91 			break;
92 		default:
93 			tst_resm(TFAIL, "unexpected returned value - %s (%i) - "
94 				 "expected %s (%i)", strerror(-TEST_RETURN),
95 				 (int)TEST_RETURN, strerror(-EXP_RET), EXP_RET);
96 			break;
97 		}
98 	}
99 
100 	cleanup();
101 	tst_exit();
102 }
103 
104 #else
105 int main(void)
106 {
107 	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
108 }
109 #endif
110