mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 0/9] TLV integration tests and test/py cleanup
@ 2025-09-29  8:03 Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 1/9] test: when testfs feature is available, always enable it Jonas Rebmann
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:03 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

With TLV signature coming up, we want to test all things TLV more
thoroughly, including "roundtrip" integration tests that include the
bareboxtlv-generator python-script and the tlv barebox-command.

As this is the third test module to make use of the testfs, it seemed
adequate to revisit its implementation.

Avoid integration test logic outside pytest; migrate logic from .github/
and scripts/ into pytest.

Use fixtures for testcase preconditions and migrate existing testdata
preparation from scripts/generate_testfs.sh.

Cleanups here and there.

The ci-container needs to be rebuilt before the TLV tests will succeed
in CI.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
Changes in v2:
- work around a corner case where a failed network test leads to
  unrelated pritinting above the tlv command output (triggered by
  accessing the 9pfs)
- move fitimage testdata generation to fixture and drop script
- Enable CMD_TLV for multi_v7 and multi_v8 (required for tlv_command test)
- Skip tlv_command test if CMD_TLV is disabled
- Ensure that pwd is returned to / after dm_verity test even on failure
- Silently skip generating testdata for the fit tests for platforms for
  which no files are provided to prevent ci failure on mips and riscv
- minor improvements in style and consistency
- Link to v1: https://lore.barebox.org/barebox/20250926-tlv-integration-v1-0-45dc68b9b602@pengutronix.de

---
Jonas Rebmann (9):
      test: when testfs feature is available, always enable it
      test: provide testfs via fixture
      test: move dm-verity testdata generation to fixture
      test: move fitimage testdata generation to fixture and drop script
      test: py: test_bootchooser: remove dead code
      commands: tlv: clarify error opening tlv
      ci: container: install crcmod and cryptography
      configs: enable tlv command for multi_v7 and multi_v8
      test: py: add TLV integration tests

 .github/workflows/test-labgrid-pytest.yml          | 13 ----
 arch/arm/configs/multi_v7_defconfig                |  2 +
 arch/arm/configs/multi_v8_defconfig                |  2 +
 commands/tlv.c                                     |  8 ++-
 conftest.py                                        | 14 ++++
 scripts/generate_testfs.sh                         | 77 ---------------------
 test/Containerfile                                 |  8 ++-
 test/py/test_bootchooser.py                        |  4 --
 test/py/test_dm.py                                 | 59 ++++++++++++++--
 test/py/test_fit.py                                | 46 +++++++++++--
 test/py/test_tlv.py                                | 78 ++++++++++++++++++++++
 .../testdata}/multi_v7_defconfig-gzipped.its       |  0
 .../testdata}/multi_v8_defconfig-gzipped.its       |  0
 13 files changed, 200 insertions(+), 111 deletions(-)
---
base-commit: 1b817ae40c2ba628ba0ce413564ea77e91a6009b
change-id: 20250926-tlv-integration-945bdd7903d9

Best regards,
--  
Jonas Rebmann <jre@pengutronix.de>




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/9] test: when testfs feature is available, always enable it
  2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
@ 2025-09-29  8:03 ` Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 2/9] test: provide testfs via fixture Jonas Rebmann
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:03 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

Add 9pfs devices to the qemu commandline on all platforms that support
it (multi_v7, multi_v8) so tests relying upon it can be ran without
specifying --fs testfs=${KBUILD_OUTPUT}/testfs.

Moving logic out of the github workflow into pytest makes integration
tests more accessible to developers.

Introduce the fixture in existing test and drop obsolete test.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 .github/workflows/test-labgrid-pytest.yml | 3 ---
 conftest.py                               | 6 ++++++
 test/py/test_dm.py                        | 6 +-----
 test/py/test_fit.py                       | 4 ----
 4 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/test-labgrid-pytest.yml b/.github/workflows/test-labgrid-pytest.yml
index ccf8ae172c..604f1db2fb 100644
--- a/.github/workflows/test-labgrid-pytest.yml
+++ b/.github/workflows/test-labgrid-pytest.yml
@@ -116,9 +116,6 @@ jobs:
           grep -wq '\(QEMUDriver\|ExternalConsoleDriver\):' "$i" || continue
 
           extraargs="${{matrix.lgargs}}"
-          if grep -wq 'testfs' "$i"; then
-            extraargs="${extraargs} --fs testfs=${KBUILD_OUTPUT}/testfs"
-          fi
 
           cfg=$(basename $i .yaml)
           echo "Testing $cfg"
diff --git a/conftest.py b/conftest.py
index 06321c938d..00969e62df 100644
--- a/conftest.py
+++ b/conftest.py
@@ -208,6 +208,12 @@ def strategy(request, target, pytestconfig):
     for arg in pytestconfig.option.qemu_arg:
         strategy.append_qemu_args(arg)
 
+    if "testfs" in features:
+        if not any(fs and fs[0] == "testfs" for fs in pytestconfig.option.qemu_fs):
+            testfs_path = os.path.join(os.environ["LG_BUILDDIR"], "testfs")
+            pytestconfig.option.qemu_fs.append(["testfs", testfs_path])
+            os.makedirs(testfs_path, exist_ok=True)
+
     for i, fs in enumerate(pytestconfig.option.qemu_fs):
         if virtio:
             path = fs.pop()
diff --git a/test/py/test_dm.py b/test/py/test_dm.py
index a9debd85b5..8bdacf7b4e 100644
--- a/test/py/test_dm.py
+++ b/test/py/test_dm.py
@@ -6,11 +6,7 @@ from .helper import of_get_property
 
 
 
-def test_dm_verity(barebox):
-    _, _, returncode = barebox.run("ls /mnt/9p/testfs")
-    if returncode != 0:
-        pytest.xfail("skipping test due to missing --fs testfs=")
-
+def test_dm_verity(barebox, testfs):
     barebox.run_check("cd /mnt/9p/testfs")
 
     # Since commands run in a subshell, export the root hash in a
diff --git a/test/py/test_fit.py b/test/py/test_fit.py
index 1a23a53a32..08d5feba5c 100644
--- a/test/py/test_fit.py
+++ b/test/py/test_fit.py
@@ -19,10 +19,6 @@ 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=")
-
     _, _, returncode = barebox.run(f"ls {fit_name('gzipped')}")
     if returncode != 0:
         pytest.xfail("skipping test due to missing FIT image")

-- 
2.51.0.297.gca2559c1d6




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 2/9] test: provide testfs via fixture
  2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 1/9] test: when testfs feature is available, always enable it Jonas Rebmann
@ 2025-09-29  8:03 ` Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 3/9] test: move dm-verity testdata generation to fixture Jonas Rebmann
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:03 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

Move the logic of providing testfs out of the tests and into a fixture.
Pytest-modules that prepare testing data in their own fixtures should
build on top of this.

Tests using the fixture will be skipped if the feature is unavailable;
remove that check from existing tests.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 conftest.py         | 8 ++++++++
 test/py/test_fit.py | 5 +----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/conftest.py b/conftest.py
index 00969e62df..116beb5d14 100644
--- a/conftest.py
+++ b/conftest.py
@@ -231,3 +231,11 @@ def strategy(request, target, pytestconfig):
         strategy.force(state)
 
     return strategy
+
+@pytest.fixture(scope="session")
+def testfs(strategy, env):
+    if "testfs" not in env.get_target_features():
+        pytest.skip("testfs not supported on this platform")
+
+    path = os.path.join(os.environ["LG_BUILDDIR"], "testfs")
+    return path
diff --git a/test/py/test_fit.py b/test/py/test_fit.py
index 08d5feba5c..3b2b8ff871 100644
--- a/test/py/test_fit.py
+++ b/test/py/test_fit.py
@@ -15,10 +15,7 @@ def generate_bootscript(barebox, image, name="test"):
     return name
 
 
-def test_fit(barebox, env, target, barebox_config):
-    if 'testfs' not in env.get_target_features():
-        pytest.xfail("testfs feature not specified")
-
+def test_fit(barebox, env, target, barebox_config, testfs):
     _, _, returncode = barebox.run(f"ls {fit_name('gzipped')}")
     if returncode != 0:
         pytest.xfail("skipping test due to missing FIT image")

-- 
2.51.0.297.gca2559c1d6




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 3/9] test: move dm-verity testdata generation to fixture
  2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 1/9] test: when testfs feature is available, always enable it Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 2/9] test: provide testfs via fixture Jonas Rebmann
@ 2025-09-29  8:03 ` Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 4/9] test: move fitimage testdata generation to fixture and drop script Jonas Rebmann
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:03 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

Simplify barebox integration test setup by moving logic away from
scripts/ and .github/.

Instead of generating testdata in separate scripts, they should be
implemented as testfs fixtures which are automatically ran as part of
the test suite.

Includes error handling and cleanup.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 scripts/generate_testfs.sh | 44 -----------------------------------
 test/py/test_dm.py         | 57 ++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 55 insertions(+), 46 deletions(-)

diff --git a/scripts/generate_testfs.sh b/scripts/generate_testfs.sh
index e0a4013e05..d52772e6bf 100755
--- a/scripts/generate_testfs.sh
+++ b/scripts/generate_testfs.sh
@@ -31,47 +31,3 @@ generate_fit()
 if [ -f .github/testfs/${KBUILD_DEFCONFIG}-gzipped.its ]; then
 	generate_fit
 fi
-
-alias pad128k="dd if=/dev/zero bs=128k count=1 status=none"
-
-generate_dm_verity()
-{
-    work=$(mktemp -d)
-    cd ${work}
-
-    # Create two dummy files; use lots of padding to make sure that
-    # when we alter the contents of 'english' in root-bad, 'latin' is
-    # still be readable, as their contents wont (a) share the same
-    # hash block and (b) the block cache layer won't accedentally read
-    # the invalid block.
-
-    pad128k  >latin
-    echo -n "veritas vos liberabit" >>latin
-    pad128k >>latin
-
-    pad128k  >english
-    echo -n "truth will set you free" >>english
-    pad128k >>english
-
-    truncate -s 1M good.fat
-    mkfs.vfat good.fat
-    mcopy -i good.fat latin english ::
-
-    veritysetup format \
-		--root-hash-file=good.hash \
-		good.fat good.verity
-
-    sed 's/truth will set you free/LIAR LIAR PANTS ON FIRE/' \
-	<good.fat >bad.fat
-
-    cd -
-    cp \
-	${work}/good.fat \
-	${work}/good.verity \
-	${work}/good.hash \
-	${work}/bad.fat \
-	${KBUILD_OUTPUT}/testfs
-
-    rm -rf ${work}
-}
-generate_dm_verity
diff --git a/test/py/test_dm.py b/test/py/test_dm.py
index 8bdacf7b4e..adeb9cbe03 100644
--- a/test/py/test_dm.py
+++ b/test/py/test_dm.py
@@ -4,10 +4,63 @@ import re
 import pytest
 from .helper import of_get_property
 
+import os, subprocess, shutil
 
+def pad128k(f):
+    f.write(b"\0" * 128 * 1024)
 
-def test_dm_verity(barebox, testfs):
-    barebox.run_check("cd /mnt/9p/testfs")
+@pytest.fixture(scope="module")
+def dm_testdata(testfs):
+    path = os.path.join(testfs, "dm")
+    os.makedirs(path, exist_ok=True)
+    cwd = os.getcwd()
+    os.chdir(path)
+
+    with open("latin", "wb") as f:
+        pad128k(f)
+        f.write(b"veritas vos liberabit")
+        pad128k(f)
+
+    with open("english", "wb") as f:
+        pad128k(f)
+        f.write(b"truth will set you free")
+        pad128k(f)
+
+    try:
+        subprocess.run(["truncate", "-s", "1M", "good.fat"], check=True)
+        subprocess.run(["mkfs.vfat", "good.fat"], check=True)
+        subprocess.run(["mcopy", "-i", "good.fat", "latin", "english", "::"], check=True)
+
+        subprocess.run([
+            "veritysetup", "format",
+            "--root-hash-file=good.hash",
+            "good.fat", "good.verity"
+        ], check=True)
+    except FileNotFoundError as e:
+        os.chdir(cwd)
+        shutil.rmtree(path)
+        pytest.skip(f"missing dependency: {e}")
+
+    with open("good.fat", "rb") as f: data = f.read()
+    with open("bad.fat", "wb") as f:
+        f.write(data.replace(
+            b"truth will set you free",
+            b"LIAR LIAR PANTS ON FIRE"
+        ))
+
+    os.chdir(cwd)
+
+    yield path
+
+    shutil.rmtree(path)
+
+@pytest.fixture(autouse=True)
+def reset_pwd(barebox):
+    yield
+    barebox.run("cd")
+
+def test_dm_verity(barebox, dm_testdata):
+    barebox.run_check("cd /mnt/9p/testfs/dm")
 
     # Since commands run in a subshell, export the root hash in a
     # global, so that we can access it from subsequent commands

-- 
2.51.0.297.gca2559c1d6




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 4/9] test: move fitimage testdata generation to fixture and drop script
  2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
                   ` (2 preceding siblings ...)
  2025-09-29  8:03 ` [PATCH v2 3/9] test: move dm-verity testdata generation to fixture Jonas Rebmann
@ 2025-09-29  8:03 ` Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 5/9] test: py: test_bootchooser: remove dead code Jonas Rebmann
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:03 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

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@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)
+
+
+@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




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 5/9] test: py: test_bootchooser: remove dead code
  2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
                   ` (3 preceding siblings ...)
  2025-09-29  8:03 ` [PATCH v2 4/9] test: move fitimage testdata generation to fixture and drop script Jonas Rebmann
@ 2025-09-29  8:03 ` Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 6/9] commands: tlv: clarify error opening tlv Jonas Rebmann
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:03 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

This seems to have landed here by accident.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 test/py/test_bootchooser.py | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/test/py/test_bootchooser.py b/test/py/test_bootchooser.py
index a5f2b25d65..bd8aee7399 100644
--- a/test/py/test_bootchooser.py
+++ b/test/py/test_bootchooser.py
@@ -5,10 +5,6 @@ from .helper import globalvars_set, devinfo, getparam_int, \
                     getstate_int, getenv_int
 
 
-def fit_name(suffix):
-    return f"/mnt/9p/testfs/barebox-{suffix}.fit"
-
-
 def generate_bootscript(barebox, command, name="test"):
     barebox.run_check(f"echo -o /env/boot/{name} '#!/bin/sh'")
     barebox.run_check(f"echo -a /env/boot/{name} '{command}'")

-- 
2.51.0.297.gca2559c1d6




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 6/9] commands: tlv: clarify error opening tlv
  2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
                   ` (4 preceding siblings ...)
  2025-09-29  8:03 ` [PATCH v2 5/9] test: py: test_bootchooser: remove dead code Jonas Rebmann
@ 2025-09-29  8:03 ` Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 7/9] ci: container: install crcmod and cryptography Jonas Rebmann
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:03 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

Returning PTR_ERR(tlvdev) instead of printing an error message leads to
the same output when CONFIG_CMD_TLV and when the specified path could
not be read:

  tlv: No such file or directory

In the latter case, print an explanatory message instead.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 commands/tlv.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/commands/tlv.c b/commands/tlv.c
index 53fbc2a291..6118a2947f 100644
--- a/commands/tlv.c
+++ b/commands/tlv.c
@@ -28,9 +28,11 @@ static int do_tlv(int argc, char *argv[])
 	if (!filename)
 		return COMMAND_ERROR_USAGE;
 
-	tlvdev = tlv_register_device_by_path(argv[optind], NULL);
-	if (IS_ERR(tlvdev))
-		return PTR_ERR(tlvdev);
+	tlvdev = tlv_register_device_by_path(filename, NULL);
+	if (IS_ERR(tlvdev)) {
+		printf("Could not open \"%s\": %m\n", filename);
+		return COMMAND_ERROR;
+	}
 
 	if (fixup)
 		return tlv_of_register_fixup(tlvdev);

-- 
2.51.0.297.gca2559c1d6




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 7/9] ci: container: install crcmod and cryptography
  2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
                   ` (5 preceding siblings ...)
  2025-09-29  8:03 ` [PATCH v2 6/9] commands: tlv: clarify error opening tlv Jonas Rebmann
@ 2025-09-29  8:03 ` Jonas Rebmann
  2025-09-29  8:03 ` [PATCH v2 8/9] configs: enable tlv command for multi_v7 and multi_v8 Jonas Rebmann
  2025-09-29  8:04 ` [PATCH v2 9/9] test: py: add TLV integration tests Jonas Rebmann
  8 siblings, 0 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:03 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

Needed for bareboxtlv-generator.py which will be part of integration
tests.

While at it, sort python packages alphabetically.

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 test/Containerfile | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/test/Containerfile b/test/Containerfile
index c6c3c57596..f2e785d17c 100644
--- a/test/Containerfile
+++ b/test/Containerfile
@@ -43,11 +43,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
 	qemu-system-common \
 	ovmf \
 	python3 \
-	python3-pip \
-	python3-virtualenv \
-	python3-setuptools \
+	python3-crcmod \
+	python3-cryptography \
 	python3-jsonschema \
 	python3-libfdt \
+	python3-pip \
+	python3-setuptools \
+	python3-virtualenv \
 	python3-yaml \
 	virtualenv \
 	sudo \

-- 
2.51.0.297.gca2559c1d6




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 8/9] configs: enable tlv command for multi_v7 and multi_v8
  2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
                   ` (6 preceding siblings ...)
  2025-09-29  8:03 ` [PATCH v2 7/9] ci: container: install crcmod and cryptography Jonas Rebmann
@ 2025-09-29  8:03 ` Jonas Rebmann
  2025-09-29  8:04 ` [PATCH v2 9/9] test: py: add TLV integration tests Jonas Rebmann
  8 siblings, 0 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:03 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

Required for TLV integration tests

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 arch/arm/configs/multi_v7_defconfig | 2 ++
 arch/arm/configs/multi_v8_defconfig | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index f198a1ddac..93f79c79d2 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -121,6 +121,7 @@ CONFIG_PARTITION_DISK_EFI=y
 # CONFIG_PARTITION_DISK_EFI_GPT_COMPARE is not set
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_REBOOT_MODE=y
+CONFIG_TLV=y
 CONFIG_STATE=y
 CONFIG_BOOTCHOOSER=y
 CONFIG_RESET_SOURCE=y
@@ -203,6 +204,7 @@ CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OF_OVERLAY=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_TLV=y
 CONFIG_NET=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_FASTBOOT=y
diff --git a/arch/arm/configs/multi_v8_defconfig b/arch/arm/configs/multi_v8_defconfig
index bd6fceb941..2cb0256f86 100644
--- a/arch/arm/configs/multi_v8_defconfig
+++ b/arch/arm/configs/multi_v8_defconfig
@@ -66,6 +66,7 @@ CONFIG_PBL_CONSOLE=y
 CONFIG_CONSOLE_RATP=y
 CONFIG_PARTITION_DISK_EFI=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
+CONFIG_TLV=y
 CONFIG_STATE=y
 CONFIG_BOOTCHOOSER=y
 CONFIG_RESET_SOURCE=y
@@ -147,6 +148,7 @@ CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OF_OVERLAY=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
+CONFIG_CMD_TLV=y
 CONFIG_NET=y
 CONFIG_NET_NETCONSOLE=y
 CONFIG_NET_SNTP=y

-- 
2.51.0.297.gca2559c1d6




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 9/9] test: py: add TLV integration tests
  2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
                   ` (7 preceding siblings ...)
  2025-09-29  8:03 ` [PATCH v2 8/9] configs: enable tlv command for multi_v7 and multi_v8 Jonas Rebmann
@ 2025-09-29  8:04 ` Jonas Rebmann
  8 siblings, 0 replies; 10+ messages in thread
From: Jonas Rebmann @ 2025-09-29  8:04 UTC (permalink / raw)
  To: Sascha Hauer, BAREBOX; +Cc: Tobias Waldekranz, Jonas Rebmann

With TLV signature coming up, we want to test all things TLV more
thoroughly, including "roundtrip" integration tests that include the
bareboxtlv-generator python-script and the tlv barebox-command.

 - Encode the example TLV data
 - Add a "corrupted" variant of that tlv binary with a bit error
 - Test decoding those binaries using bareboxtlv-generator
 - Test decoding those binaries using the tlv-command

Signed-off-by: Jonas Rebmann <jre@pengutronix.de>
---
 test/py/test_tlv.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/test/py/test_tlv.py b/test/py/test_tlv.py
new file mode 100644
index 0000000000..963f3749b3
--- /dev/null
+++ b/test/py/test_tlv.py
@@ -0,0 +1,78 @@
+import os
+import re
+import subprocess
+from pathlib import Path
+from crcmod.predefined import mkPredefinedCrcFun
+from .helper import skip_disabled
+
+_crc32_mpeg = mkPredefinedCrcFun("crc-32-mpeg")
+
+import pytest
+
+
+class _TLV_Testdata:
+    def generator(self, args, check=True):
+        cmd = [os.sys.executable, str(self.generator_py)] + args
+        res = subprocess.run(cmd, text=True)
+        if check and res.returncode != 0:
+            raise RuntimeError(f"generator failed ({res.returncode}): {res.stdout}\n{res.stderr}")
+        return res
+
+    def __init__(self, testfs):
+        self.dir = Path(testfs)
+        self.scripts_dir = Path("scripts/bareboxtlv-generator")
+        self.data = self.scripts_dir / "data-example.yaml"
+        self.schema = self.scripts_dir / "schema-example.yaml"
+        self.generator_py = self.scripts_dir / "bareboxtlv-generator.py"
+        self.unsigned_bin = self.dir / 'unsigned.tlv'
+        self.corrupted_bin = self.dir / 'unsigned_corrupted.tlv'
+
+@pytest.fixture(scope="module")
+def tlv_testdata(testfs):
+    t = _TLV_Testdata(testfs)
+    t.generator(["--input-data", str(t.data), str(t.schema), str(t.unsigned_bin)])
+    assert t.unsigned_bin.exists(), "unsigned TLV not created"
+
+    with open(t.unsigned_bin, 'r+b') as f:
+        data = bytearray(f.read())
+    data[0x20] ^= 1
+    with open(t.corrupted_bin, "wb") as f:
+        f.write(data)
+
+    return t
+
+def test_tlv_generator(tlv_testdata):
+    t = tlv_testdata
+    out_yaml = t.dir / 'out.yaml'
+
+
+    good = t.generator(["--output-data", str(out_yaml), str(t.schema), str(t.unsigned_bin)], check=False)
+    assert good.returncode == 0, f"valid unsigned TLV failed to decode: {good.stderr}\n{good.stdout}"
+
+    bad = t.generator(["--output-data", str(t.dir / 'bad.yaml'), str(t.schema), str(t.corrupted_bin)], check=False)
+    assert bad.returncode != 0, "unsigned TLV with invalid CRC unexpectedly decoded successfully"
+
+def test_tlv_command(barebox, barebox_config, tlv_testdata):
+    skip_disabled(barebox_config, "CONFIG_CMD_TLV")
+    t = tlv_testdata
+    with open(t.data, 'r', encoding='utf-8') as f:
+        yaml_lines = [l.strip() for l in f if l.strip() and not l.strip().startswith('#')]
+
+    stdout = barebox.run_check(f"tlv /mnt/9p/testfs/{t.unsigned_bin.name}")
+
+    # work around 9pfs printing here after a failed network test
+    tlv_offset = next((i for i, line in enumerate(stdout) if line.startswith("tlv")), None)
+    tlv_lines = stdout[tlv_offset + 1:-1]
+
+    assert len(yaml_lines) == len(tlv_lines), \
+        f"YAML and TLV output line count mismatch for {t.unsigned_bin.name}"
+
+    for yline, tline in zip(yaml_lines, tlv_lines):
+        m = re.match(r'^\s*([^=]+) = "(.*)";$', tline)
+        assert m, f"malformed tlv line: {tline}"
+        tkey, tval = m.group(1), m.group(2)
+        m = re.match(r'^([^:]+):\s*(?:"([^"]*)"\s*|(.*))$', yline)
+        assert m, f"malformed yaml line: {yline}"
+        ykey, yval = m.group(1), m.group(2) or m.group(3)
+        assert ykey == tkey, f"key mismatch: {ykey} != {tkey}"
+        assert str(yval) == str(tval), f"value mismatch for {ykey}: {yval} != {tval}"

-- 
2.51.0.297.gca2559c1d6




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-09-29  8:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-29  8:03 [PATCH v2 0/9] TLV integration tests and test/py cleanup Jonas Rebmann
2025-09-29  8:03 ` [PATCH v2 1/9] test: when testfs feature is available, always enable it Jonas Rebmann
2025-09-29  8:03 ` [PATCH v2 2/9] test: provide testfs via fixture Jonas Rebmann
2025-09-29  8:03 ` [PATCH v2 3/9] test: move dm-verity testdata generation to fixture Jonas Rebmann
2025-09-29  8:03 ` [PATCH v2 4/9] test: move fitimage testdata generation to fixture and drop script Jonas Rebmann
2025-09-29  8:03 ` [PATCH v2 5/9] test: py: test_bootchooser: remove dead code Jonas Rebmann
2025-09-29  8:03 ` [PATCH v2 6/9] commands: tlv: clarify error opening tlv Jonas Rebmann
2025-09-29  8:03 ` [PATCH v2 7/9] ci: container: install crcmod and cryptography Jonas Rebmann
2025-09-29  8:03 ` [PATCH v2 8/9] configs: enable tlv command for multi_v7 and multi_v8 Jonas Rebmann
2025-09-29  8:04 ` [PATCH v2 9/9] test: py: add TLV integration tests Jonas Rebmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox