From patchwork Fri Apr 12 23:37:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 13628373 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDF48152DEE; Fri, 12 Apr 2024 23:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712965038; cv=none; b=S3XQTG+CQNTApDarzDW4ARNg05o5BZ35SAYAvuNbncThaD7ZM/VzprxSBTgmArhqJV+lX7rNxs027NFrWusoVD8AqniCMFtcGuHzMrpWDZVZkuFRX2Oy2yXD/hJCgrNZqNfHV+oHxXvkyao4aoV3ebGzjtSQItqYdq+31a1ZEVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712965038; c=relaxed/simple; bh=U5+EVNFryCl6AbqRDTDECqncYZkgnEzOhvv/pOI/KNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FgbryvUY7NEKbDGd9jmQP6SxHKVFaWotj1GSuYzSgOuQsmZhQIiQB0pu61Exo3l+ZdB+1qPMnpz1979tP3rGlUzIRz3UWM6HsDgOPrLkmROtD3qOBJ7DIIDqu5vJyRZX6oFEYeYAPt6W5Hej+HqY/q2kx48VQ3gj7iOshnZXODs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lDxTuecH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lDxTuecH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 402D5C4AF0A; Fri, 12 Apr 2024 23:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712965037; bh=U5+EVNFryCl6AbqRDTDECqncYZkgnEzOhvv/pOI/KNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lDxTuecHdLnPQQPQxy6caTBndoq3qkWOnkzSotuUackQPnRK/EVFzMe/i1czRpgla GnxNBlK8CJ9fqZODNbAoCIk4As6fu5MtgwpKZndKfjNVS75pK0h0BK19oTNYyTvLL/ v6fi+Tw/LqSwJF8mW/efxMi9T1u8tjkgtCn+me36gJdNH+mbEcz3PlZfsPZaqZ9Lyp RSXaOmB9mTT+C/dVEre2c9pdx4fZW7/Vix30iKh702KDqrafg0xtXYLSn0GAVRd3ds YEbeUMjm3BLr/vUFHe9XHX7iI/+zO0hU6UBQNBbTR/qUfJQOUK3777CcPg7YIxBP2y lIKYf9Aqr6+Ag== From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, shuah@kernel.org, petrm@nvidia.com, linux-kselftest@vger.kernel.org, willemb@google.com, Jakub Kicinski Subject: [PATCH net-next 3/5] selftests: drv-net: factor out parsing of the env Date: Fri, 12 Apr 2024 16:37:03 -0700 Message-ID: <20240412233705.1066444-4-kuba@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240412233705.1066444-1-kuba@kernel.org> References: <20240412233705.1066444-1-kuba@kernel.org> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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. Signed-off-by: Jakub Kicinski --- .../selftests/drivers/net/lib/py/env.py | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py index e1abe9491daf..a081e168f3db 100644 --- a/tools/testing/selftests/drivers/net/lib/py/env.py +++ b/tools/testing/selftests/drivers/net/lib/py/env.py @@ -6,12 +6,36 @@ from pathlib import Path from lib.py import ip from lib.py import NetdevSimDev + +def _load_env_file(src_path): + env = os.environ.copy() + + src_dir = Path(src_path).parent.resolve() + 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 + return env + + class NetDrvEnv: + """ + Class for a single NIC / host env, with no remote end + """ def __init__(self, src_path): self._ns = None - self.env = os.environ.copy() - self._load_env_file(src_path) + self.env = _load_env_file(src_path) if 'NETIF' in self.env: self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0] @@ -34,19 +58,4 @@ from lib.py import NetdevSimDev self._ns.remove() self._ns = None - def _load_env_file(self, src_path): - src_dir = Path(src_path).parent.resolve() - if not (src_dir / "net.config").exists(): - return - lexer = shlex.shlex(open((src_dir / "net.config").as_posix(), 'r').read()) - k = None - for token in lexer: - if k is None: - k = token - self.env[k] = "" - elif token == "=": - pass - else: - self.env[k] = token - k = None