diff options
| -rw-r--r-- | .clangd | 1 | ||||
| -rw-r--r-- | .devcontainer/x86-64/devcontainer.json | 2 | ||||
| -rw-r--r-- | libs/acpi/CMakeLists.txt | 19 | ||||
| -rw-r--r-- | libs/acpi/acpi/pointers.cpp | 4 | ||||
| -rw-r--r-- | libs/acpi/acpi/pointers.test.cpp | 29 |
5 files changed, 52 insertions, 3 deletions
@@ -11,6 +11,7 @@ Documentation: If: PathMatch: - "libs/.*/tests/.*\\.cpp" + - "libs/.*/.*\\.test\\.cpp" - "kernel/.*\\.tests.cpp" Diagnostics: ClangTidy: diff --git a/.devcontainer/x86-64/devcontainer.json b/.devcontainer/x86-64/devcontainer.json index 6bf1616..775da72 100644 --- a/.devcontainer/x86-64/devcontainer.json +++ b/.devcontainer/x86-64/devcontainer.json @@ -5,7 +5,7 @@ "ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers/features/git-lfs:1": {}, "ghcr.io/devcontainers-extra/features/apt-packages:1": { - "packages": "build-essential,clang-tidy,clangd,cmake,grub2-common,grub-pc,mtools,ninja-build,qemu-system-x86,ssh,xorriso,gdb" + "packages": "acpica-tools,build-essential,clang-tidy,clangd,cmake,grub2-common,grub-pc,mtools,ninja-build,qemu-system-x86,ssh,xorriso,gdb" } }, "customizations": { diff --git a/libs/acpi/CMakeLists.txt b/libs/acpi/CMakeLists.txt index c6e63b9..b8face4 100644 --- a/libs/acpi/CMakeLists.txt +++ b/libs/acpi/CMakeLists.txt @@ -27,3 +27,22 @@ target_sources("acpi" PUBLIC target_link_libraries("acpi" PUBLIC "libs::kstd" ) + +if(NOT CMAKE_CROSSCOMPILING) + add_executable("acpi_tests" + "acpi/pointers.test.cpp" + ) + + target_link_libraries("acpi_tests" PRIVATE + "Catch2::Catch2WithMain" + "libs::acpi" + ) + + set_target_properties("acpi_tests" PROPERTIES + C_CLANG_TIDY "" + CXX_CLANG_TIDY "" + EXCLUDE_FROM_ALL NO + ) + + catch_discover_tests("acpi_tests") +endif() diff --git a/libs/acpi/acpi/pointers.cpp b/libs/acpi/acpi/pointers.cpp index b206cc6..8a8629f 100644 --- a/libs/acpi/acpi/pointers.cpp +++ b/libs/acpi/acpi/pointers.cpp @@ -34,7 +34,7 @@ namespace acpi auto rsdp::validate() const noexcept -> bool { - return validate_checksum({reinterpret_cast<std::byte const *>(this), sizeof(rsdp)}); + return signature() == "RSD PTR " && validate_checksum({reinterpret_cast<std::byte const *>(this), sizeof(rsdp)}); } auto xsdp::length() const noexcept -> kstd::units::bytes @@ -49,7 +49,7 @@ namespace acpi auto xsdp::validate() const noexcept -> bool { - return validate_checksum({reinterpret_cast<std::byte const *>(this), m_length}); + return signature() == "RSD PTR " && validate_checksum({reinterpret_cast<std::byte const *>(this), m_length}); } } // namespace acpi diff --git a/libs/acpi/acpi/pointers.test.cpp b/libs/acpi/acpi/pointers.test.cpp new file mode 100644 index 0000000..06ce1a4 --- /dev/null +++ b/libs/acpi/acpi/pointers.test.cpp @@ -0,0 +1,29 @@ +#include <acpi/pointers.hpp> +#include <catch2/catch_test_macros.hpp> + +#include <array> +#include <bit> +#include <cstddef> + +SCENARIO("ACPI root pointer parsing", "[acpi]") +{ + GIVEN("A null-filled pointer") + { + auto data = std::array<std::byte, sizeof(acpi::rsdp)>{}; + + WHEN("parsing the data") + { + auto rsdp = std::bit_cast<acpi::rsdp>(data); + + THEN("the signature is invalid") + { + REQUIRE(rsdp.signature() != "RSD PTR "); + } + + THEN("validate returns false") + { + REQUIRE_FALSE(rsdp.validate()); + } + } + } +} |
