Debian Codegraph @

tests/ts/lsns/netnsid-for-persistent-namespaces

raw symbols SCIP
1 #!/bin/bash
2 #
3 # Copyright (C) 2025 Masatake YAMATO <[email protected]>
4 #
5 # This file is part of util-linux.
6 #
7 # This file is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This file is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17
18 TS_TOPDIR="${0%/*}/../.."
19 TS_DESC="NETNSID of a namespace where no process belongs to"
20
21 . "$TS_TOPDIR"/functions.sh
22 ts_init "$*"
23
24 ts_check_test_command "$TS_CMD_LSNS"
25 ts_check_prog "ip"
26 ts_skip_nonroot
27
28 ts_skip_netns
29 ts_cd "$TS_OUTDIR"
30
31 NETNSID=$$
32 NS=LSNS-TEST-NETNSID-NS-FOR-PN-"$NETNSID"
33 NULL=/dev/null
34 LOG=/dev/null #/root/foo.log
35
36 function cleanup {
37 ip netns delete "$NS" 2> $NULL || :
38 }
39
40 echo "==Cleanup" >> $LOG
41 cleanup
42
43 echo "==Netns ADD" >> $LOG
44 if ip netns add "$NS" &&
45 ip netns set "$NS" "$NETNSID"; then
46 echo "===Netns EXEC" >> $LOG
47 else
48 cleanup
49 ts_skip "failed to initialize"
50 fi
51
52 function netnsid_subtest {
53 local column=$1
54 local eval_func=eval_"$column"
55 local O
56 local rc
57
58 ts_init_subtest "$1"
59 O=$($TS_CMD_LSNS --raw --noheadings --filter "NETNSID == '$NETNSID'" --output $1)
60 rc=$?
61 if [[ $rc -eq 0 ]]; then
62 if "$eval_func" "$O"; then
63 echo OK
64 else
65 echo ERROR
66 echo "$O"
67 fi
68 else
69 echo ERROR $rc
70 fi > "$TS_OUTPUT" 2>&1
71 ts_finalize_subtest
72 }
73
74 function eval_NETNSID {
75 [[ "$1" == "$NETNSID" ]]
76 }
77
78 function eval_TYPE {
79 [[ "$1" == "net" ]]
80 }
81
82 function eval_NSFS {
83 [[ ${1##*/} == "$NS" ]]
84 }
85
86 netnsid_subtest NETNSID
87 netnsid_subtest TYPE
88 netnsid_subtest NSFS
89
90 cleanup
91 ts_finalize
92