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