• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_cancel01";
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_cancel attempts to cancel an asynchronous I/O operation  previously
50    submitted  with  the io_submit system call.  ctx_id is the AIO context
51    ID of the operation to be cancelled.  If the AIO context is found, the
52    event  will be cancelled and then copied into the memory pointed to by
53    result without being placed into the completion queue.
54 
55    RETURN VALUE
56    io_cancel returns 0 on success; otherwise, it returns one of  the  er-
57    rors listed in the "Errors" section.
58 
59    ERRORS
60    EINVAL The AIO context specified by ctx_id is invalid.
61 
62    EFAULT One of the data structures points to invalid data.
63  */
64 
65 #define EXP_RET (-EFAULT)
66 
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69 	int lc;
70 
71 	io_context_t ctx;
72 
73 	memset(&ctx, 0, sizeof(ctx));
74 
75 	tst_parse_opts(argc, argv, NULL, NULL);
76 
77 	setup();
78 
79 	for (lc = 0; TEST_LOOPING(lc); lc++) {
80 		tst_count = 0;
81 
82 		TEST(io_cancel(ctx, NULL, NULL));
83 
84 		switch (TEST_RETURN) {
85 		case 0:
86 			tst_resm(TFAIL, "call succeeded unexpectedly");
87 			break;
88 		case EXP_RET:
89 			tst_resm(TPASS, "expected failure - "
90 				 "returned value = %ld : %s", TEST_RETURN,
91 				 strerror(-TEST_RETURN));
92 			break;
93 		case -ENOSYS:
94 			tst_resm(TCONF, "io_cancel returned ENOSYS");
95 			break;
96 		default:
97 			tst_resm(TFAIL, "unexpected returned value - %s (%i) - "
98 				 "expected %s (%i)", strerror(-TEST_RETURN),
99 				 (int)TEST_RETURN, strerror(-EXP_RET), EXP_RET);
100 			break;
101 		}
102 
103 	}
104 
105 	cleanup();
106 	tst_exit();
107 }
108 #else
main(int argc,char * argv[])109 int main(int argc, char *argv[])
110 {
111 	tst_brkm(TCONF, NULL, "System doesn't have libaio support");
112 }
113 #endif
114