[PATCH 13/16] test: py: add test for initrd concatenation

Ahmad Fatoum
2026-03-12T15:03:18Z

Now that the FIT code supports processing multiple entries in the
ramdisk property, add a test to ensure this doesn't regress.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
test/py/test_fit.py | 38 +++++++++++++-------
test/py/testfs.py | 23 ++++++++++++
test/testdata/multi_v7_defconfig-gzipped.its | 28 +++++++++++++--
test/testdata/multi_v8_defconfig-gzipped.its | 28 +++++++++++++--
4 files changed, 98 insertions(+), 19 deletions(-)
create mode 100644 test/py/testfs.py

diff --git a/test/py/test_fit.py b/test/py/test_fit.py
index 8bcee6a75f23..0fd5a3c5dcc5 100644
--- a/test/py/test_fit.py
+++ b/test/py/test_fit.py
@@ -7,6 +7,7 @@ import shutil
import subprocess
from pathlib import Path
from .helper import of_get_property, filter_errors
+from .testfs import mkcpio

def generate_bootscript(barebox, image, name="test"):
@@ -37,16 +38,9 @@ def fit_testdata(barebox_config, testfs):
input=(builddir / "images" / "barebox-dt-2nd.img").read_bytes(),
stdout=open(builddir / "barebox-dt-2nd.img.gz", "wb"))

- find = subprocess.Popen(["find", "COPYING", "LICENSES/"],
- stdout=subprocess.PIPE)
- cpio = subprocess.Popen(["cpio", "-o", "-H", "newc"],
- stdin=find.stdout, stdout=subprocess.PIPE)
- gzip = subprocess.Popen(["gzip"], stdin=cpio.stdout,
- stdout=open(builddir / "ramdisk.cpio.gz", "wb"))
-
- find.wait()
- cpio.wait()
- gzip.wait()
+ mkcpio("COPYING", outdir / "ramdisk1.cpio.gz")
+ mkcpio("LICENSES/exceptions/", outdir / "ramdisk2.cpio")
+ mkcpio("LICENSES/preferred/", outdir / "ramdisk3.cpio.gz")

run(["mkimage", "-G", "test/self/development_rsa2048.pem", "-r", "-f",
str(builddir / its_name), str(outfile)])
@@ -105,6 +99,15 @@ def test_fit(barebox, strategy, fitimage):

barebox.run_check("global linux.bootargs.testarg=barebox.chainloaded")

+ barebox.run_check("cat -o /tmp/ramdisks.cpio /mnt/9p/testfs/ramdisk*.cpio*")
+ [hashsum1] = barebox.run_check("md5sum /tmp/ramdisks.cpio")
+
+ hashsum1 = re.split("/tmp/ramdisks.cpio", hashsum1, maxsplit=1)[0]
+ # Get the actual size of the concatenated ramdisks file
+ [fileinfo] = barebox.run_check("ls -l /tmp/ramdisks.cpio")
+ # Parse the size from ls -l output (format: permissions links user group size ...)
+ actual_size = int(fileinfo.split()[1])
+
boottarget = generate_bootscript(barebox, fitimage)

with strategy.boot_barebox(boottarget) as barebox:
@@ -118,7 +121,16 @@ def test_fit(barebox, strategy, fitimage):
bootargs = of_get_property(barebox, "/chosen/bootargs")
assert "barebox.chainloaded" in bootargs

- initrd_start = of_get_property(barebox, "/chosen/linux,initrd-start", 0)
- initrd_end = of_get_property(barebox, "/chosen/linux,initrd-end", 0)
+ initrd_start = of_get_property(barebox, "/chosen/linux,initrd-start", ncells=0)
+ initrd_end = of_get_property(barebox, "/chosen/linux,initrd-end", ncells=0)
+ initrd_size = initrd_end - initrd_start

- assert initrd_start < initrd_end
+ # Verify the DT-reported size matches the actual file size
+ assert initrd_size == actual_size, \
+ f"Initrd size mismatch: DT says {initrd_size}, file is {actual_size}"
+
+ [hashsum2] = barebox.run_check(f"md5sum {initrd_start}+{initrd_size}")
+
+ hashsum2 = re.split("/dev/mem", hashsum2, maxsplit=1)[0]
+
+ assert hashsum1 == hashsum2
diff --git a/test/py/testfs.py b/test/py/testfs.py
new file mode 100644
index 000000000000..3ead67c0621b
--- /dev/null
+++ b/test/py/testfs.py
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import subprocess
+
+
+def mkcpio(inpath, outname):
+ compress = outname.suffix == ".gz"
+
+ find = subprocess.Popen(["find", inpath], stdout=subprocess.PIPE)
+
+ with open(outname, "wb") as outfile:
+ cpio = subprocess.Popen(["cpio", "-o", "-H", "newc"], stdin=find.stdout,
+ stdout=(subprocess.PIPE if compress else outfile))
+
+ find.stdout.close()
+
+ if compress:
+ gzip = subprocess.Popen(["gzip"], stdin=cpio.stdout, stdout=outfile)
+ cpio.stdout.close()
+ gzip.wait()
+
+ cpio.wait()
+ find.wait()
diff --git a/test/testdata/multi_v7_defconfig-gzipped.its b/test/testdata/multi_v7_defconfig-gzipped.its
index 11595c39baa1..1cb84fd41564 100644
--- a/test/testdata/multi_v7_defconfig-gzipped.its
+++ b/test/testdata/multi_v7_defconfig-gzipped.its
@@ -26,8 +26,30 @@
};
};
ramdisk-1 {
- description = "initramfs";
- data = /incbin/("ramdisk.cpio.gz");
+ description = "initramfs 1 (compressed)";
+ data = /incbin/("testfs/ramdisk1.cpio.gz");
+ type = "ramdisk";
+ arch = "arm";
+ os = "linux";
+ compression = "none";
+ hash-1 {
+ algo = "sha256";
+ };
+ };
+ ramdisk-2 {
+ description = "initramfs 2 (uncompressed)";
+ data = /incbin/("testfs/ramdisk2.cpio");
+ type = "ramdisk";
+ arch = "arm";
+ os = "linux";
+ compression = "none";
+ hash-1 {
+ algo = "sha256";
+ };
+ };
+ ramdisk-3 {
+ description = "initramfs 3 (compressed)";
+ data = /incbin/("testfs/ramdisk3.cpio.gz");
type = "ramdisk";
arch = "arm";
os = "linux";
@@ -44,7 +66,7 @@
description = "Qemu Virt32";
kernel = "kernel-1";
fdt = "fdt-qemu-virt32.dtb";
- ramdisk = "ramdisk-1";
+ ramdisk = "ramdisk-1", "ramdisk-2", "ramdisk-3";
compatible = "linux,dummy-virt";
signature-1 {
algo = "sha256,rsa2048";
diff --git a/test/testdata/multi_v8_defconfig-gzipped.its b/test/testdata/multi_v8_defconfig-gzipped.its
index 5ce678eec9a8..3786d0f12187 100644
--- a/test/testdata/multi_v8_defconfig-gzipped.its
+++ b/test/testdata/multi_v8_defconfig-gzipped.its
@@ -26,8 +26,30 @@
};
};
ramdisk-1 {
- description = "initramfs";
- data = /incbin/("ramdisk.cpio.gz");
+ description = "initramfs 1 (compressed)";
+ data = /incbin/("testfs/ramdisk1.cpio.gz");
+ type = "ramdisk";
+ arch = "arm64";
+ os = "linux";
+ compression = "none";
+ hash-1 {
+ algo = "sha256";
+ };
+ };
+ ramdisk-2 {
+ description = "initramfs 2 (uncompressed)";
+ data = /incbin/("testfs/ramdisk2.cpio");
+ type = "ramdisk";
+ arch = "arm64";
+ os = "linux";
+ compression = "none";
+ hash-1 {
+ algo = "sha256";
+ };
+ };
+ ramdisk-3 {
+ description = "initramfs 3 (compressed)";
+ data = /incbin/("testfs/ramdisk3.cpio.gz");
type = "ramdisk";
arch = "arm64";
os = "linux";
@@ -44,7 +66,7 @@
description = "Qemu Virt64";
kernel = "kernel-1";
fdt = "fdt-qemu-virt64.dtb";
- ramdisk = "ramdisk-1";
+ ramdisk = "ramdisk-1", "ramdisk-2", "ramdisk-3";
compatible = "linux,dummy-virt";
signature-1 {
algo = "sha256,rsa2048";
--
2.47.3