From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] test: py: add test with actual TFTP server
Date: Mon, 19 Jan 2026 12:35:16 +0100 [thread overview]
Message-ID: <20260119113517.1611633-1-a.fatoum@pengutronix.de> (raw)
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
reply other threads:[~2026-01-19 11:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260119113517.1611633-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox