summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen LaHaise <bcrl@kvack.org>2002-04-18 03:42:13 +0000
committerBen LaHaise <bcrl@kvack.org>2002-04-18 03:42:13 +0000
commit536d7c1d7c2147c4e5a99c6117214f8de0aa152b (patch)
treedbfb244d8bb1934a8bd1825dfae5dbfe034c61e8
parent2df493dbcb9c5d7a64cb285b0e032d08752e37c7 (diff)
downloadlibaio-536d7c1d7c2147c4e5a99c6117214f8de0aa152b.tar.gz
add test harness
-rw-r--r--harness/Makefile32
-rw-r--r--harness/attic/0.t9
-rw-r--r--harness/attic/1.t9
-rw-r--r--harness/cases/2.t42
-rw-r--r--harness/cases/3.t39
-rw-r--r--harness/cases/aio_setup.h37
-rw-r--r--harness/main.c32
-rwxr-xr-xharness/runtests.sh19
8 files changed, 219 insertions, 0 deletions
diff --git a/harness/Makefile b/harness/Makefile
new file mode 100644
index 0000000..e0cdb9a
--- /dev/null
+++ b/harness/Makefile
@@ -0,0 +1,32 @@
+# foo.
+TEST_SRCS:=$(shell find cases/ -name \*.t)
+PROGS:=$(patsubst %.t,%.p,$(TEST_SRCS))
+HARNESS_SRCS:=main.c
+# io_queue.c
+
+CFLAGS=-Wall -g -O -laio -lredhat-kernel
+#-lpthread -lrt
+
+all: $(PROGS)
+
+$(PROGS): %.p: %.t $(HARNESS_SRCS)
+ $(CC) $(CFLAGS) -DTEST_NAME=\"$<\" -o $@ main.c
+
+clean:
+ rm -f $(PROGS) *.o runtests.out rofile wofile rwfile
+
+rofile:
+ touch $@
+ chmod 400 $@
+
+wofile:
+ touch $@
+ chmod 200 $@
+
+rwfile:
+ touch $@
+ chmod 600 $@
+
+check: $(PROGS) rofile rwfile wofile
+ ./runtests.sh $(PROGS)
+
diff --git a/harness/attic/0.t b/harness/attic/0.t
new file mode 100644
index 0000000..033e62c
--- /dev/null
+++ b/harness/attic/0.t
@@ -0,0 +1,9 @@
+/* 0.t
+ Test harness check: okay.
+*/
+int test_main(void)
+{
+ printf("test_main: okay\n");
+ return 0;
+}
+
diff --git a/harness/attic/1.t b/harness/attic/1.t
new file mode 100644
index 0000000..799ffd1
--- /dev/null
+++ b/harness/attic/1.t
@@ -0,0 +1,9 @@
+/* 1.t
+ Test harness check: fail.
+*/
+int test_main(void)
+{
+ printf("test_main: fail\n");
+ return 1;
+}
+
diff --git a/harness/cases/2.t b/harness/cases/2.t
new file mode 100644
index 0000000..d6d548d
--- /dev/null
+++ b/harness/cases/2.t
@@ -0,0 +1,42 @@
+/* 2.t
+- io_setup (#2)
+ - with invalid context pointer
+ - with maxevents <= 0
+ - with an already initialized ctxp
+*/
+#define io_setup vsys_io_setup
+extern int io_setup(unsigned nr_reqs, io_context_t *ctxp);
+
+int attempt(int n, io_context_t *ctxp, int expect)
+{
+ int res;
+
+ printf("expect %3d: io_setup(%5d, %p) = ", expect, n, ctxp);
+ fflush(stdout);
+ res = io_setup(n, ctxp);
+ printf("%3d [%s]\n", res, strerror(-res));
+ if (res != expect)
+ return 1;
+
+ return 0;
+}
+
+int test_main(void)
+{
+ io_context_t ctx;
+ int status = 0;
+
+ ctx = NULL;
+ status |= attempt(-1000, KERNEL_RW_POINTER, -EFAULT);
+ status |= attempt( 1000, KERNEL_RW_POINTER, -EFAULT);
+ status |= attempt( 0, KERNEL_RW_POINTER, -EFAULT);
+ status |= attempt(-1000, &ctx, -EINVAL);
+ status |= attempt( -1, &ctx, -EINVAL);
+ status |= attempt( 0, &ctx, -EINVAL);
+ assert(ctx == NULL);
+ status |= attempt( 1, &ctx, 0);
+ status |= attempt( 1, &ctx, -EINVAL);
+
+ return status;
+}
+
diff --git a/harness/cases/3.t b/harness/cases/3.t
new file mode 100644
index 0000000..cc77fb7
--- /dev/null
+++ b/harness/cases/3.t
@@ -0,0 +1,39 @@
+/* 3.t
+- io_submit/io_getevents with invalid addresses (3.t)
+
+*/
+#include "aio_setup.h"
+
+int attempt(io_context_t ctx, long nr, struct iocb *ios[], int expect)
+{
+ int res;
+
+ printf("expect %3d: io_submit(%10p, %3ld, %10p) = ", expect, ctx, nr, ios);
+ fflush(stdout);
+ res = io_submit(ctx, nr, ios);
+ printf("%3d [%s]\n", res, (res <= 0) ? strerror(-res) : "");
+ if (res != expect)
+ return 1;
+
+ return 0;
+}
+
+int test_main(void)
+{
+ struct iocb a, b;
+ struct iocb *good_ios[] = { &a, &b };
+ struct iocb *bad1_ios[] = { NULL, &b };
+ struct iocb *bad2_ios[] = { KERNEL_RW_POINTER, &a };
+ int status = 0;
+
+ status |= attempt(BAD_CTX, 1, good_ios, -EINVAL);
+ status |= attempt( io_ctx, 0, good_ios, 0);
+ status |= attempt( io_ctx, 1, NULL, -EFAULT);
+ status |= attempt( io_ctx, 1, (void *)-1, -EFAULT);
+ status |= attempt( io_ctx, 2, bad1_ios, -EFAULT);
+ status |= attempt( io_ctx, 2, bad2_ios, -EFAULT);
+ status |= attempt( io_ctx, -1, good_ios, -EINVAL);
+
+ return status;
+}
+
diff --git a/harness/cases/aio_setup.h b/harness/cases/aio_setup.h
new file mode 100644
index 0000000..fccb7f7
--- /dev/null
+++ b/harness/cases/aio_setup.h
@@ -0,0 +1,37 @@
+io_context_t io_ctx;
+#define BAD_CTX ((io_context_t)-1)
+
+void aio_setup(int n)
+{
+ int res = io_queue_init(n, &io_ctx);
+ if (res != 0) {
+ printf("io_queue_setup(%d) returned %d (%s)\n",
+ n, res, strerror(-res));
+ exit(3);
+ }
+}
+
+void sync_submit(struct iocb *iocb, struct io_event *event)
+{
+ struct iocb *iocbs[] = { iocb };
+ int res;
+
+ /* 30 second timeout should be enough */
+ struct timespec ts;
+ ts.tv_sec = 30;
+ ts.tv_nsec = 0;
+
+ res = io_submit(io_ctx, 1, iocbs);
+ if (res != 1) {
+ printf("sync_submit: io_submit res=%d [%s]\n", res, strerror(-res));
+ exit(3);
+ }
+
+ 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);
+ }
+}
+
+#define SETUP aio_setup(1024)
diff --git a/harness/main.c b/harness/main.c
new file mode 100644
index 0000000..4f8b8cc
--- /dev/null
+++ b/harness/main.c
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <errno.h>
+#include <libaio.h>
+#include <assert.h>
+#include <stdlib.h>
+
+#if defined(__i386__)
+#define KERNEL_RW_POINTER ((void *)0xc0010000)
+#else
+#error Configure for arch.
+#endif
+
+
+char test_name[] = TEST_NAME;
+
+#include TEST_NAME
+
+int main(void)
+{
+ int res;
+
+#if defined(SETUP)
+ SETUP;
+#endif
+
+ res = test_main();
+ printf("test %s completed %s.\n", test_name,
+ res ? "FAILED" : "PASSED"
+ );
+ fflush(stdout);
+ return res ? 1 : 0;
+}
diff --git a/harness/runtests.sh b/harness/runtests.sh
new file mode 100755
index 0000000..bbb20b7
--- /dev/null
+++ b/harness/runtests.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+passes=0
+fails=0
+
+echo "Test run starting at" `date`
+
+while [ $# -ge 1 ] ; do
+ this_test=$1
+ shift
+ echo "Starting $this_test"
+ $this_test 2>&1
+ res=$?
+ if [ $res -eq 0 ] ; then passes=$[passes + 1] ; else fails=$[fails + 1] ; fi
+ echo "Completed $this_test with $res"
+done
+
+echo "Pass: $passes Fail: $fails"
+echo "Test run complete at" `date`