From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
linux-kselftest@vger.kernel.org, willemdebruijn.kernel@gmail.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 3/4] selftests: drv-net: reimplement the config parser
Date: Wed, 24 Apr 2024 15:14:43 -0700 [thread overview]
Message-ID: <20240424221444.4194069-4-kuba@kernel.org> (raw)
In-Reply-To: <20240424221444.4194069-1-kuba@kernel.org>
The shell lexer is not helping much, do very basic parsing
manually.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
.../selftests/drivers/net/lib/py/env.py | 26 ++++++++++---------
1 file changed, 14 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index a3db1bb1afeb..a6a5a5f9c6db 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -1,7 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
import os
-import shlex
from pathlib import Path
from lib.py import KsftSkipEx
from lib.py import cmd, ip
@@ -16,17 +15,20 @@ from .remote import Remote
if not (src_dir / "net.config").exists():
return env
- lexer = shlex.shlex(open((src_dir / "net.config").as_posix(), 'r').read())
- k = None
- for token in lexer:
- if k is None:
- k = token
- env[k] = ""
- elif token == "=":
- pass
- else:
- env[k] = token
- k = None
+ with open((src_dir / "net.config").as_posix(), 'r') as fp:
+ for line in fp.readlines():
+ full_file = line
+ # Strip comments
+ pos = line.find("#")
+ if pos >= 0:
+ line = line[:pos]
+ line = line.strip()
+ if not line:
+ continue
+ pos = line.find("=")
+ if pos <= 0:
+ raise Exception("Can't parse configuration line:", full_file)
+ env[line[:pos]] = line[pos+1:]
return env
--
2.44.0
next prev parent reply other threads:[~2024-04-24 22:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-24 22:14 [PATCH net-next 0/4] selftests: drv-net: round some sharp edges Jakub Kicinski
2024-04-24 22:14 ` [PATCH net-next 1/4] selftests: drv-net: force pseudo-terminal allocation in ssh Jakub Kicinski
2024-04-24 22:56 ` Jakub Kicinski
2024-04-24 22:14 ` [PATCH net-next 2/4] selftests: drv-net: extend the README with more info and example Jakub Kicinski
2024-04-24 22:14 ` Jakub Kicinski [this message]
2024-04-25 1:43 ` [PATCH net-next 3/4] selftests: drv-net: reimplement the config parser Willem de Bruijn
2024-04-24 22:14 ` [PATCH net-next 4/4] selftests: drv-net: validate the environment Jakub Kicinski
2024-04-25 1:43 ` Willem de Bruijn
2024-04-25 1:45 ` [PATCH net-next 0/4] selftests: drv-net: round some sharp edges Willem de Bruijn
2024-04-25 22:22 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240424221444.4194069-4-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=willemdebruijn.kernel@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.