summaryrefslogtreecommitdiff
path: root/na/test/test_fdt.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-04-21 23:23:49 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-04-21 23:23:49 +0800
commit51899557c770b3dc9bd02579abf491745e607d92 (patch)
tree9681432a6db30a29f47aa1b21bbad777dfadd6c9 /na/test/test_fdt.cc
parentab2c0a8ea472679c846e74ca40823091becc5bf0 (diff)
downloadlume-51899557c770b3dc9bd02579abf491745e607d92.tar.gz
lume-51899557c770b3dc9bd02579abf491745e607d92.tar.xz
feat: add boot self-tests for various kernel components
- Implemented a self-test runner in `selftest.cc` to invoke all test suites. - Added tests for atomic operations in `test_atomic.cc`, covering construction, store/load, exchange, arithmetic, and compare-and-swap. - Created tests for the Flattened Device Tree (FDT) in `test_fdt.cc`, verifying node access and compatibility queries. - Developed a comprehensive Physical Memory Manager (PMM) test suite in `test_pmm.cc`, including allocation, deallocation, reference counting, and boundary conditions. - Implemented Red-Black Tree tests in `test_rbtree.cc`, validating insertion, deletion, and iteration. - Added Slab Allocator tests in `test_slab.cc`, covering various allocation sizes, edge cases, and operator overloads. - Created Spinlock tests in `test_spinlock.cc`, ensuring proper locking behavior and interrupt state preservation. - Developed Virtual Memory Area (VMA) tests in `test_vma.cc`, validating region mapping, unmapping, and fault handling. - Added tests for Virtual Memory Management (VMM) in `test_vmm.cc`, verifying address translation and page alignment.
Diffstat (limited to 'na/test/test_fdt.cc')
-rw-r--r--na/test/test_fdt.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/na/test/test_fdt.cc b/na/test/test_fdt.cc
new file mode 100644
index 0000000..cf09029
--- /dev/null
+++ b/na/test/test_fdt.cc
@@ -0,0 +1,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();
+}