From patchwork Fri Jan 9 23:11:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1402 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000364; bh=Y3jKJOfgkBtcoq7461/ZZa36NWQUSLWsC+tgYqvIjd4=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=pIkYKXcuuT/E6FFqj9Al4YwTmKGQU/RQVDlInzc+d0U7gtGcawxbaFy4GSKycJHE4 cQ1h5csvCzku/wgHwO85aI17orxgnJVxmRV7mJrYRcuvJeYGW8ZkQN4+LSttFsl8sp l8Vlp1zszXQBh7XOLodhJGNDOQYZJdh+aPHlZz+pFKH+ehB/FBwzQ6eXhJWnYOC1Xi EC32LxX/bK1NuipzT8a5JOlWrN4X7XCjj4sPeAFHALadC7udvyK5o3gQ4wJN/dS+m+ TulPqsfg+I2jHjdzw6y/dajFKRAyqbn8ED+jAVWk7vS4DILC8wA/9+SsJXBWbjSz9Q XTQUhpTmBVuWw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D781869218 for ; Fri, 9 Jan 2026 16:12:44 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 7iZWmeJ9dQ5k for ; Fri, 9 Jan 2026 16:12:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000364; bh=Y3jKJOfgkBtcoq7461/ZZa36NWQUSLWsC+tgYqvIjd4=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=pIkYKXcuuT/E6FFqj9Al4YwTmKGQU/RQVDlInzc+d0U7gtGcawxbaFy4GSKycJHE4 cQ1h5csvCzku/wgHwO85aI17orxgnJVxmRV7mJrYRcuvJeYGW8ZkQN4+LSttFsl8sp l8Vlp1zszXQBh7XOLodhJGNDOQYZJdh+aPHlZz+pFKH+ehB/FBwzQ6eXhJWnYOC1Xi EC32LxX/bK1NuipzT8a5JOlWrN4X7XCjj4sPeAFHALadC7udvyK5o3gQ4wJN/dS+m+ TulPqsfg+I2jHjdzw6y/dajFKRAyqbn8ED+jAVWk7vS4DILC8wA/9+SsJXBWbjSz9Q XTQUhpTmBVuWw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C333569240 for ; Fri, 9 Jan 2026 16:12:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000362; bh=l0qpEcDMby30KdMdfz10U18ak5q8ycSzkCYU/VTd3q0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WD6fG0hdxYrgz5wsWoFzJBjMNyKFDxQ/jvRV2BGcA24X/hZmtTK0gmOaDzmyiUEH/ 5uwEbywjKW5V1zNgslGIX8veB4xZ80aZY6DXkkMVWd9j+uQF4EotVCVboVxWMm2Km6 fVEDyAtzbAFPD1pvSvJWJ1PH+NuaCsRamFWyAUDDdoUVXv9f9xfhjj31URu5sASk3q OY/cgv/aKpU765CBjnmThxv1EMtaKmhLDjqNxz8byfWFCD9Di1usJsrhh4VlMDI1Fc iHPflInMYAVcwYfsY+gJK21Mab7B4fz61vd+gXs+i4T3Aa5RPs9PT0oQ2rIQTCXoqo rOeQgDLo/pavg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E589C69235; Fri, 9 Jan 2026 16:12:42 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id P2HACfXKWwG3; Fri, 9 Jan 2026 16:12:42 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000358; bh=zU608lj3XabyZY8jiCwDr+3KQbKtRX8AiDuXCeK0AYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FeO+K0dpG06TaPQlGSW1P9QjaPItiyjt0VxghR7KWcDqFWnfwUvxP6ADe1ia0Zfr2 Nei7jreiJWTKYyG92QTB/pIm0r2Y3nuc3Ghws0+nZQOlqBMNGWEDFN0HUfuhnN0gXA A7hoHfLP1q40F0rRFdSleu+Zj/8eM5IlkTPc9cRkg2X5IcxutLxYjMLhktcHzsknyb WlNuvjPDP15pdVr8g4D6UGLptpeHaNk89Xuxs1ONZCDEoqYzGsz4H5ll0rOGRiMDXx xShWVBxw3zg7X24MaNUhOBGYAd9X9VRMbPB0hKHa3Rf9lHZ+FwvyAou8T08n4aQiyU Yh8l5WVflsBWQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 80D6B69206; Fri, 9 Jan 2026 16:12:38 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 9 Jan 2026 16:11:15 -0700 Message-ID: <20260109231151.4056804-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260109231151.4056804-1-sjg@u-boot.org> References: <20260109231151.4056804-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: QLTI3E5DLOOU7GKRBNEUBKBIJ5PH3UVO X-Message-ID-Hash: QLTI3E5DLOOU7GKRBNEUBKBIJ5PH3UVO X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 06/32] boot: pxe: Update tests to use the new API List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Update pxe_test_fdtdir_norun() and pxe_test_errors_norun() to use the new API calls, to avoid having to go through the syslinux command. This will make it easier to build on the tests over time. We still have the other tests to check syslinux. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- test/boot/pxe.c | 217 ++++++++++++++++++++++++++++++------------------ 1 file changed, 134 insertions(+), 83 deletions(-) diff --git a/test/boot/pxe.c b/test/boot/pxe.c index db1cf48d7a5..2ee2ad24a7d 100644 --- a/test/boot/pxe.c +++ b/test/boot/pxe.c @@ -126,37 +126,6 @@ static int pxe_check_menu(struct unit_test_state *uts, const char *say_msg, return 0; } -/** - * pxe_check_fdtdir() - Check fdtdir test menu and boot output - * - * Helper for pxe_test_fdtdir_norun() that checks the menu output and boot - * file retrieval messages for the fdtdir test configuration. - * - * @uts: Unit test state - * @dtb_name: Expected DTB filename (e.g., "test-board.dtb") - * Return: 0 if OK, -ve on error - */ -static int pxe_check_fdtdir(struct unit_test_state *uts, const char *dtb_name) -{ - /* Menu output */ - ut_assert_nextline("Retrieving file: /extlinux/extlinux.conf"); - ut_assert_nextline("Test Boot Menu"); - ut_assert_nextline("1:\tTest fdtfile env var"); - ut_assert_nextline("2:\tTest soc/board construction"); - ut_assert_nextline("Enter choice: 1:\tTest fdtfile env var"); - - /* Boot file retrieval - FDT/overlays loaded before append is printed */ - ut_assert_nextline("Retrieving file: /vmlinuz"); - ut_assert_nextline("Retrieving file: /dtb/%s", dtb_name); - ut_assert_nextline("Retrieving file: /dtb/overlay1.dtbo"); - ut_assert_nextline("append: console=ttyS0"); - - /* Boot fails on sandbox */ - ut_assert_nextline("Unrecognized zImage"); - - return 0; -} - /** * Test parsing an extlinux.conf file * @@ -413,10 +382,9 @@ PXE_TEST_ARGS(pxe_test_sysboot_norun, UTF_CONSOLE | UTF_MANUAL, { "cfg_path", UT_ARG_STR }); /** - * Test fdtdir path resolution via sysboot + * Test fdtdir path resolution * - * This test verifies fdtdir path construction by running sysboot and - * checking console output: + * This test verifies: * 1. fdtdir with fdtfile env var - uses fdtfile value directly * 2. fdtdir with soc/board env vars - constructs {soc}-{board}.dtb * 3. fdtdir without trailing slash - slash is inserted @@ -425,57 +393,97 @@ static int pxe_test_fdtdir_norun(struct unit_test_state *uts) { const char *fs_image = ut_str(PXE_ARG_FS_IMAGE); const char *cfg_path = ut_str(PXE_ARG_CFG_PATH); + struct pxe_test_info info; + struct pxe_context ctx; + struct pxe_label *label; + struct pxe_menu *cfg; + ulong addr = PXE_LOAD_ADDR; void *fdt; ut_assertnonnull(fs_image); ut_assertnonnull(cfg_path); + info.uts = uts; + /* Bind the filesystem image */ ut_assertok(run_commandf("host bind 0 %s", fs_image)); + /* Set up the PXE context */ + ut_assertok(pxe_setup_ctx(&ctx, pxe_test_getfile, &info, true, cfg_path, + false, false, NULL)); + + /* Read and parse the config file */ + ut_asserteq(1, get_pxe_file(&ctx, cfg_path, addr)); + + cfg = parse_pxefile(&ctx, addr); + ut_assertnonnull(cfg); + + /* Consume parsing output */ + ut_assert_nextline("Retrieving file: %s", cfg_path); + ut_assert_console_end(); + /* * Test 1: fdtdir with fdtfile env var - * The first label uses fdtdir=/dtb/ and we set fdtfile=test-board.dtb - * so it should retrieve /dtb/test-board.dtb + * Set fdtfile=test-board.dtb, load should find /dtb/test-board.dtb */ - ut_assertok(env_set_hex("pxefile_addr_r", PXE_LOAD_ADDR)); + ut_assertok(env_set("fdtfile", "test-board.dtb")); ut_assertok(env_set_hex("kernel_addr_r", PXE_KERNEL_ADDR)); ut_assertok(env_set_hex("fdt_addr_r", PXE_FDT_ADDR)); ut_assertok(env_set_hex("fdtoverlay_addr_r", PXE_OVERLAY_ADDR)); - ut_assertok(env_set("fdtfile", "test-board.dtb")); - ut_assertok(env_set("bootfile", cfg_path)); - ut_assertok(run_commandf("sysboot host 0:0 any %x %s", - PXE_LOAD_ADDR, cfg_path)); - ut_assertok(pxe_check_fdtdir(uts, "test-board.dtb")); + /* Get first label (fdtfile-test) and load its files */ + label = list_first_entry(&cfg->labels, struct pxe_label, list); + ut_asserteq_str("fdtfile-test", label->name); + ut_asserteq_str("/dtb/", label->fdtdir); + ut_assertnull(label->fdt); + + ut_assertok(pxe_load_label(&ctx, label)); - /* Verify FDT was loaded correctly */ + /* Verify FDT was loaded */ + ut_asserteq(PXE_FDT_ADDR, ctx.conf_fdt); fdt = map_sysmem(PXE_FDT_ADDR, 0); ut_assertok(fdt_check_header(fdt)); + /* Check console output shows the constructed path */ + ut_assert_nextline("Retrieving file: /vmlinuz"); + ut_assert_nextline("Retrieving file: /dtb/test-board.dtb"); + ut_assert_nextline("Retrieving file: /dtb/overlay1.dtbo"); + ut_assert_console_end(); + /* * Test 2: fdtdir with soc/board env vars (no fdtfile) - * Clear fdtfile and set soc/board - the default label (fdtfile-test) - * will now construct the path from soc-board: /dtb/tegra-jetson.dtb + * Set soc=tegra, board=jetson -> /dtb/tegra-jetson.dtb */ ut_assertok(env_set("fdtfile", NULL)); /* Clear fdtfile */ ut_assertok(env_set("soc", "tegra")); ut_assertok(env_set("board", "jetson")); + ctx.conf_fdt = 0; /* Reset for next load */ - ut_assertok(run_commandf("sysboot host 0:0 any %x %s", - PXE_LOAD_ADDR, cfg_path)); - ut_assertok(pxe_check_fdtdir(uts, "tegra-jetson.dtb")); - ut_assert_console_end(); + /* Get second label (socboard-test) */ + label = list_entry(label->list.next, struct pxe_label, list); + ut_asserteq_str("socboard-test", label->name); + ut_asserteq_str("/dtb", label->fdtdir); /* No trailing slash */ - /* Verify FDT was loaded */ + ut_assertok(pxe_load_label(&ctx, label)); + + /* Verify FDT was loaded (slash was inserted) */ + ut_asserteq(PXE_FDT_ADDR, ctx.conf_fdt); fdt = map_sysmem(PXE_FDT_ADDR, 0); - ut_asserteq(FDT_MAGIC, fdt_magic(fdt)); + ut_assertok(fdt_check_header(fdt)); + + /* Check console output shows soc-board construction with slash */ + ut_assert_nextline("Retrieving file: /vmlinuz"); + ut_assert_nextline("Retrieving file: /dtb/tegra-jetson.dtb"); + ut_assert_console_end(); /* Clean up env vars */ env_set("fdtfile", NULL); env_set("soc", NULL); env_set("board", NULL); + destroy_pxe_menu(cfg); + pxe_destroy_ctx(&ctx); + return 0; } PXE_TEST_ARGS(pxe_test_fdtdir_norun, UTF_CONSOLE | UTF_MANUAL, @@ -483,77 +491,117 @@ PXE_TEST_ARGS(pxe_test_fdtdir_norun, UTF_CONSOLE | UTF_MANUAL, { "cfg_path", UT_ARG_STR }); /** - * Test error handling for missing FDT files via sysboot + * Test error handling for missing FDT and overlay files * - * This test verifies error handling by running sysboot and checking - * console output: - * 1. Explicit FDT not found - label fails with error, tries next label - * 2. fdtdir FDT not found - warns but continues to boot attempt + * This test verifies: + * 1. Explicit FDT not found - label should fail with error + * 2. fdtdir FDT not found - should warn but continue (return success) + * 3. Missing overlay - should warn but continue loading other overlays */ static int pxe_test_errors_norun(struct unit_test_state *uts) { const char *fs_image = ut_str(PXE_ARG_FS_IMAGE); const char *cfg_path = ut_str(PXE_ARG_CFG_PATH); + struct pxe_test_info info; + struct pxe_context ctx; + struct pxe_label *label; + struct pxe_menu *cfg; + ulong addr = PXE_LOAD_ADDR; + void *fdt; ut_assertnonnull(fs_image); ut_assertnonnull(cfg_path); + info.uts = uts; + /* Bind the filesystem image */ ut_assertok(run_commandf("host bind 0 %s", fs_image)); + /* Set up the PXE context */ + ut_assertok(pxe_setup_ctx(&ctx, pxe_test_getfile, &info, true, cfg_path, + false, false, NULL)); + + /* Read and parse the config file */ + ut_asserteq(1, get_pxe_file(&ctx, cfg_path, addr)); + + cfg = parse_pxefile(&ctx, addr); + ut_assertnonnull(cfg); + + /* Consume parsing output */ + ut_assert_nextline("Retrieving file: %s", cfg_path); + ut_assert_console_end(); + /* Set up environment for loading */ - ut_assertok(env_set_hex("pxefile_addr_r", PXE_LOAD_ADDR)); ut_assertok(env_set_hex("kernel_addr_r", PXE_KERNEL_ADDR)); ut_assertok(env_set_hex("fdt_addr_r", PXE_FDT_ADDR)); ut_assertok(env_set_hex("fdtoverlay_addr_r", PXE_OVERLAY_ADDR)); ut_assertok(env_set("fdtfile", "missing.dtb")); /* For fdtdir test */ - ut_assertok(env_set("bootfile", cfg_path)); /* - * Run sysboot - it will try labels in sequence: - * 1. missing-fdt: fails because explicit FDT doesn't exist - * 2. missing-fdtdir: warns about missing FDT but attempts boot - * 3. missing-overlay: loads FDT, warns about missing overlay, boots + * Test 1: Explicit FDT file not found + * Label has fdt=/dtb/nonexistent.dtb - should fail with -ENOENT */ - ut_assertok(run_commandf("sysboot host 0:0 any %x %s", - PXE_LOAD_ADDR, cfg_path)); + label = list_first_entry(&cfg->labels, struct pxe_label, list); + ut_asserteq_str("missing-fdt", label->name); + ut_asserteq_str("/dtb/nonexistent.dtb", label->fdt); - /* Check menu output */ - ut_assert_nextline("Retrieving file: /extlinux/extlinux.conf"); - ut_assert_nextline("Test Boot Menu"); - ut_assert_nextline("1:\tMissing explicit FDT"); - ut_assert_nextline("2:\tMissing fdtdir FDT"); - ut_assert_nextline("3:\tMissing overlay"); - ut_assert_nextline("Enter choice: 1:\tMissing explicit FDT"); + ut_asserteq(-ENOENT, pxe_load_label(&ctx, label)); - /* - * Test 1: Explicit FDT file not found - * First label (missing-fdt) has fdt=/dtb/nonexistent.dtb - * Should fail and move to next label - */ + /* Check error message */ ut_assert_nextline("Retrieving file: /vmlinuz"); ut_assert_nextline("Retrieving file: /dtb/nonexistent.dtb"); ut_assert_nextline("Skipping missing-fdt for failure retrieving FDT"); + ut_assert_console_end(); /* * Test 2: fdtdir with missing FDT file - * Second label (missing-fdtdir) has fdtdir=/dtb/ but fdtfile=missing.dtb - * Should warn but continue to boot attempt + * Label has fdtdir=/dtb/ but fdtfile=missing.dtb doesn't exist + * Should warn but return success (label continues without FDT) */ - ut_assert_nextline("2:\tMissing fdtdir FDT"); + ctx.conf_fdt = 0; + label = list_entry(label->list.next, struct pxe_label, list); + ut_asserteq_str("missing-fdtdir", label->name); + ut_asserteq_str("/dtb/", label->fdtdir); + ut_assertnull(label->fdt); + + ut_assertok(pxe_load_label(&ctx, label)); + + /* Check warning message */ ut_assert_nextline("Retrieving file: /vmlinuz"); ut_assert_nextline("Retrieving file: /dtb/missing.dtb"); ut_assert_nextline("Skipping fdtdir /dtb/ for failure retrieving dts"); + ut_assert_console_end(); /* - * Boot attempt without FDT - sandbox can't boot, but this verifies - * that label loading continued despite missing fdtdir FDT + * Test 3: Missing overlay file (but valid FDT) + * Label has fdt=/dtb/board.dtb (exists) and two overlays: + * - /dtb/nonexistent.dtbo (missing - should warn) + * - /dtb/overlay1.dtbo (exists - should load) */ - ut_assert_nextline("Unrecognized zImage"); + ctx.conf_fdt = 0; + label = list_entry(label->list.next, struct pxe_label, list); + ut_asserteq_str("missing-overlay", label->name); + ut_asserteq_str("/dtb/board.dtb", label->fdt); + + ut_assertok(pxe_load_label(&ctx, label)); + + /* FDT should be loaded */ + ut_asserteq(PXE_FDT_ADDR, ctx.conf_fdt); + fdt = map_sysmem(PXE_FDT_ADDR, 0); + ut_assertok(fdt_check_header(fdt)); + + /* Check console output */ + ut_assert_nextline("Retrieving file: /vmlinuz"); + ut_assert_nextline("Retrieving file: /dtb/board.dtb"); + ut_assert_nextline("Retrieving file: /dtb/nonexistent.dtbo"); + ut_assert_nextline("Failed loading overlay /dtb/nonexistent.dtbo"); + ut_assert_nextline("Retrieving file: /dtb/overlay1.dtbo"); ut_assert_console_end(); - /* Clean up env vars */ + /* Clean up */ env_set("fdtfile", NULL); + destroy_pxe_menu(cfg); + pxe_destroy_ctx(&ctx); return 0; } @@ -695,6 +743,9 @@ static int pxe_test_ipappend_norun(struct unit_test_state *uts) ut_assertok(env_set("gatewayip", "192.168.1.254")); ut_assertok(env_set("netmask", "255.255.255.0")); + /* Clear fdtfile to ensure rescue label's fdtdir tries /dtb/.dtb */ + ut_assertok(env_set("fdtfile", NULL)); + /* Override to boot the rescue label which has ipappend=3 */ ut_assertok(env_set("pxe_label_override", "rescue")); ut_assertok(env_set("pxe_timeout", "1"));