[Concept,05/16] test: pxe: Test include directive

Message ID 20260109015323.3411528-6-sjg@u-boot.org
State New
Headers
Series test: pxe: Add some decent tests for the PXE/extlinux parser |

Commit Message

Simon Glass Jan. 9, 2026, 1:53 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Test the 'include' directive which allows one extlinux.conf file to
include another. Create an extra.conf file with an additional label
and verify it is parsed correctly when included from the main config.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 test/boot/pxe.c                  | 20 ++++++++++++++++++++
 test/py/tests/test_pxe_parser.py | 16 ++++++++++++++--
 2 files changed, 34 insertions(+), 2 deletions(-)
  

Patch

diff --git a/test/boot/pxe.c b/test/boot/pxe.c
index ef42026e748..45948ab4ef4 100644
--- a/test/boot/pxe.c
+++ b/test/boot/pxe.c
@@ -104,6 +104,7 @@  static int pxe_test_parse_norun(struct unit_test_state *uts)
 	/* Verify 'say' keyword printed its message during parsing */
 	ut_assert_nextline("Retrieving file: %s", cfg_path);
 	ut_assert_nextline("Booting default Linux kernel");
+	ut_assert_nextline("Retrieving file: /extlinux/extra.conf");
 
 	/* Verify menu properties */
 	ut_asserteq_str("Test Boot Menu", cfg->title);
@@ -190,6 +191,25 @@  static int pxe_test_parse_norun(struct unit_test_state *uts)
 	ut_asserteq(0, label->localboot_val);
 	ut_asserteq(0, label->kaslrseed);
 
+	/* Verify fifth label: included (from include directive) */
+	label = list_entry(label->list.next, struct pxe_label, list);
+	ut_asserteq_str("", label->num);
+	ut_asserteq_str("included", label->name);
+	ut_asserteq_str("Included Label", label->menu);
+	ut_asserteq_str("/boot/included-kernel", label->kernel_label);
+	ut_asserteq_str("/boot/included-kernel", label->kernel);
+	ut_assertnull(label->config);
+	ut_asserteq_str("root=/dev/sdb1", label->append);
+	ut_assertnull(label->initrd);
+	ut_assertnull(label->fdt);
+	ut_assertnull(label->fdtdir);
+	ut_assertnull(label->fdtoverlays);
+	ut_asserteq(0, label->ipappend);
+	ut_asserteq(0, label->attempted);
+	ut_asserteq(0, label->localboot);
+	ut_asserteq(0, label->localboot_val);
+	ut_asserteq(0, label->kaslrseed);
+
 	/* Verify no more console output */
 	ut_assert_console_end();
 
diff --git a/test/py/tests/test_pxe_parser.py b/test/py/tests/test_pxe_parser.py
index 1d51116a97a..b289bf58b11 100644
--- a/test/py/tests/test_pxe_parser.py
+++ b/test/py/tests/test_pxe_parser.py
@@ -72,8 +72,6 @@  def create_extlinux_conf(srcdir, labels, menu_opts=None):
             fd.write(f"menu background {menu_opts['background']}\n")
         if 'say' in menu_opts:
             fd.write(f"say {menu_opts['say']}\n")
-        if 'include' in menu_opts:
-            fd.write(f"include {menu_opts['include']}\n")
 
         for label in labels:
             if label.get('default'):
@@ -108,6 +106,10 @@  def create_extlinux_conf(srcdir, labels, menu_opts=None):
             if 'say' in label:
                 fd.write(f"    say {label['say']}\n")
 
+        # Write include at the end so included labels come after main labels
+        if 'include' in menu_opts:
+            fd.write(f"\ninclude {menu_opts['include']}\n")
+
     return '/extlinux/extlinux.conf'
 
 
@@ -159,10 +161,20 @@  def pxe_image(u_boot_config):
         'fallback': 'rescue',
         'ontimeout': 'linux',
         'background': '/boot/background.bmp',
+        'include': '/extlinux/extra.conf',
     }
 
     cfg_path = create_extlinux_conf(fsh.srcdir, labels, menu_opts)
 
+    # Create an included config file with an additional label
+    extra_path = os.path.join(fsh.srcdir, 'extlinux', 'extra.conf')
+    with open(extra_path, 'w', encoding='ascii') as fd:
+        fd.write("# Included configuration\n")
+        fd.write("label included\n")
+        fd.write("    menu label Included Label\n")
+        fd.write("    kernel /boot/included-kernel\n")
+        fd.write("    append root=/dev/sdb1\n")
+
     # Create the filesystem
     fsh.mk_fs()