diff options
author | dzwdz | 2021-08-03 17:47:00 +0200 |
---|---|---|
committer | dzwdz | 2021-08-03 17:47:00 +0200 |
commit | 5b2bb4e025919d74090d23cbabadfeec3b1e9dc4 (patch) | |
tree | ab01b589041bf509e1fd62650d5ed2fbaba5849e /src | |
parent | b2e43dd96f385e275c08ad531cd1c6bb65e2011f (diff) |
a bad testing framework
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/main.c | 4 | ||||
-rw-r--r-- | src/kernel/tests/base.h | 23 | ||||
-rw-r--r-- | src/kernel/tests/main.c | 19 | ||||
-rw-r--r-- | src/kernel/tests/tests.h | 3 |
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(); |