summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen LaHaise <bcrl@kvack.org>2002-04-18 16:23:20 +0000
committerBen LaHaise <bcrl@kvack.org>2002-04-18 16:23:20 +0000
commit0b262957ca2bd7a4c128b05b91b410d830f7697e (patch)
tree58421294a67d580b6a69139658ad90f137fe050d
parent15051818cc016bca67d939f12e09e24384520dca (diff)
downloadlibaio-0b262957ca2bd7a4c128b05b91b410d830f7697e.tar.gz
add O_APPEND test
-rw-r--r--harness/cases/4.t33
-rw-r--r--harness/main.c1
2 files changed, 23 insertions, 11 deletions
diff --git a/harness/cases/4.t b/harness/cases/4.t
index 002e462..4ca1329 100644
--- a/harness/cases/4.t
+++ b/harness/cases/4.t
@@ -1,6 +1,7 @@
/* 4.t
- read of descriptor without read permission (4.t)
- write to descriptor without write permission (4.t)
+- check that O_APPEND writes actually append
*/
#include "aio_setup.h"
@@ -8,17 +9,14 @@
#define SIZE 512
#define READ 'r'
#define WRITE 'w'
-int attempt(int fd, int rw, int expect)
+int attempt(int fd, void *buf, int count, int rw, int expect)
{
- char buf[SIZE];
struct iocb iocb;
int res;
- memset(buf, 0, SIZE);
-
switch(rw) {
- case READ: io_prep_pread (&iocb, fd, buf, SIZE, 0); break;
- case WRITE: io_prep_pwrite(&iocb, fd, buf, SIZE, 0); break;
+ case READ: io_prep_pread (&iocb, fd, buf, count, 0); break;
+ case WRITE: io_prep_pwrite(&iocb, fd, buf, count, 0); break;
}
printf("expect %3d: (%c), res = ", expect, rw);
@@ -33,17 +31,30 @@ int attempt(int fd, int rw, int expect)
int test_main(void)
{
+ char buf[SIZE];
int rofd, wofd, rwfd;
- int status = 0;
+ int status = 0, res;
+
+ memset(buf, 0, SIZE);
rofd = open("rofile", O_RDONLY); assert(rofd != -1);
wofd = open("wofile", O_WRONLY); assert(wofd != -1);
rwfd = open("rwfile", O_RDWR); assert(rwfd != -1);
- status |= attempt(rofd, WRITE, -EBADF);
- status |= attempt(wofd, READ, -EBADF);
- status |= attempt(rwfd, WRITE, SIZE);
- status |= attempt(rwfd, READ, SIZE);
+ status |= attempt(rofd, buf, SIZE, WRITE, -EBADF);
+ status |= attempt(wofd, buf, SIZE, READ, -EBADF);
+ status |= attempt(rwfd, buf, SIZE, WRITE, SIZE);
+ status |= attempt(rwfd, buf, SIZE, READ, SIZE);
+
+ rwfd = open("rwfile", O_RDWR | O_APPEND); assert(rwfd != -1);
+ res = ftruncate(rwfd, 0); assert(res == 0);
+ status |= attempt(rwfd, buf, SIZE, READ, 0);
+ status |= attempt(rwfd, "1234", 4, WRITE, 4);
+ status |= attempt(rwfd, "5678", 4, WRITE, 4);
+ memset(buf, 0, SIZE);
+ status |= attempt(rwfd, buf, SIZE, READ, 8);
+ printf("read after append: [%s]\n", buf);
+ assert(memcmp(buf, "12345678", 8) == 0);
return status;
}
diff --git a/harness/main.c b/harness/main.c
index ff0b303..44981f5 100644
--- a/harness/main.c
+++ b/harness/main.c
@@ -6,6 +6,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <unistd.h>
#include <libaio.h>