]>
git.ipfire.org Git - thirdparty/glibc.git/blob - rt/tst-aio.c
83833ee117ba0571c97f7f19c7f7906968664983
1 /* Tests for AIO in librt.
2 Copyright (C) 1998 Free Software Foundation, Inc.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
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.
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.
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. */
29 /* prototype for our test function. */
30 extern int do_test (int argc
, char *argv
[]);
33 /* We might need a bit longer timeout. */
34 #define TIMEOUT 20 /* sec */
36 /* This defines the `main' function and some more. */
37 #include <test-skeleton.c>
41 test_file (const void *buf
, size_t size
, int fd
, const char *msg
)
47 if (fstat (fd
, &st
) < 0)
49 error (0, errno
, "%s: failed stat", msg
);
53 if (st
.st_size
!= size
)
55 error (0, errno
, "%s: wrong size: %lu, should be %lu",
56 msg
, (unsigned long int) st
.st_size
, (unsigned long int) size
);
60 if (pread (fd
, tmp
, size
, 0) != size
)
62 error (0, errno
, "%s: failed stat", msg
);
66 if (memcmp (buf
, tmp
, size
) != 0)
68 error (0, errno
, "%s: failed comparison", msg
);
72 printf ("%s test ok\n", msg
);
79 do_wait (struct aiocb
**cbp
, size_t nent
)
86 aio_suspend ((const struct aiocb
*const *) cbp
, nent
, NULL
);
88 for (cnt
= 0; cnt
< nent
; ++cnt
)
89 if (cbp
[cnt
] != NULL
&& aio_error (cbp
[cnt
]) == EINPROGRESS
)
99 do_test (int argc
, char *argv
[])
103 struct aiocb cbs
[10];
104 struct aiocb
*cbp
[10];
110 name_len
= strlen (test_dir
);
111 name
= malloc (name_len
+ sizeof ("/aioXXXXXX"));
112 mempcpy (mempcpy (name
, test_dir
, name_len
),
113 "/aioXXXXXX", sizeof ("/aioXXXXXX"));
114 add_temp_file (name
);
116 /* Open our test file. */
119 error (EXIT_FAILURE
, errno
, "cannot open test file `%s'", name
);
122 for (cnt
= 0; cnt
< 10; ++cnt
)
124 cbs
[cnt
].aio_fildes
= fd
;
125 cbs
[cnt
].aio_reqprio
= 0;
126 cbs
[cnt
].aio_buf
= memset (&buf
[cnt
* 100], '0' + cnt
, 100);
127 cbs
[cnt
].aio_nbytes
= 100;
128 cbs
[cnt
].aio_offset
= cnt
* 100;
129 cbs
[cnt
].aio_sigevent
.sigev_notify
= SIGEV_NONE
;
131 cbp
[cnt
] = &cbs
[cnt
];
134 /* First a simple test. */
135 for (cnt
= 10; cnt
> 0; )
136 aio_write (cbp
[--cnt
]);
137 /* Wait 'til the results are there. */
140 result
|= test_file (buf
, sizeof (buf
), fd
, "aio_write");
142 /* Read now as we've written it. */
143 memset (buf
, '\0', sizeof (buf
));
144 /* Issue the commands. */
145 for (cnt
= 10; cnt
> 0; )
148 cbp
[cnt
] = &cbs
[cnt
];
151 /* Wait 'til the results are there. */
154 for (cnt
= 0; cnt
< 1000; ++cnt
)
155 if (buf
[cnt
] != '0' + (cnt
/ 100))
158 error (0, 0, "comparison failed for aio_read test");
163 puts ("aio_read test ok");
165 /* Remove the test file contents. */
166 if (ftruncate (fd
, 0) < 0)
168 error (0, errno
, "ftruncate failed\n");
172 /* Test lio_listio. */
173 for (cnt
= 0; cnt
< 10; ++cnt
)
175 cbs
[cnt
].aio_lio_opcode
= LIO_WRITE
;
176 cbp
[cnt
] = &cbs
[cnt
];
178 /* Issue the command. */
179 lio_listio (LIO_WAIT
, cbp
, 10, NULL
);
180 /* ...and immediately test it since we started it in wait mode. */
181 result
|= test_file (buf
, sizeof (buf
), fd
, "lio_listio (write)");