Debian Codegraph @

tests/ts/lsfd/mkfds-unix-dgram

raw
1 #!/bin/bash
2 #
3 # Copyright (C) 2022 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 TS_TOPDIR="${0%/*}/../.."
18 TS_DESC="UNIX dgram sockets"
19
20 . "$TS_TOPDIR"/functions.sh
21 ts_init "$*"
22
23 . "$TS_SELF/lsfd-functions.bash"
24 ts_check_test_command "$TS_CMD_LSFD"
25 ts_check_test_command "$TS_HELPER_MKFDS"
26
27 ts_cd "$TS_OUTDIR"
28
29 PID=
30 FDS=3
31 FDC=4
32 EXPR='(TYPE == "UNIX") and ((FD == 3) or (FD == 4))'
33
34 make_state_connected()
35 {
36 # The first one is for rewriting NAME column.
37 # The second one is for rewriting STATE column.
38 lsfd_make_state_connected | sed -e 's/unconnected/connected/'
39 }
40
41 ts_init_subtest "non-abstract"
42 {
43 coproc MKFDS { "$TS_HELPER_MKFDS" unix-dgram $FDS $FDC \
44 path=test_mkfds-unix-dgram ; }
45 if read -r -u "${MKFDS[0]}" PID; then
46 ${TS_CMD_LSFD} -n \
47 -r \
48 -o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \
49 -p "${PID}" -Q "${EXPR}" | make_state_connected
50 echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]}
51
52 echo DONE >&"${MKFDS[1]}"
53 fi
54 wait "${MKFDS_PID}"
55 } > "$TS_OUTPUT" 2>&1
56 ts_finalize_subtest
57
58 ts_init_subtest "abstract"
59 {
60 coproc MKFDS { "$TS_HELPER_MKFDS" unix-dgram $FDS $FDC \
61 path=test_mkfds-unix-dgram \
62 abstract=true ; }
63 if read -r -u "${MKFDS[0]}" PID; then
64 ${TS_CMD_LSFD} -n \
65 -r \
66 -o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \
67 -p "${PID}" -Q "${EXPR}" | make_state_connected
68 echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': $?
69
70 echo DONE >&"${MKFDS[1]}"
71 fi
72 wait "${MKFDS_PID}"
73 } > "$TS_OUTPUT" 2>&1
74 ts_finalize_subtest
75
76 ts_init_subtest "ENDPOINTS-column"
77 if ! lsfd_check_sockdiag --subtest unix; then
78 # lsfd_check_sockdiag calls ts_skip_subtest or ts_failed_subtest.
79 :
80 elif ts_is_in_docker; then
81 ts_skip_subtest "unsupported in docker environment"
82 else
83 {
84 coproc MKFDS { "$TS_HELPER_MKFDS" unix-dgram $FDS $FDC \
85 path=test_mkfds-unix-dgram \
86 abstract=true ; }
87
88 if read -r -u "${MKFDS[0]}" PID; then
89 endpoint_c=$(${TS_CMD_LSFD} -n -r -Q "PID == ${PID} && FD == $FDC" -o ENDPOINTS)
90 echo endpoint_c: $?
91
92 test "$endpoint_c" = "${PID},test_mkfds,${FDS}rw"
93 echo "endpoint_c == PID,test_mkfs,${FDS}rw:" $?
94
95 endpoint_s=$(${TS_CMD_LSFD} -n -r -Q "PID == ${PID} && FD == $FDS" -o ENDPOINTS)
96 echo endpoint_s: $?
97
98 test "$endpoint_s" = "${PID},test_mkfds,${FDC}rw"
99 echo "endpoint_s == PID,test_mkfs,${FDC}rw:" $?
100
101 echo DONE >&"${MKFDS[1]}"
102 fi
103 wait "${MKFDS_PID}"
104 } > "$TS_OUTPUT" 2>&1
105 ts_finalize_subtest
106 fi
107
108 ts_init_subtest "UNIX.IPEEER-column"
109 if ! lsfd_check_sockdiag --subtest unix; then
110 # lsfd_check_sockdiag calls ts_skip_subtest or ts_failed_subtest.
111 :
112 elif ts_is_in_docker; then
113 ts_skip_subtest "unsupported in docker environment"
114 else
115 {
116 coproc MKFDS { "$TS_HELPER_MKFDS" unix-dgram $FDS $FDC \
117 path=test_mkfds-unix-dgram \
118 abstract=true ; }
119
120 if read -r -u "${MKFDS[0]}" PID; then
121 inode_s=$(${TS_CMD_LSFD} -n -r -p "${PID}" -Q "FD == $FDS" -o INODE)
122 echo inode_s: $?
123 inode_c=$(${TS_CMD_LSFD} -n -r -p "${PID}" -Q "FD == $FDC" -o INODE)
124 echo inode_c: $?
125
126 ipeer_s=$(${TS_CMD_LSFD} -n -r -p "${PID}" -Q "FD == $FDS" -o UNIX.IPEER)
127 echo ipeer_s: $?
128
129 ipeer_c=$(${TS_CMD_LSFD} -n -r -p "${PID}" -Q "FD == $FDC" -o UNIX.IPEER)
130 echo ipeer_c: $?
131
132 test "$ipeer_s" = 0
133 echo "ipeer_s == 0:" $?
134
135 test "$ipeer_c" = "$inode_s"
136 echo "ipeer_s == inode_s:" $?
137
138 echo DONE >&"${MKFDS[1]}"
139 fi
140 wait "${MKFDS_PID}"
141 } > "$TS_OUTPUT" 2>&1
142 ts_finalize_subtest
143 fi
144
145 ts_finalize