1 /* 2 * 3 * Copyright (c) Crackerjack Project., 2007 4 * Copyright (c) 2011 Cyril Hrubis <chrubis@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@redhat.com> */ 23 24 #include <errno.h> 25 #include <string.h> 26 27 #include "config.h" 28 #include "test.h" 29 30 char *TCID = "io_setup01"; 31 32 int TST_TOTAL = 4; 33 34 #ifdef HAVE_LIBAIO 35 #include <libaio.h> 36 37 static void cleanup(void) 38 { 39 } 40 41 static void setup(void) 42 { 43 tst_sig(NOFORK, DEF_HANDLER, cleanup); 44 45 TEST_PAUSE; 46 } 47 48 /* 49 DESCRIPTION 50 io_setup creates an asynchronous I/O context capable of receiving at 51 least nr_events. ctxp must not point to an AIO context that already 52 exists, and must be initialized to 0 prior to the call. On successful 53 creation of the AIO context, *ctxp is filled in with the resulting 54 handle. 55 */ 56 int main(int argc, char *argv[]) 57 { 58 int lc; 59 60 io_context_t ctx; 61 int expected_return; 62 63 tst_parse_opts(argc, argv, NULL, NULL); 64 65 setup(); 66 67 for (lc = 0; TEST_LOOPING(lc); lc++) { 68 tst_count = 0; 69 70 memset(&ctx, 0, sizeof(ctx)); 71 expected_return = 0; 72 TEST(io_setup(1, &ctx)); 73 74 if (TEST_RETURN == expected_return) { 75 tst_resm(TPASS, "call succeeded expectedly"); 76 io_destroy(ctx); 77 } else { 78 tst_resm(TFAIL, "unexpected returned value - %ld - " 79 "expected %d", TEST_RETURN, expected_return); 80 } 81 82 memset(&ctx, 1, sizeof(ctx)); 83 expected_return = -EINVAL; 84 TEST(io_setup(1, &ctx)); 85 86 if (TEST_RETURN == 0) { 87 tst_resm(TFAIL, "call succeeded unexpectedly"); 88 io_destroy(ctx); 89 } else if (TEST_RETURN == expected_return) { 90 tst_resm(TPASS, "expected failure - " 91 "returned value = %ld : %s", TEST_RETURN, 92 strerror(-1 * TEST_RETURN)); 93 } else { 94 tst_resm(TFAIL, "unexpected returned value - %ld - " 95 "expected %d", TEST_RETURN, expected_return); 96 } 97 98 memset(&ctx, 0, sizeof(ctx)); 99 expected_return = -EINVAL; 100 TEST(io_setup(-1, &ctx)); 101 if (TEST_RETURN == 0) { 102 tst_resm(TFAIL, "call succeeded unexpectedly"); 103 io_destroy(ctx); 104 } else if (TEST_RETURN == expected_return) { 105 tst_resm(TPASS, "expected failure - " 106 "returned value = %ld : %s", TEST_RETURN, 107 strerror(-1 * TEST_RETURN)); 108 } else { 109 tst_resm(TFAIL, "unexpected returned value - %ld - " 110 "expected %d", TEST_RETURN, expected_return); 111 } 112 113 /* 114 EFAULT An invalid pointer is passed for ctxp. 115 */ 116 expected_return = -EFAULT; 117 TEST(io_setup(1, NULL)); 118 if (TEST_RETURN == 0) { 119 tst_resm(TFAIL, "call succeeded unexpectedly"); 120 io_destroy(ctx); 121 } else if (TEST_RETURN == expected_return) { 122 tst_resm(TPASS, "expected failure - " 123 "returned value = %ld : %s", TEST_RETURN, 124 strerror(-1 * TEST_RETURN)); 125 } else { 126 tst_resm(TFAIL, "unexpected returned value - %ld - " 127 "expected %d", TEST_RETURN, expected_return); 128 } 129 130 } 131 cleanup(); 132 133 tst_exit(); 134 } 135 136 #else 137 int main(void) 138 { 139 tst_brkm(TCONF, NULL, "test requires libaio and it's development packages"); 140 } 141 #endif 142