From: Cyril H. <su...@li...> - 2011-11-16 16:34:47
|
The branch, master, has been updated via a084875df76c68bbe2e7fc1925094672d2517df7 (commit) via 7a0726ca51d2ba3a4ba068f6cc1833486f44304c (commit) from 0761d86885ff17949ceb5ad105795fc350ccb15a (commit) - Log ----------------------------------------------------------------- commit a084875df76c68bbe2e7fc1925094672d2517df7 Author: Cyril Hrubis <ch...@su...> Date: Wed Nov 16 17:29:40 2011 +0100 aio_cancel/7-1: clean up the code Signed-off-by: Cyril Hrubis <ch...@su...> commit 7a0726ca51d2ba3a4ba068f6cc1833486f44304c Author: Peng Haitao <pe...@cn...> Date: Mon Sep 5 09:25:53 2011 +0800 aio_cancel/7-1: fix fail occasionally due to aio_error() returns EBADF Change the code to close the fd after the aio operation and also close the fd in all codepaths. Signed-off-by: Peng Haitao <pe...@cn...> ----------------------------------------------------------------------- Summary of changes: .../conformance/interfaces/aio_cancel/7-1.c | 72 +++++++++---------- 1 files changed, 34 insertions(+), 38 deletions(-) diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c index c37f184..ad094db 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_cancel/7-1.c @@ -43,7 +43,7 @@ #define BUF_NB 128 #define BUF_SIZE 1024 -int main() +int main(void) { char tmpfname[256]; int fd; @@ -60,8 +60,7 @@ int main() unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); - if (fd == -1) - { + if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); return PTS_UNRESOLVED; @@ -70,32 +69,34 @@ int main() unlink(tmpfname); /* create AIO req */ - - for (i = 0; i < BUF_NB; i++) - { + for (i = 0; i < BUF_NB; i++) { aiocb[i] = malloc(sizeof(struct aiocb)); - if (aiocb[i] == NULL) - { + + if (aiocb[i] == NULL) { printf(TNAME " Error at malloc(): %s\n", strerror(errno)); + close(fd); return PTS_UNRESOLVED; } + aiocb[i]->aio_fildes = fd; aiocb[i]->aio_buf = malloc(BUF_SIZE); - if (aiocb[i]->aio_buf == NULL) - { + + if (aiocb[i]->aio_buf == NULL) { printf(TNAME " Error at malloc(): %s\n", strerror(errno)); + close(fd); return PTS_UNRESOLVED; } + aiocb[i]->aio_nbytes = BUF_SIZE; aiocb[i]->aio_offset = 0; aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE; - if (aio_write(aiocb[i]) == -1) - { + if (aio_write(aiocb[i]) == -1) { printf(TNAME " loop %d: Error at aio_write(): %s\n", i, strerror(errno)); + close(fd); return PTS_FAIL; } } @@ -103,63 +104,58 @@ int main() /* try to cancel all * we hope to have enough time to cancel at least one */ - gret = aio_cancel(fd, NULL); - if (gret == -1) - { + if (gret == -1) { printf(TNAME " Error at aio_cancel(): %s\n", strerror(errno)); + close(fd); return PTS_FAIL; } - close(fd); - do { in_progress = 0; - for (i = 0; i < BUF_NB; i++) - { - int ret; - - ret = (aio_error(aiocb[i])); + for (i = 0; i < BUF_NB; i++) { + int ret = aio_error(aiocb[i]); - if (ret == -1) - { + switch (ret) { + case -1: printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); + close(fd); return PTS_FAIL; - } - else if (ret == EINPROGRESS) - { + break; + case EINPROGRESS: /* at this point, all operations should be: * canceled * or in progress * with aio_cancel() == AIO_NOTCANCELED */ - - if (gret != AIO_NOTCANCELED) - { - printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); + if (gret != AIO_NOTCANCELED) { + printf(TNAME " Error at aio_error(): %s\n", + strerror(errno)); + close(fd); return PTS_FAIL; } in_progress = 1; - } - else if (ret == 0) - { + break; + case 0: /* we seek one not canceled and check why. * (perhaps) it has not been canceled * because it was in progress * during the cancel operation */ - - if (gret == AIO_NOTCANCELED) - { + if (gret == AIO_NOTCANCELED) { printf ("Test PASSED\n"); + close(fd); return PTS_PASS; } + break; } } } while (in_progress); + close(fd); + return PTS_UNRESOLVED; -} \ No newline at end of file +} hooks/post-receive -- ltp |