diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-01 09:36:31 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-01 09:37:52 +0200 |
| commit | fa1ea53e6f3dd6b9b5f5f8160776b230184a30bf (patch) | |
| tree | 483d7a4b48a879d535b80d20ae43dcebaec99079 /kernel/tests/src | |
| parent | 5ae03c52fe33882416aa6044993d8422ccb33ab4 (diff) | |
| download | teachos-fa1ea53e6f3dd6b9b5f5f8160776b230184a30bf.tar.xz teachos-fa1ea53e6f3dd6b9b5f5f8160776b230184a30bf.zip | |
kernel/tests: implement platform CIO kapi
Diffstat (limited to 'kernel/tests/src')
| -rw-r--r-- | kernel/tests/src/log_buffer.cpp | 39 | ||||
| -rw-r--r-- | kernel/tests/src/main.cpp | 4 | ||||
| -rw-r--r-- | kernel/tests/src/test_support.cpp | 19 | ||||
| -rw-r--r-- | kernel/tests/src/test_support.tests.cpp | 51 |
4 files changed, 94 insertions, 19 deletions
diff --git a/kernel/tests/src/log_buffer.cpp b/kernel/tests/src/log_buffer.cpp new file mode 100644 index 0000000..9e30afb --- /dev/null +++ b/kernel/tests/src/log_buffer.cpp @@ -0,0 +1,39 @@ +#include "kernel/tests/log_buffer.hpp" + +#include <algorithm> +#include <string> +#include <vector> + +namespace kernel::tests::log_buffer +{ + + namespace + { + std::vector<std::string> recorded_messages{}; + } + + auto append(std::string const & message) -> void + { + recorded_messages.push_back(message); + } + + auto clear() -> void + { + recorded_messages.clear(); + } + + auto flat_messages() -> std::string + { + return std::ranges::fold_left(recorded_messages, std::string{}, + [](std::string accumulator, std::string const & message) { + accumulator += message; + return accumulator; + }); + } + + auto messages() -> std::vector<std::string> const & + { + return recorded_messages; + } + +} // namespace kernel::tests::log_buffer diff --git a/kernel/tests/src/main.cpp b/kernel/tests/src/main.cpp index 89bb1c7..f1f9bb4 100644 --- a/kernel/tests/src/main.cpp +++ b/kernel/tests/src/main.cpp @@ -1,6 +1,10 @@ +#include <kapi/cio.hpp> + #include <catch2/catch_session.hpp> auto main(int argc, char ** argv) -> int { + kapi::cio::init(); + return Catch::Session().run(argc, argv); }
\ No newline at end of file diff --git a/kernel/tests/src/test_support.cpp b/kernel/tests/src/test_support.cpp deleted file mode 100644 index bbf5dc0..0000000 --- a/kernel/tests/src/test_support.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "kapi/cpu.hpp" - -#include "kernel/tests/cpu.hpp" - -#include <catch2/catch_test_macros.hpp> - -SCENARIO("Kernel test support infrastructure", "[support]") -{ - GIVEN("the test support infrastructure is initialized") - { - WHEN("when a CPU halt is requested") - { - THEN("the correct exception is thrown") - { - REQUIRE_THROWS_AS(kapi::cpu::halt(), kernel::tests::cpu::halt); - } - } - } -}
\ No newline at end of file diff --git a/kernel/tests/src/test_support.tests.cpp b/kernel/tests/src/test_support.tests.cpp new file mode 100644 index 0000000..f835e65 --- /dev/null +++ b/kernel/tests/src/test_support.tests.cpp @@ -0,0 +1,51 @@ +#include "kapi/cpu.hpp" +#include "kapi/system.hpp" + +#include "kernel/tests/cpu.hpp" +#include "kernel/tests/log_buffer.hpp" + +#include <kstd/print> + +#include <catch2/catch_test_macros.hpp> + +SCENARIO("Kernel test support infrastructure", "[support]") +{ + GIVEN("the test support infrastructure is initialized") + { + WHEN("a CPU halt is requested") + { + THEN("the correct exception is thrown") + { + REQUIRE_THROWS_AS(kapi::cpu::halt(), kernel::tests::cpu::halt); + } + } + + WHEN("a the system panics") + { + kernel::tests::log_buffer::clear(); + + THEN("the correct exception is thrown") + { + REQUIRE_THROWS_AS(kapi::system::panic("[kernel:tests] Test Panic"), kernel::tests::cpu::halt); + } + + THEN("the message is appended to the log buffer") + { + CHECK_THROWS(kapi::system::panic("[kernel:tests] Test Panic")); + REQUIRE(kernel::tests::log_buffer::flat_messages().contains("[kernel:tests] Test Panic")); + } + } + + WHEN("a regular print is issued") + { + kernel::tests::log_buffer::clear(); + + kstd::println("[kernel:tests] Test Print"); + + THEN("the message is appended to the log buffer") + { + REQUIRE(kernel::tests::log_buffer::flat_messages().contains("[kernel:tests] Test Print")); + } + } + } +}
\ No newline at end of file |
