1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <assert.h>
#include <aio.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
int x;
int main(void)
{
#define LEN 10
char buf1[LEN];
char buf2[LEN];
char buf3[LEN];
struct iovec vec_array[] = {{buf1, LEN}, {buf2, LEN}, {buf3, LEN}};
//struct iovec bad_array[] = {{NULL, LEN}, {buf2, LEN}, {buf3, LEN}};
struct aiocb a;
memset(&a, 0, sizeof(struct aiocb));
a.aio_fildes = -1;
a.aio_offset = 0;
a.aio_iov = NULL;
a.aio_iovcnt = 3;
a.aio_reqprio = 0;
a.aio_lio_opcode = 0; // ignored
//------------------------------------------------------------------------
// The cases where aiocbp itself points to bogus memory is handled in
// memcheck/tests/darwin/scalar.c, so we don't check that here.
//------------------------------------------------------------------------
// XXX: This causes an unexpected undef value error later, at the XXX mark.
// Not sure why, it shouldn't.
// assert( aio_return(&a) < 0); // (iocb hasn't been inited)
//------------------------------------------------------------------------
assert( aio_readv(&a) < 0); // invalid fd
//------------------------------------------------------------------------
a.aio_fildes = open("aio.c", O_RDONLY);
assert(a.aio_fildes >= 0);
// unaddressable aio_iov
assert( aio_readv(&a) < 0);
//------------------------------------------------------------------------
//a.aio_iov = bad_array;
// unaddressable first element in aio_iov
// but it doesn't fail!
//assert( aio_readv(&a) < 0 );
a.aio_iov = vec_array;
assert( aio_readv(&a) == 0 );
// undefined -- aio_return() not called yet
if (((char*)(vec_array[0].iov_base))[0] == ((char*)(vec_array[0].iov_base))[9]) x++;
// also failed on macOS
// (don't crash on the repeated &a)
//assert( aio_readv(&a) == 0 );
while (0 != aio_error(&a)) { }
assert( aio_return(&a) > 0 ); // XXX: (undefined value error here)
if (((char*)(vec_array[0].iov_base))[0] == ((char*)(vec_array[0].iov_base))[9]) x++;
assert( aio_return(&a) < 0 ); // (repeated aio_return(); fails because
// Valgrind can't find &a in the table)
//------------------------------------------------------------------------
a.aio_iov = 0;
a.aio_fildes = creat("mytmpfile", S_IRUSR|S_IWUSR);
assert(a.aio_fildes >= 0);
// unaddressable aio_buf
assert( aio_writev(&a) < 0);
//------------------------------------------------------------------------
a.aio_iov = vec_array;
assert( aio_writev(&a) == 0 );
// (don't crash on the repeated &a)
// this failed on macOS
//assert( aio_writev(&a) < 0 );
while (0 != aio_error(&a)) { };
assert( aio_return(&a) > 0 );
assert( aio_return(&a) < 0 ); // (repeated aio_return(); fails because
// Valgrind can't find &a in the table)
unlink("mytmpfile");
return x;
}
|