tests: check for HAVE_LINUX_NET_NAMESPACE_H

* use one cleanup function
* check if kernel headers support net namespace
* enable netnsid test

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2017-11-28 13:19:20 +01:00
parent 68433f1e31
commit 57358f50f3
2 changed files with 27 additions and 25 deletions

29
tests/ts/lsns/netnsid Normal file → Executable file
View File

@ -16,27 +16,34 @@
#
TS_TOPDIR="${0%/*}/../.."
TS_DESC="compare NETNSID reported by lsns and that by ip-link"
TS_DESC="NETNSID compare to ip-link"
. $TS_TOPDIR/functions.sh
ts_init "$*"
ts_check_test_command "$TS_CMD_LSNS"
ts_check_prog "ip"
ts_check_prog "dd"
ts_check_prog "mkfifo"
ts_check_prog "sed"
ts_skip_nonroot
grep -q '#define HAVE_LINUX_NET_NAMESPACE_H' ${top_builddir}/config.h || ts_skip "no netns support"
ts_cd "$TS_OUTDIR"
vetha=lsns-vetha
vethb=lsns-vethb
NS=UTIL-LINUX-LSNS-TEST-NS
FIFO=$TS_OUTDIR/UTIL-LINUX-LSNS-TEST-FIFO
NS=LSNS-TEST-NETNSID-NS
FIFO=$TS_OUTDIR/FIFO-NETNSID
NULL=/dev/null
ip netns delete $NS 2> $NULL || :
ip link delete $vetha 2> $NULL || :
function cleanup {
ip link delete $vetha 2> $NULL || :
ip netns delete $NS 2> $NULL || :
rm -f $FIFO
}
rm -f $FIFO
cleanup
mkfifo $FIFO
if ip netns add $NS &&
@ -44,6 +51,9 @@ if ip netns add $NS &&
ip link set $vethb netns $NS; then
ip netns exec $NS dd if=$FIFO bs=1 count=2 of=$NULL 2> $NULL &
PID=$!
else
cleanup
ts_skip "failed to initialize"
fi
{
dd if=/dev/zero bs=1 count=1 2> $NULL
@ -55,11 +65,8 @@ fi
dd if=/dev/zero bs=1 count=1 2> $NULL
} > $FIFO
rm $FIFO
ip link delete $vetha
ip netns delete $NS
test "$IP_ID" = "$LSNS_ID"
echo $? >> $TS_OUTPUT
cleanup
ts_finalize

View File

@ -16,7 +16,7 @@
#
TS_TOPDIR="${0%/*}/../.."
TS_DESC="list NSFS for namespaces created by ip-netns-add"
TS_DESC="NSFS for ip-netns-add"
. $TS_TOPDIR/functions.sh
ts_init "$*"
@ -30,6 +30,9 @@ ts_check_prog "ip"
ts_check_prog "dd"
ts_check_prog "touch"
ts_check_prog "mkfifo"
ts_check_prog "sed"
grep -q '#define HAVE_LINUX_NET_NAMESPACE_H' ${top_builddir}/config.h || ts_skip "no netns support"
ts_cd "$TS_OUTDIR"
@ -37,24 +40,17 @@ NAME1=ABC
NAME2=XYZ
PATH1=/run/netns/$NAME1
PATH2=$TS_OUTDIR/$NAME2
FIFO=$TS_OUTDIR/FIFO
FIFO=$TS_OUTDIR/FIFO-NSFS
NULL=/dev/null
function cleanup {
rm $FIFO
$TS_CMD_UMOUNT $PATH2
rm -f $FIFO
$TS_CMD_UMOUNT $PATH2 2> /dev/null || :
rm -f $PATH2
ip netns delete $NAME1
ip netns delete $NAME1 2> /dev/null || :
}
set -x
ip netns delete $NAME1 2> /dev/null || :
$TS_CMD_UMOUNT $PATH2 2>/dev/null || :
rm -f $PATH2
rm -f $FIFO
cleanup
mkfifo $FIFO
if ip netns add $NAME1 &&
@ -78,7 +74,6 @@ test "$NSFS_NAMES_MLINES" = "$PATH1
$PATH2" && test "$NSFS_NAMES_1LINE" = "$PATH1,$PATH2"
RESULT=$?
echo $RESULT >> $TS_OUTPUT
if [ $RESULT -ne 0 ]; then