1c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak/* 2c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * 3c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * Copyright (c) Crackerjack Project., 2007 4d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz> 5c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * 6c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * This program is free software; you can redistribute it and/or modify 7c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * it under the terms of the GNU General Public License as published by 8c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * the Free Software Foundation; either version 2 of the License, or 9c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * (at your option) any later version. 10c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * 11c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * This program is distributed in the hope that it will be useful, 12c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * but WITHOUT ANY WARRANTY; without even the implied warranty of 13c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 14c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * the GNU General Public License for more details. 15c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * 16c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * You should have received a copy of the GNU General Public License 17c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak * along with this program; if not, write to the Free Software 184548c6cf9bcdd96d8303caa4130ab638b61f8a30Wanlong Gao * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak */ 20c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 21c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak/* Porting from Crackerjack to LTP is done 22c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak by Masatake YAMATO <yamato@redhat.com> */ 23c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 245271b00a7cb41ae0b2ceb6de3aa752afceb15737Petr Vorel#include <errno.h> 255271b00a7cb41ae0b2ceb6de3aa752afceb15737Petr Vorel#include <string.h> 265271b00a7cb41ae0b2ceb6de3aa752afceb15737Petr Vorel 2779cefc1dfd157fae7903709bf4b7dce00bee343fsubrata_modak#include "config.h" 28c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak#include "test.h" 29c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 30d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubischar *TCID = "io_setup01"; 31c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 3218dc0c2e1682ab0e22c4121ca46ccea1ed5840d3subrata_modakint TST_TOTAL = 4; 33c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 345271b00a7cb41ae0b2ceb6de3aa752afceb15737Petr Vorel#ifdef HAVE_LIBAIO 3579cefc1dfd157fae7903709bf4b7dce00bee343fsubrata_modak#include <libaio.h> 3679cefc1dfd157fae7903709bf4b7dce00bee343fsubrata_modak 37d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubisstatic void cleanup(void) 38c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak{ 39c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak} 40c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 41d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubisstatic void setup(void) 42c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak{ 4356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak tst_sig(NOFORK, DEF_HANDLER, cleanup); 44c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 4556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak TEST_PAUSE; 462c28215423293e443469a07ae7011135d058b671Garrett Cooper} 47c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 48d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis/* 49d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis DESCRIPTION 50d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis io_setup creates an asynchronous I/O context capable of receiving at 51d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis least nr_events. ctxp must not point to an AIO context that already 52d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis exists, and must be initialized to 0 prior to the call. On successful 53d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis creation of the AIO context, *ctxp is filled in with the resulting 54d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis handle. 55d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis */ 56d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubisint main(int argc, char *argv[]) 57c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak{ 58d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis int lc; 59c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 60d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis io_context_t ctx; 61c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak int expected_return; 62bdbaec51a423e715c2b03ed9e497e9a1fba6103esubrata_modak 63d6d11d08678aac1ed2c370ea8e42e5f45aea07beCyril Hrubis tst_parse_opts(argc, argv, NULL, NULL); 64c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 65c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak setup(); 66c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 67c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak for (lc = 0; TEST_LOOPING(lc); lc++) { 68d59a659cd639ca2780b00049d102acd2a783d585Caspar Zhang tst_count = 0; 69c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 70d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis memset(&ctx, 0, sizeof(ctx)); 71c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak expected_return = 0; 7256207cec7732e09c216c751c0b5f88a242bacae6subrata_modak TEST(io_setup(1, &ctx)); 73c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 74c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak if (TEST_RETURN == expected_return) { 75c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak tst_resm(TPASS, "call succeeded expectedly"); 7656207cec7732e09c216c751c0b5f88a242bacae6subrata_modak io_destroy(ctx); 77c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } else { 78358c3ee75ca13279ceb0165ef0351e99be271ee6subrata_modak tst_resm(TFAIL, "unexpected returned value - %ld - " 7956207cec7732e09c216c751c0b5f88a242bacae6subrata_modak "expected %d", TEST_RETURN, expected_return); 80c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } 8156207cec7732e09c216c751c0b5f88a242bacae6subrata_modak 82d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis memset(&ctx, 1, sizeof(ctx)); 83c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak expected_return = -EINVAL; 8456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak TEST(io_setup(1, &ctx)); 85c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 86c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak if (TEST_RETURN == 0) { 87c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak tst_resm(TFAIL, "call succeeded unexpectedly"); 8856207cec7732e09c216c751c0b5f88a242bacae6subrata_modak io_destroy(ctx); 89c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } else if (TEST_RETURN == expected_return) { 90c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak tst_resm(TPASS, "expected failure - " 91358c3ee75ca13279ceb0165ef0351e99be271ee6subrata_modak "returned value = %ld : %s", TEST_RETURN, 92c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak strerror(-1 * TEST_RETURN)); 93c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } else { 94358c3ee75ca13279ceb0165ef0351e99be271ee6subrata_modak tst_resm(TFAIL, "unexpected returned value - %ld - " 9556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak "expected %d", TEST_RETURN, expected_return); 96c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } 97c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 98d8a90be180f7201a34ef81afc9b779b3c3256fc2Cyril Hrubis memset(&ctx, 0, sizeof(ctx)); 99c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak expected_return = -EINVAL; 10056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak TEST(io_setup(-1, &ctx)); 101c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak if (TEST_RETURN == 0) { 102c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak tst_resm(TFAIL, "call succeeded unexpectedly"); 10356207cec7732e09c216c751c0b5f88a242bacae6subrata_modak io_destroy(ctx); 104c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } else if (TEST_RETURN == expected_return) { 105c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak tst_resm(TPASS, "expected failure - " 106358c3ee75ca13279ceb0165ef0351e99be271ee6subrata_modak "returned value = %ld : %s", TEST_RETURN, 107c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak strerror(-1 * TEST_RETURN)); 108c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } else { 109358c3ee75ca13279ceb0165ef0351e99be271ee6subrata_modak tst_resm(TFAIL, "unexpected returned value - %ld - " 11056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak "expected %d", TEST_RETURN, expected_return); 111c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } 112c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 113c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak /* 11456207cec7732e09c216c751c0b5f88a242bacae6subrata_modak EFAULT An invalid pointer is passed for ctxp. 11556207cec7732e09c216c751c0b5f88a242bacae6subrata_modak */ 116c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak expected_return = -EFAULT; 11756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak TEST(io_setup(1, NULL)); 118c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak if (TEST_RETURN == 0) { 119c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak tst_resm(TFAIL, "call succeeded unexpectedly"); 12056207cec7732e09c216c751c0b5f88a242bacae6subrata_modak io_destroy(ctx); 121c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } else if (TEST_RETURN == expected_return) { 122c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak tst_resm(TPASS, "expected failure - " 123358c3ee75ca13279ceb0165ef0351e99be271ee6subrata_modak "returned value = %ld : %s", TEST_RETURN, 124c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak strerror(-1 * TEST_RETURN)); 125c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } else { 126358c3ee75ca13279ceb0165ef0351e99be271ee6subrata_modak tst_resm(TFAIL, "unexpected returned value - %ld - " 12756207cec7732e09c216c751c0b5f88a242bacae6subrata_modak "expected %d", TEST_RETURN, expected_return); 128c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } 129c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 130c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak } 131c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak cleanup(); 132c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak 1332c28215423293e443469a07ae7011135d058b671Garrett Cooper tst_exit(); 134c5792c959060d847f6706b253b0e7ad1f60200ccsubrata_modak} 1355271b00a7cb41ae0b2ceb6de3aa752afceb15737Petr Vorel 13679cefc1dfd157fae7903709bf4b7dce00bee343fsubrata_modak#else 1375271b00a7cb41ae0b2ceb6de3aa752afceb15737Petr Vorelint main(void) 13879cefc1dfd157fae7903709bf4b7dce00bee343fsubrata_modak{ 1395271b00a7cb41ae0b2ceb6de3aa752afceb15737Petr Vorel tst_brkm(TCONF, NULL, "test requires libaio and it's development packages"); 14079cefc1dfd157fae7903709bf4b7dce00bee343fsubrata_modak} 14154587dd1be6024368e9c77ebdef7f06ec2cef5edGarrett Cooper#endif 142