]> git.ipfire.org Git - thirdparty/util-linux.git/blob - tests/ts/lsfd/lsfd-functions.bash
43c02ad7045fe0ac5d0f6d8eb13b55bcf85cf7e8
[thirdparty/util-linux.git] / tests / ts / lsfd / lsfd-functions.bash
1 #!/bin/bash
2 #
3 # Copyright (C) 2021 Masatake YAMATO <yamato@redhat.com>
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 # The exit-status used in a test target.
19 readonly EPERM=18
20 readonly ENOPROTOOPT=19
21 readonly EPROTONOSUPPORT=20
22 readonly EACCESS=21
23
24 function lsfd_wait_for_pausing {
25 ts_check_prog "sleep"
26
27 local PID=$1
28 until [[ $(ps --no-headers -ostat "${PID}") =~ S.* ]]; do
29 sleep 1
30 done
31 }
32
33 function lsfd_compare_dev {
34 local LSFD=$1
35 local FILE=$2
36 local EXPR=$3
37
38 ts_check_prog "grep"
39 ts_check_prog "expr"
40 ts_check_prog "stat"
41
42 local DEV=$("${LSFD}" --raw -n -o DEV -Q "${EXPR}")
43 echo 'DEV[RUN]:' $?
44 local MAJ=${DEV%:*}
45 local MIN=${DEV#*:}
46 local DEVNUM=$(( ( MAJ << 8 ) + MIN ))
47 local STAT_DEVNUM=$(stat -c "%d" "$FILE")
48 echo 'STAT[RUN]:' $?
49 if [ "${DEVNUM}" == "${STAT_DEVNUM}" ]; then
50 echo 'DEVNUM[STR]:' 0
51 else
52 echo 'DEVNUM[STR]:' 1
53 # Print more information for debugging
54 echo 'DEV:' "${DEV}"
55 echo 'MAJ:MIN' "${MAJ}:${MIN}"
56 echo 'DEVNUM:' "${DEVNUM}"
57 echo 'STAT_DEVNUM:' "${STAT_DEVNUM}"
58 fi
59 }
60
61 lsfd_strip_type_stream()
62 {
63 # lsfd changes the output of NAME column for a unix stream socket
64 # whether the kernel reports it is a "UNIX-STREAM" socket or a
65 # "UNIX" socket. For "UNIX", lsfd appends "type=stream" to the
66 # NAME column. Let's delete the appended string before comparing.
67 sed -e 's/ type=stream//'
68 }
69
70 lsfd_make_state_connected()
71 {
72 # Newer kernels report the states of unix dgram sockets created by
73 # sockerpair(2) are "connected" via /proc/net/unix though Older
74 # kernels report "unconnected".
75 #
76 # Newer kernels report the states of unix dgram sockets already
77 # connect(2)'ed are "connected", too.
78 #
79 # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=83301b5367a98c17ec0d76c7bc0ccdc3c7e7ad6d
80 #
81 # This rewriting adjusts the output of lsfd running on older kernels
82 # to that on newer kernels.
83 sed -e 's/state=unconnected/state=connected/'
84 }
85
86 function lsfd_check_mkfds_factory
87 {
88 local FACTORY=$1
89
90 ts_check_test_command "$TS_HELPER_MKFDS"
91 if ! "$TS_HELPER_MKFDS" --is-available "$FACTORY"; then
92 ts_skip "test_mkfds has no factory for $FACTORY"
93 fi
94 }