summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen LaHaise <bcrl@kvack.org>2002-04-19 19:50:33 +0000
committerBen LaHaise <bcrl@kvack.org>2002-04-19 19:50:33 +0000
commit869154f74b9de746843b1a41101975c8a38f0b27 (patch)
treeece2544869472e3480e999331554aef4bd9f4dd6
parent0b262957ca2bd7a4c128b05b91b410d830f7697e (diff)
downloadlibaio-869154f74b9de746843b1a41101975c8a38f0b27.tar.gz
more test cases
-rw-r--r--harness/Makefile10
-rw-r--r--harness/README17
-rw-r--r--harness/cases/4.t36
-rw-r--r--harness/cases/5.t33
-rw-r--r--harness/cases/6.t57
-rw-r--r--harness/cases/aio_setup.h24
6 files changed, 157 insertions, 20 deletions
diff --git a/harness/Makefile b/harness/Makefile
index d2331c4..dadedde 100644
--- a/harness/Makefile
+++ b/harness/Makefile
@@ -1,5 +1,5 @@
# foo.
-TEST_SRCS:=$(shell find cases/ -name \*.t)
+TEST_SRCS:=$(shell find cases/ -name \*.t | sort -n)
PROGS:=$(patsubst %.t,%.p,$(TEST_SRCS))
HARNESS_SRCS:=main.c
# io_queue.c
@@ -17,21 +17,21 @@ clean:
.PHONY:
-rofile: .PHONY
+testdir/rofile: .PHONY
rm -f $@
echo "test" >$@
chmod 400 $@
-wofile: .PHONY
+testdir/wofile: .PHONY
rm -f $@
echo "test" >$@
chmod 200 $@
-rwfile: .PHONY
+testdir/rwfile: .PHONY
rm -f $@
echo "test" >$@
chmod 600 $@
-check: $(PROGS) rofile rwfile wofile
+check: $(PROGS) testdir/rofile testdir/rwfile testdir/wofile
./runtests.sh $(PROGS)
diff --git a/harness/README b/harness/README
new file mode 100644
index 0000000..3569ea2
--- /dev/null
+++ b/harness/README
@@ -0,0 +1,17 @@
+Notes on running this test suite:
+
+To run the test suite, run "make check". All test cases should pass
+and there should be 0 fails.
+
+Several of the test cases require a directory on the filesystem under
+test for the creation of test files, as well as the generation of
+error conditions. The test cases assume the directories (or symlinks
+to directories) are as follows:
+
+ testdir/
+ - used for general read/write test cases. Must have at
+ least as much free space as the machine has RAM (up
+ to 768MB).
+ testdir.enospc/
+ - a filesystem that has space for writing 8KB out, but
+ fails with -ENOSPC beyond 8KB.
diff --git a/harness/cases/4.t b/harness/cases/4.t
index 4ca1329..26e79c5 100644
--- a/harness/cases/4.t
+++ b/harness/cases/4.t
@@ -9,14 +9,14 @@
#define SIZE 512
#define READ 'r'
#define WRITE 'w'
-int attempt(int fd, void *buf, int count, int rw, int expect)
+int attempt(int fd, void *buf, int count, long long pos, int rw, int expect)
{
struct iocb iocb;
int res;
switch(rw) {
- case READ: io_prep_pread (&iocb, fd, buf, count, 0); break;
- case WRITE: io_prep_pwrite(&iocb, fd, buf, count, 0); break;
+ case READ: io_prep_pread (&iocb, fd, buf, count, pos); break;
+ case WRITE: io_prep_pwrite(&iocb, fd, buf, count, pos); break;
}
printf("expect %3d: (%c), res = ", expect, rw);
@@ -37,25 +37,31 @@ int test_main(void)
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);
+ rofd = open("testdir/rofile", O_RDONLY); assert(rofd != -1);
+ wofd = open("testdir/wofile", O_WRONLY); assert(wofd != -1);
+ rwfd = open("testdir/rwfile", O_RDWR); assert(rwfd != -1);
- 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);
+ status |= attempt(rofd, buf, SIZE, 0, WRITE, -EBADF);
+ status |= attempt(wofd, buf, SIZE, 0, READ, -EBADF);
+ status |= attempt(rwfd, buf, SIZE, 0, WRITE, SIZE);
+ status |= attempt(rwfd, buf, SIZE, 0, READ, SIZE);
+ status |= attempt(rwfd, buf, SIZE, -1, READ, -EINVAL);
+ status |= attempt(rwfd, buf, SIZE, -1, WRITE, -EINVAL);
- rwfd = open("rwfile", O_RDWR | O_APPEND); assert(rwfd != -1);
+ rwfd = open("testdir/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);
+ status |= attempt(rwfd, buf, SIZE, 0, READ, 0);
+ status |= attempt(rwfd, "1234", 4, 0, WRITE, 4);
+ status |= attempt(rwfd, "5678", 4, 0, WRITE, 4);
memset(buf, 0, SIZE);
- status |= attempt(rwfd, buf, SIZE, READ, 8);
+ status |= attempt(rwfd, buf, SIZE, 0, READ, 8);
printf("read after append: [%s]\n", buf);
assert(memcmp(buf, "12345678", 8) == 0);
+ status |= attempt(rwfd, KERNEL_RW_POINTER, SIZE, 0, READ, -EFAULT);
+ status |= attempt(rwfd, KERNEL_RW_POINTER, SIZE, 0, WRITE, -EFAULT);
+ status |= attempt(rwfd, NULL, SIZE, 0, WRITE, -EFAULT);
+
return status;
}
diff --git a/harness/cases/5.t b/harness/cases/5.t
new file mode 100644
index 0000000..07bbfd1
--- /dev/null
+++ b/harness/cases/5.t
@@ -0,0 +1,33 @@
+/* 5.t
+- Write from a mmap() of the same file. (5.t)
+*/
+#include "aio_setup.h"
+#include <sys/mman.h>
+
+int test_main(void)
+{
+ int page_size = getpagesize();
+#define SIZE 512
+ char *buf;
+ int rwfd;
+ int status = 0, res;
+
+ rwfd = open("testdir/rwfile", O_RDWR); assert(rwfd != -1);
+ res = ftruncate(rwfd, 512); assert(res == 0);
+
+ buf = mmap(0, page_size, PROT_READ|PROT_WRITE, MAP_SHARED, rwfd, 0);
+ assert(buf != (char *)-1);
+
+ status |= attempt_rw(rwfd, buf, SIZE, 0, WRITE, SIZE);
+ status |= attempt_rw(rwfd, buf, SIZE, 0, READ, SIZE);
+
+ res = munmap(buf, page_size); assert(res == 0);
+ buf = mmap(0, page_size, PROT_READ|PROT_WRITE, MAP_SHARED, rwfd, 0);
+ assert(buf != (char *)-1);
+
+ status |= attempt_rw(rwfd, buf, SIZE, 0, READ, SIZE);
+ status |= attempt_rw(rwfd, buf, SIZE, 0, WRITE, SIZE);
+
+ return status;
+}
+
diff --git a/harness/cases/6.t b/harness/cases/6.t
new file mode 100644
index 0000000..e4fb5e6
--- /dev/null
+++ b/harness/cases/6.t
@@ -0,0 +1,57 @@
+/* 6.t
+- huge reads (pinned pages) (6.t)
+- huge writes (6.t)
+*/
+#include "aio_setup.h"
+#include <sys/mman.h>
+
+long getmemsize(void)
+{
+ FILE *f = fopen("/proc/meminfo", "r");
+ long size;
+ int gotit = 0;
+ char str[256];
+
+ assert(f != NULL);
+ while (NULL != fgets(str, 255, f)) {
+ str[255] = 0;
+ if (0 == memcmp(str, "MemTotal:", 9)) {
+ if (1 == sscanf(str + 9, "%ld", &size)) {
+ gotit = 1;
+ break;
+ }
+ }
+ }
+ fclose(f);
+
+ assert(gotit != 0);
+ return size;
+}
+
+int test_main(void)
+{
+ char *buf;
+ int rwfd;
+ int status = 0, res;
+ long size;
+
+ size = getmemsize();
+ printf("size = %ld\n", size);
+ assert(size >= (16 * 1024));
+ if (size > (768 * 1024))
+ size = 768 * 1024;
+ size *= 1024;
+
+ rwfd = open("testdir/rwfile", O_RDWR); assert(rwfd != -1);
+ res = ftruncate(rwfd, 0); assert(res == 0);
+ buf = malloc(size); assert(buf != NULL);
+ memset(buf, 0, size);
+
+ status |= attempt_rw(rwfd, buf, size, 0, WRITE, size);
+ status |= attempt_rw(rwfd, buf, size, 0, READ, size);
+
+ res = ftruncate(rwfd, 0); assert(res == 0);
+
+ return status;
+}
+
diff --git a/harness/cases/aio_setup.h b/harness/cases/aio_setup.h
index 204be0b..bcaf8a5 100644
--- a/harness/cases/aio_setup.h
+++ b/harness/cases/aio_setup.h
@@ -37,3 +37,27 @@ int sync_submit(struct iocb *iocb)
}
#define SETUP aio_setup(1024)
+
+
+#define READ 'r'
+#define WRITE 'w'
+int attempt_rw(int fd, void *buf, int count, long long pos, int rw, int expect)
+{
+ struct iocb iocb;
+ int res;
+
+ switch(rw) {
+ case READ: io_prep_pread (&iocb, fd, buf, count, pos); break;
+ case WRITE: io_prep_pwrite(&iocb, fd, buf, count, pos); 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;
+}
+