1 /* 2 * Copyright (c) 2004, Bull SA. All rights reserved. 3 * Created by: Laurent.Vivier (at) bull.net 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 */ 8 9 /* 10 * assertion: 11 * 12 * It the operations has not yet completed, [EINPROGRESS] shall be 13 * returned. 14 * 15 * method: 16 * 17 * queue a lot of aio_write() to a given fildes. 18 * then check if at least on is EINPROGRESS 19 * if yes, result is pass otherwise unresolved 20 * 21 */ 22 23 #define _XOPEN_SOURCE 600 24 #include <stdio.h> 25 #include <sys/types.h> 26 #include <unistd.h> 27 #include <sys/stat.h> 28 #include <fcntl.h> 29 #include <string.h> 30 #include <errno.h> 31 #include <stdlib.h> 32 #include <aio.h> 33 34 #include "posixtest.h" 35 36 #define TNAME "aio_error/2-1.c" 37 38 #define BUF_NB 128 39 #define BUF_SIZE 1024 40 41 int main(void) 42 { 43 char tmpfname[256]; 44 int fd; 45 struct aiocb *aiocb[BUF_NB]; 46 int i; 47 int ret; 48 49 if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L) 50 return PTS_UNSUPPORTED; 51 52 snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_error_2_1_%d", 53 getpid()); 54 unlink(tmpfname); 55 fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); 56 if (fd == -1) { 57 printf(TNAME " Error at open(): %s\n", strerror(errno)); 58 return PTS_UNRESOLVED; 59 } 60 61 unlink(tmpfname); 62 63 /* create AIO req */ 64 65 for (i = 0; i < BUF_NB; i++) { 66 aiocb[i] = calloc(1, sizeof(struct aiocb)); 67 if (aiocb[i] == NULL) { 68 printf(TNAME " Error at malloc(): %s\n", 69 strerror(errno)); 70 return PTS_UNRESOLVED; 71 } 72 aiocb[i]->aio_fildes = fd; 73 aiocb[i]->aio_buf = malloc(BUF_SIZE); 74 if (aiocb[i]->aio_buf == NULL) { 75 printf(TNAME " Error at malloc(): %s\n", 76 strerror(errno)); 77 return PTS_UNRESOLVED; 78 } 79 aiocb[i]->aio_nbytes = BUF_SIZE; 80 aiocb[i]->aio_offset = 0; 81 aiocb[i]->aio_sigevent.sigev_notify = SIGEV_NONE; 82 83 if (aio_write(aiocb[i]) == -1) { 84 printf(TNAME " loop %d: Error at aio_write(): %s\n", 85 i, strerror(errno)); 86 return PTS_FAIL; 87 } 88 } 89 90 ret = PTS_UNRESOLVED; 91 for (i = 0; i < BUF_NB; i++) { 92 if (aio_error(aiocb[i]) == EINPROGRESS) { 93 ret = PTS_PASS; 94 break; 95 } 96 } 97 98 return ret; 99 } 100