-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'selftests-drv-net-support-testing-with-a-remote-system'
Jakub Kicinski says: ==================== selftests: drv-net: support testing with a remote system Implement support for tests which require access to a remote system / endpoint which can generate traffic. This series concludes the "groundwork" for upstream driver tests. I wanted to support the three models which came up in discussions: - SW testing with netdevsim - "local" testing with two ports on the same system in a loopback - "remote" testing via SSH so there is a tiny bit of an abstraction which wraps up how "remote" commands are executed. Otherwise hopefully there's nothing surprising. I'm only adding a ping test. I had a bigger one written but I was worried we'll get into discussing the details of the test itself and how I chose to hack up netdevsim, instead of the test infra... So that test will be a follow up :) v4: https://lore.kernel.org/all/20240418233844.2762396-1-kuba@kernel.org v3: https://lore.kernel.org/all/20240417231146.2435572-1-kuba@kernel.org v2: https://lore.kernel.org/all/20240416004556.1618804-1-kuba@kernel.org v1: https://lore.kernel.org/all/20240412233705.1066444-1-kuba@kernel.org ==================== Link: https://lore.kernel.org/r/20240420025237.3309296-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
- Loading branch information
Showing
12 changed files
with
417 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
sys.exit(4) | ||
|
||
from .env import * | ||
from .remote import Remote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
import os | ||
import importlib | ||
|
||
_modules = {} | ||
|
||
def Remote(kind, args, src_path): | ||
global _modules | ||
|
||
if kind not in _modules: | ||
_modules[kind] = importlib.import_module("..remote_" + kind, __name__) | ||
|
||
dir_path = os.path.abspath(src_path + "/../") | ||
return getattr(_modules[kind], "Remote")(args, dir_path) |
21 changes: 21 additions & 0 deletions
21
tools/testing/selftests/drivers/net/lib/py/remote_netns.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
import os | ||
import subprocess | ||
|
||
from lib.py import cmd | ||
|
||
|
||
class Remote: | ||
def __init__(self, name, dir_path): | ||
self.name = name | ||
self.dir_path = dir_path | ||
|
||
def cmd(self, comm): | ||
return subprocess.Popen(["ip", "netns", "exec", self.name, "bash", "-c", comm], | ||
stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
||
def deploy(self, what): | ||
if os.path.isabs(what): | ||
return what | ||
return os.path.abspath(self.dir_path + "/" + what) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
import os | ||
import string | ||
import subprocess | ||
import random | ||
|
||
from lib.py import cmd | ||
|
||
|
||
class Remote: | ||
def __init__(self, name, dir_path): | ||
self.name = name | ||
self.dir_path = dir_path | ||
self._tmpdir = None | ||
|
||
def __del__(self): | ||
if self._tmpdir: | ||
cmd("rm -rf " + self._tmpdir, host=self) | ||
self._tmpdir = None | ||
|
||
def cmd(self, comm): | ||
return subprocess.Popen(["ssh", "-q", self.name, comm], | ||
stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
||
def _mktmp(self): | ||
return ''.join(random.choice(string.ascii_lowercase) for _ in range(8)) | ||
|
||
def deploy(self, what): | ||
if not self._tmpdir: | ||
self._tmpdir = "/tmp/" + self._mktmp() | ||
cmd("mkdir " + self._tmpdir, host=self) | ||
file_name = self._tmpdir + "/" + self._mktmp() + os.path.basename(what) | ||
|
||
if not os.path.isabs(what): | ||
what = os.path.abspath(self.dir_path + "/" + what) | ||
|
||
cmd(f"scp {what} {self.name}:{file_name}") | ||
return file_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/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_v4() | ||
|
||
cmd(f"ping -c 1 -W0.5 {cfg.remote_v4}") | ||
cmd(f"ping -c 1 -W0.5 {cfg.v4}", host=cfg.remote) | ||
|
||
|
||
def test_v6(cfg) -> None: | ||
cfg.require_v6() | ||
|
||
cmd(f"ping -c 1 -W0.5 {cfg.remote_v6}") | ||
cmd(f"ping -c 1 -W0.5 {cfg.v6}", 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.