blob: b727a4a406e5a174c0c0988ccba283b039d05ca5 [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_setup01";
subrata_modakc5792c92008-07-11 20:21:42 +000028
subrata_modak18dc0c22008-07-21 10:55:34 +000029int TST_TOTAL = 4;
subrata_modakc5792c92008-07-11 20:21:42 +000030
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_setup creates an asynchronous I/O context capable of receiving at
50 least nr_events. ctxp must not point to an AIO context that already
51 exists, and must be initialized to 0 prior to the call. On successful
52 creation of the AIO context, *ctxp is filled in with the resulting
53 handle.
54 */
55int main(int argc, char *argv[])
subrata_modakc5792c92008-07-11 20:21:42 +000056{
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010057 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020058 const char *msg;
subrata_modakc5792c92008-07-11 20:21:42 +000059
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010060 io_context_t ctx;
subrata_modakc5792c92008-07-11 20:21:42 +000061 int expected_return;
subrata_modakbdbaec52009-02-26 12:14:51 +000062
Garrett Cooper53740502010-12-16 00:04:01 -080063 if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080064 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modakc5792c92008-07-11 20:21:42 +000065
66 setup();
67
subrata_modakc5792c92008-07-11 20:21:42 +000068 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080069 tst_count = 0;
subrata_modakc5792c92008-07-11 20:21:42 +000070
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010071 memset(&ctx, 0, sizeof(ctx));
subrata_modakc5792c92008-07-11 20:21:42 +000072 expected_return = 0;
subrata_modak56207ce2009-03-23 13:35:39 +000073 TEST(io_setup(1, &ctx));
subrata_modakc5792c92008-07-11 20:21:42 +000074
75 if (TEST_RETURN == expected_return) {
76 tst_resm(TPASS, "call succeeded expectedly");
subrata_modak56207ce2009-03-23 13:35:39 +000077 io_destroy(ctx);
subrata_modakc5792c92008-07-11 20:21:42 +000078 } else {
subrata_modak358c3ee2009-10-26 14:55:46 +000079 tst_resm(TFAIL, "unexpected returned value - %ld - "
subrata_modak56207ce2009-03-23 13:35:39 +000080 "expected %d", TEST_RETURN, expected_return);
subrata_modakc5792c92008-07-11 20:21:42 +000081 }
subrata_modakc5792c92008-07-11 20:21:42 +000082
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010083 memset(&ctx, 1, sizeof(ctx));
subrata_modakc5792c92008-07-11 20:21:42 +000084 expected_return = -EINVAL;
subrata_modak56207ce2009-03-23 13:35:39 +000085 TEST(io_setup(1, &ctx));
subrata_modakc5792c92008-07-11 20:21:42 +000086
87 if (TEST_RETURN == 0) {
88 tst_resm(TFAIL, "call succeeded unexpectedly");
subrata_modak56207ce2009-03-23 13:35:39 +000089 io_destroy(ctx);
subrata_modakc5792c92008-07-11 20:21:42 +000090 } else if (TEST_RETURN == expected_return) {
91 tst_resm(TPASS, "expected failure - "
subrata_modak358c3ee2009-10-26 14:55:46 +000092 "returned value = %ld : %s", TEST_RETURN,
subrata_modakc5792c92008-07-11 20:21:42 +000093 strerror(-1 * TEST_RETURN));
94 } else {
subrata_modak358c3ee2009-10-26 14:55:46 +000095 tst_resm(TFAIL, "unexpected returned value - %ld - "
subrata_modak56207ce2009-03-23 13:35:39 +000096 "expected %d", TEST_RETURN, expected_return);
subrata_modakc5792c92008-07-11 20:21:42 +000097 }
98
Cyril Hrubisd8a90be2011-03-16 18:13:38 +010099 memset(&ctx, 0, sizeof(ctx));
subrata_modakc5792c92008-07-11 20:21:42 +0000100 expected_return = -EINVAL;
subrata_modak56207ce2009-03-23 13:35:39 +0000101 TEST(io_setup(-1, &ctx));
subrata_modakc5792c92008-07-11 20:21:42 +0000102 if (TEST_RETURN == 0) {
103 tst_resm(TFAIL, "call succeeded unexpectedly");
subrata_modak56207ce2009-03-23 13:35:39 +0000104 io_destroy(ctx);
subrata_modakc5792c92008-07-11 20:21:42 +0000105 } else if (TEST_RETURN == expected_return) {
106 tst_resm(TPASS, "expected failure - "
subrata_modak358c3ee2009-10-26 14:55:46 +0000107 "returned value = %ld : %s", TEST_RETURN,
subrata_modakc5792c92008-07-11 20:21:42 +0000108 strerror(-1 * TEST_RETURN));
109 } else {
subrata_modak358c3ee2009-10-26 14:55:46 +0000110 tst_resm(TFAIL, "unexpected returned value - %ld - "
subrata_modak56207ce2009-03-23 13:35:39 +0000111 "expected %d", TEST_RETURN, expected_return);
subrata_modakc5792c92008-07-11 20:21:42 +0000112 }
113
subrata_modakc5792c92008-07-11 20:21:42 +0000114 /*
subrata_modak56207ce2009-03-23 13:35:39 +0000115 EFAULT An invalid pointer is passed for ctxp.
116 */
subrata_modakc5792c92008-07-11 20:21:42 +0000117 expected_return = -EFAULT;
subrata_modak56207ce2009-03-23 13:35:39 +0000118 TEST(io_setup(1, NULL));
subrata_modakc5792c92008-07-11 20:21:42 +0000119 if (TEST_RETURN == 0) {
120 tst_resm(TFAIL, "call succeeded unexpectedly");
subrata_modak56207ce2009-03-23 13:35:39 +0000121 io_destroy(ctx);
subrata_modakc5792c92008-07-11 20:21:42 +0000122 } else if (TEST_RETURN == expected_return) {
123 tst_resm(TPASS, "expected failure - "
subrata_modak358c3ee2009-10-26 14:55:46 +0000124 "returned value = %ld : %s", TEST_RETURN,
subrata_modakc5792c92008-07-11 20:21:42 +0000125 strerror(-1 * TEST_RETURN));
126 } else {
subrata_modak358c3ee2009-10-26 14:55:46 +0000127 tst_resm(TFAIL, "unexpected returned value - %ld - "
subrata_modak56207ce2009-03-23 13:35:39 +0000128 "expected %d", TEST_RETURN, expected_return);
subrata_modakc5792c92008-07-11 20:21:42 +0000129 }
130
subrata_modakc5792c92008-07-11 20:21:42 +0000131 }
132 cleanup();
133
Garrett Cooper2c282152010-12-16 00:55:50 -0800134 tst_exit();
subrata_modakc5792c92008-07-11 20:21:42 +0000135}
subrata_modak79cefc12009-01-20 10:48:41 +0000136#else
Cyril Hrubisd8a90be2011-03-16 18:13:38 +0100137int main(int argc, char *argv[])
subrata_modak79cefc12009-01-20 10:48:41 +0000138{
Garrett Cooper54587dd2010-12-21 11:37:16 -0800139 tst_brkm(TCONF, NULL, "System doesn't support execution of the test");
subrata_modak79cefc12009-01-20 10:48:41 +0000140}
Garrett Cooper54587dd2010-12-21 11:37:16 -0800141#endif