Skip to content

Commit 6d006a4

Browse files
Fabian Frederickummakynes
authored andcommitted
selftests: netfilter: add checktool function
avoid repeating the same test for different toolcheck Signed-off-by: Fabian Frederick <fabf@skynet.be> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 59136aa commit 6d006a4

1 file changed

Lines changed: 11 additions & 22 deletions

File tree

‎tools/testing/selftests/netfilter/nft_flowtable.sh‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,18 @@ ns2out=""
2121

2222
log_netns=$(sysctl -n net.netfilter.nf_log_all_netns)
2323

24-
nft --version > /dev/null 2>&1
25-
if [ $? -ne 0 ];then
26-
echo "SKIP: Could not run test without nft tool"
27-
exit $ksft_skip
28-
fi
29-
30-
ip -Version > /dev/null 2>&1
31-
if [ $? -ne 0 ];then
32-
echo "SKIP: Could not run test without ip tool"
33-
exit $ksft_skip
34-
fi
35-
36-
which nc > /dev/null 2>&1
37-
if [ $? -ne 0 ];then
38-
echo "SKIP: Could not run test without nc (netcat)"
39-
exit $ksft_skip
40-
fi
24+
checktool (){
25+
$1 > /dev/null 2>&1
26+
if [ $? -ne 0 ];then
27+
echo "SKIP: Could not $2"
28+
exit $ksft_skip
29+
fi
30+
}
4131

42-
ip netns add nsr1
43-
if [ $? -ne 0 ];then
44-
echo "SKIP: Could not create net namespace"
45-
exit $ksft_skip
46-
fi
32+
checktool "nft --version" "run test without nft tool"
33+
checktool "ip -Version" "run test without ip tool"
34+
checktool "which nc" "run test without nc (netcat)"
35+
checktool "ip netns add nsr1" "create net namespace"
4736

4837
ip netns add ns1
4938
ip netns add ns2

0 commit comments

Comments
 (0)