]> git.ipfire.org Git - thirdparty/glibc.git/blame - rt/tst-aio6.c
Test for timeout with aio_suspend.
[thirdparty/glibc.git] / rt / tst-aio6.c
CommitLineData
a95d1236
UD
1/* Test for timeout handling.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20#include <aio.h>
21#include <errno.h>
22#include <stdio.h>
23#include <unistd.h>
24#include <sys/time.h>
25
26
27/* We expect to wait for 3 seconds so we have to increase the timeout. */
28#define TIMEOUT 10 /* sec */
29
30
31#define TEST_FUNCTION do_test ()
32int
33do_test (void)
34{
35 struct aiocb *arr[1];
36 struct aiocb cb;
37 char buf[100];
38 struct timeval before;
39 struct timeval after;
40 struct timespec timeout;
41 int result = 0;
42
43 arr[0] = &cb;
44
45 cb.aio_fildes = STDIN_FILENO;
46 cb.aio_lio_opcode = LIO_WRITE;
47 cb.aio_reqprio = 0;
48 cb.aio_buf = (void *) buf;
49 cb.aio_nbytes = sizeof (buf) - 1;
50 cb.aio_sigevent.sigev_notify = SIGEV_NONE;
51
52 /* Try to read from stdin where nothing will be available. */
53 if (aio_read (arr[0]) < 0)
54 {
55 printf ("aio_write failed: %m\n");
56 return 1;
57 }
58
59 /* Get the current time. */
60 gettimeofday (&before, NULL);
61
62 /* Wait for input which is unsuccess and therefore the function will
63 time out. */
64 timeout.tv_sec = 3;
65 timeout.tv_nsec = 0;
66 if (aio_suspend ((const struct aiocb *const*) arr, 1, &timeout) != -1)
67 {
68 puts ("aio_suspend() didn't return -1");
69 result = 1;
70 }
71 else if (errno != EAGAIN)
72 {
73 puts ("error not set to EAGAIN");
74 result = 1;
75 }
76 else
77 {
78 gettimeofday (&after, NULL);
79 if (after.tv_sec < before.tv_sec + 1)
80 {
81 puts ("timeout came too early");
82 result = 1;
83 }
84 }
85
86 return result;
87}
88
89#include "../test-skeleton.c"