diff options
author | Jakub Kicinski <kuba@kernel.org> | 2025-08-12 07:20:54 -0700 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2025-08-14 17:44:46 -0700 |
commit | f09fc24dd9a5ec989dfdde7090624924ede6ddc7 (patch) | |
tree | b0ecbe79157688965b1c5b9434dd6a2cb08add75 /tools/testing/selftests/net/lib/py/utils.py | |
parent | df979273bd716a93ca9ffa8f84aeb205c9bf2ab6 (diff) |
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.
Reviewed-by: Joe Damato <joe@dama.to>
Link: https://patch.msgid.link/20250812142054.750282-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/testing/selftests/net/lib/py/utils.py')
-rw-r--r-- | tools/testing/selftests/net/lib/py/utils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py index 4ac9249c85ab..b188cac49738 100644 --- a/tools/testing/selftests/net/lib/py/utils.py +++ b/tools/testing/selftests/net/lib/py/utils.py @@ -252,3 +252,21 @@ def wait_port_listen(port, proto="tcp", ns=None, host=None, sleep=0.005, deadlin 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) |