* sysdeps/m68k/dl-machine.h (RTLD_START): Readd _dl_start_user
[glibc/pb-stable.git] / rt / tst-aio64.c
blob60db0dd1aaa0f5cf72df8545e96b037781027fee
1 /* Tests for 64bit AIO in librt.
2 Copyright (C) 1998, 1999 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. */
20 #define _LARGEFILE_SOURCE 1
21 #include <aio.h>
22 #include <errno.h>
23 #include <error.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <unistd.h>
27 #include <sys/stat.h>
30 /* Prototype for our test function. */
31 extern void do_prepare (int argc, char *argv[]);
32 extern int do_test (int argc, char *argv[]);
34 /* We have a preparation function. */
35 #define PREPARE do_prepare
37 /* We might need a bit longer timeout. */
38 #define TIMEOUT 20 /* sec */
40 /* This defines the `main' function and some more. */
41 #include <test-skeleton.c>
44 /* These are for the temporary file we generate. */
45 char *name;
46 int fd;
48 void
49 do_prepare (int argc, char *argv[])
51 char name_len;
53 name_len = strlen (test_dir);
54 name = malloc (name_len + sizeof ("/aioXXXXXX"));
55 mempcpy (mempcpy (name, test_dir, name_len),
56 "/aioXXXXXX", sizeof ("/aioXXXXXX"));
57 add_temp_file (name);
59 /* Open our test file. */
60 fd = mkstemp (name);
61 if (fd == -1)
62 error (EXIT_FAILURE, errno, "cannot open test file `%s'", name);
66 int
67 test_file (const void *buf, size_t size, int fd, const char *msg)
69 struct stat st;
70 char tmp[size];
72 errno = 0;
73 if (fstat (fd, &st) < 0)
75 error (0, errno, "%s: failed stat", msg);
76 return 1;
79 if (st.st_size != size)
81 error (0, errno, "%s: wrong size: %lu, should be %lu",
82 msg, (unsigned long int) st.st_size, (unsigned long int) size);
83 return 1;
86 if (pread (fd, tmp, size, 0) != size)
88 error (0, errno, "%s: failed stat", msg);
89 return 1;
92 if (memcmp (buf, tmp, size) != 0)
94 error (0, errno, "%s: failed comparison", msg);
95 return 1;
98 printf ("%s test ok\n", msg);
100 return 0;
104 void
105 do_wait (struct aiocb64 **cbp, size_t nent)
107 int go_on;
110 size_t cnt;
112 aio_suspend64 ((const struct aiocb64 *const *) cbp, nent, NULL);
113 go_on = 0;
114 for (cnt = 0; cnt < nent; ++cnt)
115 if (cbp[cnt] != NULL && aio_error64 (cbp[cnt]) == EINPROGRESS)
116 go_on = 1;
117 else
118 cbp[cnt] = NULL;
120 while (go_on);
125 do_test (int argc, char *argv[])
127 struct aiocb64 cbs[10];
128 struct aiocb64 *cbp[10];
129 char buf[1000];
130 size_t cnt;
131 int result = 0;
133 /* Preparation. */
134 for (cnt = 0; cnt < 10; ++cnt)
136 cbs[cnt].aio_fildes = fd;
137 cbs[cnt].aio_reqprio = 0;
138 cbs[cnt].aio_buf = memset (&buf[cnt * 100], '0' + cnt, 100);
139 cbs[cnt].aio_nbytes = 100;
140 cbs[cnt].aio_offset = cnt * 100;
141 cbs[cnt].aio_sigevent.sigev_notify = SIGEV_NONE;
143 cbp[cnt] = &cbs[cnt];
146 /* First a simple test. */
147 for (cnt = 10; cnt > 0; )
148 aio_write64 (cbp[--cnt]);
149 /* Wait 'til the results are there. */
150 do_wait (cbp, 10);
151 /* Test this. */
152 result |= test_file (buf, sizeof (buf), fd, "aio_write");
154 /* Read now as we've written it. */
155 memset (buf, '\0', sizeof (buf));
156 /* Issue the commands. */
157 for (cnt = 10; cnt > 0; )
159 --cnt;
160 cbp[cnt] = &cbs[cnt];
161 aio_read64 (cbp[cnt]);
163 /* Wait 'til the results are there. */
164 do_wait (cbp, 10);
165 /* Test this. */
166 for (cnt = 0; cnt < 1000; ++cnt)
167 if (buf[cnt] != '0' + (cnt / 100))
169 result = 1;
170 error (0, 0, "comparison failed for aio_read test");
171 break;
174 if (cnt == 1000)
175 puts ("aio_read test ok");
177 /* Remove the test file contents. */
178 if (ftruncate64 (fd, 0) < 0)
180 error (0, errno, "ftruncate failed\n");
181 result = 1;
184 /* Test lio_listio. */
185 for (cnt = 0; cnt < 10; ++cnt)
187 cbs[cnt].aio_lio_opcode = LIO_WRITE;
188 cbp[cnt] = &cbs[cnt];
190 /* Issue the command. */
191 lio_listio64 (LIO_WAIT, cbp, 10, NULL);
192 /* ...and immediately test it since we started it in wait mode. */
193 result |= test_file (buf, sizeof (buf), fd, "lio_listio (write)");
195 return result;