| 1 | #include <sys/types.h> |
|---|
| 2 | #include <sys/wait.h> |
|---|
| 3 | #include <unistd.h> |
|---|
| 4 | #include <signal.h> |
|---|
| 5 | |
|---|
| 6 | #include "aio_setup.h" |
|---|
| 7 | #include <sys/mman.h> |
|---|
| 8 | |
|---|
| 9 | #define SIZE 768*1024*1024 |
|---|
| 10 | |
|---|
| 11 | //just submit an I/O |
|---|
| 12 | |
|---|
| 13 | int test_child(void) |
|---|
| 14 | { |
|---|
| 15 | char *buf; |
|---|
| 16 | int rwfd; |
|---|
| 17 | int res; |
|---|
| 18 | long size; |
|---|
| 19 | struct iocb iocb; |
|---|
| 20 | struct iocb *iocbs[] = { &iocb }; |
|---|
| 21 | int loop = 10; |
|---|
| 22 | int i; |
|---|
| 23 | |
|---|
| 24 | aio_setup(1024); |
|---|
| 25 | |
|---|
| 26 | size = SIZE; |
|---|
| 27 | |
|---|
| 28 | printf("size = %ld\n", size); |
|---|
| 29 | |
|---|
| 30 | rwfd = open("testdir/rwfile", O_RDWR); assert(rwfd != |
|---|
| 31 | -1); |
|---|
| 32 | res = ftruncate(rwfd, 0); assert(res == 0); |
|---|
| 33 | buf = malloc(size); assert(buf != |
|---|
| 34 | NULL); |
|---|
| 35 | |
|---|
| 36 | for(i=0;i<loop;i++) { |
|---|
| 37 | |
|---|
| 38 | switch(i%2) { |
|---|
| 39 | case 0: |
|---|
| 40 | io_prep_pwrite(&iocb, rwfd, buf, size, 0); |
|---|
| 41 | break; |
|---|
| 42 | case 1: |
|---|
| 43 | io_prep_pread(&iocb, rwfd, buf, size, 0); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | res = io_submit(io_ctx, 1, iocbs); |
|---|
| 47 | if (res != 1) { |
|---|
| 48 | printf("child: submit: io_submit res=%d [%s]\n", res, |
|---|
| 49 | strerror(-res)); |
|---|
| 50 | _exit(1); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | res = ftruncate(rwfd, 0); assert(res == 0); |
|---|
| 55 | |
|---|
| 56 | _exit(0); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | /* from 12.t */ |
|---|
| 60 | int test_main(void) |
|---|
| 61 | { |
|---|
| 62 | int res, status; |
|---|
| 63 | pid_t pid; |
|---|
| 64 | |
|---|
| 65 | if (attempt_io_submit(io_ctx, 0, NULL, 0)) |
|---|
| 66 | return 1; |
|---|
| 67 | |
|---|
| 68 | sigblock(sigmask(SIGCHLD) | siggetmask()); |
|---|
| 69 | fflush(NULL); |
|---|
| 70 | pid = fork(); assert(pid != -1); |
|---|
| 71 | |
|---|
| 72 | if (pid == 0) |
|---|
| 73 | test_child(); |
|---|
| 74 | |
|---|
| 75 | res = waitpid(pid, &status, 0); |
|---|
| 76 | |
|---|
| 77 | if (WIFEXITED(status)) { |
|---|
| 78 | int failed = (WEXITSTATUS(status) != 0); |
|---|
| 79 | printf("child exited with status %d%s\n", WEXITSTATUS(status), |
|---|
| 80 | failed ? " -- FAILED" : ""); |
|---|
| 81 | return failed; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /* anything else: failed */ |
|---|
| 85 | if (WIFSIGNALED(status)) |
|---|
| 86 | printf("child killed by signal %d -- FAILED.\n", |
|---|
| 87 | WTERMSIG(status)); |
|---|
| 88 | |
|---|
| 89 | return 1; |
|---|
| 90 | } |
|---|