subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) Crackerjack Project., 2007 |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 4 | * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz> |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* Porting from Crackerjack to LTP is done |
| 22 | by Masatake YAMATO <yamato@redhat.com> */ |
| 23 | |
subrata_modak | 79cefc1 | 2009-01-20 10:48:41 +0000 | [diff] [blame] | 24 | #include "config.h" |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 25 | #include "test.h" |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 26 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 27 | char *TCID = "io_setup01"; |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 28 | |
subrata_modak | 18dc0c2 | 2008-07-21 10:55:34 +0000 | [diff] [blame] | 29 | int TST_TOTAL = 4; |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 30 | |
subrata_modak | 79cefc1 | 2009-01-20 10:48:41 +0000 | [diff] [blame] | 31 | #ifdef HAVE_LIBAIO_H |
| 32 | #include <libaio.h> |
| 33 | #include <errno.h> |
| 34 | #include <string.h> |
| 35 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 36 | static void cleanup(void) |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 37 | { |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 40 | static void setup(void) |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 41 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 42 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 43 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 44 | TEST_PAUSE; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 45 | } |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 46 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 47 | /* |
| 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 | */ |
| 55 | int main(int argc, char *argv[]) |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 56 | { |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 57 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 58 | const char *msg; |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 59 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 60 | io_context_t ctx; |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 61 | int expected_return; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 62 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 63 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 64 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 65 | |
| 66 | setup(); |
| 67 | |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 68 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 69 | tst_count = 0; |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 70 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 71 | memset(&ctx, 0, sizeof(ctx)); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 72 | expected_return = 0; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 73 | TEST(io_setup(1, &ctx)); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 74 | |
| 75 | if (TEST_RETURN == expected_return) { |
| 76 | tst_resm(TPASS, "call succeeded expectedly"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 77 | io_destroy(ctx); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 78 | } else { |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 79 | tst_resm(TFAIL, "unexpected returned value - %ld - " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 80 | "expected %d", TEST_RETURN, expected_return); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 81 | } |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 82 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 83 | memset(&ctx, 1, sizeof(ctx)); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 84 | expected_return = -EINVAL; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | TEST(io_setup(1, &ctx)); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 86 | |
| 87 | if (TEST_RETURN == 0) { |
| 88 | tst_resm(TFAIL, "call succeeded unexpectedly"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | io_destroy(ctx); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 90 | } else if (TEST_RETURN == expected_return) { |
| 91 | tst_resm(TPASS, "expected failure - " |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 92 | "returned value = %ld : %s", TEST_RETURN, |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 93 | strerror(-1 * TEST_RETURN)); |
| 94 | } else { |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 95 | tst_resm(TFAIL, "unexpected returned value - %ld - " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 96 | "expected %d", TEST_RETURN, expected_return); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 99 | memset(&ctx, 0, sizeof(ctx)); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 100 | expected_return = -EINVAL; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 101 | TEST(io_setup(-1, &ctx)); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 102 | if (TEST_RETURN == 0) { |
| 103 | tst_resm(TFAIL, "call succeeded unexpectedly"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | io_destroy(ctx); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 105 | } else if (TEST_RETURN == expected_return) { |
| 106 | tst_resm(TPASS, "expected failure - " |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 107 | "returned value = %ld : %s", TEST_RETURN, |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 108 | strerror(-1 * TEST_RETURN)); |
| 109 | } else { |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 110 | tst_resm(TFAIL, "unexpected returned value - %ld - " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 111 | "expected %d", TEST_RETURN, expected_return); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 112 | } |
| 113 | |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 114 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | EFAULT An invalid pointer is passed for ctxp. |
| 116 | */ |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 117 | expected_return = -EFAULT; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 118 | TEST(io_setup(1, NULL)); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 119 | if (TEST_RETURN == 0) { |
| 120 | tst_resm(TFAIL, "call succeeded unexpectedly"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 121 | io_destroy(ctx); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 122 | } else if (TEST_RETURN == expected_return) { |
| 123 | tst_resm(TPASS, "expected failure - " |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 124 | "returned value = %ld : %s", TEST_RETURN, |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 125 | strerror(-1 * TEST_RETURN)); |
| 126 | } else { |
subrata_modak | 358c3ee | 2009-10-26 14:55:46 +0000 | [diff] [blame] | 127 | tst_resm(TFAIL, "unexpected returned value - %ld - " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 128 | "expected %d", TEST_RETURN, expected_return); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 129 | } |
| 130 | |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 131 | } |
| 132 | cleanup(); |
| 133 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 134 | tst_exit(); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 135 | } |
subrata_modak | 79cefc1 | 2009-01-20 10:48:41 +0000 | [diff] [blame] | 136 | #else |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 137 | int main(int argc, char *argv[]) |
subrata_modak | 79cefc1 | 2009-01-20 10:48:41 +0000 | [diff] [blame] | 138 | { |
Garrett Cooper | 54587dd | 2010-12-21 11:37:16 -0800 | [diff] [blame] | 139 | tst_brkm(TCONF, NULL, "System doesn't support execution of the test"); |
subrata_modak | 79cefc1 | 2009-01-20 10:48:41 +0000 | [diff] [blame] | 140 | } |
Garrett Cooper | 54587dd | 2010-12-21 11:37:16 -0800 | [diff] [blame] | 141 | #endif |