summaryrefslogtreecommitdiff
path: root/src/kernel/core
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2010-09-10 18:46:00 +0200
committerAlexis211 <alexis211@gmail.com>2010-09-10 18:46:00 +0200
commitaba6ed4b91aff5d914be11704e34de75bfd4d003 (patch)
tree3d5cf90e9ccad09d352c6a61e90027ef552dd87f /src/kernel/core
parent5fc3baaa17a6ffb34490bb8accb86f53ef3d6d15 (diff)
downloadTCE-aba6ed4b91aff5d914be11704e34de75bfd4d003.tar.gz
TCE-aba6ed4b91aff5d914be11704e34de75bfd4d003.zip
Each thread has its own stack. Added simple unit tests for kmalloc,kfree
Found a bug in heap_contract (not sure) but didn't fix it.
Diffstat (limited to 'src/kernel/core')
-rw-r--r--src/kernel/core/kmain.c3
-rw-r--r--src/kernel/core/monitor.h3
-rw-r--r--src/kernel/core/sys.c2
-rw-r--r--src/kernel/core/test.c31
-rw-r--r--src/kernel/core/test.h6
5 files changed, 43 insertions, 2 deletions
diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c
index 65a39e6..6c9700e 100644
--- a/src/kernel/core/kmain.c
+++ b/src/kernel/core/kmain.c
@@ -2,6 +2,7 @@
#include "multiboot.h"
#include "monitor.h"
#include "sys.h"
+#include "test.h"
#include <task/idt.h>
#include <task/timer.h>
#include <task/task.h>
@@ -63,6 +64,8 @@ void kmain(struct multiboot_info_t* mbd, int32_t magic) {
}
}
+ test_run();
+
monitor_write("Modules now RULE THE WORLD !\n");
sti();
tasking_switch();
diff --git a/src/kernel/core/monitor.h b/src/kernel/core/monitor.h
index c04632e..bb8e16e 100644
--- a/src/kernel/core/monitor.h
+++ b/src/kernel/core/monitor.h
@@ -10,11 +10,12 @@ void monitor_writeHex(uint32_t v);
void monitor_writeDec(uint32_t v);
#define NL monitor_put('\n');
+#define TAB monitor_put('\t');
#define WHERE { monitor_write("(kernel:"); \
monitor_write(__FILE__); \
monitor_write(":"); \
monitor_writeDec(__LINE__); \
- monitor_write(") "); }
+ monitor_write(")\t"); }
#endif
diff --git a/src/kernel/core/sys.c b/src/kernel/core/sys.c
index 56de038..05a7bc5 100644
--- a/src/kernel/core/sys.c
+++ b/src/kernel/core/sys.c
@@ -28,7 +28,7 @@ uint16_t inw(uint16_t port) {
void stack_trace(size_t bp) {
uint32_t *stack = (uint32_t*)bp, i;
for (i = 0; i < 5 && stack > 0xE0000000 && stack < (bp + 0x8000); i++) {
- monitor_write(" "); monitor_writeHex(stack);
+ monitor_write("| "); monitor_writeHex(stack);
monitor_write("\tnext:"); monitor_writeHex(stack[0]); monitor_write("\t\tret:"); monitor_writeHex(stack[1]);
monitor_write("\n");
stack = (uint32_t*)stack[0];
diff --git a/src/kernel/core/test.c b/src/kernel/core/test.c
new file mode 100644
index 0000000..77c7029
--- /dev/null
+++ b/src/kernel/core/test.c
@@ -0,0 +1,31 @@
+#include "test.h"
+#include "monitor.h"
+#include <mem/mem.h>
+#include "sys.h"
+
+#define TEST_KMALLOC(var, sz) monitor_write("kmalloc:"); monitor_writeHex(sz); void *var = kmalloc(sz); \
+ if (var < 0xE0000000) { monitor_write(":FAIL\t"); PANIC("A test failed."); } \
+ else monitor_write(":OK:"); monitor_writeHex(var); monitor_write("\t");
+#define TEST_KFREE(var) if (var != 0) { monitor_write("kfree:"); monitor_writeHex(var); kfree(var); monitor_write(":OK\t"); }
+
+void test_run() {
+ monitor_write("Run kmalloc() and kfree() unit tests:\n");
+ int i;
+ for (i = 1; i <= 5; i++) {
+ monitor_write("\nMALLOC TEST SERIES #"); monitor_writeDec(i); monitor_write(":\n");
+ TEST_KMALLOC(a, 32);
+ TEST_KMALLOC(b, 64);
+ TEST_KMALLOC(c, 256);
+ TEST_KMALLOC(d, 512);
+ TEST_KMALLOC(e, 1024);
+ TEST_KMALLOC(f, 4096);
+ TEST_KMALLOC(g, 16384);
+ TEST_KFREE(b);
+ TEST_KFREE(c);
+ TEST_KFREE(d);
+ TEST_KFREE(e);
+ TEST_KFREE(f);
+ TEST_KFREE(g);
+ }
+ monitor_write("\nUnit tests finished.\n");
+}
diff --git a/src/kernel/core/test.h b/src/kernel/core/test.h
new file mode 100644
index 0000000..ee689c6
--- /dev/null
+++ b/src/kernel/core/test.h
@@ -0,0 +1,6 @@
+#ifndef DEF_TEST_H
+#define DEF_TEST_H
+
+void test_run(); //run basic unit tests on kmalloc() and kfree()
+
+#endif