selftests: forwarding: lib: Move require_command to net, generalize
authorPetr Machata <petrm@nvidia.com>
Fri, 14 Feb 2025 16:18:22 +0000 (17:18 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 18 Feb 2025 12:06:43 +0000 (13:06 +0100)
This helper could be useful to more than just forwarding tests.
Move it upstairs and port over to log_test_skip().

Split the function into two parts: the bit that actually checks and
reports skip, which is in a new function check_command(). And a bit
that exits the test script if the check fails. This allows users
consistent checking behavior while giving an option to bail out from
a single test without bailing out of the whole script.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
tools/testing/selftests/net/forwarding/lib.sh
tools/testing/selftests/net/lib.sh

index 8de80acf249ea055797faf3118ded9aea5b87abe..508f3c700d71988b03cceda9119e8158064c25b5 100644 (file)
@@ -291,16 +291,6 @@ if [[ "$CHECK_TC" = "yes" ]]; then
        check_tc_version
 fi
 
-require_command()
-{
-       local cmd=$1; shift
-
-       if [[ ! -x "$(command -v "$cmd")" ]]; then
-               echo "SKIP: $cmd not installed"
-               exit $ksft_skip
-       fi
-}
-
 # IPv6 support was added in v3.0
 check_mtools_version()
 {
index 0bd9a038a1f0e0421ca03cb201cad9f758115acb..975be4fdbcdbeabd7e5607a7c6441e7c4fa4c721 100644 (file)
@@ -450,6 +450,25 @@ kill_process()
        { kill $pid && wait $pid; } 2>/dev/null
 }
 
+check_command()
+{
+       local cmd=$1; shift
+
+       if [[ ! -x "$(command -v "$cmd")" ]]; then
+               log_test_skip "$cmd not installed"
+               return $EXIT_STATUS
+       fi
+}
+
+require_command()
+{
+       local cmd=$1; shift
+
+       if ! check_command "$cmd"; then
+               exit $EXIT_STATUS
+       fi
+}
+
 ip_link_add()
 {
        local name=$1; shift