blob: 3407edc37c0d9e18f393649faab640812912a750 [file] [log] [blame]
subrata_modak06e466f2008-06-26 13:27:17 +00001/*
2 *
3 * Copyright (c) Crackerjack Project., 2007
Cyril Hrubisd8a90be2011-03-16 18:13:38 +01004 * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
subrata_modak06e466f2008-06-26 13:27:17 +00005 *
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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
subrata_modak06e466f2008-06-26 13:27:17 +000019 */
20
21/* Porting from Crackerjack to LTP is done
22 by Masatake YAMATO <yamato@redhat.com> */
23
subrata_modak79cefc12009-01-20 10:48:41 +000024#include "config.h"
subrata_modak06e466f2008-06-26 13:27:17 +000025#include "test.h"
subrata_modak06e466f2008-06-26 13:27:17 +000026
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010027char *TCID = "io_cancel01";
subrata_modak06e466f2008-06-26 13:27:17 +000028
29int TST_TOTAL = 1;
30
subrata_modak79cefc12009-01-20 10:48:41 +000031#ifdef HAVE_LIBAIO_H
32#include <libaio.h>
33#include <errno.h>
34#include <string.h>
35
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010036static void cleanup(void)
subrata_modak06e466f2008-06-26 13:27:17 +000037{
subrata_modak06e466f2008-06-26 13:27:17 +000038}
39
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010040static void setup(void)
subrata_modak06e466f2008-06-26 13:27:17 +000041{
subrata_modak56207ce2009-03-23 13:35:39 +000042 tst_sig(NOFORK, DEF_HANDLER, cleanup);
subrata_modak06e466f2008-06-26 13:27:17 +000043
subrata_modak56207ce2009-03-23 13:35:39 +000044 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -080045}
subrata_modak06e466f2008-06-26 13:27:17 +000046
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010047/*
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.
subrata_modak06e466f2008-06-26 13:27:17 +000054
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010055 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
67int main(int argc, char *argv[])
68{
69 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020070 const char *msg;
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010071
72 io_context_t ctx;
73
74 memset(&ctx, 0, sizeof(ctx));
subrata_modak06e466f2008-06-26 13:27:17 +000075
Garrett Cooper9ab64b82010-12-21 11:27:06 -080076 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080077 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak06e466f2008-06-26 13:27:17 +000078
79 setup();
80
subrata_modak06e466f2008-06-26 13:27:17 +000081 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080082 tst_count = 0;
subrata_modak06e466f2008-06-26 13:27:17 +000083
subrata_modak56207ce2009-03-23 13:35:39 +000084 TEST(io_cancel(ctx, NULL, NULL));
subrata_modak06e466f2008-06-26 13:27:17 +000085
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010086 switch (TEST_RETURN) {
87 case 0:
subrata_modak06e466f2008-06-26 13:27:17 +000088 tst_resm(TFAIL, "call succeeded unexpectedly");
Wanlong Gao354ebb42012-12-07 10:10:04 +080089 break;
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010090 case EXP_RET:
subrata_modak06e466f2008-06-26 13:27:17 +000091 tst_resm(TPASS, "expected failure - "
subrata_modak358c3ee2009-10-26 14:55:46 +000092 "returned value = %ld : %s", TEST_RETURN,
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010093 strerror(-TEST_RETURN));
Wanlong Gao354ebb42012-12-07 10:10:04 +080094 break;
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010095 case -ENOSYS:
96 tst_resm(TCONF, "io_cancel returned ENOSYS");
Wanlong Gao354ebb42012-12-07 10:10:04 +080097 break;
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010098 default:
99 tst_resm(TFAIL, "unexpected returned value - %s (%i) - "
100 "expected %s (%i)", strerror(-TEST_RETURN),
101 (int)TEST_RETURN, strerror(-EXP_RET), EXP_RET);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800102 break;
subrata_modak06e466f2008-06-26 13:27:17 +0000103 }
104
subrata_modak06e466f2008-06-26 13:27:17 +0000105 }
subrata_modak06e466f2008-06-26 13:27:17 +0000106
Cyril Hrubisd8a90be2011-03-16 18:13:38 +0100107 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -0800108 tst_exit();
subrata_modak06e466f2008-06-26 13:27:17 +0000109}
subrata_modak79cefc12009-01-20 10:48:41 +0000110#else
Cyril Hrubisd8a90be2011-03-16 18:13:38 +0100111int main(int argc, char *argv[])
subrata_modak79cefc12009-01-20 10:48:41 +0000112{
Garrett Cooper9ab64b82010-12-21 11:27:06 -0800113 tst_brkm(TCONF, NULL, "System doesn't have libaio support");
subrata_modak79cefc12009-01-20 10:48:41 +0000114}
Garrett Cooper9ab64b82010-12-21 11:27:06 -0800115#endif