1 #!/usr/bin/env python3 1 #!/usr/bin/env python3 2 # SPDX-License-Identifier: GPL-2.0 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 from lib.py import ksft_run, ksft_exit 4 from lib.py import ksft_run, ksft_exit 5 from lib.py import ksft_eq 5 from lib.py import ksft_eq 6 from lib.py import NetDrvEpEnv 6 from lib.py import NetDrvEpEnv 7 from lib.py import bkg, cmd, wait_port_listen, 7 from lib.py import bkg, cmd, wait_port_listen, rand_port 8 8 9 9 10 def test_v4(cfg) -> None: 10 def test_v4(cfg) -> None: 11 cfg.require_v4() 11 cfg.require_v4() 12 12 13 cmd(f"ping -c 1 -W0.5 {cfg.remote_v4}") 13 cmd(f"ping -c 1 -W0.5 {cfg.remote_v4}") 14 cmd(f"ping -c 1 -W0.5 {cfg.v4}", host=cfg. 14 cmd(f"ping -c 1 -W0.5 {cfg.v4}", host=cfg.remote) 15 15 16 16 17 def test_v6(cfg) -> None: 17 def test_v6(cfg) -> None: 18 cfg.require_v6() 18 cfg.require_v6() 19 19 20 cmd(f"ping -c 1 -W0.5 {cfg.remote_v6}") 20 cmd(f"ping -c 1 -W0.5 {cfg.remote_v6}") 21 cmd(f"ping -c 1 -W0.5 {cfg.v6}", host=cfg. 21 cmd(f"ping -c 1 -W0.5 {cfg.v6}", host=cfg.remote) 22 22 23 23 24 def test_tcp(cfg) -> None: 24 def test_tcp(cfg) -> None: 25 cfg.require_cmd("socat", remote=True) 25 cfg.require_cmd("socat", remote=True) 26 26 27 port = rand_port() 27 port = rand_port() 28 listen_cmd = f"socat -{cfg.addr_ipver} -t 28 listen_cmd = f"socat -{cfg.addr_ipver} -t 2 -u TCP-LISTEN:{port},reuseport STDOUT" 29 29 30 with bkg(listen_cmd, exit_wait=True) as nc 30 with bkg(listen_cmd, exit_wait=True) as nc: 31 wait_port_listen(port) 31 wait_port_listen(port) 32 32 33 cmd(f"echo ping | socat -t 2 -u STDIN 33 cmd(f"echo ping | socat -t 2 -u STDIN TCP:{cfg.baddr}:{port}", 34 shell=True, host=cfg.remote) 34 shell=True, host=cfg.remote) 35 ksft_eq(nc.stdout.strip(), "ping") 35 ksft_eq(nc.stdout.strip(), "ping") 36 36 37 with bkg(listen_cmd, host=cfg.remote, exit 37 with bkg(listen_cmd, host=cfg.remote, exit_wait=True) as nc: 38 wait_port_listen(port, host=cfg.remote 38 wait_port_listen(port, host=cfg.remote) 39 39 40 cmd(f"echo ping | socat -t 2 -u STDIN 40 cmd(f"echo ping | socat -t 2 -u STDIN TCP:{cfg.remote_baddr}:{port}", shell=True) 41 ksft_eq(nc.stdout.strip(), "ping") 41 ksft_eq(nc.stdout.strip(), "ping") 42 42 43 43 44 def main() -> None: 44 def main() -> None: 45 with NetDrvEpEnv(__file__) as cfg: 45 with NetDrvEpEnv(__file__) as cfg: 46 ksft_run(globs=globals(), case_pfx={"t 46 ksft_run(globs=globals(), case_pfx={"test_"}, args=(cfg, )) 47 ksft_exit() 47 ksft_exit() 48 48 49 49 50 if __name__ == "__main__": 50 if __name__ == "__main__": 51 main() 51 main()
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.