source: trunk/packages/xen-3.1/xen-3.1/tools/libaio/harness/cases/4.t @ 34

Last change on this file since 34 was 34, checked in by hartmans, 17 years ago

Add xen and xen-common

File size: 2.1 KB
Line 
1/* 4.t
2- read of descriptor without read permission (4.t)
3- write to descriptor without write permission (4.t)
4- check that O_APPEND writes actually append
5
6*/
7#include "aio_setup.h"
8
9#define SIZE    512
10#define READ    'r'
11#define WRITE   'w'
12int attempt(int fd, void *buf, int count, long long pos, int rw, int expect)
13{
14        struct iocb iocb;
15        int res;
16
17        switch(rw) {
18        case READ:      io_prep_pread (&iocb, fd, buf, count, pos); break;
19        case WRITE:     io_prep_pwrite(&iocb, fd, buf, count, pos); break;
20        }
21
22        printf("expect %3d: (%c), res = ", expect, rw);
23        fflush(stdout);
24        res = sync_submit(&iocb);
25        printf("%3d [%s]%s\n", res, (res <= 0) ? strerror(-res) : "Success",
26                (res != expect) ? " -- FAILED" : "");
27        if (res != expect)
28                return 1;
29
30        return 0;
31}
32
33int test_main(void)
34{
35        char buf[SIZE];
36        int rofd, wofd, rwfd;
37        int     status = 0, res;
38
39        memset(buf, 0, SIZE);
40
41        rofd = open("testdir/rofile", O_RDONLY);        assert(rofd != -1);
42        wofd = open("testdir/wofile", O_WRONLY);        assert(wofd != -1);
43        rwfd = open("testdir/rwfile", O_RDWR);          assert(rwfd != -1);
44
45        status |= attempt(rofd, buf, SIZE,  0, WRITE, -EBADF);
46        status |= attempt(wofd, buf, SIZE,  0,  READ, -EBADF);
47        status |= attempt(rwfd, buf, SIZE,  0, WRITE, SIZE);
48        status |= attempt(rwfd, buf, SIZE,  0,  READ, SIZE);
49        status |= attempt(rwfd, buf, SIZE, -1,  READ, -EINVAL);
50        status |= attempt(rwfd, buf, SIZE, -1, WRITE, -EINVAL);
51
52        rwfd = open("testdir/rwfile", O_RDWR|O_APPEND); assert(rwfd != -1);
53        res = ftruncate(rwfd, 0);                       assert(res == 0);
54        status |= attempt(rwfd, buf,    SIZE, 0,  READ, 0);
55        status |= attempt(rwfd, "1234",    4, 0, WRITE, 4);
56        status |= attempt(rwfd, "5678",    4, 0, WRITE, 4);
57        memset(buf, 0, SIZE);
58        status |= attempt(rwfd,    buf, SIZE, 0,  READ, 8);
59        printf("read after append: [%s]\n", buf);
60        assert(memcmp(buf, "12345678", 8) == 0);
61
62        status |= attempt(rwfd, KERNEL_RW_POINTER, SIZE, 0,  READ, -EFAULT);
63        status |= attempt(rwfd, KERNEL_RW_POINTER, SIZE, 0, WRITE, -EFAULT);
64
65        /* Some architectures map the 0 page.  Ugh. */
66#if !defined(__ia64__)
67        status |= attempt(rwfd,              NULL, SIZE, 0, WRITE, -EFAULT);
68#endif
69
70        return status;
71}
72
Note: See TracBrowser for help on using the repository browser.