mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Looks like more and more tests want to iterate over IP version, run the same test over ipv4 and ipv6. The current naming of members in the env class makes it a bit awkward, we have separate members for ipv4 and ipv6 parameters. Store the parameters inside dicts, so that tests can easily index them with ip version. Reviewed-by: Willem de Bruijn <willemb@google.com> Link: https://patch.msgid.link/20250218225426.77726-4-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
51 lines
1.4 KiB
Python
Executable file
51 lines
1.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
from lib.py import ksft_run, ksft_exit
|
|
from lib.py import ksft_eq
|
|
from lib.py import NetDrvEpEnv
|
|
from lib.py import bkg, cmd, wait_port_listen, rand_port
|
|
|
|
|
|
def test_v4(cfg) -> None:
|
|
cfg.require_ipver("4")
|
|
|
|
cmd("ping -c 1 -W0.5 " + cfg.remote_addr_v["4"])
|
|
cmd("ping -c 1 -W0.5 " + cfg.addr_v["4"], host=cfg.remote)
|
|
|
|
|
|
def test_v6(cfg) -> None:
|
|
cfg.require_ipver("6")
|
|
|
|
cmd("ping -c 1 -W0.5 " + cfg.remote_addr_v["6"])
|
|
cmd("ping -c 1 -W0.5 " + cfg.addr_v["6"], host=cfg.remote)
|
|
|
|
|
|
def test_tcp(cfg) -> None:
|
|
cfg.require_cmd("socat", remote=True)
|
|
|
|
port = rand_port()
|
|
listen_cmd = f"socat -{cfg.addr_ipver} -t 2 -u TCP-LISTEN:{port},reuseport STDOUT"
|
|
|
|
with bkg(listen_cmd, exit_wait=True) as nc:
|
|
wait_port_listen(port)
|
|
|
|
cmd(f"echo ping | socat -t 2 -u STDIN TCP:{cfg.baddr}:{port}",
|
|
shell=True, host=cfg.remote)
|
|
ksft_eq(nc.stdout.strip(), "ping")
|
|
|
|
with bkg(listen_cmd, host=cfg.remote, exit_wait=True) as nc:
|
|
wait_port_listen(port, host=cfg.remote)
|
|
|
|
cmd(f"echo ping | socat -t 2 -u STDIN TCP:{cfg.remote_baddr}:{port}", shell=True)
|
|
ksft_eq(nc.stdout.strip(), "ping")
|
|
|
|
|
|
def main() -> None:
|
|
with NetDrvEpEnv(__file__) as cfg:
|
|
ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, ))
|
|
ksft_exit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|