blob: cf0902975977bd8858dffa7c09a6d1c8702ca748 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* Copyright (C) 2026 Richard Qin */
/*
* Boot Self-Test: FDT (Flattened Device Tree)
*/
#include <lume/selftest.h>
#include <lume/fdt.h>
// Manually declare what we need to avoid header conflicts with toolchain libc
extern "C" int strcmp(const char *s1, const char *s2);
void selftest_fdt() {
st_begin("fdt: tree root access");
{
DeviceNode* root = fdt_get_node_by_path("/");
ST_ASSERT(root != nullptr);
ST_ASSERT_EQ(strcmp(root->get_name(), ""), 0);
}
st_pass();
st_begin("fdt: find existing compatible node (UART)");
{
// QEMU virt RISC-V platform always has a ns16550a UART
DeviceNode* uart = fdt_find_compatible("ns16550a");
ST_ASSERT(uart != nullptr);
// Use get_prop_string which is convenience helper
const char* compat = uart->get_prop_string("compatible");
ST_ASSERT(compat != nullptr);
// Check raw property access
const FdtProperty* reg = uart->get_prop("reg");
ST_ASSERT(reg != nullptr);
ST_ASSERT(reg->value != nullptr);
ST_ASSERT(reg->len > 0);
}
st_pass();
st_begin("fdt: non-existent node/compatible queries");
{
DeviceNode* missing1 = fdt_get_node_by_path("/definitely_does_not_exist_node_12345");
ST_ASSERT(missing1 == nullptr);
DeviceNode* missing2 = fdt_find_compatible("invalid_compatible_string_xyz");
ST_ASSERT(missing2 == nullptr);
}
st_pass();
}
|