mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:47:34 +00:00
LibDeviceTree: Add a simple DeviceTree class
This makes it easier to work with device tree nodes and properties, then writing simple state machines to parse the device tree. This also makes the old slow traversal methods use the DeviceTreeProperty helper class, and adds a simple test.
This commit is contained in:
parent
0fa718ead8
commit
21a21c6a11
10 changed files with 316 additions and 31 deletions
9
Tests/LibDeviceTree/CMakeLists.txt
Normal file
9
Tests/LibDeviceTree/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
set(TEST_SOURCES
|
||||
TestLookup.cpp
|
||||
)
|
||||
|
||||
foreach(source IN LISTS TEST_SOURCES)
|
||||
serenity_test("${source}" LibDeviceTree LIBS LibDeviceTree LibFileSystem)
|
||||
endforeach()
|
||||
|
||||
install(FILES dtb.dtb DESTINATION usr/Tests/LibDeviceTree)
|
29
Tests/LibDeviceTree/TestLookup.cpp
Normal file
29
Tests/LibDeviceTree/TestLookup.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Leon Albrecht <leon.a@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibDeviceTree/DeviceTree.h>
|
||||
#include <LibDeviceTree/FlattenedDeviceTree.h>
|
||||
|
||||
TEST_CASE(basic_functionality)
|
||||
{
|
||||
auto fdt_file = TRY_OR_FAIL(Core::File::open("/usr/Tests/LibDeviceTree/dtb.dtb"sv, Core::File::OpenMode::Read));
|
||||
auto fdt = TRY_OR_FAIL(fdt_file->read_until_eof());
|
||||
|
||||
auto device_tree = TRY_OR_FAIL(DeviceTree::DeviceTree::parse(fdt));
|
||||
|
||||
auto boot_args = device_tree->resolve_property("/chosen/bootargs"sv);
|
||||
EXPECT(boot_args.has_value());
|
||||
EXPECT_EQ(boot_args->as_string(), "hello root=nvme0:1:0 serial_debug"sv);
|
||||
|
||||
EXPECT(device_tree->phandle(1));
|
||||
auto device_type = device_tree->phandle(1)->get_property("device_type"sv);
|
||||
EXPECT(device_type.has_value());
|
||||
EXPECT_EQ(device_type->as_string(), "cpu"sv);
|
||||
}
|
BIN
Tests/LibDeviceTree/dtb.dtb
Normal file
BIN
Tests/LibDeviceTree/dtb.dtb
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue