aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
Diffstat (limited to 'libs')
-rw-r--r--libs/acpi/CMakeLists.txt19
-rw-r--r--libs/acpi/acpi/pointers.cpp4
-rw-r--r--libs/acpi/acpi/pointers.test.cpp29
3 files changed, 50 insertions, 2 deletions
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());
+ }
+ }
+ }
+}