From: Simon Glass <simon.glass@canonical.com> Add a test that verifies that pxe_label_override can override the default boot label, and that an invalid override prints an error message. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- test/boot/pxe.c | 51 ++++++++++++++++++++++++++++++++ test/py/tests/test_pxe_parser.py | 7 +++++ 2 files changed, 58 insertions(+) diff --git a/test/boot/pxe.c b/test/boot/pxe.c index 505628ab92d..a6761ecc447 100644 --- a/test/boot/pxe.c +++ b/test/boot/pxe.c @@ -709,3 +709,54 @@ static int pxe_test_fdt_fallback(struct unit_test_state *uts) return 0; } PXE_TEST(pxe_test_fdt_fallback, 0); + +/** + * Test pxe_label_override environment variable + * + * This tests that pxe_label_override can override the default label, + * and that an invalid override prints an error message. + */ +static int pxe_test_label_override_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); + + ut_assertnonnull(fs_image); + ut_assertnonnull(cfg_path); + + /* Bind the filesystem image */ + ut_assertok(run_commandf("host bind 0 %s", fs_image)); + + /* Set environment variables for file 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("ramdisk_addr_r", PXE_INITRD_ADDR)); + ut_assertok(env_set_hex("fdt_addr_r", PXE_FDT_ADDR)); + ut_assertok(env_set("bootfile", cfg_path)); + ut_assertok(env_set("pxe_timeout", "1")); + + /* Test 1: Override to 'local' label (localboot) */ + ut_assertok(env_set("pxe_label_override", "local")); + ut_assertok(run_commandf("sysboot host 0:0 any %x %s", + PXE_LOAD_ADDR, cfg_path)); + + /* Should boot 'local' label instead of default 'linux' */ + ut_assert_skip_to_line("3:\tLocal Boot"); + ut_assert_skip_to_line("missing environment variable: localcmd"); + + /* Test 2: Invalid override - should print error */ + ut_assertok(env_set("pxe_label_override", "nonexistent")); + ut_assertok(run_commandf("sysboot host 0:0 any %x %s", + PXE_LOAD_ADDR, cfg_path)); + + ut_assert_skip_to_line("Missing override pxe label: nonexistent"); + + /* Clean up */ + ut_assertok(env_set("pxe_label_override", NULL)); + ut_assertok(env_set("pxe_timeout", NULL)); + + return 0; +} +PXE_TEST_ARGS(pxe_test_label_override_norun, UTF_CONSOLE | UTF_MANUAL, + { "fs_image", UT_ARG_STR }, + { "cfg_path", UT_ARG_STR }); diff --git a/test/py/tests/test_pxe_parser.py b/test/py/tests/test_pxe_parser.py index f3ae3ff9f78..8462b53c8d8 100644 --- a/test/py/tests/test_pxe_parser.py +++ b/test/py/tests/test_pxe_parser.py @@ -436,3 +436,10 @@ class TestPxeParser: with ubman.log.section('Test PXE ipappend'): ubman.run_ut('pxe', 'pxe_test_ipappend', fs_image=fs_img, cfg_path=cfg_path) + + def test_pxe_label_override(self, ubman, pxe_image): + """Test pxe_label_override environment variable""" + fs_img, cfg_path = pxe_image + with ubman.log.section('Test PXE label override'): + ubman.run_ut('pxe', 'pxe_test_label_override', + fs_image=fs_img, cfg_path=cfg_path) -- 2.43.0