Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: drv-net: factor out parsing of the env

The tests with a remote end will use a different class,
for clarity, but will also need to parse the env.
So factor parsing the env out to a function.

Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://lore.kernel.org/r/20240420025237.3309296-3-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+26 -17
+26 -17
tools/testing/selftests/drivers/net/lib/py/env.py
··· 6 6 from lib.py import ip 7 7 from lib.py import NetdevSimDev 8 8 9 + 10 + def _load_env_file(src_path): 11 + env = os.environ.copy() 12 + 13 + src_dir = Path(src_path).parent.resolve() 14 + if not (src_dir / "net.config").exists(): 15 + return env 16 + 17 + lexer = shlex.shlex(open((src_dir / "net.config").as_posix(), 'r').read()) 18 + k = None 19 + for token in lexer: 20 + if k is None: 21 + k = token 22 + env[k] = "" 23 + elif token == "=": 24 + pass 25 + else: 26 + env[k] = token 27 + k = None 28 + return env 29 + 30 + 9 31 class NetDrvEnv: 32 + """ 33 + Class for a single NIC / host env, with no remote end 34 + """ 10 35 def __init__(self, src_path): 11 36 self._ns = None 12 37 13 - self.env = os.environ.copy() 14 - self._load_env_file(src_path) 38 + self.env = _load_env_file(src_path) 15 39 16 40 if 'NETIF' in self.env: 17 41 self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0] ··· 58 34 self._ns.remove() 59 35 self._ns = None 60 36 61 - def _load_env_file(self, src_path): 62 - src_dir = Path(src_path).parent.resolve() 63 - if not (src_dir / "net.config").exists(): 64 - return 65 37 66 - lexer = shlex.shlex(open((src_dir / "net.config").as_posix(), 'r').read()) 67 - k = None 68 - for token in lexer: 69 - if k is None: 70 - k = token 71 - self.env[k] = "" 72 - elif token == "=": 73 - pass 74 - else: 75 - self.env[k] = token 76 - k = None