diff mbox series

[net-next,4/4] selftests: drv-net: validate the environment

Message ID 20240424221444.4194069-5-kuba@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series selftests: drv-net: round some sharp edges | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 1 maintainers not CCed: shuah@kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 32 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-25--09-00 (tests: 995)

Commit Message

Jakub Kicinski April 24, 2024, 10:14 p.m. UTC
Throw a slightly more helpful exception when env variables
are partially populated. Prior to this change we'd get
a dictionary key exception somewhere later on.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 .../selftests/drivers/net/lib/py/env.py       | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Willem de Bruijn April 25, 2024, 1:43 a.m. UTC | #1
Jakub Kicinski wrote:
> Throw a slightly more helpful exception when env variables
> are partially populated. Prior to this change we'd get
> a dictionary key exception somewhere later on.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
>  .../selftests/drivers/net/lib/py/env.py       | 20 +++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
> index a6a5a5f9c6db..fda4967503de 100644
> --- a/tools/testing/selftests/drivers/net/lib/py/env.py
> +++ b/tools/testing/selftests/drivers/net/lib/py/env.py
> @@ -88,6 +88,7 @@ from .remote import Remote
>          self._ns_peer = None
>  
>          if "NETIF" in self.env:
> +            self._check_env()
>              self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0]
>  
>              self.v4 = self.env.get("LOCAL_V4")
> @@ -143,6 +144,25 @@ from .remote import Remote
>          ip(f"-6 addr add dev {self._ns_peer.nsims[0].ifname} {self.nsim_v6_pfx}2/64 nodad", ns=self._netns)
>          ip(f"   link set dev {self._ns_peer.nsims[0].ifname} up", ns=self._netns)
>  
> +    def _check_env(self):
> +        vars_needed = [
> +            ["LOCAL_V4", "LOCAL_V6"],
> +            ["REMOTE_V4", "REMOTE_V6"],
> +            ["REMOTE_TYPE"],
> +            ["REMOTE_ARGS"]
> +        ]
> +        missing = []
> +
> +        for choice in vars_needed:
> +            for entry in choice:
> +                if entry in self.env:
> +                    break
> +            else:
> +                missing.append(choice)
> +        if missing:
> +            raise Exception("Invalid environment, missing configuration:", missing,
> +                            "Please see tools/testing/selftests/drivers/net/README.rst")
> +

I suppose this could still reach the exception if a file contains
LOCAL_V4 and REMOTE_V6 or vice versa.

But this is best effort anyway.
diff mbox series

Patch

diff --git a/tools/testing/selftests/drivers/net/lib/py/env.py b/tools/testing/selftests/drivers/net/lib/py/env.py
index a6a5a5f9c6db..fda4967503de 100644
--- a/tools/testing/selftests/drivers/net/lib/py/env.py
+++ b/tools/testing/selftests/drivers/net/lib/py/env.py
@@ -88,6 +88,7 @@  from .remote import Remote
         self._ns_peer = None
 
         if "NETIF" in self.env:
+            self._check_env()
             self.dev = ip("link show dev " + self.env['NETIF'], json=True)[0]
 
             self.v4 = self.env.get("LOCAL_V4")
@@ -143,6 +144,25 @@  from .remote import Remote
         ip(f"-6 addr add dev {self._ns_peer.nsims[0].ifname} {self.nsim_v6_pfx}2/64 nodad", ns=self._netns)
         ip(f"   link set dev {self._ns_peer.nsims[0].ifname} up", ns=self._netns)
 
+    def _check_env(self):
+        vars_needed = [
+            ["LOCAL_V4", "LOCAL_V6"],
+            ["REMOTE_V4", "REMOTE_V6"],
+            ["REMOTE_TYPE"],
+            ["REMOTE_ARGS"]
+        ]
+        missing = []
+
+        for choice in vars_needed:
+            for entry in choice:
+                if entry in self.env:
+                    break
+            else:
+                missing.append(choice)
+        if missing:
+            raise Exception("Invalid environment, missing configuration:", missing,
+                            "Please see tools/testing/selftests/drivers/net/README.rst")
+
     def __enter__(self):
         return self