From: Cyril H. <su...@li...> - 2013-04-02 18:21:23
|
The branch, master, has been updated via 03680e04310ea3cea4cab18c62fdf86b30127c40 (commit) via 261e997abb5e29b85038fcc3ea21d2a6d4b4a520 (commit) via 07700becb55f19298a3c90c88ad56bf6b8ee9c09 (commit) from cbec02d252c8032c5c585f55af0854a2200b1d65 (commit) - Log ----------------------------------------------------------------- commit 03680e04310ea3cea4cab18c62fdf86b30127c40 Author: Cyril Hrubis <ch...@su...> Date: Tue Apr 2 19:17:42 2013 +0200 open_posix_testsuite/.../lio_listio/11-1.c: Remove. The testcase is invalid as POSIX doesn't define what 'successfully queued' means. On Linux (with glibc) 'successfully queued' means that the operation was added to the list of aio requests to be dealt with later which is in accordance with POSIX which request the lio_listio() with mode LIO_NOWAIT to return immediately when the requests are queued. Signed-off-by: Cyril Hrubis <ch...@su...> commit 261e997abb5e29b85038fcc3ea21d2a6d4b4a520 Author: Cyril Hrubis <ch...@su...> Date: Tue Apr 2 15:36:59 2013 +0200 open_posix_testsuite/.../aio_suspend/9-1.c Fix the testcase to adjust aio request sizes as runtime. This testcase fails on machines that are fast enough to complete the hardcoded request size before we get to the aio_suspend(). This patch changes the testcase to do several tries with increasing buffer sizes in order to cover both small embedded systems and large mainframes. There were several race conditions in the original code that had to be fixed in order to be able to run the test repeatedly. Signed-off-by: Cyril Hrubis <ch...@su...> commit 07700becb55f19298a3c90c88ad56bf6b8ee9c09 Author: Cyril Hrubis <ch...@su...> Date: Tue Apr 2 17:30:33 2013 +0200 open_posix_testsuite/.../aio_suspend/7-1.c: Remove. Remove the 7-1.c test which is nearly identical to 9-1.c. Signed-off-by: Cyril Hrubis <ch...@su...> ----------------------------------------------------------------------- Summary of changes: .../conformance/interfaces/aio_suspend/7-1.c | 220 -------------------- .../conformance/interfaces/aio_suspend/9-1.c | 176 ++++++++-------- .../conformance/interfaces/lio_listio/11-1.c | 184 ---------------- 3 files changed, 92 insertions(+), 488 deletions(-) delete mode 100644 testcases/open_posix_testsuite/conformance/interfaces/aio_suspend/7-1.c delete mode 100644 testcases/open_posix_testsuite/conformance/interfaces/lio_listio/11-1.c diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_suspend/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_suspend/7-1.c deleted file mode 100644 index e9e14a5..0000000 --- a/testcases/open_posix_testsuite/conformance/interfaces/aio_suspend/7-1.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2004, Bull SA. All rights reserved. - * Created by: Lau...@bu... - * This file is licensed under the GPL license. For the full content - * of this license, see the COPYING file at the top level of this - * source tree. - */ - -/* - * assertion: - * - * aio_suspend() shall return the value -1 and set errno to indicate error - * if it returns before at least one AIO operation have completed. - * - * method: Testing for a non NULL timeout - * - * - write to a file - * - submit a list of read requests - * - check that the selected request has not completed - * - suspend on selected request - * - check that the suspend timed out - * - check that aio_suspend returns -1 and errno is set to EAGAIN - */ - -#define _XOPEN_SOURCE 600 -#include <sys/stat.h> -#include <aio.h> -#include <errno.h> -#include <fcntl.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "posixtest.h" - -#define TNAME "aio_suspend/7-1.c" - -#define NUM_AIOCBS 10 -#define BUF_SIZE (1024*1024) -#define WAIT_FOR_AIOCB 6 - -static int received_all; - -static void sigrt1_handler(int signum, siginfo_t *info, void *context) -{ - received_all = 1; -} - -int main(void) -{ - char tmpfname[256]; - int fd; - - struct aiocb **aiocbs; - struct aiocb *plist[2]; - char *bufs; - struct sigaction action; - struct sigevent event; - struct timespec ts = { 0, 1000 }; /* 10 ms */ - int errors = 0; - int ret; - int err; - int i; - - if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L) - return PTS_UNSUPPORTED; - - snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_suspend_7_1_%d", - getpid()); - unlink(tmpfname); - - fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); - - if (fd == -1) { - printf(TNAME " Error at open(): %s\n", strerror(errno)); - exit(PTS_UNRESOLVED); - } - - unlink(tmpfname); - - bufs = malloc(NUM_AIOCBS * BUF_SIZE); - - if (bufs == NULL) { - printf(TNAME " Error at malloc(): %s\n", strerror(errno)); - close(fd); - exit(PTS_UNRESOLVED); - } - - if (write(fd, bufs, NUM_AIOCBS * BUF_SIZE) != (NUM_AIOCBS * BUF_SIZE)) { - printf(TNAME " Error at write(): %s\n", strerror(errno)); - free(bufs); - close(fd); - exit(PTS_UNRESOLVED); - } - - aiocbs = malloc(sizeof(struct aiocb *) * NUM_AIOCBS); - - /* Queue up a bunch of aio reads */ - for (i = 0; i < NUM_AIOCBS; i++) { - - aiocbs[i] = malloc(sizeof(struct aiocb)); - memset(aiocbs[i], 0, sizeof(struct aiocb)); - - aiocbs[i]->aio_fildes = fd; - aiocbs[i]->aio_offset = i * BUF_SIZE; - aiocbs[i]->aio_buf = &bufs[i * BUF_SIZE]; - aiocbs[i]->aio_nbytes = BUF_SIZE; - aiocbs[i]->aio_lio_opcode = LIO_READ; - } - - /* Use SIGRTMIN + 1 for list completion */ - event.sigev_notify = SIGEV_SIGNAL; - event.sigev_signo = SIGRTMIN + 1; - event.sigev_value.sival_ptr = NULL; - - /* Setup handler for list completion */ - action.sa_sigaction = sigrt1_handler; - sigemptyset(&action.sa_mask); - action.sa_flags = SA_SIGINFO | SA_RESTART; - sigaction(SIGRTMIN + 1, &action, NULL); - - /* Setup suspend list */ - plist[0] = NULL; - plist[1] = aiocbs[WAIT_FOR_AIOCB]; - - /* Submit request list */ - ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); - - if (ret) { - printf(TNAME " Error at lio_listio() %d: %s\n", - errno, strerror(errno)); - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - free(aiocbs); - close(fd); - exit(PTS_UNRESOLVED); - } - - /* Check selected request has not completed yet */ - if (aio_error(aiocbs[WAIT_FOR_AIOCB]) != EINPROGRESS) { - printf(TNAME " Error : AIOCB %d already completed" - " before suspend\n", WAIT_FOR_AIOCB); - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - free(aiocbs); - close(fd); - exit(PTS_FAIL); - } - - /* Suspend on selected request */ - ret = aio_suspend((const struct aiocb **)plist, 2, &ts); - - /* Check selected request has not completed */ - if (aio_error(aiocbs[WAIT_FOR_AIOCB]) != EINPROGRESS) { - printf(TNAME " Error : AIOCB %d should not have completed" - " after timed out suspend\n", WAIT_FOR_AIOCB); - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - free(aiocbs); - close(fd); - exit(PTS_FAIL); - } - - /* timed out aio_suspend should return -1 and set errno to EAGAIN */ - if (ret != -1) { - printf(TNAME " aio_suspend() should return -1\n"); - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - free(aiocbs); - close(fd); - exit(PTS_FAIL); - } - - if (errno != EAGAIN) { - printf(TNAME " aio_suspend() should set errno to EAGAIN:" - " %d (%s)\n", errno, strerror(errno)); - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - free(aiocbs); - close(fd); - exit(PTS_FAIL); - } - - /* Wait for list processing completion */ - while (!received_all) - sleep(1); - - /* Check return code and free things */ - for (i = 0; i < NUM_AIOCBS; i++) { - err = aio_error(aiocbs[i]); - ret = aio_return(aiocbs[i]); - - if ((err != 0) && (ret != BUF_SIZE)) { - printf(TNAME " req %d: error = %d - return = %d\n", - i, err, ret); - errors++; - } - - free(aiocbs[i]); - } - - free(bufs); - free(aiocbs); - - close(fd); - - if (errors != 0) - exit(PTS_FAIL); - - printf(TNAME " PASSED\n"); - - return PTS_PASS; -} diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_suspend/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_suspend/9-1.c index c14480e..d6ca793 100644 --- a/testcases/open_posix_testsuite/conformance/interfaces/aio_suspend/9-1.c +++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_suspend/9-1.c @@ -1,6 +1,8 @@ /* * Copyright (c) 2004, Bull SA. All rights reserved. - * Created by: Lau...@bu... + * Created by: Lau...@bu... + * Copyright (c) 2013 Cyril Hrubis <ch...@su...> + * * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @@ -10,7 +12,7 @@ * assertion: * * aio_suspend() shall fail if: - [EAGAIN] No AIO indicated in the list completed before timeout + * [EAGAIN] No AIO indicated in the list completed before timeout * * method: * @@ -35,38 +37,29 @@ #include "posixtest.h" -#define TNAME "aio_suspend/9-1.c" - -#define NUM_AIOCBS 10 -#define BUF_SIZE (1024*1024) #define WAIT_FOR_AIOCB 6 -static int received_all; +static sig_atomic_t received_all; -static void sigrt1_handler(int signum, siginfo_t *info, void *context) +static void sigrt1_handler() { received_all = 1; } -int main(void) +static int do_test(int num_aiocbs, size_t buf_size) { char tmpfname[256]; int fd; - - struct aiocb **aiocbs; + struct aiocb *aiocbs[num_aiocbs]; struct aiocb *plist[2]; char *bufs; struct sigaction action; struct sigevent event; - struct timespec ts = { 0, 1000000 }; /* 1 ms */ - int errors = 0; - int ret; - int err; + struct timespec ts = {0, 1000000}; /* 1 ms */ + int ret, ret2; + int err = PTS_UNRESOLVED; int i; - if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L) - return PTS_UNSUPPORTED; - snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_suspend_9_1_%d", getpid()); unlink(tmpfname); @@ -74,42 +67,48 @@ int main(void) fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { - printf(TNAME " Error at open(): %s\n", strerror(errno)); - exit(PTS_UNRESOLVED); + printf("Error at open(): %s\n", strerror(errno)); + goto err0; } unlink(tmpfname); - bufs = malloc(NUM_AIOCBS * BUF_SIZE); + int file_size = num_aiocbs * buf_size; + + bufs = malloc(file_size); if (bufs == NULL) { - printf(TNAME " Error at malloc(): %s\n", strerror(errno)); - close(fd); - exit(PTS_UNRESOLVED); + printf("Error at malloc(): %s\n", strerror(errno)); + goto err1; } - if (write(fd, bufs, NUM_AIOCBS * BUF_SIZE) != (NUM_AIOCBS * BUF_SIZE)) { - printf(TNAME " Error at write(): %s\n", strerror(errno)); - free(bufs); - close(fd); - exit(PTS_UNRESOLVED); - } + ret = write(fd, bufs, file_size); + if (ret != file_size) { - aiocbs = malloc(sizeof(struct aiocb *) * NUM_AIOCBS); + if (ret < 0) + printf("Error at write(): %s\n", strerror(errno)); + else + printf("Error at write(): %i of %i written\n", + ret, file_size); - /* Queue up a bunch of aio reads */ - for (i = 0; i < NUM_AIOCBS; i++) { + goto err2; + } + /* Queue up a bunch of aio reads */ + for (i = 0; i < num_aiocbs; i++) { aiocbs[i] = malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; - aiocbs[i]->aio_offset = i * BUF_SIZE; - aiocbs[i]->aio_buf = &bufs[i * BUF_SIZE]; - aiocbs[i]->aio_nbytes = BUF_SIZE; + aiocbs[i]->aio_offset = i * buf_size; + aiocbs[i]->aio_buf = &bufs[i * buf_size]; + aiocbs[i]->aio_nbytes = buf_size; aiocbs[i]->aio_lio_opcode = LIO_READ; } + /* reset the completion flag */ + received_all = 0; + /* Use SIGRTMIN+1 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN + 1; @@ -125,82 +124,91 @@ int main(void) plist[1] = aiocbs[WAIT_FOR_AIOCB]; /* Submit request list */ - ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); + ret = lio_listio(LIO_NOWAIT, aiocbs, num_aiocbs, &event); if (ret) { - printf(TNAME " Error at lio_listio() %d: %s\n", + printf(" Error at lio_listio() %d: %s\n", errno, strerror(errno)); - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - free(aiocbs); - close(fd); - exit(PTS_UNRESOLVED); + goto err3; } + /* Suspend on selected request */ + ret = aio_suspend((const struct aiocb **)plist, 2, &ts); + /* Check selected request has not completed yet */ - err = aio_error(aiocbs[WAIT_FOR_AIOCB]); - if (err != EINPROGRESS) { - printf(TNAME " Error : AIOCB %d already completed" - " before suspend\n", WAIT_FOR_AIOCB); - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - free(aiocbs); - close(fd); - exit(PTS_FAIL); + ret2 = aio_error(aiocbs[WAIT_FOR_AIOCB]); + if (ret2 != EINPROGRESS) { + /* + * The operation was too fast, wait for completion + * and redo it with larger buffers. + */ + err = -1; + goto err4; } - /* Suspend on selected request */ - ret = aio_suspend((const struct aiocb **)plist, 2, &ts); /* timed out aio_suspend should return -1 and set errno to EAGAIN */ if (ret != -1) { - printf(TNAME " aio_suspend() should return -1\n"); - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - free(aiocbs); - close(fd); - exit(PTS_FAIL); + printf("aio_suspend() should return -1\n"); + err = PTS_FAIL; + goto err4; } if (errno != EAGAIN) { - printf(TNAME " aio_suspend() should set errno to EAGAIN:" - " %d (%s)\n", errno, strerror(errno)); - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - free(aiocbs); - close(fd); - exit(PTS_FAIL); + printf("aio_suspend() should set errno to EAGAIN: %d (%s)\n", + errno, strerror(errno)); + err = PTS_FAIL; + goto err4; } /* Wait for list processing completion */ while (!received_all) - sleep(1); + usleep(10000); - /* Check return code and free things */ - for (i = 0; i < NUM_AIOCBS; i++) { + /* Check return values and errors */ + err = PTS_PASS; + + for (i = 0; i < num_aiocbs; i++) { err = aio_error(aiocbs[i]); ret = aio_return(aiocbs[i]); - if ((err != 0) && (ret != BUF_SIZE)) { - printf(TNAME " req %d: error = %d - return = %d\n", + if ((err != 0) && ((size_t)ret != buf_size)) { + printf("req %d: error = %d - return = %d\n", i, err, ret); - errors++; + err = PTS_FAIL; } - - free(aiocbs[i]); } +err4: + while (!received_all) + usleep(10000); +err3: + for (i = 0; i < num_aiocbs; i++) + free(aiocbs[i]); +err2: free(bufs); - free(aiocbs); - +err1: close(fd); +err0: + return err; +} + +int main(void) +{ + int aio_cbs = 10; + int buf_size = 1024 * 64; + int ret; + + if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L) + return PTS_UNSUPPORTED; - if (errors != 0) - exit(PTS_FAIL); + /* Repeat the test with increasing buffer size */ + do { + ret = do_test(aio_cbs, buf_size); + buf_size += buf_size / 4; + } while (ret == -1); - printf(TNAME " PASSED\n"); + if (ret != 0) + return ret; + printf("(buf_size = %i)\nTest PASSED\n", buf_size); return PTS_PASS; } diff --git a/testcases/open_posix_testsuite/conformance/interfaces/lio_listio/11-1.c b/testcases/open_posix_testsuite/conformance/interfaces/lio_listio/11-1.c deleted file mode 100644 index 7277187..0000000 --- a/testcases/open_posix_testsuite/conformance/interfaces/lio_listio/11-1.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2004, Bull SA. All rights reserved. - * Created by: Lau...@bu... - * This file is licensed under the GPL license. For the full content - * of this license, see the COPYING file at the top level of this - * source tree. - */ - -/* - * assertion: - * - * if mode is LIO_NOWAIT, lio_listio() shall return the value -1 and set - * errno to indicate error if the operation is not succesfully queued. - * - * method: - * - * - open a file for writing - * - submit a list with invalid opcodes to lio_listio in LIO_NOWAIT mode - * - check that lio_listio returns -1 - * - */ - -#define _XOPEN_SOURCE 600 -#include <sys/stat.h> -#include <aio.h> -#include <errno.h> -#include <fcntl.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include "posixtest.h" - -#define TNAME "lio_listio/11-1.c" - -#define NUM_AIOCBS 10 -#define BUF_SIZE 1024 - -int received_selected = 0; -int received_all = 0; - -void sigrt1_handler(int signum, siginfo_t * info, void *context) -{ - received_selected = info->si_value.sival_int; -} - -void sigrt2_handler(int signum, siginfo_t * info, void *context) -{ - received_all = 1; -} - -int main(void) -{ - char tmpfname[256]; - int fd; - - struct aiocb *aiocbs[NUM_AIOCBS]; - char *bufs; - struct sigaction action; - struct sigevent event; - int errors = 0; - int ret; - int err; - int i; - - if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L) - exit(PTS_UNSUPPORTED); - - snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_11_1_%d", - getpid()); - unlink(tmpfname); - - fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); - - if (fd == -1) { - printf(TNAME " Error at open(): %s\n", strerror(errno)); - exit(PTS_UNRESOLVED); - } - - unlink(tmpfname); - - bufs = (char *)malloc(NUM_AIOCBS * BUF_SIZE); - - if (bufs == NULL) { - printf(TNAME " Error at malloc(): %s\n", strerror(errno)); - close(fd); - exit(PTS_UNRESOLVED); - } - - /* Queue up a bunch of aio writes */ - for (i = 0; i < NUM_AIOCBS; i++) { - - aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); - memset(aiocbs[i], 0, sizeof(struct aiocb)); - - aiocbs[i]->aio_fildes = fd; - aiocbs[i]->aio_offset = 0; - aiocbs[i]->aio_buf = &bufs[i * BUF_SIZE]; - aiocbs[i]->aio_nbytes = BUF_SIZE; - - if (i == 2) - aiocbs[i]->aio_lio_opcode = -1; - else - aiocbs[i]->aio_lio_opcode = LIO_WRITE; - - /* Use SIRTMIN+1 for individual completions */ - aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; - aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN + 1; - aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; - } - - /* Use SIGRTMIN+2 for list completion */ - event.sigev_notify = SIGEV_SIGNAL; - event.sigev_signo = SIGRTMIN + 2; - event.sigev_value.sival_ptr = NULL; - - /* Setup handler for individual operation completion */ - action.sa_sigaction = sigrt1_handler; - sigemptyset(&action.sa_mask); - action.sa_flags = SA_SIGINFO | SA_RESTART; - sigaction(SIGRTMIN + 1, &action, NULL); - - /* Setup handler for list completion */ - action.sa_sigaction = sigrt2_handler; - sigemptyset(&action.sa_mask); - action.sa_flags = SA_SIGINFO | SA_RESTART; - sigaction(SIGRTMIN + 2, &action, NULL); - - /* Submit request list */ - ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); - - if (ret == 0) { - printf(TNAME " Error lio_listio() should have returned -1\n"); - - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - free(bufs); - close(fd); - exit(PTS_FAIL); - } - - if (errno != EIO) { - printf(TNAME " lio_listio() should set errno to EIO %d\n", - errno); - - for (i = 0; i < NUM_AIOCBS; i++) - free(aiocbs[i]); - - close(fd); - exit(PTS_FAIL); - } - - while (received_all == 0) - sleep(1); - - /* Check return code and free things */ - for (i = 0; i < NUM_AIOCBS; i++) { - if (i == 2) - continue; - - err = aio_error(aiocbs[i]); - ret = aio_return(aiocbs[i]); - - if ((err != 0) && (ret != BUF_SIZE)) { - printf(TNAME " req %d: error = %d - return = %d\n", i, - err, ret); - errors++; - } - - free(aiocbs[i]); - } - - free(bufs); - - close(fd); - - if (errors != 0) - exit(PTS_FAIL); - - printf(TNAME " PASSED\n"); - - return PTS_PASS; -} hooks/post-receive -- ltp |