summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/main.c4
-rw-r--r--src/kernel/tests/base.h23
-rw-r--r--src/kernel/tests/main.c19
-rw-r--r--src/kernel/tests/tests.h3
4 files changed, 49 insertions, 0 deletions
diff --git a/src/kernel/main.c b/src/kernel/main.c
index 7864699..effdd45 100644
--- a/src/kernel/main.c
+++ b/src/kernel/main.c
@@ -3,6 +3,7 @@
#include <kernel/mem.h>
#include <kernel/panic.h>
#include <kernel/proc.h>
+#include <kernel/tests/tests.h>
#include <kernel/util.h>
#include <stdint.h>
@@ -26,6 +27,9 @@ void kmain(struct kmain_info info) {
log_const("mem...");
mem_init(&info);
+ log_const("tests...");
+ tests_all();
+
log_const("loading init...");
run_init(&info);
diff --git a/src/kernel/tests/base.h b/src/kernel/tests/base.h
new file mode 100644
index 0000000..877b179
--- /dev/null
+++ b/src/kernel/tests/base.h
@@ -0,0 +1,23 @@
+#pragma once
+#include <kernel/arch/log.h>
+#include <kernel/util.h>
+#include <stdbool.h>
+
+extern bool _did_tests_fail;
+
+// tests MUST be used
+#pragma GCC diagnostic error "-Wunused-function"
+
+#define TEST(name) \
+ static void __test_##name()
+
+#define TEST_RUN(name) \
+ __test_##name();
+
+#define TEST_IF(cond) \
+ if (!(cond)) { \
+ _did_tests_fail = true; \
+ log_const("TEST_IF failed at " \
+ __FILE__ ":" NUM2STR(__LINE__) \
+ " "); \
+ }
diff --git a/src/kernel/tests/main.c b/src/kernel/tests/main.c
new file mode 100644
index 0000000..a7e9534
--- /dev/null
+++ b/src/kernel/tests/main.c
@@ -0,0 +1,19 @@
+#include <kernel/panic.h>
+#include <kernel/tests/base.h>
+#include <kernel/tests/tests.h>
+
+bool _did_tests_fail;
+
+TEST(basic_math) {
+ TEST_IF(2 + 2 == 4);
+ TEST_IF(2 * 2 == 4);
+}
+
+void tests_all() {
+ _did_tests_fail = false;
+
+ TEST_RUN(basic_math);
+
+ if (_did_tests_fail)
+ panic();
+}
diff --git a/src/kernel/tests/tests.h b/src/kernel/tests/tests.h
new file mode 100644
index 0000000..d9abce4
--- /dev/null
+++ b/src/kernel/tests/tests.h
@@ -0,0 +1,3 @@
+#pragma once
+
+void tests_all();