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
30char *TCID = "io_getevents01";
31int TST_TOTAL = 1;
32
33#ifdef HAVE_LIBAIO
34#include <libaio.h>
35
36static void cleanup(void)
37{
38}
39
40static void setup(void)
41{
42	tst_sig(NOFORK, DEF_HANDLER, cleanup);
43
44	TEST_PAUSE;
45}
46
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.
55
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
67int main(int argc, char *argv[])
68{
69	int lc;
70
71	io_context_t ctx;
72
73	memset(&ctx, 0, sizeof(ctx));
74
75	tst_parse_opts(argc, argv, NULL, NULL);
76
77	setup();
78
79	for (lc = 0; TEST_LOOPING(lc); lc++) {
80		tst_count = 0;
81
82		TEST(io_getevents(ctx, 0, 0, NULL, NULL));
83
84		switch (TEST_RETURN) {
85		case 0:
86			tst_resm(TFAIL, "call succeeded unexpectedly");
87			break;
88		case EXP_RET:
89			tst_resm(TPASS, "expected failure - "
90				 "returned value = %ld : %s", TEST_RETURN,
91				 strerror(-TEST_RETURN));
92			break;
93		case -ENOSYS:
94			tst_resm(TCONF, "io_cancel returned ENOSYS");
95			break;
96		default:
97			tst_resm(TFAIL, "unexpected returned value - %s (%i) - "
98				 "expected %s (%i)", strerror(-TEST_RETURN),
99				 (int)TEST_RETURN, strerror(-EXP_RET), EXP_RET);
100			break;
101		}
102	}
103
104	cleanup();
105	tst_exit();
106}
107
108#else
109int main(void)
110{
111	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
112}
113#endif
114