[PATCH v2 3/9] test: move dm-verity testdata generation to fixture
Jonas Rebmann
jre at pengutronix.de
Mon Sep 29 01:03:54 PDT 2025
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 at 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")
+ at 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)
+
+ at 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
More information about the barebox
mailing list