| 1 |
/* COVERAGE: io_setup io_submit io_getevents io_cancel io_destroy */ |
| 2 |
|
| 3 |
#include <stdio.h> |
| 4 |
#include <unistd.h> |
| 5 |
#include <sys/syscall.h> |
| 6 |
#include <linux/aio_abi.h> |
| 7 |
#include <fcntl.h> |
| 8 |
#include <string.h> |
| 9 |
#include <inttypes.h> |
| 10 |
|
| 11 |
static inline int __io_setup(unsigned nr_events, aio_context_t *ctx_idp) |
| 12 |
{ |
| 13 |
return syscall(__NR_io_setup, nr_events, ctx_idp); |
| 14 |
} |
| 15 |
|
| 16 |
static inline int __io_submit(aio_context_t ctx_id, long nr, struct iocb **iocbpp) |
| 17 |
{ |
| 18 |
return syscall(__NR_io_submit, ctx_id, nr, iocbpp); |
| 19 |
} |
| 20 |
|
| 21 |
static inline int __io_getevents(aio_context_t ctx_id, long min_nr, long nr, |
| 22 |
struct io_event *events, struct timespec *timeout) |
| 23 |
{ |
| 24 |
return syscall(__NR_io_getevents, ctx_id, min_nr, nr, events, timeout); |
| 25 |
} |
| 26 |
|
| 27 |
static inline int __io_cancel(aio_context_t ctx_id, struct iocb *iocb, |
| 28 |
struct io_event *result) |
| 29 |
{ |
| 30 |
return syscall(__NR_io_cancel, ctx_id, iocb, result); |
| 31 |
} |
| 32 |
|
| 33 |
static inline int __io_destroy(aio_context_t ctx_id) |
| 34 |
{ |
| 35 |
return syscall(__NR_io_destroy, ctx_id); |
| 36 |
} |
| 37 |
|
| 38 |
int main() { |
| 39 |
aio_context_t ctx; |
| 40 |
struct iocb cb; |
| 41 |
struct iocb *cbs[1]; |
| 42 |
char data[9]; |
| 43 |
struct io_event events[1]; |
| 44 |
int ret; |
| 45 |
int fd; |
| 46 |
|
| 47 |
fd = open("testfile", O_RDWR | O_CREAT, 0644); |
| 48 |
ctx = 0; |
| 49 |
|
| 50 |
// ----- test normal operation |
| 51 |
|
| 52 |
ret = __io_setup(128, &ctx); |
| 53 |
//staptest// io_setup (128, XXXX) = NNNN |
| 54 |
if (ret < 0) { |
| 55 |
perror("io_setup failed"); |
| 56 |
return -1; |
| 57 |
} |
| 58 |
|
| 59 |
strcpy(data, "testdata"); |
| 60 |
memset(&cb, 0, sizeof(cb)); |
| 61 |
cb.aio_fildes = fd; |
| 62 |
cb.aio_lio_opcode = IOCB_CMD_PWRITE; |
| 63 |
cb.aio_buf = (unsigned long)data; |
| 64 |
cb.aio_offset = 0; |
| 65 |
cb.aio_nbytes = 8; |
| 66 |
cbs[0] = &cb; |
| 67 |
|
| 68 |
ret = __io_submit(ctx, 1, cbs); |
| 69 |
//staptest// io_submit (NNNN, 1, XXXX) = NNNN |
| 70 |
if (ret != 1) { |
| 71 |
perror("io_sumbit failed"); |
| 72 |
return -1; |
| 73 |
} |
| 74 |
|
| 75 |
ret = __io_getevents(ctx, 1, 1, events, NULL); |
| 76 |
//staptest// io_getevents (NNNN, 1, 1, XXXX, NULL) = NNNN |
| 77 |
printf("%d\n", ret); |
| 78 |
|
| 79 |
ret = __io_destroy(ctx); |
| 80 |
//staptest// io_destroy (NNNN) = NNNN |
| 81 |
if (ret < 0) { |
| 82 |
perror("io_destroy failed"); |
| 83 |
return -1; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
// ----- test nasty things |
| 88 |
|
| 89 |
__io_setup((unsigned)-1, &ctx); |
| 90 |
//staptest// io_setup (4294967295, XXXX) = NNNN |
| 91 |
|
| 92 |
__io_setup(1, (aio_context_t *)-1); |
| 93 |
#ifdef __s390__ |
| 94 |
//staptest// io_setup (1, 0x[7]?[f]+) = NNNN |
| 95 |
#else |
| 96 |
//staptest// io_setup (1, 0x[f]+) = NNNN |
| 97 |
#endif |
| 98 |
|
| 99 |
__io_submit((aio_context_t)-1, 1, cbs); |
| 100 |
#if __WORDSIZE == 64 |
| 101 |
//staptest// io_submit (18446744073709551615, 1, XXXX) = NNNN |
| 102 |
#else |
| 103 |
//staptest// io_submit (4294967295, 1, XXXX) = NNNN |
| 104 |
#endif |
| 105 |
|
| 106 |
__io_submit(0, (long)-1, cbs); |
| 107 |
//staptest// io_submit (0, -1, XXXX) = NNNN |
| 108 |
|
| 109 |
__io_submit(0, 1, (struct iocb **)-1); |
| 110 |
#ifdef __s390__ |
| 111 |
//staptest// io_submit (0, 1, 0x[7]?[f]+) = NNNN |
| 112 |
#else |
| 113 |
//staptest// io_submit (0, 1, 0x[f]+) = NNNN |
| 114 |
#endif |
| 115 |
|
| 116 |
__io_getevents((aio_context_t)-1, 1, 1, events, NULL); |
| 117 |
#if __WORDSIZE == 64 |
| 118 |
//staptest// io_getevents (18446744073709551615, 1, 1, XXXX, NULL) = NNNN |
| 119 |
#else |
| 120 |
//staptest// io_getevents (4294967295, 1, 1, XXXX, NULL) = NNNN |
| 121 |
#endif |
| 122 |
|
| 123 |
__io_getevents(0, (long)-1, 1, events, NULL); |
| 124 |
//staptest// io_getevents (0, -1, 1, XXXX, NULL) = NNNN |
| 125 |
|
| 126 |
__io_getevents(0, 1, (long)-1, events, NULL); |
| 127 |
//staptest// io_getevents (0, 1, -1, XXXX, NULL) = NNNN |
| 128 |
|
| 129 |
__io_getevents(0, 1, 1, (struct io_event *)-1, NULL); |
| 130 |
#ifdef __s390__ |
| 131 |
//staptest// io_getevents (0, 1, 1, 0x[7]?[f]+, NULL) = NNNN |
| 132 |
#else |
| 133 |
//staptest// io_getevents (0, 1, 1, 0x[f]+, NULL) = NNNN |
| 134 |
#endif |
| 135 |
|
| 136 |
__io_getevents(0, 1, 1, events, (struct timespec *)-1); |
| 137 |
#ifdef __s390__ |
| 138 |
//staptest// io_getevents (0, 1, 1, XXXX, 0x[7]?[f]+) = NNNN |
| 139 |
#else |
| 140 |
//staptest// io_getevents (0, 1, 1, XXXX, 0x[f]+) = NNNN |
| 141 |
#endif |
| 142 |
|
| 143 |
__io_cancel(1, (struct iocb *)1, (struct io_event *)1); |
| 144 |
//staptest// io_cancel (1, 0x1, 0x1) = NNNN |
| 145 |
|
| 146 |
__io_cancel((aio_context_t)-1, (struct iocb *)1, (struct io_event *)1); |
| 147 |
#if __WORDSIZE == 64 |
| 148 |
//staptest// io_cancel (18446744073709551615, 0x1, 0x1) = NNNN |
| 149 |
#else |
| 150 |
//staptest// io_cancel (4294967295, 0x1, 0x1) = NNNN |
| 151 |
#endif |
| 152 |
|
| 153 |
__io_cancel(1, (struct iocb *)-1, (struct io_event *)1); |
| 154 |
#ifdef __s390__ |
| 155 |
//staptest// io_cancel (1, 0x[7]?[f]+, 0x1) = NNNN |
| 156 |
#else |
| 157 |
//staptest// io_cancel (1, 0x[f]+, 0x1) = NNNN |
| 158 |
#endif |
| 159 |
|
| 160 |
__io_cancel(1, (struct iocb *)1, (struct io_event *)-1); |
| 161 |
#ifdef __s390__ |
| 162 |
//staptest// io_cancel (1, 0x1, 0x[7]?[f]+) = NNNN |
| 163 |
#else |
| 164 |
//staptest// io_cancel (1, 0x1, 0x[f]+) = NNNN |
| 165 |
#endif |
| 166 |
|
| 167 |
__io_destroy((aio_context_t)-1); |
| 168 |
#if __WORDSIZE == 64 |
| 169 |
//staptest// io_destroy (18446744073709551615) = NNNN |
| 170 |
#else |
| 171 |
//staptest// io_destroy (4294967295) = NNNN |
| 172 |
#endif |
| 173 |
|
| 174 |
close(fd); |
| 175 |
|
| 176 |
return 0; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|