summaryrefslogtreecommitdiffstats
path: root/tests/ts/lsns
diff options
context:
space:
mode:
authorMasatake YAMATO2017-11-24 11:31:05 +0100
committerKarel Zak2017-11-27 15:54:54 +0100
commit5d075a7828f6be1bd4d186b4cdc51aaffd9d59a6 (patch)
treee418e611d0696d08275b3a27ff1e0932ebb9a65f /tests/ts/lsns
parentlsns: disable netnsid column by default (diff)
downloadkernel-qcow2-util-linux-5d075a7828f6be1bd4d186b4cdc51aaffd9d59a6.tar.gz
kernel-qcow2-util-linux-5d075a7828f6be1bd4d186b4cdc51aaffd9d59a6.tar.xz
kernel-qcow2-util-linux-5d075a7828f6be1bd4d186b4cdc51aaffd9d59a6.zip
lsns: add a case for testing netnsid column
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Diffstat (limited to 'tests/ts/lsns')
-rw-r--r--tests/ts/lsns/netnsid65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/ts/lsns/netnsid b/tests/ts/lsns/netnsid
new file mode 100644
index 000000000..ad93dd49c
--- /dev/null
+++ b/tests/ts/lsns/netnsid
@@ -0,0 +1,65 @@
+#!/bin/bash
+#
+# Copyright (C) 2017 Masatake YAMATO <yamato@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="compare NETNSID reported by lsns and that by ip-link"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSNS"
+
+ts_skip_nonroot
+
+ts_cd "$TS_OUTDIR"
+
+vetha=lsns-vetha
+vethb=lsns-vethb
+NS=UTIL-LINUX-LSNS-TEST-NS
+FIFO=$TS_OUTDIR/UTIL-LINUX-LSNS-TEST-FIFO
+NULL=/dev/null
+
+ip netns delete $NS 2> $NULL || :
+ip link delete $vetha 2> $NULL || :
+
+rm -f $FIFO
+mkfifo $FIFO
+
+if ip netns add $NS &&
+ ip link add name $vetha type veth peer name $vethb &&
+ ip link set $vethb netns $NS; then
+ ip netns exec $NS dd if=$FIFO bs=1 count=2 of=$NULL 2> $NULL &
+ PID=$!
+fi
+{
+ dd if=/dev/zero bs=1 count=1 2> $NULL
+ {
+ ip -o link show dev $vetha > $NULL
+ IP_ID=$(ip -o link show dev $vetha | sed -ne 's/.* *link-netnsid *\([0-9]*\)/\1/p')
+ LSNS_ID=$($TS_CMD_LSNS -n -o NETNSID --type net --task $PID | { read VAL; echo $VAL; } )
+ }
+ 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
+
+ts_finalize