aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-14 19:15:43 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-14 19:15:43 +0100
commit1ca147f9e08202dfbc78692e204adac280f8238b (patch)
tree70cf40c14aae874bae814a9dcddbfdf5aba52079 /src/tests
parent74ea640f40285220dfa93492a143a35426b867d1 (diff)
downloadkogata-1ca147f9e08202dfbc78692e204adac280f8238b.tar.gz
kogata-1ca147f9e08202dfbc78692e204adac280f8238b.zip
Rearrange testing architecture : just type 'make run_tests'
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Makefile2
l---------src/tests/ktests/breakpoint/Makefile1
-rw-r--r--src/tests/ktests/breakpoint/test.c13
l---------src/tests/ktests/cmdline/Makefile1
-rw-r--r--src/tests/ktests/cmdline/test.c24
l---------src/tests/ktests/hashtbl1/Makefile1
-rw-r--r--src/tests/ktests/hashtbl1/test.c41
l---------src/tests/ktests/hashtbl2/Makefile1
-rw-r--r--src/tests/ktests/hashtbl2/test.c42
l---------src/tests/ktests/kmalloc/Makefile1
-rw-r--r--src/tests/ktests/kmalloc/test.c32
l---------src/tests/ktests/region1/Makefile1
-rw-r--r--src/tests/ktests/region1/test.c36
l---------src/tests/ktests/region2/Makefile1
-rw-r--r--src/tests/ktests/region2/test.c34
-rw-r--r--src/tests/ktests/rules.make17
-rwxr-xr-xsrc/tests/ktests/run_qemu_test.sh12
-rwxr-xr-xsrc/tests/run_tests.sh13
-rw-r--r--src/tests/slab_test/Makefile5
-rw-r--r--src/tests/slab_test/slab_test.c (renamed from src/tests/slab_test.c)0
20 files changed, 276 insertions, 2 deletions
diff --git a/src/tests/Makefile b/src/tests/Makefile
deleted file mode 100644
index 4a21edf..0000000
--- a/src/tests/Makefile
+++ /dev/null
@@ -1,2 +0,0 @@
-slab_test.bin: slab_test.c ../include/slab_alloc.h ../lib/slab_alloc.c
- gcc -m32 -o $@ -std=c99 -I ../include slab_test.c ../lib/slab_alloc.c
diff --git a/src/tests/ktests/breakpoint/Makefile b/src/tests/ktests/breakpoint/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/ktests/breakpoint/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/ktests/breakpoint/test.c b/src/tests/ktests/breakpoint/test.c
new file mode 100644
index 0000000..cd577e0
--- /dev/null
+++ b/src/tests/ktests/breakpoint/test.c
@@ -0,0 +1,13 @@
+
+void test_breakpoint() {
+ BEGIN_TEST("breakpoint-test");
+
+ asm volatile("int $0x3"); // test breakpoint
+
+ TEST_OK;
+}
+
+#undef TEST_PLACEHOLDER_AFTER_IDT
+#define TEST_PLACEHOLDER_AFTER_IDT { test_breakpoint(); }
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/tests/ktests/cmdline/Makefile b/src/tests/ktests/cmdline/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/ktests/cmdline/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/ktests/cmdline/test.c b/src/tests/ktests/cmdline/test.c
new file mode 100644
index 0000000..a6d0a4c
--- /dev/null
+++ b/src/tests/ktests/cmdline/test.c
@@ -0,0 +1,24 @@
+
+void test_cmdline(multiboot_info_t *mbd, fs_t *devfs) {
+ BEGIN_TEST("test-cmdline");
+
+ fs_handle_t *f = fs_open(devfs, "/cmdline", FM_READ);
+ ASSERT(f != 0);
+
+ char buf[256];
+ size_t l = file_read(f, 0, 255, buf);
+ ASSERT(l > 0);
+ buf[l] = 0;
+
+ unref_file(f);
+ dbg_printf("Command line as in /cmdline file: '%s'.\n", buf);
+
+ ASSERT(strcmp(buf, (char*)mbd->cmdline) == 0);
+
+ TEST_OK;
+}
+
+#undef TEST_PLACEHOLDER_AFTER_DEVFS
+#define TEST_PLACEHOLDER_AFTER_DEVFS { test_cmdline(mbd, devfs); }
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/tests/ktests/hashtbl1/Makefile b/src/tests/ktests/hashtbl1/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/ktests/hashtbl1/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/ktests/hashtbl1/test.c b/src/tests/ktests/hashtbl1/test.c
new file mode 100644
index 0000000..993718c
--- /dev/null
+++ b/src/tests/ktests/hashtbl1/test.c
@@ -0,0 +1,41 @@
+#include <hashtbl.h>
+
+void test_hashtbl_1() {
+ BEGIN_TEST("test-hashtbl-1");
+
+ // hashtable test
+ hashtbl_t *ht = create_hashtbl(str_key_eq_fun, str_hash_fun, 0);
+ ASSERT(ht != 0);
+
+ ASSERT(hashtbl_add(ht, "test1", "STRTEST1"));
+ ASSERT(hashtbl_add(ht, "test2", "STRTEST2"));
+ ASSERT(hashtbl_find(ht, "test1") != 0 &&
+ strcmp(hashtbl_find(ht, "test1"), "STRTEST1") == 0);
+ ASSERT(hashtbl_find(ht, "test2") != 0 &&
+ strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0);
+ ASSERT(hashtbl_find(ht, "test") == 0);
+
+ ASSERT(hashtbl_add(ht, "test", "Forever alone"));
+ ASSERT(hashtbl_find(ht, "test1") != 0 &&
+ strcmp(hashtbl_find(ht, "test1"), "STRTEST1") == 0);
+ ASSERT(hashtbl_find(ht, "test2") != 0 &&
+ strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0);
+ ASSERT(hashtbl_find(ht, "test") != 0 &&
+ strcmp(hashtbl_find(ht, "test"), "Forever alone") == 0);
+
+ hashtbl_remove(ht, "test1");
+ ASSERT(hashtbl_find(ht, "test1") == 0);
+ ASSERT(hashtbl_find(ht, "test2") != 0 &&
+ strcmp(hashtbl_find(ht, "test2"), "STRTEST2") == 0);
+ ASSERT(hashtbl_find(ht, "test") != 0 &&
+ strcmp(hashtbl_find(ht, "test"), "Forever alone") == 0);
+
+ delete_hashtbl(ht);
+
+ TEST_OK;
+}
+
+#undef TEST_PLACEHOLDER_AFTER_TASKING
+#define TEST_PLACEHOLDER_AFTER_TASKING { test_hashtbl_1(); }
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/tests/ktests/hashtbl2/Makefile b/src/tests/ktests/hashtbl2/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/ktests/hashtbl2/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/ktests/hashtbl2/test.c b/src/tests/ktests/hashtbl2/test.c
new file mode 100644
index 0000000..2441e79
--- /dev/null
+++ b/src/tests/ktests/hashtbl2/test.c
@@ -0,0 +1,42 @@
+#include <hashtbl.h>
+
+void test_hashtbl_2() {
+ BEGIN_TEST("test-hashtbl-2");
+
+ hashtbl_t *ht = create_hashtbl(id_key_eq_fun, id_hash_fun, 0);
+ ASSERT(ht != 0);
+
+ ASSERT(hashtbl_add(ht, (void*)12, "TESTSTR12"));
+ ASSERT(hashtbl_add(ht, (void*)777, "TESTSTR777"));
+
+ ASSERT(hashtbl_find(ht, (void*)12) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)12), "TESTSTR12") == 0);
+ ASSERT(hashtbl_find(ht, (void*)777) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0);
+ ASSERT(hashtbl_find(ht, (void*)144) == 0);
+
+ ASSERT(hashtbl_add(ht, (void*)144, "Forever alone"));
+
+ ASSERT(hashtbl_find(ht, (void*)12) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)12), "TESTSTR12") == 0);
+ ASSERT(hashtbl_find(ht, (void*)144) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)144), "Forever alone") == 0);
+ ASSERT(hashtbl_find(ht, (void*)777) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0);
+
+ hashtbl_remove(ht, (void*)12);
+ ASSERT(hashtbl_find(ht, (void*)12) == 0);
+ ASSERT(hashtbl_find(ht, (void*)144) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)144), "Forever alone") == 0);
+ ASSERT(hashtbl_find(ht, (void*)777) != 0 &&
+ strcmp(hashtbl_find(ht, (void*)777), "TESTSTR777") == 0);
+
+ delete_hashtbl(ht);
+
+ TEST_OK;
+}
+
+#undef TEST_PLACEHOLDER_AFTER_TASKING
+#define TEST_PLACEHOLDER_AFTER_TASKING { test_hashtbl_2(); }
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/tests/ktests/kmalloc/Makefile b/src/tests/ktests/kmalloc/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/ktests/kmalloc/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/ktests/kmalloc/test.c b/src/tests/ktests/kmalloc/test.c
new file mode 100644
index 0000000..2b5dc6d
--- /dev/null
+++ b/src/tests/ktests/kmalloc/test.c
@@ -0,0 +1,32 @@
+
+void kmalloc_test(void* kernel_data_end) {
+ BEGIN_TEST("kmalloc-test");
+
+ dbg_print_region_info();
+ 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((void*)ptr[i] >= kernel_data_end && (size_t)ptr[i] < 0xFFC00000);
+ *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("Kmalloc test OK.\n");
+ dbg_print_region_info();
+
+ TEST_OK;
+}
+
+#undef TEST_PLACEHOLDER_AFTER_KMALLOC
+#define TEST_PLACEHOLDER_AFTER_KMALLOC { kmalloc_test(kernel_data_end); }
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/tests/ktests/region1/Makefile b/src/tests/ktests/region1/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/ktests/region1/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/ktests/region1/test.c b/src/tests/ktests/region1/test.c
new file mode 100644
index 0000000..1a42638
--- /dev/null
+++ b/src/tests/ktests/region1/test.c
@@ -0,0 +1,36 @@
+
+void test_region_1() {
+ BEGIN_TEST("region-test-1");
+
+ void* p = region_alloc(0x1000, "Test region", 0);
+ dbg_printf("Allocated one-page region: 0x%p\n", p);
+ dbg_print_region_info();
+ void* q = region_alloc(0x1000, "Test region", 0);
+ dbg_printf("Allocated one-page region: 0x%p\n", q);
+ dbg_print_region_info();
+ void* r = region_alloc(0x2000, "Test region", 0);
+ dbg_printf("Allocated two-page region: 0x%p\n", r);
+ dbg_print_region_info();
+ void* s = region_alloc(0x10000, "Test region", 0);
+ dbg_printf("Allocated 16-page region: 0x%p\n", s);
+ dbg_print_region_info();
+ region_free(p);
+ dbg_printf("Freed region 0x%p\n", p);
+ dbg_print_region_info();
+ region_free(q);
+ dbg_printf("Freed region 0x%p\n", q);
+ dbg_print_region_info();
+ region_free(r);
+ dbg_printf("Freed region 0x%p\n", r);
+ dbg_print_region_info();
+ region_free(s);
+ dbg_printf("Freed region 0x%p\n", s);
+ dbg_print_region_info();
+
+ TEST_OK;
+}
+
+#undef TEST_PLACEHOLDER_AFTER_REGION
+#define TEST_PLACEHOLDER_AFTER_REGION { test_region_1(); }
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/tests/ktests/region2/Makefile b/src/tests/ktests/region2/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/ktests/region2/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/ktests/region2/test.c b/src/tests/ktests/region2/test.c
new file mode 100644
index 0000000..24908b0
--- /dev/null
+++ b/src/tests/ktests/region2/test.c
@@ -0,0 +1,34 @@
+
+void test_region_2() {
+ BEGIN_TEST("region-test-2");
+
+ // allocate a big region and try to write into it
+ const size_t n = 200;
+ void* p0 = region_alloc(n * PAGE_SIZE, "Test big region", default_allocator_pf_handler);
+ for (size_t i = 0; i < n; i++) {
+ uint32_t *x = (uint32_t*)(p0 + i * PAGE_SIZE);
+ x[0] = 12;
+ x[1] = (i * 20422) % 122;
+ }
+ // unmap memory
+ for (size_t i = 0; i < n; i++) {
+ void* p = p0 + i * PAGE_SIZE;
+ uint32_t *x = (uint32_t*)p;
+ ASSERT(x[1] == (i * 20422) % 122);
+
+ uint32_t f = pd_get_frame(p);
+ ASSERT(f != 0);
+ pd_unmap_page(p);
+ ASSERT(pd_get_frame(p) == 0);
+
+ frame_free(f, 1);
+ }
+ region_free(p0);
+
+ TEST_OK;
+}
+
+#undef TEST_PLACEHOLDER_AFTER_REGION
+#define TEST_PLACEHOLDER_AFTER_REGION { test_region_2(); }
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/tests/ktests/rules.make b/src/tests/ktests/rules.make
new file mode 100644
index 0000000..f31ab89
--- /dev/null
+++ b/src/tests/ktests/rules.make
@@ -0,0 +1,17 @@
+LIB = ../../../kernel/kernel.lib
+
+OBJ = kmain.o
+
+CFLAGS = -I . -I ../../../common/include -I ../../../kernel/include -DIS_A_TEST
+LDFLAGS = -T ../../../kernel/linker.ld -Xlinker -Map=test_kernel.map
+
+OUT = test_kernel.bin
+
+include ../../../rules.make
+
+kmain.o: ../../../kernel/core/kmain.c test.c
+ $(CC) -c $< -o $@ $(CFLAGS)
+
+run_test: all
+ ../run_qemu_test.sh
+
diff --git a/src/tests/ktests/run_qemu_test.sh b/src/tests/ktests/run_qemu_test.sh
new file mode 100755
index 0000000..93c7320
--- /dev/null
+++ b/src/tests/ktests/run_qemu_test.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+(qemu-system-i386 -kernel test_kernel.bin -serial stdio -m 16 -display none & echo $! >&3) 3>pid \
+ | tee >(grep -m 1 "TEST-" >result; kill -INT `cat pid`) \
+
+RESULT=`cat result`
+
+rm result
+rm pid
+
+if [ $RESULT != '(TEST-OK)' ]; then exit 1; fi
+
diff --git a/src/tests/run_tests.sh b/src/tests/run_tests.sh
new file mode 100755
index 0000000..bd23801
--- /dev/null
+++ b/src/tests/run_tests.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+cd `dirname $0`
+
+for FILE in */Makefile */*/Makefile; do
+ TEST=`dirname $FILE`
+ echo -n "Running test $TEST ... "
+ if make -C $TEST run_test > $TEST/test.log 2>&1; then
+ echo OK
+ else
+ echo FAIL
+ fi
+done
diff --git a/src/tests/slab_test/Makefile b/src/tests/slab_test/Makefile
new file mode 100644
index 0000000..4cda341
--- /dev/null
+++ b/src/tests/slab_test/Makefile
@@ -0,0 +1,5 @@
+slab_test.bin: slab_test.c ../../common/include/slab_alloc.h ../../common/libkogata/slab_alloc.c
+ gcc -m32 -o $@ -std=c99 -I ../../common/include slab_test.c ../../common/libkogata/slab_alloc.c
+
+run_test: slab_test.bin
+ ./slab_test.bin
diff --git a/src/tests/slab_test.c b/src/tests/slab_test/slab_test.c
index 747c785..747c785 100644
--- a/src/tests/slab_test.c
+++ b/src/tests/slab_test/slab_test.c