selftests: drv-net: wait for carrier
Subsystems (3)
Jakub Kicinski
maintainerPATCH v2 1/1 selftests: drv-net: wait for carrier
On fast machines the tests run in quick succession so even when tests clean up after themselves the carrier may need some time to come back.
Specifically in NIPA when ping.py runs right after netpoll_basic.py the first ping command fails.
Since the context manager callbacks are now common NetDrvEpEnv gets an ip link up call as well.
---
v2:
- add an empty __del__
v1: https://lore.kernel.org/[email protected]
--- .../selftests/drivers/net/lib/py/__init__.py | 2 +- .../selftests/drivers/net/lib/py/env.py | 41 +++++++++---------- tools/testing/selftests/net/lib/py/utils.py | 18 ++++++++ 3 files changed, 39 insertions(+), 22 deletions(-)
tools/testing/selftests/drivers/net/lib/py/__init__.py +1 -1
@@ -15,7 +15,7 @@ KSFT_DIR = (Path(__file__).parent / "../../../..").resolve() NlError, RtnlFamily, DevlinkFamily from net.lib.py import CmdExitFailure from net.lib.py import bkg, cmd, bpftool, bpftrace, defer, ethtool, \ - fd_read_timeout, ip, rand_port, tool, wait_port_listen + fd_read_timeout, ip, rand_port, tool, wait_port_listen, wait_file from net.lib.py import fd_read_timeout from net.lib.py import KsftSkipEx, KsftFailEx, KsftXfailEx from net.lib.py import ksft_disruptive, ksft_exit, ksft_pr, ksft_run, \
tools/testing/selftests/drivers/net/lib/py/env.py +20 -21
71 lines not on this page · raw message
tools/testing/selftests/net/lib/py/utils.py +18 -0
@@ -249,3 +249,21 @@ global_defer_queue = [] if time.monotonic() > end: raise Exception("Waiting for port listen timed out") time.sleep(sleep) + + +def wait_file(fname, test_fn, sleep=0.005, deadline=5, encoding='utf-8'): + """ + Wait for file contents on the local system to satisfy a condition. + test_fn() should take one argument (file contents) and return whether + condition is met. + """ + end = time.monotonic() + deadline + + with open(fname, "r", encoding=encoding) as fp: + while True: + if test_fn(fp.read()): + break + fp.seek(0) + if time.monotonic() > end: + raise TimeoutError("Wait for file contents failed", fname) + time.sleep(sleep)
Signature · 1 line
2.50.1
Quoted 20 lines · Jakub Kicinski
On fast machines the tests run in quick succession so even when tests clean up after themselves the carrier may need some time to come back.
Specifically in NIPA when
ping.pyruns right afternetpoll_basic.pythe first ping command fails.Since the context manager callbacks are now common NetDrvEpEnv gets an ip link up call as well.
Signed-off-by Jakub Kicinski <[email protected]>---
v2:
- add an empty__del__
v1: https://lore.kernel.org/[email protected]
Quoted 5 lines
--- .../selftests/drivers/net/lib/py/__init__.py | 2 +- .../selftests/drivers/net/lib/py/env.py | 41 +++++++++---------- tools/testing/selftests/net/lib/py/utils.py | 18 ++++++++ 3 files changed, 39 insertions(+), 22 deletions(-)
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Tue, 12 Aug 2025 07:20:54 -0700 you wrote:
On fast machines the tests run in quick succession so even when tests clean up after themselves the carrier may need some time to come back.
Specifically in NIPA when
ping.pyruns right afternetpoll_basic.pythe first ping command fails.[...]
Here is the summary with links:
- [net-next,v2] selftests: drv-net: wait for carrier
https://git.kernel.org/netdev/net-next/c/f09fc24dd9a5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html