diff mbox series

[net-next,02/10] selftests: forwarding: lib.sh: Validate NETIFS

Message ID 4a7602678782a1f526bdcc895de437bebc96a695.1712940759.git.petrm@nvidia.com (mailing list archive)
State Accepted
Commit 2291752fae3d2d773f2d29c159d383138411d06f
Delegated to: Netdev Maintainers
Headers show
Series selftests: Assortment of fixes | 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: liuhangbin@gmail.com
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 net selftest script(s) already in Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 108 exceeds 80 columns
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-15--15-00 (tests: 961)

Commit Message

Petr Machata April 12, 2024, 5:03 p.m. UTC
The variable should contain at least NUM_NETIFS interfaces, stored
as keys named "p$i", for i in `seq $NUM_NETIFS`.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Benjamin Poirier <bpoirier@nvidia.com>
---
 tools/testing/selftests/net/forwarding/lib.sh | 22 ++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

Comments

Hangbin Liu April 15, 2024, 7:47 a.m. UTC | #1
On Fri, Apr 12, 2024 at 07:03:05PM +0200, Petr Machata wrote:
> The variable should contain at least NUM_NETIFS interfaces, stored
> as keys named "p$i", for i in `seq $NUM_NETIFS`.
> 
> Signed-off-by: Petr Machata <petrm@nvidia.com>
> Reviewed-by: Benjamin Poirier <bpoirier@nvidia.com>
> ---
>  tools/testing/selftests/net/forwarding/lib.sh | 22 ++++++++++++++-----
>  1 file changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
> index 658e4e7bf4b9..3cbbc2fd4d7d 100644
> --- a/tools/testing/selftests/net/forwarding/lib.sh
> +++ b/tools/testing/selftests/net/forwarding/lib.sh
> @@ -273,11 +273,6 @@ if [[ "$REQUIRE_MTOOLS" = "yes" ]]; then
>  	require_command mreceive
>  fi
>  
> -if [[ ! -v NUM_NETIFS ]]; then
> -	echo "SKIP: importer does not define \"NUM_NETIFS\""
> -	exit $ksft_skip
> -fi
> -
>  ##############################################################################
>  # Command line options handling
>  
> @@ -296,6 +291,23 @@ done
>  ##############################################################################
>  # Network interfaces configuration
>  
> +if [[ ! -v NUM_NETIFS ]]; then
> +	echo "SKIP: importer does not define \"NUM_NETIFS\""
> +	exit $ksft_skip
> +fi
> +
> +if (( NUM_NETIFS > ${#NETIFS[@]} )); then
> +	echo "SKIP: Importer requires $NUM_NETIFS NETIFS, but only ${#NETIFS[@]} are defined (${NETIFS[@]})"
> +	exit $ksft_skip
> +fi
> +
> +for i in $(seq ${#NETIFS[@]}); do
> +	if [[ ! ${NETIFS[p$i]} ]]; then
> +		echo "SKIP: NETIFS[p$i] not given"
> +		exit $ksft_skip
> +	fi
> +done
> +
>  create_netif_veth()
>  {
>  	local i
> -- 
> 2.43.0
> 

Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index 658e4e7bf4b9..3cbbc2fd4d7d 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -273,11 +273,6 @@  if [[ "$REQUIRE_MTOOLS" = "yes" ]]; then
 	require_command mreceive
 fi
 
-if [[ ! -v NUM_NETIFS ]]; then
-	echo "SKIP: importer does not define \"NUM_NETIFS\""
-	exit $ksft_skip
-fi
-
 ##############################################################################
 # Command line options handling
 
@@ -296,6 +291,23 @@  done
 ##############################################################################
 # Network interfaces configuration
 
+if [[ ! -v NUM_NETIFS ]]; then
+	echo "SKIP: importer does not define \"NUM_NETIFS\""
+	exit $ksft_skip
+fi
+
+if (( NUM_NETIFS > ${#NETIFS[@]} )); then
+	echo "SKIP: Importer requires $NUM_NETIFS NETIFS, but only ${#NETIFS[@]} are defined (${NETIFS[@]})"
+	exit $ksft_skip
+fi
+
+for i in $(seq ${#NETIFS[@]}); do
+	if [[ ! ${NETIFS[p$i]} ]]; then
+		echo "SKIP: NETIFS[p$i] not given"
+		exit $ksft_skip
+	fi
+done
+
 create_netif_veth()
 {
 	local i