mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-04 07:09:41 +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
Notes:
sideshowbarker
2024-07-17 02:55:44 +09:00
Author: https://github.com/Hendiadyoin1
Commit: 21a21c6a11
Pull-request: https://github.com/SerenityOS/serenity/pull/22948
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/kleinesfilmroellchen
Reviewed-by: https://github.com/spholz
10 changed files with 316 additions and 31 deletions
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue