selftests: netfilter: place checktool helper in lib.sh
authorFlorian Westphal <fw@strlen.de>
Thu, 11 Apr 2024 23:36:14 +0000 (01:36 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 13 Apr 2024 00:51:26 +0000 (17:51 -0700)
... so it doesn't have to be repeated everywhere.

Signed-off-by: Florian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20240411233624.8129-10-fw@strlen.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/netfilter/br_netfilter.sh
tools/testing/selftests/net/netfilter/conntrack_ipip_mtu.sh
tools/testing/selftests/net/netfilter/lib.sh

index ea3afd6d401f2ff939b50b4602adbcf7f0fdc38f..1084faf88f0b51f99095849ccf034584db59df4c 100755 (executable)
 
 source lib.sh
 
-nft --version > /dev/null 2>&1
-if [ $? -ne 0 ];then
-       echo "SKIP: Could not run test without nft tool"
-       exit $ksft_skip
-fi
+checktool "nft --version" "run test without nft tool"
 
 cleanup() {
        cleanup_all_ns
index f87ca4c59d3b69ec20a135374a15cdf51eda6a02..ac0dff0f80d772e1afb6d373f2cd225506dae6b5 100755 (executable)
@@ -24,13 +24,6 @@ source lib.sh
 
 rx=$(mktemp)
 
-checktool (){
-       if ! $1 > /dev/null 2>&1; then
-               echo "SKIP: Could not $2"
-               exit $ksft_skip
-       fi
-}
-
 checktool "iptables --version" "run test without iptables"
 checktool "socat -h" "run test without socat"
 
index eb109eb527dbd160928a8636571cde765d73ffe5..bedd35298e15bc7cbc1755bb4216a3bda8c18e9a 100644 (file)
@@ -1,3 +1,10 @@
 net_netfilter_dir=$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")
 
 source "$net_netfilter_dir/../lib.sh"
+
+checktool (){
+       if ! $1 > /dev/null 2>&1; then
+               echo "SKIP: Could not $2"
+               exit $ksft_skip
+       fi
+}