mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] test: py: add test with actual TFTP server
@ 2026-01-19 11:35 Ahmad Fatoum
  0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2026-01-19 11:35 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Expose testfs via QEMU's built-in TFTP server and make sure we can
communicate with it.

This will be especially useful later to test network booting in QEMU.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 conftest.py             |  1 +
 test/py/test_network.py | 26 +++++++++++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/conftest.py b/conftest.py
index ef6ca221a5db..ce5cdaf0dffa 100644
--- a/conftest.py
+++ b/conftest.py
@@ -229,6 +229,7 @@ def strategy(request, target, pytestconfig):  # noqa: max-complexity=30
             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)
+            strategy.append_qemu_args("-nic", f"user,id=net0,tftp={testfs_path}")
 
     for i, fs in enumerate(pytestconfig.option.qemu_fs):
         if virtio:
diff --git a/test/py/test_network.py b/test/py/test_network.py
index e76aad1cc6f6..8994782b7652 100644
--- a/test/py/test_network.py
+++ b/test/py/test_network.py
@@ -6,6 +6,7 @@ from labgrid import driver
 import socket
 import threading
 import re
+from pathlib import Path
 import warnings
 from .helper import skip_disabled
 
@@ -71,15 +72,21 @@ def tftp_conversation(barebox, barebox_interface, guestaddr):
         barebox.run_check("ifdown eth0")
 
 
-def test_barebox_network(barebox, barebox_config, env):
-    skip_disabled(barebox_config, "CONFIG_CMD_TFTP")
+@pytest.fixture(scope="module")
+def testfs_hostname(testfs):
+    with open(Path(testfs) / "hostname", "w", encoding="utf-8") as f:
+        f.write("QEMU\n")
 
+
+@pytest.fixture(scope="function")
+def barebox_interfaces(barebox, env, testfs):
     # on DUTs without network feature, this is expected to fail
     # 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")
 
+    barebox.run_check("ifdown -a")
     stdout = barebox.run_check("ifup -a")
 
     interfaces = []
@@ -94,7 +101,13 @@ def test_barebox_network(barebox, barebox_config, env):
 
     assert interfaces, "Network testing is only possible with at least one DHCP interface"
 
-    for iface in interfaces:
+    return interfaces
+
+
+def test_barebox_network_mock_tftp(barebox, barebox_config, barebox_interfaces):
+    skip_disabled(barebox_config, "CONFIG_CMD_TFTP")
+
+    for iface in barebox_interfaces:
         ifname = iface[0]
         ifaddr = iface[1]
 
@@ -115,3 +128,10 @@ def test_barebox_network(barebox, barebox_config, env):
         if not success:
             pytest.fail("Could not converse with DUT on any of the found DHCP interfaces!")
 
+
+def test_barebox_network_real_tftp(barebox, barebox_config,
+                                   testfs_hostname, barebox_interfaces):
+    skip_disabled(barebox_config, "CONFIG_CMD_TFTP")
+
+    barebox.run_check(f"tftp hostname", timeout=3)
+    assert barebox.run_check(f"cat hostname") == ["QEMU"]
-- 
2.47.3




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-01-19 11:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-19 11:35 [PATCH] test: py: add test with actual TFTP server Ahmad Fatoum

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