From: Simon Glass <simon.glass@canonical.com>
Add a test for the include directive with maximum nesting depth: a chain
of 16 include files (the MAX_NEST_LEVEL limit), each adding a label.
This checks that the nest_level tracking in struct pxe_include works
correctly through all levels.
Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
test/boot/pxe.c | 11 +++++++++++
test/py/tests/test_pxe_parser.py | 31 +++++++++++++++++++++++--------
2 files changed, 34 insertions(+), 8 deletions(-)
@@ -79,6 +79,8 @@ static int pxe_test_parse_norun(struct unit_test_state *uts)
struct pxe_context ctx;
struct pxe_label *label;
struct pxe_menu *cfg;
+ char name[16];
+ uint i;
int ret;
ut_assertnonnull(fs_image);
@@ -105,6 +107,8 @@ static int pxe_test_parse_norun(struct unit_test_state *uts)
ut_assert_nextline("Retrieving file: %s", cfg_path);
ut_assert_nextline("Booting default Linux kernel");
ut_assert_nextline("Retrieving file: /extlinux/extra.conf");
+ for (i = 3; i <= 16; i++)
+ ut_assert_nextline("Retrieving file: /extlinux/nest%d.conf", i);
/* Verify menu properties */
ut_asserteq_str("Test Boot Menu", cfg->title);
@@ -210,6 +214,13 @@ static int pxe_test_parse_norun(struct unit_test_state *uts)
ut_asserteq(0, label->localboot_val);
ut_asserteq(0, label->kaslrseed);
+ /* Verify labels from nested includes (levels 3-16) - just check names */
+ for (i = 3; i <= 16; i++) {
+ label = list_entry(label->list.next, struct pxe_label, list);
+ snprintf(name, sizeof(name), "level%d", i);
+ ut_asserteq_str(name, label->name);
+ }
+
/* Verify no more console output */
ut_assert_console_end();
@@ -166,14 +166,29 @@ def pxe_image(u_boot_config):
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 a chain of 16 nested include files to test MAX_NEST_LEVEL
+ # Level 1 is extlinux.conf, levels 2-16 are extra.conf, nest3.conf, etc.
+ for level in range(2, 17):
+ if level == 2:
+ fname = 'extra.conf'
+ label_name = 'included'
+ label_menu = 'Included Label'
+ else:
+ fname = f'nest{level}.conf'
+ label_name = f'level{level}'
+ label_menu = f'Level {level} Label'
+
+ fpath = os.path.join(fsh.srcdir, 'extlinux', fname)
+ with open(fpath, 'w', encoding='ascii') as fd:
+ fd.write(f"# Level {level} configuration\n")
+ fd.write(f"label {label_name}\n")
+ fd.write(f" menu label {label_menu}\n")
+ fd.write(f" kernel /boot/{label_name}-kernel\n")
+ fd.write(f" append root=/dev/sd{chr(ord('a') + level - 1)}1\n")
+ # Include next level unless we're at level 16
+ if level < 16:
+ next_fname = f'nest{level + 1}.conf'
+ fd.write(f"\ninclude /extlinux/{next_fname}\n")
# Create the filesystem
fsh.mk_fs()