blob: b0a28e171022534c47c2e9f8d5253f21e901ab89 [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_getevents01";
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_getevents attempts to read at least min_nr events and up to nr
50 events from the completion queue of the AIO context specified by
51 ctx_id. timeout specifies the amount of time to wait for events,
52 where a NULL timeout waits until at least min_nr events have been
53 seen. Note that timeout is relative and will be updated if not NULL
54 and the operation blocks.
subrata_modakc5792c92008-07-11 20:21:42 +000055
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010056 RETURN VALUE
57 io_getevents returns the number of events read: 0 if no events are
58 available or < min_nr if the timeout has elapsed.
59
60 ERRORS
61 EINVAL ctx_id is invalid. min_nr is out of range or nr is out of
62 range.
63 */
64
65#define EXP_RET (-EINVAL)
66
67int main(int argc, char *argv[])
68{
69 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020070 const char *msg;
Chris Dearman37550cf2012-10-17 19:54:01 -070071
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010072 io_context_t ctx;
73
74 memset(&ctx, 0, sizeof(ctx));
subrata_modakc5792c92008-07-11 20:21:42 +000075
Garrett Cooper54587dd2010-12-21 11:37:16 -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_modakc5792c92008-07-11 20:21:42 +000078
79 setup();
80
subrata_modakc5792c92008-07-11 20:21:42 +000081 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080082 tst_count = 0;
subrata_modakc5792c92008-07-11 20:21:42 +000083
subrata_modak56207ce2009-03-23 13:35:39 +000084 TEST(io_getevents(ctx, 0, 0, NULL, NULL));
subrata_modakc5792c92008-07-11 20:21:42 +000085
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010086 switch (TEST_RETURN) {
87 case 0:
subrata_modakc5792c92008-07-11 20:21:42 +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_modakc5792c92008-07-11 20:21:42 +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_modakc5792c92008-07-11 20:21:42 +0000103 }
subrata_modakc5792c92008-07-11 20:21:42 +0000104 }
Chris Dearman37550cf2012-10-17 19:54:01 -0700105
subrata_modakc5792c92008-07-11 20:21:42 +0000106 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -0800107 tst_exit();
subrata_modakc5792c92008-07-11 20:21:42 +0000108}
subrata_modak79cefc12009-01-20 10:48:41 +0000109#else
Cyril Hrubisd8a90be2011-03-16 18:13:38 +0100110int main(int argc, char *argv[])
subrata_modak79cefc12009-01-20 10:48:41 +0000111{
Garrett Cooper54587dd2010-12-21 11:37:16 -0800112 tst_brkm(TCONF, NULL, "System doesn't support execution of the test");
subrata_modak79cefc12009-01-20 10:48:41 +0000113}
Garrett Cooper54587dd2010-12-21 11:37:16 -0800114#endif