]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[fdt] Add tests for device tree creation
authorMichael Brown <mcb30@ipxe.org>
Fri, 30 May 2025 13:15:43 +0000 (14:15 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 30 May 2025 13:21:53 +0000 (14:21 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/tests/fdt_test.c

index 0a143ec62d4ebd1eed1e4c787a6781bf7a23b529..1dead2126071b40d33753e90ac9ff72af2b29521 100644 (file)
@@ -34,6 +34,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
 #include <string.h>
 #include <ipxe/fdt.h>
+#include <ipxe/image.h>
 #include <ipxe/test.h>
 
 /** Simplified QEMU sifive_u device tree blob */
@@ -164,6 +165,7 @@ static void fdt_test_exec ( void ) {
        struct fdt_header *hdr;
        struct fdt fdt;
        const char *string;
+       struct image *image;
        uint32_t u32;
        uint64_t u64;
        unsigned int count;
@@ -260,6 +262,22 @@ static void fdt_test_exec ( void ) {
        ok ( strcmp ( desc.name, "device_type" ) == 0 );
        ok ( strcmp ( desc.data, "memory" ) == 0 );
        ok ( desc.depth == 0 );
+
+       /* Verify device tree creation */
+       image = image_memory ( "test.dtb", sifive_u, sizeof ( sifive_u ) );
+       ok ( image != NULL );
+       image_tag ( image, &fdt_image );
+       ok ( fdt_create ( &hdr, "hello world", 0xabcd0000, 0x00001234 ) == 0 );
+       ok ( fdt_parse ( &fdt, hdr, -1UL ) == 0 );
+       ok ( fdt_path ( &fdt, "/chosen", &offset ) == 0 );
+       ok ( ( string = fdt_string ( &fdt, offset, "bootargs" ) ) != NULL );
+       ok ( strcmp ( string, "hello world" ) == 0 );
+       ok ( fdt_u64 ( &fdt, offset, "linux,initrd-start", &u64 ) == 0 );
+       ok ( u64 == 0xabcd0000 );
+       ok ( fdt_u64 ( &fdt, offset, "linux,initrd-end", &u64 ) == 0 );
+       ok ( u64 == 0xabcd1234 );
+       fdt_remove ( hdr );
+       unregister_image ( image );
 }
 
 /** FDT self-test */