2 # SPDX-License-Identifier: GPL-2.0
4 from lib.py import ksft_run, ksft_exit
5 from lib.py import ksft_eq
6 from lib.py import NetDrvEpEnv
7 from lib.py import bkg, cmd, wait_port_listen, rand_port
10 def test_v4(cfg) -> None:
13 cmd(f"ping -c 1 -W0.5 {cfg.remote_v4}")
14 cmd(f"ping -c 1 -W0.5 {cfg.v4}", host=cfg.remote)
17 def test_v6(cfg) -> None:
20 cmd(f"ping -c 1 -W0.5 {cfg.remote_v6}")
21 cmd(f"ping -c 1 -W0.5 {cfg.v6}", host=cfg.remote)
24 def test_tcp(cfg) -> None:
25 cfg.require_cmd("socat", remote=True)
28 listen_cmd = f"socat -{cfg.addr_ipver} -t 2 -u TCP-LISTEN:{port},reuseport STDOUT"
30 with bkg(listen_cmd, exit_wait=True) as nc:
31 wait_port_listen(port)
33 cmd(f"echo ping | socat -t 2 -u STDIN TCP:{cfg.baddr}:{port}",
34 shell=True, host=cfg.remote)
35 ksft_eq(nc.stdout.strip(), "ping")
37 with bkg(listen_cmd, host=cfg.remote, exit_wait=True) as nc:
38 wait_port_listen(port, host=cfg.remote)
40 cmd(f"echo ping | socat -t 2 -u STDIN TCP:{cfg.remote_baddr}:{port}", shell=True)
41 ksft_eq(nc.stdout.strip(), "ping")
45 with NetDrvEpEnv(__file__) as cfg:
46 ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, ))
50 if __name__ == "__main__":