Skip to contentSkip to conversation

test: fit: power cycle after tests in booted barebox

PATCH Applied Ahmad Fatoum 2 participants 2 messages Oct 21, 2025 – Oct 23, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test: fit: power cycle after tests in booted barebox

Networking in QEMU may run into issues in the chainloaded barebox. Power cycle the virtual machine after the end of the FIT tests to avoid this interference.

---
 test/py/test_fit.py | 34 ++++++++++++++++------------------
 test/strategy.py    | 15 +++++++++++++++
 2 files changed, 31 insertions(+), 18 deletions(-)
test/py/test_fit.py +16 -18
index 2a51ac1bc075..97fdac0c79d9 100644
@@ -58,7 +58,7 @@ def fit_testdata(barebox_config, testfs):
         pytest.skip(f"Skip dm tests due to missing dependency: {e}")
 
 
-def test_fit(barebox, target, testfs, fit_testdata):
+def test_fit(barebox, strategy, testfs, fit_testdata):
     _, _, returncode = barebox.run(f"ls {fit_name('gzipped')}")
     if returncode != 0:
         pytest.xfail("skipping test due to missing FIT image")
@@ -77,25 +77,23 @@ def test_fit(barebox, target, testfs, fit_testdata):
     barebox.run_check("global linux.bootargs.testarg=barebox.chainloaded")
 
     boottarget = generate_bootscript(barebox, fit_name('gzipped'))
-    barebox.boot(boottarget)
-    target.deactivate(barebox)
-    target.activate(barebox)
 
-    assert of_get_property(barebox, "/chosen/barebox-version") == f'"{ver}"', \
-           "/chosen/barebox-version suggests we did not chainload"
+    with strategy.boot(boottarget):
+        assert of_get_property(barebox, "/chosen/barebox-version") == f'"{ver}"', \
+               "/chosen/barebox-version suggests we did not chainload"
 
-    assert of_get_property(barebox, "/chosen/barebox,boot-count") == '<0x1>', \
-           "/chosen/barebox,boot-count suggests we got bultin DT"
+        assert of_get_property(barebox, "/chosen/barebox,boot-count") == '<0x1>', \
+               "/chosen/barebox,boot-count suggests we got bultin DT"
 
-    # Check that command line arguments were fixed up
-    bootargs = of_get_property(barebox, "/chosen/bootargs")
-    assert "barebox.chainloaded" in bootargs
+        # Check that command line arguments were fixed up
+        bootargs = of_get_property(barebox, "/chosen/bootargs")
+        assert "barebox.chainloaded" in bootargs
 
-    initrd_start = of_get_property(barebox, "/chosen/linux,initrd-start")
-    initrd_end = of_get_property(barebox, "/chosen/linux,initrd-end")
+        initrd_start = of_get_property(barebox, "/chosen/linux,initrd-start")
+        initrd_end = of_get_property(barebox, "/chosen/linux,initrd-end")
 
-    addr_regex = r"<(0x[0-9a-f]{1,8} ?)+>"
-    assert re.search(addr_regex, initrd_start), \
-        f"initrd start {initrd_start} malformed"
-    assert re.search(addr_regex, initrd_end), \
-        f"initrd end {initrd_end} malformed"
+        addr_regex = r"<(0x[0-9a-f]{1,8} ?)+>"
+        assert re.search(addr_regex, initrd_start), \
+            f"initrd start {initrd_start} malformed"
+        assert re.search(addr_regex, initrd_end), \
+            f"initrd end {initrd_end} malformed"
test/strategy.py +15 -0
index bf4dacfefd81..fc65895daece 100644
@@ -6,6 +6,7 @@ import attr
 import pytest
 import subprocess
 import re
+from contextlib import contextmanager
 
 from labgrid import target_factory, step, driver
 from labgrid.strategy import Strategy, StrategyError
@@ -71,6 +72,20 @@ class BareboxTestStrategy(Strategy):
             )
         self.status = status
 
+    @contextmanager
+    def boot(self, boottarget=None):
+        self.transition(Status.barebox)
+
+        try:
+            self.barebox.boot(boottarget)
+            self.target.deactivate(self.barebox)
+            self.target.activate(self.barebox)
+            yield
+        finally:
+            self.target.deactivate(self.barebox)
+            self.power.cycle()
+            self.target.activate(self.barebox)
+
     def force(self, state):
         self.transition(Status.off)  # pylint: disable=missing-kwoa
 
Signature · 1 line
2.47.3