[PATCH 2/4] test: py: add FIT boot test
Ahmad Fatoum
a.fatoum at barebox.org
Thu Jun 12 01:56:01 PDT 2025
This test verifies that FIT image can be booted and device tree is fixed
up with command line, initrd location, generic and custom fixups.
It already caught a regression in next that broke initrd loading on
ARM64 & RISC-V.
Cc: Stefan Kerkmann <s.kerkmann at pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
test/arm/virt at multi_v7_defconfig.yaml | 1 +
test/arm/virt at multi_v8_defconfig.yaml | 1 +
test/py/helper.py | 15 +++++++
test/py/test_fit.py | 63 +++++++++++++++++++++++++++
4 files changed, 80 insertions(+)
create mode 100644 test/py/test_fit.py
diff --git a/test/arm/virt at multi_v7_defconfig.yaml b/test/arm/virt at multi_v7_defconfig.yaml
index 203f17bfc7f0..637d132d3967 100644
--- a/test/arm/virt at multi_v7_defconfig.yaml
+++ b/test/arm/virt at multi_v7_defconfig.yaml
@@ -14,6 +14,7 @@ targets:
BareboxTestStrategy: {}
features:
- virtio-mmio
+ - testfs
images:
barebox-dt-2nd.img: !template "$LG_BUILDDIR/images/barebox-dt-2nd.img"
imports:
diff --git a/test/arm/virt at multi_v8_defconfig.yaml b/test/arm/virt at multi_v8_defconfig.yaml
index 42ce10328d7c..d018af06aa53 100644
--- a/test/arm/virt at multi_v8_defconfig.yaml
+++ b/test/arm/virt at multi_v8_defconfig.yaml
@@ -15,6 +15,7 @@ targets:
features:
- virtio-mmio
- network
+ - testfs
runner:
tuxmake_arch: arm64
images:
diff --git a/test/py/helper.py b/test/py/helper.py
index 4a68e83669ba..cfcc9c337fec 100644
--- a/test/py/helper.py
+++ b/test/py/helper.py
@@ -30,6 +30,21 @@ def get_config(command):
return options
+def of_get_property(barebox, path):
+ node, prop = os.path.split(path)
+
+ stdout = barebox.run_check(f"of_dump -p {node}")
+ for line in stdout:
+ if line == '{prop};':
+ return True
+
+ prefix = f'{prop} = '
+ if line.startswith(prefix):
+ # Also drop the semicolon
+ return line[len(prefix):-1]
+ return False
+
+
def skip_disabled(config, *options):
if bool(config):
undefined = list(filterfalse(config.__contains__, options))
diff --git a/test/py/test_fit.py b/test/py/test_fit.py
new file mode 100644
index 000000000000..c53a1ece1445
--- /dev/null
+++ b/test/py/test_fit.py
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import re
+import pytest
+from .helper import of_get_property
+
+
+def fit_name(suffix):
+ return f"/mnt/9p/testfs/barebox-{suffix}.fit"
+
+
+def generate_bootscript(barebox, image, name="test"):
+ barebox.run_check(f"echo -o /env/boot/{name} '#!/bin/sh'")
+ barebox.run_check(f"echo -a /env/boot/{name} bootm {image}")
+ return name
+
+
+def test_fit(barebox, env, target, barebox_config):
+ if 'testfs' not in env.get_target_features():
+ pytest.xfail("testfs feature not specified")
+
+ _, _, returncode = barebox.run("ls /mnt/9p/testfs")
+ if returncode != 0:
+ pytest.xfail("skipping test due to missing --fs testfs=")
+
+ barebox.run_check(f"ls {fit_name('gzipped')}")
+
+ # Sanity check, this is only fixed up on first boot
+ assert of_get_property(barebox, "/chosen/barebox-version") is False
+ [ver] = barebox.run_check("echo barebox-$global.version")
+ assert ver.startswith('barebox-2')
+
+ barebox.run_check("of_property -s /chosen barebox,boot-count '<0x0>'")
+ assert of_get_property(barebox, "/chosen/barebox,boot-count") == '<0x0>'
+
+ barebox.run_check("of_property -fs /chosen barebox,boot-count '<0x1>'")
+ assert of_get_property(barebox, "/chosen/barebox,boot-count") == '<0x0>'
+
+ barebox.run_check("global linux.bootargs.testarg=barebox.chainloaded")
+
+ boottarget = generate_bootscript(barebox, fit_name('gzipped'))
+ barebox.boot(boottarget)
+ target.deactivate(barebox)
+ target.activate(barebox)
+
+ assert of_get_property(barebox, "/chosen/barebox-version") == f'"{ver}"', \
+ "/chosen/barebox-version suggests we did not chainload"
+
+ assert of_get_property(barebox, "/chosen/barebox,boot-count") == '<0x1>', \
+ "/chosen/barebox,boot-count suggests we got bultin DT"
+
+ # Check that command line arguments were fixed up
+ bootargs = of_get_property(barebox, "/chosen/bootargs")
+ assert "barebox.chainloaded" in bootargs
+
+ initrd_start = of_get_property(barebox, "/chosen/linux,initrd-start")
+ initrd_end = of_get_property(barebox, "/chosen/linux,initrd-end")
+
+ addr_regex = r"<(0x[0-9a-f]{1,8} ?)+>"
+ assert re.search(addr_regex, initrd_start), \
+ f"initrd start {initrd_start} malformed"
+ assert re.search(addr_regex, initrd_end), \
+ f"initrd end {initrd_end} malformed"
--
2.39.5
More information about the barebox
mailing list