summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen LaHaise <bcrl@kvack.org>2002-04-18 06:25:24 +0000
committerBen LaHaise <bcrl@kvack.org>2002-04-18 06:25:24 +0000
commit15051818cc016bca67d939f12e09e24384520dca (patch)
tree47ee6a95f4ed25e805849dbb27931abaed278a6c
parent536d7c1d7c2147c4e5a99c6117214f8de0aa152b (diff)
downloadlibaio-15051818cc016bca67d939f12e09e24384520dca.tar.gz
add rw test perm test case
-rw-r--r--harness/Makefile17
-rw-r--r--harness/cases/4.t50
-rw-r--r--harness/cases/aio_setup.h10
-rw-r--r--harness/main.c7
4 files changed, 73 insertions, 11 deletions
diff --git a/harness/Makefile b/harness/Makefile
index e0cdb9a..d2331c4 100644
--- a/harness/Makefile
+++ b/harness/Makefile
@@ -15,16 +15,21 @@ $(PROGS): %.p: %.t $(HARNESS_SRCS)
clean:
rm -f $(PROGS) *.o runtests.out rofile wofile rwfile
-rofile:
- touch $@
+.PHONY:
+
+rofile: .PHONY
+ rm -f $@
+ echo "test" >$@
chmod 400 $@
-wofile:
- touch $@
+wofile: .PHONY
+ rm -f $@
+ echo "test" >$@
chmod 200 $@
-rwfile:
- touch $@
+rwfile: .PHONY
+ rm -f $@
+ echo "test" >$@
chmod 600 $@
check: $(PROGS) rofile rwfile wofile
diff --git a/harness/cases/4.t b/harness/cases/4.t
new file mode 100644
index 0000000..002e462
--- /dev/null
+++ b/harness/cases/4.t
@@ -0,0 +1,50 @@
+/* 4.t
+- read of descriptor without read permission (4.t)
+- write to descriptor without write permission (4.t)
+
+*/
+#include "aio_setup.h"
+
+#define SIZE 512
+#define READ 'r'
+#define WRITE 'w'
+int attempt(int fd, 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;
+ }
+
+ printf("expect %3d: (%c), res = ", expect, rw);
+ fflush(stdout);
+ res = sync_submit(&iocb);
+ printf("%3d [%s]\n", res, (res <= 0) ? strerror(-res) : "Success");
+ if (res != expect)
+ return 1;
+
+ return 0;
+}
+
+int test_main(void)
+{
+ int rofd, wofd, rwfd;
+ int status = 0;
+
+ 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);
+
+ return status;
+}
+
diff --git a/harness/cases/aio_setup.h b/harness/cases/aio_setup.h
index fccb7f7..204be0b 100644
--- a/harness/cases/aio_setup.h
+++ b/harness/cases/aio_setup.h
@@ -11,8 +11,9 @@ void aio_setup(int n)
}
}
-void sync_submit(struct iocb *iocb, struct io_event *event)
+int sync_submit(struct iocb *iocb)
{
+ struct io_event event;
struct iocb *iocbs[] = { iocb };
int res;
@@ -24,14 +25,15 @@ void sync_submit(struct iocb *iocb, struct io_event *event)
res = io_submit(io_ctx, 1, iocbs);
if (res != 1) {
printf("sync_submit: io_submit res=%d [%s]\n", res, strerror(-res));
- exit(3);
+ return res;
}
- res = io_getevents(io_ctx, 1, event, &ts);
+ res = io_getevents(io_ctx, 1, &event, &ts);
if (res != 1) {
printf("sync_submit: io_getevents res=%d [%s]\n", res, strerror(-res));
- exit(3);
+ return res;
}
+ return event.res;
}
#define SETUP aio_setup(1024)
diff --git a/harness/main.c b/harness/main.c
index 4f8b8cc..ff0b303 100644
--- a/harness/main.c
+++ b/harness/main.c
@@ -1,9 +1,14 @@
#include <stdio.h>
#include <errno.h>
-#include <libaio.h>
#include <assert.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <libaio.h>
+
#if defined(__i386__)
#define KERNEL_RW_POINTER ((void *)0xc0010000)
#else