1 /* 2 * 3 * Copyright (c) Crackerjack Project., 2007 4 * Copyright (c) 2011 Cyril Hrubis <chrubis (at) suse.cz> 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 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 /* Porting from Crackerjack to LTP is done 22 by Masatake YAMATO <yamato (at) redhat.com> */ 23 24 #include "config.h" 25 #include "test.h" 26 27 char *TCID = "io_setup01"; 28 29 int TST_TOTAL = 4; 30 31 #ifdef HAVE_LIBAIO_H 32 #include <libaio.h> 33 #include <errno.h> 34 #include <string.h> 35 36 static void cleanup(void) 37 { 38 } 39 40 static void setup(void) 41 { 42 tst_sig(NOFORK, DEF_HANDLER, cleanup); 43 44 TEST_PAUSE; 45 } 46 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[]) 56 { 57 int lc; 58 59 io_context_t ctx; 60 int expected_return; 61 62 tst_parse_opts(argc, argv, NULL, NULL); 63 64 setup(); 65 66 for (lc = 0; TEST_LOOPING(lc); lc++) { 67 tst_count = 0; 68 69 memset(&ctx, 0, sizeof(ctx)); 70 expected_return = 0; 71 TEST(io_setup(1, &ctx)); 72 73 if (TEST_RETURN == expected_return) { 74 tst_resm(TPASS, "call succeeded expectedly"); 75 io_destroy(ctx); 76 } else { 77 tst_resm(TFAIL, "unexpected returned value - %ld - " 78 "expected %d", TEST_RETURN, expected_return); 79 } 80 81 memset(&ctx, 1, sizeof(ctx)); 82 expected_return = -EINVAL; 83 TEST(io_setup(1, &ctx)); 84 85 if (TEST_RETURN == 0) { 86 tst_resm(TFAIL, "call succeeded unexpectedly"); 87 io_destroy(ctx); 88 } else if (TEST_RETURN == expected_return) { 89 tst_resm(TPASS, "expected failure - " 90 "returned value = %ld : %s", TEST_RETURN, 91 strerror(-1 * TEST_RETURN)); 92 } else { 93 tst_resm(TFAIL, "unexpected returned value - %ld - " 94 "expected %d", TEST_RETURN, expected_return); 95 } 96 97 memset(&ctx, 0, sizeof(ctx)); 98 expected_return = -EINVAL; 99 TEST(io_setup(-1, &ctx)); 100 if (TEST_RETURN == 0) { 101 tst_resm(TFAIL, "call succeeded unexpectedly"); 102 io_destroy(ctx); 103 } else if (TEST_RETURN == expected_return) { 104 tst_resm(TPASS, "expected failure - " 105 "returned value = %ld : %s", TEST_RETURN, 106 strerror(-1 * TEST_RETURN)); 107 } else { 108 tst_resm(TFAIL, "unexpected returned value - %ld - " 109 "expected %d", TEST_RETURN, expected_return); 110 } 111 112 /* 113 EFAULT An invalid pointer is passed for ctxp. 114 */ 115 expected_return = -EFAULT; 116 TEST(io_setup(1, NULL)); 117 if (TEST_RETURN == 0) { 118 tst_resm(TFAIL, "call succeeded unexpectedly"); 119 io_destroy(ctx); 120 } else if (TEST_RETURN == expected_return) { 121 tst_resm(TPASS, "expected failure - " 122 "returned value = %ld : %s", TEST_RETURN, 123 strerror(-1 * TEST_RETURN)); 124 } else { 125 tst_resm(TFAIL, "unexpected returned value - %ld - " 126 "expected %d", TEST_RETURN, expected_return); 127 } 128 129 } 130 cleanup(); 131 132 tst_exit(); 133 } 134 #else 135 int main(int argc, char *argv[]) 136 { 137 tst_brkm(TCONF, NULL, "System doesn't support execution of the test"); 138 } 139 #endif 140