1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00
* rt/tst-aio.c: Add test for aio_read and lio_listio.

	* rt/lio_listio.c: Correct total counter handling.

	* rt/aio_misc.c (handle_fildes_io): Correctly dequeue elements
	from request queue.

	* test-skeleton.c (main): Make stdout unbuffered.  Improve message
	of signal on exit even more.
This commit is contained in:
Ulrich Drepper
1998-04-11 20:19:13 +00:00
parent 18de8c733f
commit 6b9c2e671c
5 changed files with 83 additions and 25 deletions

View File

@ -1,5 +1,15 @@
1998-04-11 Ulrich Drepper <drepper@cygnus.com> 1998-04-11 Ulrich Drepper <drepper@cygnus.com>
* rt/tst-aio.c: Add test for aio_read and lio_listio.
* rt/lio_listio.c: Correct total counter handling.
* rt/aio_misc.c (handle_fildes_io): Correctly dequeue elements
from request queue.
* test-skeleton.c (main): Make stdout unbuffered. Improve message
of signal on exit even more.
* rt/aio_suspend.c (aio_suspend): Use PTHREAD_COND_INITIALIZER * rt/aio_suspend.c (aio_suspend): Use PTHREAD_COND_INITIALIZER
instead of call to pthread_cond_init. instead of call to pthread_cond_init.
* rt/lio_listio.c (lio_listio): Likewise. * rt/lio_listio.c (lio_listio): Likewise.

View File

@ -476,6 +476,8 @@ handle_fildes_io (void *arg)
runp->next_fd->last_fd = runp->last_fd; runp->next_fd->last_fd = runp->last_fd;
if (runp->last_fd != NULL) if (runp->last_fd != NULL)
runp->last_fd->next_fd = runp->next_fd; runp->last_fd->next_fd = runp->next_fd;
else
requests = runp->next_fd;
} }
else else
{ {
@ -486,6 +488,8 @@ handle_fildes_io (void *arg)
runp->next_fd->last_fd = runp->next_prio; runp->next_fd->last_fd = runp->next_prio;
if (runp->last_fd != NULL) if (runp->last_fd != NULL)
runp->last_fd->next_fd = runp->next_prio; runp->last_fd->next_fd = runp->next_prio;
else
requests = runp->next_prio;
} }
/* Free the old element. */ /* Free the old element. */

View File

@ -93,7 +93,7 @@ lio_listio (mode, list, nent, sig)
{ {
waitlist[cnt].cond = &cond; waitlist[cnt].cond = &cond;
waitlist[cnt].next = requests[cnt]->waiting; waitlist[cnt].next = requests[cnt]->waiting;
waitlist[cnt].counterp = NULL; waitlist[cnt].counterp = &total;
waitlist[cnt].sigevp = NULL; waitlist[cnt].sigevp = NULL;
requests[cnt]->waiting = &waitlist[cnt]; requests[cnt]->waiting = &waitlist[cnt];
++total; ++total;
@ -105,8 +105,7 @@ lio_listio (mode, list, nent, sig)
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate); pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &oldstate);
while (total > 0) while (total > 0)
if (pthread_cond_wait (&cond, &__aio_requests_mutex) == 0) pthread_cond_wait (&cond, &__aio_requests_mutex);
--total;
/* Now it's time to restore the cancelation state. */ /* Now it's time to restore the cancelation state. */
pthread_setcancelstate (oldstate, NULL); pthread_setcancelstate (oldstate, NULL);

View File

@ -69,16 +69,32 @@ test_file (const void *buf, size_t size, int fd, const char *msg)
return 1; return 1;
} }
if (ftruncate (fd, 0) < 0) printf ("%s test ok\n", msg);
{
error (0, errno, "%s: failed truncate", msg);
return 1;
}
return 0; return 0;
} }
void
do_wait (struct aiocb **cbp, size_t nent)
{
int go_on;
do
{
size_t cnt;
aio_suspend ((const struct aiocb *const *) cbp, nent, NULL);
go_on = 0;
for (cnt = 0; cnt < nent; ++cnt)
if (cbp[cnt] != NULL && aio_error (cbp[cnt]) == EINPROGRESS)
go_on = 1;
else
cbp[cnt] = NULL;
}
while (go_on);
}
int int
do_test (int argc, char *argv[]) do_test (int argc, char *argv[])
{ {
@ -90,7 +106,6 @@ do_test (int argc, char *argv[])
size_t cnt; size_t cnt;
int fd; int fd;
int result = 0; int result = 0;
int go_on;
name_len = strlen (test_dir); name_len = strlen (test_dir);
name = malloc (name_len + sizeof ("/aioXXXXXX")); name = malloc (name_len + sizeof ("/aioXXXXXX"));
@ -120,23 +135,50 @@ do_test (int argc, char *argv[])
for (cnt = 10; cnt > 0; ) for (cnt = 10; cnt > 0; )
aio_write (cbp[--cnt]); aio_write (cbp[--cnt]);
/* Wait 'til the results are there. */ /* Wait 'til the results are there. */
do do_wait (cbp, 10);
{
aio_suspend ((const struct aiocb *const *) cbp, 10, NULL);
go_on = 0;
for (cnt = 0; cnt < 10; ++cnt)
if (cbp[cnt] != NULL && aio_error (cbp[cnt]) == EINPROGRESS)
go_on = 1;
else
{
if (cbp[cnt] != NULL)
printf ("request %d finished\n", cnt);
cbp[cnt] = NULL;
}
}
while (go_on);
/* Test this. */ /* Test this. */
result |= test_file (buf, sizeof (buf), fd, "aio_write"); result |= test_file (buf, sizeof (buf), fd, "aio_write");
/* Read now as we've written it. */
memset (buf, '\0', sizeof (buf));
/* Issue the commands. */
for (cnt = 10; cnt > 0; )
{
--cnt;
cbp[cnt] = &cbs[cnt];
aio_read (cbp[cnt]);
}
/* Wait 'til the results are there. */
do_wait (cbp, 10);
/* Test this. */
for (cnt = 0; cnt < 1000; ++cnt)
if (buf[cnt] != '0' + (cnt / 100))
{
result = 1;
error (0, 0, "comparison failed for aio_read test");
break;
}
if (cnt == 1000)
puts ("aio_read test ok");
/* Remove the test file contents. */
if (ftruncate (fd, 0) < 0)
{
error (0, errno, "ftruncate failed\n");
result = 1;
}
/* Test lio_listio. */
for (cnt = 0; cnt < 10; ++cnt)
{
cbs[cnt].aio_lio_opcode = LIO_WRITE;
cbp[cnt] = &cbs[cnt];
}
/* Issue the command. */
lio_listio (LIO_WAIT, cbp, 10, NULL);
/* ...and immediately test it since we started it in wait mode. */
result |= test_file (buf, sizeof (buf), fd, "lio_listio (write)");
return result; return result;
} }

View File

@ -155,6 +155,9 @@ main (int argc, char *argv[])
test_dir = "/tmp"; test_dir = "/tmp";
} }
/* Make sure we see all message, even those on stdout. */
setvbuf (stdout, NULL, _IONBF, 0);
/* If we are not expected to fork run the function immediately. */ /* If we are not expected to fork run the function immediately. */
if (direct) if (direct)
return TEST_FUNCTION; return TEST_FUNCTION;
@ -213,7 +216,7 @@ main (int argc, char *argv[])
fprintf (stderr, "Incorrect signal from child: got `%s', need `%s'\n", fprintf (stderr, "Incorrect signal from child: got `%s', need `%s'\n",
strsignal (WTERMSIG (status)), strsignal (EXPECTED_SIGNAL)); strsignal (WTERMSIG (status)), strsignal (EXPECTED_SIGNAL));
else else
fprintf (stderr, "Incorrect signal from child: got `%s'\n", fprintf (stderr, "Didn't expect signal from child: got `%s'\n",
strsignal (WTERMSIG (status))); strsignal (WTERMSIG (status)));
exit (1); exit (1);
} }