• 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 <errno.h>
25 #include <string.h>
26 
27 #include "config.h"
28 #include "test.h"
29 
30 char *TCID = "io_cancel01";
31 
32 int TST_TOTAL = 1;
33 
34 #ifdef HAVE_LIBAIO
35 #include <libaio.h>
36 
cleanup(void)37 static void cleanup(void)
38 {
39 }
40 
setup(void)41 static void setup(void)
42 {
43 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
44 
45 	TEST_PAUSE;
46 }
47 
48 /*
49    DESCRIPTION
50    io_cancel attempts to cancel an asynchronous I/O operation  previously
51    submitted  with  the io_submit system call.  ctx_id is the AIO context
52    ID of the operation to be cancelled.  If the AIO context is found, the
53    event  will be cancelled and then copied into the memory pointed to by
54    result without being placed into the completion queue.
55 
56    RETURN VALUE
57    io_cancel returns 0 on success; otherwise, it returns one of  the  er-
58    rors listed in the "Errors" section.
59 
60    ERRORS
61    EINVAL The AIO context specified by ctx_id is invalid.
62 
63    EFAULT One of the data structures points to invalid data.
64  */
65 
66 #define EXP_RET (-EFAULT)
67 
main(int argc,char * argv[])68 int main(int argc, char *argv[])
69 {
70 	int lc;
71 
72 	io_context_t ctx;
73 
74 	memset(&ctx, 0, sizeof(ctx));
75 
76 	tst_parse_opts(argc, argv, NULL, NULL);
77 
78 	setup();
79 
80 	for (lc = 0; TEST_LOOPING(lc); lc++) {
81 		tst_count = 0;
82 
83 		TEST(io_cancel(ctx, NULL, NULL));
84 
85 		switch (TEST_RETURN) {
86 		case 0:
87 			tst_resm(TFAIL, "call succeeded unexpectedly");
88 			break;
89 		case EXP_RET:
90 			tst_resm(TPASS, "expected failure - "
91 				 "returned value = %ld : %s", TEST_RETURN,
92 				 strerror(-TEST_RETURN));
93 			break;
94 		case -ENOSYS:
95 			tst_resm(TCONF, "io_cancel returned ENOSYS");
96 			break;
97 		default:
98 			tst_resm(TFAIL, "unexpected returned value - %s (%i) - "
99 				 "expected %s (%i)", strerror(-TEST_RETURN),
100 				 (int)TEST_RETURN, strerror(-EXP_RET), EXP_RET);
101 			break;
102 		}
103 
104 	}
105 
106 	cleanup();
107 	tst_exit();
108 }
109 
110 #else
main(void)111 int main(void)
112 {
113 	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
114 }
115 #endif
116