From b5d4da532a8c480da7e07d67c9263e4d35dbf0ed Mon Sep 17 00:00:00 2001 From: Undefine Date: Thu, 22 Oct 2026 14:26:46 +0200 Subject: [PATCH] Tests: Add a simple test for the LibACPI AML Interpreter The test .aml file was built with iASL 20260930, using `iasl Tests/LibACPI/test-inputs/scope_and_name.dsl` --- Meta/Lagom/CMakeLists.txt | 1 + Tests/CMakeLists.txt | 1 + Tests/LibACPI/CMakeLists.txt | 9 +++++ Tests/LibACPI/TestAML.cpp | 33 +++++++++++++++++++ Tests/LibACPI/test-inputs/scope_and_name.aml | Bin 0 -> 57 bytes Tests/LibACPI/test-inputs/scope_and_name.asl | 8 +++++ 6 files changed, 52 insertions(+) create mode 100644 Tests/LibACPI/CMakeLists.txt create mode 100644 Tests/LibACPI/TestAML.cpp create mode 100644 Tests/LibACPI/test-inputs/scope_and_name.aml create mode 100644 Tests/LibACPI/test-inputs/scope_and_name.asl diff --git a/Meta/Lagom/CMakeLists.txt b/Meta/Lagom/CMakeLists.txt index 4aa9630939b..0df450cee25 100644 --- a/Meta/Lagom/CMakeLists.txt +++ b/Meta/Lagom/CMakeLists.txt @@ -691,6 +691,7 @@ if (BUILD_LAGOM) set(TEST_DIRECTORIES AK Kernel/POSIX + LibACPI LibCompress LibCrypto LibDisassembly diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index da89a26462e..926774006aa 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1,5 +1,6 @@ add_subdirectory(AK) add_subdirectory(Kernel) +add_subdirectory(LibACPI) add_subdirectory(LibAudio) add_subdirectory(LibC) add_subdirectory(LibCompress) diff --git a/Tests/LibACPI/CMakeLists.txt b/Tests/LibACPI/CMakeLists.txt new file mode 100644 index 00000000000..59490a4b185 --- /dev/null +++ b/Tests/LibACPI/CMakeLists.txt @@ -0,0 +1,9 @@ +set(TEST_SOURCES + TestAML.cpp +) + +foreach(source IN LISTS TEST_SOURCES) + serenity_test("${source}" LibACPI LIBS LibACPI) +endforeach() + +install(DIRECTORY test-inputs DESTINATION usr/Tests/LibACPI) diff --git a/Tests/LibACPI/TestAML.cpp b/Tests/LibACPI/TestAML.cpp new file mode 100644 index 00000000000..94047bed83d --- /dev/null +++ b/Tests/LibACPI/TestAML.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2026, Undefine + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include + +#ifdef AK_OS_SERENITY +# define TEST_INPUT(x) ("/usr/Tests/LibACPI/test-inputs/" x) +#else +# define TEST_INPUT(x) ("test-inputs/" x) +#endif + +TEST_CASE(scope_and_name) +{ + auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("scope_and_name.aml"sv))); + + auto interpreter = TRY_OR_FAIL(ACPI::AML::Interpreter::create()); + TRY_OR_FAIL(interpreter->load(file->bytes())); + + auto num1 = TRY_OR_FAIL(interpreter->evaluate(TRY_OR_FAIL(ACPI::AML::NameString::from_string_view("\\_SB_.NUM1"sv)))); + EXPECT(num1.is()); + EXPECT_EQ(MUST(num1.as()), 0x1234ul); + + auto num2 = TRY_OR_FAIL(interpreter->evaluate(TRY_OR_FAIL(ACPI::AML::NameString::from_string_view("\\_SB_.NUM2"sv)))); + EXPECT(num2.is()); + EXPECT_EQ(MUST(num2.as()), 42ul); +} diff --git a/Tests/LibACPI/test-inputs/scope_and_name.aml b/Tests/LibACPI/test-inputs/scope_and_name.aml new file mode 100644 index 0000000000000000000000000000000000000000..8f8eba31d357e1a47174efe0d44297116daaa00f GIT binary patch literal 57 zcmZ<>b_ua$U|?X%atd{K_jC<*4RZDK42fg}ih25l_!w}iDF}$f2Rp@c_=Wl!a+?T& IXd^By0B7P10RR91 literal 0 HcmV?d00001 diff --git a/Tests/LibACPI/test-inputs/scope_and_name.asl b/Tests/LibACPI/test-inputs/scope_and_name.asl new file mode 100644 index 00000000000..ae3f37e097b --- /dev/null +++ b/Tests/LibACPI/test-inputs/scope_and_name.asl @@ -0,0 +1,8 @@ +DefinitionBlock ("", "DSDT", 2, "BUGGIE", "SERENITY", 0x00000001) +{ + Scope (\_SB) + { + Name (NUM1, 0x1234) + Name (NUM2, 42) + } +}