blob: cbc5f7107d8a5b45bb14c9de1e5762e9bef3410b [file] [log] [blame]
subrata_modakc5792c92008-07-11 20:21:42 +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_modakc5792c92008-07-11 20:21:42 +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_modakc5792c92008-07-11 20:21:42 +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_modakc5792c92008-07-11 20:21:42 +000025#include "test.h"
subrata_modakc5792c92008-07-11 20:21:42 +000026
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010027char *TCID = "io_destroy01";
subrata_modakc5792c92008-07-11 20:21:42 +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_modakc5792c92008-07-11 20:21:42 +000037{
subrata_modakc5792c92008-07-11 20:21:42 +000038}
39
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010040static void setup(void)
subrata_modakc5792c92008-07-11 20:21:42 +000041{
subrata_modak56207ce2009-03-23 13:35:39 +000042 tst_sig(NOFORK, DEF_HANDLER, cleanup);
subrata_modakc5792c92008-07-11 20:21:42 +000043
subrata_modak56207ce2009-03-23 13:35:39 +000044 TEST_PAUSE;
Garrett Cooper2c282152010-12-16 00:55:50 -080045}
subrata_modakc5792c92008-07-11 20:21:42 +000046
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010047/*
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.
subrata_modakc5792c92008-07-11 20:21:42 +000052
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010053 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
62int main(int argc, char *argv[])
63{
64 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020065 const char *msg;
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010066
67 io_context_t ctx;
68
69 memset(&ctx, 0xff, sizeof(ctx));
subrata_modakc5792c92008-07-11 20:21:42 +000070
Garrett Cooper54587dd2010-12-21 11:37:16 -080071 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080072 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modakc5792c92008-07-11 20:21:42 +000073
74 setup();
75
subrata_modakc5792c92008-07-11 20:21:42 +000076 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080077 tst_count = 0;
subrata_modakc5792c92008-07-11 20:21:42 +000078
subrata_modak56207ce2009-03-23 13:35:39 +000079 TEST(io_destroy(ctx));
subrata_modakc5792c92008-07-11 20:21:42 +000080
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010081 switch (TEST_RETURN) {
82 case 0:
subrata_modakc5792c92008-07-11 20:21:42 +000083 tst_resm(TFAIL, "call succeeded unexpectedly");
Wanlong Gao354ebb42012-12-07 10:10:04 +080084 break;
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010085 case EXP_RET:
subrata_modakc5792c92008-07-11 20:21:42 +000086 tst_resm(TPASS, "expected failure - "
subrata_modak358c3ee2009-10-26 14:55:46 +000087 "returned value = %ld : %s", TEST_RETURN,
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010088 strerror(-TEST_RETURN));
Wanlong Gao354ebb42012-12-07 10:10:04 +080089 break;
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010090 case -ENOSYS:
91 tst_resm(TCONF, "io_cancel returned ENOSYS");
Wanlong Gao354ebb42012-12-07 10:10:04 +080092 break;
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010093 default:
94 tst_resm(TFAIL, "unexpected returned value - %s (%i) - "
95 "expected %s (%i)", strerror(-TEST_RETURN),
96 (int)TEST_RETURN, strerror(-EXP_RET), EXP_RET);
Wanlong Gao354ebb42012-12-07 10:10:04 +080097 break;
subrata_modakc5792c92008-07-11 20:21:42 +000098 }
subrata_modakc5792c92008-07-11 20:21:42 +000099 }
Chris Dearman37550cf2012-10-17 19:54:01 -0700100
subrata_modakc5792c92008-07-11 20:21:42 +0000101 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -0800102 tst_exit();
subrata_modakc5792c92008-07-11 20:21:42 +0000103}
subrata_modak79cefc12009-01-20 10:48:41 +0000104#else
Cyril Hrubisd8a90be2011-03-16 18:13:38 +0100105int main(int argc, char *argv[])
subrata_modak79cefc12009-01-20 10:48:41 +0000106{
Garrett Cooper54587dd2010-12-21 11:37:16 -0800107 tst_brkm(TCONF, NULL, "System doesn't support execution of the test");
subrata_modak79cefc12009-01-20 10:48:41 +0000108}
Garrett Cooper54587dd2010-12-21 11:37:16 -0800109#endif