Debian Codegraph @

tests/tools.sh.in

raw
1 # Copyright (C) 2012-2026 Free Software Foundation, Inc.
2 #
3 # This file is part of GNU Inetutils.
4 #
5 # GNU Inetutils is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or (at
8 # your option) any later version.
9 #
10 # GNU Inetutils is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see `http://www.gnu.org/licenses/'.
17
18 # Helpers and supporting functionality for test scripts.
19
20 GREP=${GREP:-@GREP@}
21 EGREP=${EGREP:-"@EGREP@"}
22 FGREP=${FGREP:-"@FGREP@"}
23 SED=${SED:-@SED@}
24 DD=${DD:-@DD@}
25 MKTEMP=${MKTEMP:-@MKTEMP@}
26 NETSTAT=${NETSTAT:-@NETSTAT@}
27 TARGET=${TARGET:-@TARGET@}
28 TARGET6=${TARGET6:-@TARGET6@}
29 TEST_IPV4=${TEST_IPV4:-@TEST_IPV4@}
30 TEST_IPV6=${TEST_IPV6:-@TEST_IPV6@}
31
32 srcdir=${srcdir:-.}
33
34 RUNTIME_IPV4=${RUNTIME_IPV4:-"./runtime-ipv6$EXEEXT -4"}
35 RUNTIME_IPV6=${RUNTIME_IPV6:-"./runtime-ipv6$EXEEXT -6"}
36
37 # Avoid IPv4 when not functional.
38 if test "$TEST_IPV4" = "auto"; then
39 $RUNTIME_IPV4 || { TEST_IPV4="no"
40 echo "Suppressing non-supported IPv4."; }
41 fi
42
43 # Avoid IPv6 when not functional.
44 if test "$TEST_IPV6" = "auto"; then
45 $RUNTIME_IPV6 || { TEST_IPV6="no"
46 echo "Suppressing non-supported IPv6."; }
47 fi
48
49 # Variables for signalling presence of a utility:
50 #
51 # need_toolname Set to `false' if `toolname' is missing,
52 # otherwise set to `:'.
53 #
54 # exit_no_toolname Function to exit with a message related to `toolname'.
55 #
56 # Suggested idiom:
57 #
58 # $need_toolname || exit_no_toolname
59
60 # `grep', `sed', and `uname' are used already by autoconfiguration,
61 # so their existence is not tested for.
62
63 need_id=false
64 if id >/dev/null 2>&1; then
65 need_id=:
66 fi
67
68 exit_no_id () {
69 echo >&2 'No available id(1). Skipping test.'
70 exit 77
71 }
72
73 need_dd=false
74 if eval "$DD if=/dev/zero bs=5 count=1 >/dev/null 2>&1"; then
75 need_dd=:
76 fi
77
78 exit_no_dd () {
79 echo >&2 'No available dd(1). Skipping test.'
80 exit 77
81 }
82
83 need_mktemp=false
84 if eval "$MKTEMP -u temp.XXXXXX >/dev/null 2>&1"; then
85 need_mktemp=:
86 fi
87
88 exit_no_mktemp () {
89 echo >&2 'No available mktemp(1). Skipping test.'
90 exit 77
91 }
92
93 need_netstat=false
94 if eval "$NETSTAT -n >/dev/null 2>&1"; then
95 need_netstat=:
96 fi
97
98 exit_no_netstat () {
99 echo >&2 'No available netstat(1), used for diagnosis. Skipping test.'
100 exit 77
101 }
102
103 # Some Solaris variants provide id(1) lacking `-u' switch.
104 # Work around this by some computation.
105
106 func_id_uid () {
107 id $1 2>&1 | $SED -n 's,.*uid=\([0-9]*\).*,\1,p'
108 }
109
110 func_id_user () {
111 id $1 2>&1 | $SED -n 's,.*uid=[0-9]*(\([^)]*\).*,\1,p'
112 }