Skip to content

Commit 5433892

Browse files
committed
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>
1 parent 1a20a9a commit 5433892

File tree

1 file changed

+27
-18
lines changed
  • tools/testing/selftests/drivers/net/lib/py

1 file changed

+27
-18
lines changed

tools/testing/selftests/drivers/net/lib/py/env.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,36 @@
66
from lib.py import ip
77
from lib.py import NetdevSimDev
88

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+
931
class NetDrvEnv:
32+
"""
33+
Class for a single NIC / host env, with no remote end
34+
"""
1035
def __init__(self, src_path):
1136
self._ns = None
1237

13-
self.env = os.environ.copy()
14-
self._load_env_file(src_path)
38+
self.env = _load_env_file(src_path)
1539

1640
if 'NETIF' in self.env:
1741
self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0]
@@ -34,19 +58,4 @@ def __del__(self):
3458
self._ns.remove()
3559
self._ns = None
3660

37-
def _load_env_file(self, src_path):
38-
src_dir = Path(src_path).parent.resolve()
39-
if not (src_dir / "net.config").exists():
40-
return
41-
42-
lexer = shlex.shlex(open((src_dir / "net.config").as_posix(), 'r').read())
43-
k = None
44-
for token in lexer:
45-
if k is None:
46-
k = token
47-
self.env[k] = ""
48-
elif token == "=":
49-
pass
50-
else:
51-
self.env[k] = token
52-
k = None
61+

0 commit comments

Comments
 (0)