aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/libalgo/btree.c6
-rw-r--r--src/kernel/Makefile4
-rw-r--r--src/kernel/core/kmain.c2
-rw-r--r--src/kernel/core/sys.c4
l---------src/tests/ktests/btree1/Makefile1
-rw-r--r--src/tests/ktests/btree1/test.c41
-rw-r--r--src/tests/ktests/rules.make8
-rwxr-xr-xsrc/tests/run_tests.sh4
8 files changed, 56 insertions, 14 deletions
diff --git a/src/common/libalgo/btree.c b/src/common/libalgo/btree.c
index da0e25b..08a43ef 100644
--- a/src/common/libalgo/btree.c
+++ b/src/common/libalgo/btree.c
@@ -24,7 +24,7 @@ btree_t* create_btree(key_cmp_fun_t cf, kv_iter_fun_t relf) {
if (t == 0) return 0;
t->cf = cf;
- t->releasef = relf;
+ if (t->releasef) t->releasef = relf;
t->root = 0;
t->nitems = 0;
@@ -39,7 +39,7 @@ void delete_btree(btree_t *t) {
delete_item_rec(i->left, relf);
delete_item_rec(i->right, relf);
- relf(i->key, i->val);
+ if (relf) relf(i->key, i->val);
free(i);
}
@@ -182,7 +182,7 @@ void btree_remove(btree_t *t, const void* key) {
new_i = equilibrate(new_i);
}
- t->releasef(i->key, i->val);
+ if (t->releasef) t->releasef(i->key, i->val);
free(i);
t->nitems--;
diff --git a/src/kernel/Makefile b/src/kernel/Makefile
index cbd6a96..a6f9a1b 100644
--- a/src/kernel/Makefile
+++ b/src/kernel/Makefile
@@ -1,5 +1,5 @@
-OBJ = core/loader.o core/dbglog.o core/sys.o \
+OBJ = core/loader.o core/dbglog.o \
core/gdt.o core/idt.o core/interrupt.o core/context_switch.o core/thread.o \
core/frame.o core/paging.o core/region.o core/kmalloc.o \
user/vfs.o user/nullfs.o user/process.o user/elf.o user/syscall.o
@@ -14,7 +14,7 @@ OUT = kernel.lib
include ../rules.make
-kernel.bin: kernel.lib core/kmain.o
+kernel.bin: kernel.lib core/kmain.o core/sys.o
$(LD) $(LDFLAGS) -o $@ $^
all: $(OUT) kernel.bin
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c
index 2e8991e..f5d2ace 100644
--- a/src/kernel/core/kmain.c
+++ b/src/kernel/core/kmain.c
@@ -28,7 +28,7 @@
#define TEST_PLACEHOLDER_AFTER_KMALLOC
#define TEST_PLACEHOLDER_AFTER_TASKING
#define TEST_PLACEHOLDER_AFTER_DEVFS
-#ifdef IS_A_TEST
+#ifdef BUILD_KERNEL_TEST
#define BEGIN_TEST(n) dbg_printf("(BEGIN-TEST %s)\n", n);
#define TEST_OK { dbg_printf("(TEST-OK)\n"); asm volatile("cli; hlt"); }
#include <test.c>
diff --git a/src/kernel/core/sys.c b/src/kernel/core/sys.c
index b1e69ad..fceada7 100644
--- a/src/kernel/core/sys.c
+++ b/src/kernel/core/sys.c
@@ -11,8 +11,8 @@ static void panic_do(const char* type, const char *msg, const char* file, int li
dbg_printf("| System halted -_-'\n");
dbg_printf("\\---------------------------------------------------------/");
BOCHS_BREAKPOINT;
-#ifdef IS_A_TEST
- dbg_printf("(TEST-FAIL)\n");
+#ifdef BUILD_KERNEL_TEST
+ dbg_printf("\n(TEST-FAIL)\n");
#endif
asm volatile("hlt");
}
diff --git a/src/tests/ktests/btree1/Makefile b/src/tests/ktests/btree1/Makefile
new file mode 120000
index 0000000..4630a7c
--- /dev/null
+++ b/src/tests/ktests/btree1/Makefile
@@ -0,0 +1 @@
+../rules.make \ No newline at end of file
diff --git a/src/tests/ktests/btree1/test.c b/src/tests/ktests/btree1/test.c
new file mode 100644
index 0000000..1207a28
--- /dev/null
+++ b/src/tests/ktests/btree1/test.c
@@ -0,0 +1,41 @@
+#include <btree.h>
+
+void test_btree_1() {
+ BEGIN_TEST("test-btree-1");
+
+ // hashtable test
+ btree_t *ht = create_btree(str_key_cmp_fun, 0);
+ ASSERT(ht != 0);
+
+ ASSERT(btree_add(ht, "test1", "STRTEST1"));
+ ASSERT(btree_add(ht, "test2", "STRTEST2"));
+ ASSERT(btree_find(ht, "test1") != 0 &&
+ strcmp(btree_find(ht, "test1"), "STRTEST1") == 0);
+ ASSERT(btree_find(ht, "test2") != 0 &&
+ strcmp(btree_find(ht, "test2"), "STRTEST2") == 0);
+ ASSERT(btree_find(ht, "test") == 0);
+
+ ASSERT(btree_add(ht, "test", "Forever alone"));
+ ASSERT(btree_find(ht, "test1") != 0 &&
+ strcmp(btree_find(ht, "test1"), "STRTEST1") == 0);
+ ASSERT(btree_find(ht, "test2") != 0 &&
+ strcmp(btree_find(ht, "test2"), "STRTEST2") == 0);
+ ASSERT(btree_find(ht, "test") != 0 &&
+ strcmp(btree_find(ht, "test"), "Forever alone") == 0);
+
+ btree_remove(ht, "test1");
+ ASSERT(btree_find(ht, "test1") == 0);
+ ASSERT(btree_find(ht, "test2") != 0 &&
+ strcmp(btree_find(ht, "test2"), "STRTEST2") == 0);
+ ASSERT(btree_find(ht, "test") != 0 &&
+ strcmp(btree_find(ht, "test"), "Forever alone") == 0);
+
+ delete_btree(ht);
+
+ TEST_OK;
+}
+
+#undef TEST_PLACEHOLDER_AFTER_TASKING
+#define TEST_PLACEHOLDER_AFTER_TASKING { test_btree_1(); }
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/tests/ktests/rules.make b/src/tests/ktests/rules.make
index f31ab89..fac175d 100644
--- a/src/tests/ktests/rules.make
+++ b/src/tests/ktests/rules.make
@@ -1,17 +1,17 @@
LIB = ../../../kernel/kernel.lib
-OBJ = kmain.o
+OBJ = kmain.o sys.o
-CFLAGS = -I . -I ../../../common/include -I ../../../kernel/include -DIS_A_TEST
+CFLAGS = -I . -I ../../../common/include -I ../../../kernel/include -DBUILD_KERNEL_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
+%.o: ../../../kernel/core/%.c test.c
$(CC) -c $< -o $@ $(CFLAGS)
-run_test: all
+run_test: rebuild
../run_qemu_test.sh
diff --git a/src/tests/run_tests.sh b/src/tests/run_tests.sh
index bd23801..470959b 100755
--- a/src/tests/run_tests.sh
+++ b/src/tests/run_tests.sh
@@ -6,8 +6,8 @@ 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
+ echo -e "\033[0;32mOK\033[0m"
else
- echo FAIL
+ echo -e "\033[0;31mFAIL\033[0m"
fi
done