[PATCH v2 4/9] test: move fitimage testdata generation to fixture and drop script

Jonas Rebmann jre at pengutronix.de
Mon Sep 29 01:03:55 PDT 2025


Get rid of scripts/generate_testfs.sh and the logic around it. Test data
generation should happen within pytest.

Move test data (its config for fitimages) from .github/testfs to
test/testdata for good measure.

Signed-off-by: Jonas Rebmann <jre at pengutronix.de>
---
 .github/workflows/test-labgrid-pytest.yml          | 10 -----
 scripts/generate_testfs.sh                         | 33 -----------------
 test/py/test_fit.py                                | 43 +++++++++++++++++++++-
 .../testdata}/multi_v7_defconfig-gzipped.its       |  0
 .../testdata}/multi_v8_defconfig-gzipped.its       |  0
 5 files changed, 42 insertions(+), 44 deletions(-)

diff --git a/.github/workflows/test-labgrid-pytest.yml b/.github/workflows/test-labgrid-pytest.yml
index 604f1db2fb..4569e475bc 100644
--- a/.github/workflows/test-labgrid-pytest.yml
+++ b/.github/workflows/test-labgrid-pytest.yml
@@ -97,16 +97,6 @@ jobs:
           cp /usr/share/qemu/opensbi-riscv32-generic-fw_dynamic.bin ${KBUILD_OUTPUT}/
         fi
 
-    - name: Populate testfs
-      if: steps.used-features.outputs.testfs == 'true'
-      run: |
-        export KBUILD_OUTPUT=build-${{matrix.arch}}-${{matrix.defconfig}}
-        export KBUILD_DEFCONFIG=${{matrix.defconfig}}
-
-        # Just use already built dtc
-        export PATH="$PATH:${KBUILD_OUTPUT}/scripts/dtc/"
-        exec scripts/generate_testfs.sh
-
     - name: labgrid-pytest
       if: steps.build.outcome == 'success'
       run: |
diff --git a/scripts/generate_testfs.sh b/scripts/generate_testfs.sh
deleted file mode 100755
index d52772e6bf..0000000000
--- a/scripts/generate_testfs.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-
-MKIMAGE=${MKIMAGE:-mkimage}
-KGZIP=${KGZIP:-gzip}
-
-set -e
-
-if [ -z "${KBUILD_OUTPUT}" ] || [ -z "${KBUILD_DEFCONFIG}" ] ; then
-	2>&1 echo "KBUILD_OUTPUT and KBUILD_DEFCONFIG must be set"
-	exit 1
-fi
-
-rm -rf "${KBUILD_OUTPUT}/testfs/"
-mkdir -p ${KBUILD_OUTPUT}/testfs
-
-generate_fit()
-{
-    cat ${KBUILD_OUTPUT}/images/barebox-dt-2nd.img | \
-	${KGZIP} -n -f -9 >${KBUILD_OUTPUT}/barebox-dt-2nd.img.gz
-
-    cp .github/testfs/${KBUILD_DEFCONFIG}-gzipped.its ${KBUILD_OUTPUT}/
-
-    find COPYING LICENSES/ | cpio -o -H newc | ${KGZIP} \
-						   > ${KBUILD_OUTPUT}/ramdisk.cpio.gz
-
-    ${MKIMAGE} -G $PWD/test/self/development_rsa2048.pem -r \
-	       -f ${KBUILD_OUTPUT}/${KBUILD_DEFCONFIG}-gzipped.its \
-	       ${KBUILD_OUTPUT}/testfs/barebox-gzipped.fit
-}
-
-if [ -f .github/testfs/${KBUILD_DEFCONFIG}-gzipped.its ]; then
-	generate_fit
-fi
diff --git a/test/py/test_fit.py b/test/py/test_fit.py
index 3b2b8ff871..5620996e9d 100644
--- a/test/py/test_fit.py
+++ b/test/py/test_fit.py
@@ -1,7 +1,11 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 import re
+import os
 import pytest
+import shutil
+import subprocess
+from pathlib import Path
 from .helper import of_get_property
 
 
@@ -15,7 +19,44 @@ def generate_bootscript(barebox, image, name="test"):
     return name
 
 
-def test_fit(barebox, env, target, barebox_config, testfs):
+def run(cmd, **kwargs):
+    subprocess.run(cmd, check=True, **kwargs)
+
+
+ at pytest.fixture(scope="module")
+def fit_testdata(barebox_config, testfs):
+    its_name = f"{barebox_config['CONFIG_NAME']}-gzipped.its"
+    its_location = Path("test/testdata")
+    builddir = Path(os.environ['LG_BUILDDIR'])
+    outdir = Path(testfs)
+    outfile = outdir / "barebox-gzipped.fit"
+
+    if not os.path.isfile(its_location / its_name):
+        pytest.skip(f"no fitimage testdata found at {its_location}")
+
+    shutil.copy(its_location / its_name, builddir)
+
+    try:
+        run(["gzip", "-n", "-f", "-9"],
+            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()
+
+        run([ "mkimage", "-G", "test/self/development_rsa2048.pem", "-r", "-f",
+             str(builddir / its_name), str(outfile) ])
+    except FileNotFoundError as e:
+        pytest.skip(f"Skip dm tests due to missing dependency: {e}")
+
+    yield
+
+    os.remove(outfile)
+
+def test_fit(barebox, target, testfs, fit_testdata):
     _, _, returncode = barebox.run(f"ls {fit_name('gzipped')}")
     if returncode != 0:
         pytest.xfail("skipping test due to missing FIT image")
diff --git a/.github/testfs/multi_v7_defconfig-gzipped.its b/test/testdata/multi_v7_defconfig-gzipped.its
similarity index 100%
rename from .github/testfs/multi_v7_defconfig-gzipped.its
rename to test/testdata/multi_v7_defconfig-gzipped.its
diff --git a/.github/testfs/multi_v8_defconfig-gzipped.its b/test/testdata/multi_v8_defconfig-gzipped.its
similarity index 100%
rename from .github/testfs/multi_v8_defconfig-gzipped.its
rename to test/testdata/multi_v8_defconfig-gzipped.its

-- 
2.51.0.297.gca2559c1d6




More information about the barebox mailing list