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_getevents01"; |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 28 | |
| 29 | int TST_TOTAL = 1; |
| 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_getevents attempts to read at least min_nr events and up to nr |
| 50 | events from the completion queue of the AIO context specified by |
| 51 | ctx_id. timeout specifies the amount of time to wait for events, |
| 52 | where a NULL timeout waits until at least min_nr events have been |
| 53 | seen. Note that timeout is relative and will be updated if not NULL |
| 54 | and the operation blocks. |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 55 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 56 | RETURN VALUE |
| 57 | io_getevents returns the number of events read: 0 if no events are |
| 58 | available or < min_nr if the timeout has elapsed. |
| 59 | |
| 60 | ERRORS |
| 61 | EINVAL ctx_id is invalid. min_nr is out of range or nr is out of |
| 62 | range. |
| 63 | */ |
| 64 | |
| 65 | #define EXP_RET (-EINVAL) |
| 66 | |
| 67 | int main(int argc, char *argv[]) |
| 68 | { |
| 69 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 70 | const char *msg; |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 71 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 72 | io_context_t ctx; |
| 73 | |
| 74 | memset(&ctx, 0, sizeof(ctx)); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 75 | |
Garrett Cooper | 54587dd | 2010-12-21 11:37:16 -0800 | [diff] [blame] | 76 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 77 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 78 | |
| 79 | setup(); |
| 80 | |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 81 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 82 | tst_count = 0; |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 83 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 84 | TEST(io_getevents(ctx, 0, 0, NULL, NULL)); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 85 | |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 86 | switch (TEST_RETURN) { |
| 87 | case 0: |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 88 | tst_resm(TFAIL, "call succeeded unexpectedly"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 89 | break; |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 90 | case EXP_RET: |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 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, |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 93 | strerror(-TEST_RETURN)); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 94 | break; |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 95 | case -ENOSYS: |
| 96 | tst_resm(TCONF, "io_cancel returned ENOSYS"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 97 | break; |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 98 | default: |
| 99 | tst_resm(TFAIL, "unexpected returned value - %s (%i) - " |
| 100 | "expected %s (%i)", strerror(-TEST_RETURN), |
| 101 | (int)TEST_RETURN, strerror(-EXP_RET), EXP_RET); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 102 | break; |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 103 | } |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 104 | } |
Chris Dearman | 37550cf | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 105 | |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 106 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 107 | tst_exit(); |
subrata_modak | c5792c9 | 2008-07-11 20:21:42 +0000 | [diff] [blame] | 108 | } |
subrata_modak | 79cefc1 | 2009-01-20 10:48:41 +0000 | [diff] [blame] | 109 | #else |
Cyril Hrubis | d8a90be | 2011-03-16 18:13:38 +0100 | [diff] [blame] | 110 | int main(int argc, char *argv[]) |
subrata_modak | 79cefc1 | 2009-01-20 10:48:41 +0000 | [diff] [blame] | 111 | { |
Garrett Cooper | 54587dd | 2010-12-21 11:37:16 -0800 | [diff] [blame] | 112 | tst_brkm(TCONF, NULL, "System doesn't support execution of the test"); |
subrata_modak | 79cefc1 | 2009-01-20 10:48:41 +0000 | [diff] [blame] | 113 | } |
Garrett Cooper | 54587dd | 2010-12-21 11:37:16 -0800 | [diff] [blame] | 114 | #endif |