Skip to contentSkip to conversation

test: py: dm: skip test if veritysetup command is disabled

PATCH Applied Ahmad Fatoum 3 participants 6 messages Oct 20, 2025 – Oct 27, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 test: py: dm: skip test if veritysetup command is disabled

The test depends on veritysetup being available, so skip it if this is not the case.

---
 test/py/test_dm.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
test/py/test_dm.py +5 -2
index adeb9cbe03c9..dc4e05cc77c8 100644
@@ -2,7 +2,7 @@
 
 import re
 import pytest
-from .helper import of_get_property
+from .helper import skip_disabled
 
 import os, subprocess, shutil
 
@@ -59,7 +59,10 @@ def reset_pwd(barebox):
     yield
     barebox.run("cd")
 
-def test_dm_verity(barebox, dm_testdata):
+
+def test_dm_verity(barebox, barebox_config, dm_testdata):
+    skip_disabled(barebox_config, "CONFIG_CMD_VERITYSETUP")
+
     barebox.run_check("cd /mnt/9p/testfs/dm")
 
     # Since commands run in a subshell, export the root hash in a
Signature · 1 line
2.47.3
#1 lore raw

PATCH 2/3 test: py: network: skip test if tftp command is missing

The test depends on the tftp command being available, so skip it if this is not the case.

---
 test/py/test_network.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
test/py/test_network.py +4 -1
index afaa259e2496..28efcc02e44d 100644
@@ -5,6 +5,7 @@ import socket
 import threading
 import re
 import warnings
+from .helper import skip_disabled
 
 # Setting the port to zero causes bind to choose a random ephermal port
 TFTP_TEST_PORT = 0
@@ -64,7 +65,9 @@ def tftp_conversation(barebox, barebox_interface, guestaddr):
         barebox.run_check("ifdown eth0")
 
 
-def test_barebox_network(barebox, env):
+def test_barebox_network(barebox, barebox_config, env):
+    skip_disabled(barebox_config, "CONFIG_CMD_TFTP")
+
     # on DUTs without network feature, this is expected to fail
     # set xfail_strict=True to enforce specifying the network feature if available
     if not 'network' in env.get_target_features():
Signature · 1 line
2.47.3
#2 lore raw

PATCH 3/3 test: py: fix pycodestyle warnings

In reply to Ahmad Fatoum

pycodestyle complains about some things, mostly whitespace, inconsistent indentation and unused symbols.

Fix most of these up, so actual issues are more easily noticed and while at it, add missing SPDX-License-Identifiers.

---
 conftest.py                |  48 ++++++++-------
 test/py/helper.py          |   4 ++
 test/py/test_bselftests.py |   6 +-
 test/py/test_bthread.py    |   9 ++-
 test/py/test_dm.py         |  13 +++--
 test/py/test_fit.py        |  15 +++--
 test/py/test_network.py    |  22 ++++---
 test/py/test_nvmem.py      | 116 +++++++++++++++++++++++--------------
 test/py/test_shell.py      |   9 ++-
 test/py/test_tlv.py        |   2 +
 test/strategy.py           |   8 ++-
 11 files changed, 163 insertions(+), 89 deletions(-)
conftest.py +28 -20
index eb4b04873bbb..799f0637a0de 100644
@@ -1,10 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
 import pytest
 import os
 import argparse
+from labgrid.exceptions import NoDriverFoundError
 from test.py import helper
 
 from test.py.interactive import *
 
+
 def transition_to_barebox(request, strategy):
     try:
         strategy.transition('barebox')
@@ -17,11 +21,13 @@ def transition_to_barebox(request, strategy):
             pytest.exit(f"{type(e).__name__}(\"{e}\"). Standard error:\n{stderr}",
                         returncode=3)
 
+
 @pytest.fixture(scope='function')
 def barebox(request, strategy, target):
     transition_to_barebox(request, strategy)
     return target.get_driver('BareboxDriver')
 
+
 @pytest.fixture(scope="session")
 def barebox_config(request, strategy, target):
     transition_to_barebox(request, strategy)
@@ -89,39 +95,40 @@ def pytest_configure(config):
 
 def pytest_addoption(parser):
     def assignment(arg):
-            return arg.split('=', 1)
+        return arg.split('=', 1)
 
     parser.addoption('--interactive', action='store_const', const='qemu_interactive',
-        dest='lg_initial_state',
-        help=('(for debugging) skip tests and just start Qemu interactively'))
+                     dest='lg_initial_state',
+                     help=('(for debugging) skip tests and just start Qemu interactively'))
     parser.addoption('--dry-run', action='store_const', const='qemu_dry_run',
-        dest='lg_initial_state',
-        help=('(for debugging) skip tests and just print Qemu command line'))
+                     dest='lg_initial_state',
+                     help=('(for debugging) skip tests and just print Qemu command line'))
     parser.addoption('--dump-dtb', action='store_const', const='qemu_dump_dtb',
-        dest='lg_initial_state',
-        help=('(for debugging) skip tests and just dump the Qemu device tree'))
+                     dest='lg_initial_state',
+                     help=('(for debugging) skip tests and just dump the Qemu device tree'))
     parser.addoption('--graphic', '--graphics', action='store_true', dest='qemu_graphics',
-        help=('enable QEMU graphics output'))
+                     help=('enable QEMU graphics output'))
     parser.addoption('--rng', action='count', dest='qemu_rng',
-        help=('instantiate Virt I/O random number generator'))
+                     help=('instantiate Virt I/O random number generator'))
     parser.addoption('--console', action='count', dest='qemu_console', default=0,
-        help=('Pass an extra console (Virt I/O or ns16550_pci) to emulated barebox'))
+                     help=('Pass an extra console (Virt I/O or ns16550_pci) to emulated barebox'))
     parser.addoption('--fs', action='append', dest='qemu_fs',
-        default=[], metavar="[tag=]DIR", type=assignment,
-        help=('Pass directory trees to emulated barebox. Can be specified more than once'))
+                     default=[], metavar="[tag=]DIR", type=assignment,
+                     help=('Pass directory trees to emulated barebox. Can be specified more than once'))  # noqa
     parser.addoption('--blk', action='append', dest='qemu_block',
-        default=[], metavar="FILE",
-        help=('Pass block device to emulated barebox. Can be specified more than once'))
-    parser.addoption('--env', action='append', dest='qemu_fw_cfg',
-        default=[], metavar="[envpath=]content | [envpath=]@filepath", type=assignment,
-        help=('Pass barebox environment files to barebox. Can be specified more than once'))
+                     default=[], metavar="FILE",
+                     help=('Pass block device to emulated barebox. Can be specified more than once'))  # noqa
+    parser.addoption('--env', action='append', dest='qemu_fw_cfg', type=assignment,
+                     default=[], metavar="[envpath=]content | [envpath=]@filepath",
+                     help=('Pass barebox environment files to barebox. Can be specified more than once'))  # noqa
     parser.addoption('--qemu', dest='qemu_arg', nargs=argparse.REMAINDER, default=[],
-        help=('Pass all remaining options to QEMU as is'))
+                     help=('Pass all remaining options to QEMU as is'))
     parser.addoption('--bootarg', action='append', dest='bootarg', default=[],
-        help=('Pass boot arguments to barebox for debugging purposes'))
+                     help=('Pass boot arguments to barebox for debugging purposes'))
+
 
 @pytest.fixture(scope="session")
-def strategy(request, target, pytestconfig):
+def strategy(request, target, pytestconfig):  # noqa: max-complexity=30
     try:
         strategy = target.get_driver("Strategy")
     except NoDriverFoundError as e:
@@ -234,6 +241,7 @@ def strategy(request, target, pytestconfig):
 
     return strategy
 
+
 @pytest.fixture(scope="session")
 def testfs(strategy, env):
     if "testfs" not in env.get_target_features():
test/py/helper.py +4 -0
index d4949acb63a0..756a06a8be66 100644
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
 from labgrid.driver import BareboxDriver
 import pytest
 import os
@@ -113,6 +115,7 @@ def getstate_int(barebox, var, prefix="state.bootstate"):
 def getparam_int(info, var):
     return int(info["Parameters"][var].split()[0])
 
+
 def of_get_property(barebox, path):
     node, prop = os.path.split(path)
 
@@ -127,6 +130,7 @@ def of_get_property(barebox, path):
             return line[len(prefix):-1]
     return False
 
+
 def skip_disabled(config, *options):
     if bool(config):
         undefined = [opt for opt in options if opt not in config]
test/py/test_bselftests.py +4 -2
index 7417e7434916..4b0b59e672cc 100644
@@ -1,5 +1,7 @@
-import pytest
-from .helper import *
+# SPDX-License-Identifier: GPL-2.0-only
+
+from .helper import skip_disabled
+
 
 def test_bselftest(barebox, barebox_config):
     skip_disabled(barebox_config, "CONFIG_CMD_SELFTEST")
test/py/test_bthread.py +6 -3
index 6bd1032a53dd..aa59bf828141 100644
@@ -1,5 +1,7 @@
-import pytest
-from .helper import *
+# SPDX-License-Identifier: GPL-2.0-only
+
+from .helper import skip_disabled
+
 
 def stale_spawners(barebox):
     threads = barebox.run_check("bthread -i")
@@ -7,6 +9,7 @@ def stale_spawners(barebox):
         return False
     return len([t for t in threads if t.startswith('spawner')]) > 0
 
+
 def test_bthread(barebox, barebox_config):
     skip_disabled(barebox_config, "CONFIG_CMD_BTHREAD")
 
@@ -18,7 +21,7 @@ def test_bthread(barebox, barebox_config):
     assert not stale_spawners(barebox)
 
     switches = int(barebox.run_check("bthread -c")[0].split()[0])
-    yields   = int(barebox.run_check("bthread -t")[0].split()[0])
+    yields = int(barebox.run_check("bthread -t")[0].split()[0])
 
     assert switches > 1000
     assert yields > 1000
test/py/test_dm.py +9 -4
index dc4e05cc77c8..397d4573c3e9 100644
@@ -1,14 +1,16 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import re
 import pytest
+import os
+import subprocess
+import shutil
 from .helper import skip_disabled
 
-import os, subprocess, shutil
 
 def pad128k(f):
     f.write(b"\0" * 128 * 1024)
 
+
 @pytest.fixture(scope="module")
 def dm_testdata(testfs):
     path = os.path.join(testfs, "dm")
@@ -29,7 +31,8 @@ def dm_testdata(testfs):
     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(["mcopy", "-i", "good.fat", "latin", "english", "::"],
+                       check=True)
 
         subprocess.run([
             "veritysetup", "format",
@@ -41,7 +44,8 @@ def dm_testdata(testfs):
         shutil.rmtree(path)
         pytest.skip(f"missing dependency: {e}")
 
-    with open("good.fat", "rb") as f: data = f.read()
+    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",
@@ -54,6 +58,7 @@ def dm_testdata(testfs):
 
     shutil.rmtree(path)
 
+
 @pytest.fixture(autouse=True)
 def reset_pwd(barebox):
     yield
test/py/test_fit.py +10 -5
index 7a0b9f2762d5..2a51ac1bc075 100644
@@ -41,14 +41,19 @@ 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)
+        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) ])
+        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}")
 
test/py/test_network.py +15 -7
index 28efcc02e44d..e76aad1cc6f6 100644
@@ -1,6 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
 import pytest
 
-from labgrid import driver,Environment
+from labgrid import driver
 import socket
 import threading
 import re
@@ -10,12 +12,14 @@ from .helper import skip_disabled
 # Setting the port to zero causes bind to choose a random ephermal port
 TFTP_TEST_PORT = 0
 
+
 def get_source_addr(destination_ip, destination_port):
     udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     udp_socket.connect((destination_ip, destination_port))
     source_ip, _ = udp_socket.getsockname()
     return source_ip
 
+
 def tftp_setup_socket(listen_addr, listen_port=0):
     udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     udp_socket.bind((listen_addr, listen_port))
@@ -34,6 +38,7 @@ def tftp_expect_notfound(filename, udp_socket):
     udp_socket.close()
     assert data == messages[0]
 
+
 def tftp_conversation(barebox, barebox_interface, guestaddr):
 
     listen_addr = "127.0.0.1"
@@ -44,8 +49,8 @@ def tftp_conversation(barebox, barebox_interface, guestaddr):
 
     barebox.run_check("ping $eth0.serverip", timeout=2)
 
-    tftp_socket=tftp_setup_socket(listen_addr, TFTP_TEST_PORT)
-    tftp_port_used=tftp_socket.getsockname()[1]
+    tftp_socket = tftp_setup_socket(listen_addr, TFTP_TEST_PORT)
+    tftp_port_used = tftp_socket.getsockname()[1]
 
     tftp_thread = threading.Thread(
         target=tftp_expect_notfound,
@@ -56,7 +61,8 @@ def tftp_conversation(barebox, barebox_interface, guestaddr):
     tftp_thread.start()
 
     try:
-        stdout, _, returncode = barebox.run(f"tftp -P {tftp_port_used} a", timeout=3)
+        stdout, _, returncode = barebox.run(f"tftp -P {tftp_port_used} a",
+                                            timeout=3)
         assert returncode != 0
     finally:
         # terminate a timed-out tftp
@@ -69,8 +75,9 @@ def test_barebox_network(barebox, barebox_config, env):
     skip_disabled(barebox_config, "CONFIG_CMD_TFTP")
 
     # on DUTs without network feature, this is expected to fail
-    # set xfail_strict=True to enforce specifying the network feature if available
-    if not 'network' in env.get_target_features():
+    # set xfail_strict=True to enforce specifying the network feature
+    # if available
+    if 'network' not in env.get_target_features():
         pytest.xfail("network feature not specified")
 
     stdout = barebox.run_check("ifup -a")
@@ -94,7 +101,8 @@ def test_barebox_network(barebox, barebox_config, env):
         assert ifaddr != "0.0.0.0"
         assert ifaddr == barebox.run_check(f"echo ${ifname}.ipaddr")[0]
 
-        # Attempt a conversation with the DUT, which needs to succeed only on one interface
+        # Attempt a conversation with the DUT, which needs to succeed
+        # only on one interface
         success = False
 
         try:
test/py/test_nvmem.py +73 -43

413 lines not on this page · raw message

test/py/test_shell.py +7 -2
index 1af7d597a175..3d2d85d80594 100644
@@ -1,5 +1,6 @@
-import pytest
-from .helper import *
+# SPDX-License-Identifier: GPL-2.0-only
+
+from .helper import skip_disabled
 
 
 def test_barebox_true(barebox, barebox_config):
@@ -8,12 +9,14 @@ def test_barebox_true(barebox, barebox_config):
     _, _, returncode = barebox.run('true')
     assert returncode == 0
 
+
 def test_barebox_false(barebox, barebox_config):
     skip_disabled(barebox_config, "CONFIG_CMD_FALSE")
 
     _, _, returncode = barebox.run('false')
     assert returncode == 1
 
+
 def test_barebox_md5sum(barebox, barebox_config):
     skip_disabled(barebox_config, "CONFIG_CMD_MD5SUM", "CONFIG_CMD_ECHO")
 
@@ -21,6 +24,7 @@ def test_barebox_md5sum(barebox, barebox_config):
     out = barebox.run_check("md5sum md5")
     assert out == ["d8e8fca2dc0f896fd7cb4cb0031ba249  md5"]
 
+
 def test_barebox_version(barebox, barebox_config):
     skip_disabled(barebox_config, "CONFIG_CMD_VERSION")
 
@@ -28,6 +32,7 @@ def test_barebox_version(barebox, barebox_config):
     assert 'barebox' in stdout[1]
     assert returncode == 0
 
+
 def test_barebox_no_err(barebox, barebox_config):
     skip_disabled(barebox_config, "CONFIG_CMD_DMESG")
 
test/py/test_tlv.py +2 -0
index c1bb9a17b4a8..be579629b22f 100644
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
 import sys
 import os
 import re
test/strategy.py +5 -3
index 11406b97f5f1..bf4dacfefd81 100644
@@ -1,11 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
 import enum
 
 import attr
 import pytest
 import subprocess
-import os
-import shutil
-import sys
 import re
 
 from labgrid import target_factory, step, driver
@@ -17,6 +16,7 @@ if match is None or int(match.group(1)) < 25:
     pytest.exit(f"Labgrid has version v{labgrid_version()}, "
                 f"but barebox test suite requires at least v25.")
 
+
 class Status(enum.Enum):
     unknown = 0
     off = 1
@@ -25,6 +25,7 @@ class Status(enum.Enum):
     qemu_interactive = 4
     qemu_dump_dtb = 5
 
+
 @target_factory.reg_driver
 @attr.s(eq=False)
 class BareboxTestStrategy(Strategy):
@@ -107,6 +108,7 @@ class BareboxTestStrategy(Strategy):
             self.console.boot_args = ""
         self.console.boot_args += " ".join(args)
 
+
 def quote_cmd(cmd):
     quoted = map(lambda s : s if s.find(" ") == -1 else "'" + s + "'", cmd)
     return " ".join(quoted)
Signature · 1 line
2.47.3
Applied
#3 lore raw
In reply to Ahmad Fatoum
Quoted 4 lines · Ahmad Fatoum

The test depends on veritysetup being available, so skip it if this is not the case.

Applied, thanks!

[1/3] test: py: dm: skip test if veritysetup command is disabled

      https://git.pengutronix.de/cgit/barebox/commit/?id=4566090bd769 (link may not be stable)

[2/3] test: py: network: skip test if tftp command is missing
https://git.pengutronix.de/cgit/barebox/commit/?id=a8d6203e8a23 (link may not be stable)
[3/3] test: py: fix pycodestyle warnings
https://git.pengutronix.de/cgit/barebox/commit/?id=1e3961ae1ddb (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>
#4 lore raw
Quoted 8 lines · Sascha Hauer
Quoted 4 lines · Ahmad Fatoum

The test depends on veritysetup being available, so skip it if this is not the case.

Applied, thanks!

Thanks, were they already pushed?

Quoted 9 lines

[1/3] test: py: dm: skip test if veritysetup command is disabled

      https://git.pengutronix.de/cgit/barebox/commit/?id=4566090bd769 (link may not be stable)

[2/3] test: py: network: skip test if tftp command is missing
https://git.pengutronix.de/cgit/barebox/commit/?id=a8d6203e8a23 (link may not be stable)
[3/3] test: py: fix pycodestyle warnings
https://git.pengutronix.de/cgit/barebox/commit/?id=1e3961ae1ddb (link may not be stable)

Best regards,

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#5 lore raw
Quoted 11 lines · Ahmad Fatoum
Quoted 8 lines · Sascha Hauer
Quoted 4 lines · Ahmad Fatoum

The test depends on veritysetup being available, so skip it if this is not the case.

Applied, thanks!

Thanks, were they already pushed?

They are now.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |