aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-19 19:23:34 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-19 19:23:34 +0100
commit7b27ab493b56f9e77d805c4f44a1717f3a79231e (patch)
treea3037447f4e3d428a61a5c3cfb4e2a98ea5981e4 /src/tests
parent62e5a35940198f0f8fbabdf31c80455647420c4e (diff)
downloadkogata-7b27ab493b56f9e77d805c4f44a1717f3a79231e.tar.gz
kogata-7b27ab493b56f9e77d805c4f44a1717f3a79231e.zip
Userland test infrastructure
Diffstat (limited to 'src/tests')
-rwxr-xr-xsrc/tests/ktests/run_qemu_test.sh2
l---------src/tests/utests/fs1/Makefile1
-rw-r--r--src/tests/utests/fs1/test.c40
l---------src/tests/utests/malloc/Makefile1
-rw-r--r--src/tests/utests/malloc/test.c40
-rw-r--r--src/tests/utests/rules.make14
-rwxr-xr-xsrc/tests/utests/run_qemu_test.sh23
7 files changed, 120 insertions, 1 deletions
diff --git a/src/tests/ktests/run_qemu_test.sh b/src/tests/ktests/run_qemu_test.sh
index 93c7320..e18a9d3 100755
--- a/src/tests/ktests/run_qemu_test.sh
+++ b/src/tests/ktests/run_qemu_test.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-(qemu-system-i386 -kernel test_kernel.bin -serial stdio -m 16 -display none & echo $! >&3) 3>pid \
+(qemu-system-i386 -kernel test_kernel.bin -serial stdio -m 16 -display none & echo $! >pid) \
| tee >(grep -m 1 "TEST-" >result; kill -INT `cat pid`) \
RESULT=`cat result`
diff --git a/src/tests/utests/fs1/Makefile b/src/tests/utests/fs1/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/utests/fs1/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/utests/fs1/test.c b/src/tests/utests/fs1/test.c
new file mode 100644
index 0000000..e95449d
--- /dev/null
+++ b/src/tests/utests/fs1/test.c
@@ -0,0 +1,40 @@
+#include <string.h>
+
+#include <malloc.h>
+
+#include <syscall.h>
+#include <debug.h>
+
+int main(int argc, char **argv) {
+ dbg_print("Hello, world! from user process.\n");
+
+ fd_t f = open("dev:/", FM_READDIR);
+ dbg_printf("openned /: %d\n", f);
+ dirent_t x;
+ while (readdir(f, &x)) {
+ dbg_printf("- '%s' %p %d\n", x.name, x.st.type, x.st.size);
+ if (x.st.type == FT_REGULAR) {
+ char buf[256];
+ strcpy(buf, "dev:/");
+ strcpy(buf+5, x.name);
+ dbg_printf("trying to open %s...\n", buf);
+ fd_t ff = open(buf, FM_READ);
+ if (ff != 0) {
+ dbg_printf("ok, open as %d\n", ff);
+ char* cont = malloc(x.st.size + 1);
+ ASSERT(read(ff, 0, x.st.size, cont) == x.st.size);
+ cont[x.st.size] = 0;
+ dbg_printf("> '%s'\n", cont);
+ close(ff);
+ } else {
+ dbg_printf("Could not open '%s'\n", buf);
+ }
+ }
+ }
+ close(f);
+
+ dbg_printf("(TEST-OK)\n");
+
+ return 0;
+}
+
diff --git a/src/tests/utests/malloc/Makefile b/src/tests/utests/malloc/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/utests/malloc/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/utests/malloc/test.c b/src/tests/utests/malloc/test.c
new file mode 100644
index 0000000..bc11d9d
--- /dev/null
+++ b/src/tests/utests/malloc/test.c
@@ -0,0 +1,40 @@
+#include <string.h>
+
+#include <malloc.h>
+
+#include <syscall.h>
+#include <debug.h>
+#include <user_region.h>
+
+int main(int argc, char **argv) {
+ dbg_print("(BEGIN-USER-TEST malloc-test)\n");
+
+ dbg_print_region_info();
+
+ for (int iter = 0; iter < 4; iter++) {
+ dbg_printf("Doing malloc test #%d...\n", iter + 1);
+ const int m = 200;
+ uint16_t** ptr = malloc(m * sizeof(uint32_t));
+ for (int i = 0; i < m; i++) {
+ size_t s = 1 << ((i * 7) % 11 + 2);
+ ptr[i] = (uint16_t*)malloc(s);
+ ASSERT((size_t)ptr[i] >= 0x40000000 && (size_t)ptr[i] < 0xB0000000);
+ *ptr[i] = ((i * 211) % 1024);
+ }
+ dbg_printf("Fully allocated.\n");
+ dbg_print_region_info();
+ for (int i = 0; i < m; i++) {
+ for (int j = i; j < m; j++) {
+ ASSERT(*ptr[j] == (j * 211) % 1024);
+ }
+ free(ptr[i]);
+ }
+ free(ptr);
+ dbg_printf("malloc test OK.\n");
+ dbg_print_region_info();
+ }
+
+ dbg_printf("(TEST-OK)\n");
+
+ return 0;
+}
diff --git a/src/tests/utests/rules.make b/src/tests/utests/rules.make
new file mode 100644
index 0000000..1f4bb1b
--- /dev/null
+++ b/src/tests/utests/rules.make
@@ -0,0 +1,14 @@
+LIB = ../../../lib/libkogata/libkogata.lib ../../../common/libc/libc.lib
+
+OBJ = test.o
+
+CFLAGS = -I . -I ../../../common/include -I ../../../lib/include -DBUILD_USER_TEST
+LDFLAGS = -T ../../../apps/linker.ld -Xlinker -Map=init.map
+
+OUT = init.bin
+
+include ../../../rules.make
+
+run_test: rebuild
+ ../run_qemu_test.sh
+
diff --git a/src/tests/utests/run_qemu_test.sh b/src/tests/utests/run_qemu_test.sh
new file mode 100755
index 0000000..68cf498
--- /dev/null
+++ b/src/tests/utests/run_qemu_test.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+if [ $1 = 'watchdog' ]; then
+ sleep 10 &
+ PID=$!
+ echo $PID > pid2
+ wait $PID
+ if [ $? -eq 0 ]; then echo "(TEST-FAIL)"; fi
+ exit 0
+fi
+
+(qemu-system-i386 -kernel ../../../kernel/kernel.bin -initrd init.bin -serial stdio -m 16 -display none & echo $! >pid &
+ $0 watchdog) \
+ | tee >(grep -m 1 "TEST-" >result; kill -INT `cat pid`; kill -TERM `cat pid2`) \
+
+RESULT=`cat result`
+
+rm result
+rm pid
+rm pid2
+
+if [ $RESULT != '(TEST-OK)' ]; then exit 1; fi
+