Debian Codegraph @

testsuite

raw
1 #!/bin/bash
2
3 # Run integration tests (on the installed packages).
4 #
5 # (C) 2005-2012 Martin Pitt <[email protected]>
6 # (C) 2012-2025 Christoph Berg <[email protected]>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17
18 set -eu
19
20 # default config
21 TESTSDIR="$(dirname $0)/t"
22 : ${PG_UMASKS="077"} # default umask(s) to try
23
24 help ()
25 {
26 echo "postgresql-common testsuite"
27 echo "Syntax: $0 [options] [test ...]"
28 echo " -D drop all existing clusters (USE WITH CARE)"
29 echo " -f number run tests starting at this number"
30 echo " -F suffix flavor suffix on package names, e.g. 'ee'"
31 echo " -i install packages for versions specified by -v"
32 echo " -M don't mount tmpfses, run in the host system"
33 echo " -s start a shell in the testbed on failure"
34 echo " -u 'umask ...' umasks to run testsuite with [default: 077]"
35 echo " -v 'version ...' PostgreSQL versions to test [default: client versions installed]"
36 echo " -V debug output"
37 exit ${1:-0}
38 }
39
40 # option parsing
41 while getopts "Dhf:F:iMsu:v:V" opt ; do
42 case $opt in
43 D) DROP_ALL_CLUSTERS=1 ;;
44 f) FROM="$OPTARG" ;;
45 F) export PG_FLAVOR="$OPTARG" ;;
46 i) INSTALL=1 ;;
47 h) help ;;
48 M) export NO_TMPFS=1 ;;
49 s) export FAILURE="shell" ;;
50 u) PG_UMASKS="$OPTARG" ;;
51 v) export PG_VERSIONS="$OPTARG" ;; # used in t/TestLib.pm
52 V) VERBOSE=1 ;;
53 *) help 1 ;;
54 esac
55 done
56
57 if [ "$(id -u)" != 0 ]; then
58 echo "Error: this test suite needs to be run as root" >&2
59 exit 1
60 fi
61
62 # install packages for versions specified by -v
63 # needs network for apt, so run before unshare
64 if [ "${INSTALL:-}" ] && [ -z "${UNSHARED:-}" ]; then
65 . /etc/os-release
66 case $ID in
67 debian|ubuntu)
68 for v in $PG_VERSIONS; do
69 case $v in
70 8.*|9.0) ;;
71 *) PYTHON3_PACKAGE=postgresql-plpython3-$v${PG_FLAVOR:-} ;;
72 esac
73 case $v in
74 1[89]|2*)
75 HAVE_JIT=$(perl -e 'use lib "t"; use TestLib; print TestLib::have_jit()')
76 if [ "$HAVE_JIT" ]; then
77 JIT_PACKAGE=postgresql-$v${PG_FLAVOR:-}-jit
78 fi
79 ;;
80 esac
81 apt-get install -y \
82 postgresql-contrib-$v${PG_FLAVOR:=} \
83 postgresql-plperl-$v$PG_FLAVOR \
84 ${PYTHON3_PACKAGE:-} \
85 postgresql-pltcl-$v$PG_FLAVOR \
86 ${JIT_PACKAGE:-} \
87 postgresql-server-dev-$v$PG_FLAVOR \
88 postgresql-doc-$v$PG_FLAVOR
89 done
90 apt-get install -y \
91 build-essential \
92 debhelper \
93 fakeroot \
94 hunspell-en-us \
95 iproute2 \
96 libecpg-dev \
97 locales-all \
98 logrotate \
99 netcat-openbsd \
100 perl \
101 postgresql-common-dev \
102 postgresql-doc \
103 procps \
104 systemd
105 ;;
106 redhat|centos)
107 for v in $PG_VERSIONS; do
108 vv=$(echo $v | tr -d .)
109 yum install -y \
110 postgresql$vv${PG_FLAVOR:=}-contrib \
111 postgresql$vv$PG_FLAVOR-plperl \
112 postgresql$vv$PG_FLAVOR-plpython3 \
113 postgresql$vv$PG_FLAVOR-pltcl \
114 postgresql$vv$PG_FLAVOR-devel \
115 postgresql$vv$PG_FLAVOR-doc
116 done
117 yum install -y \
118 nmap-ncat \
119 perl-Test-Simple perl-Time-HiRes \
120 gcc
121 ;;
122 *)
123 echo "Unknown distribution ID $ID in /etc/os-release"
124 exit 1
125 ;;
126 esac
127 fi
128
129 # shift away args
130 shift $(($OPTIND - 1))
131
132 # stop currently running clusters
133 if [ -d /run/systemd/system ] ; then
134 # stop postgresql@* explicitly (#759725)
135 systemctl stop postgresql "postgresql@*" "pg_receivewal@*"
136 else
137 service postgresql stop
138 fi
139
140 # drop all existing clusters if the user requested it
141 if [ "${DROP_ALL_CLUSTERS:-}" ]; then
142 pg_lsclusters -h | while read ver cluster rest; do
143 pg_dropcluster $ver $cluster
144 done
145 fi
146
147 # set up test directories
148 dirs="/etc/postgresql /var/lib/postgresql /var/log/postgresql /var/run/postgresql /var/backups/postgresql"
149
150 if [ -z "${NO_TMPFS:-}" ]; then
151 # clean up after us
152 cleanup () {
153 set +e
154 umount -l $dirs
155 sed -i -e '/# by pg-testsuite/d' /etc/postgresql-common/createcluster.conf
156 ./pg_updateaptconfig
157 systemctl daemon-reload 2> /dev/null || : # poke generator to handle the system's clusters again
158 exit
159 }
160 trap "cleanup" 0 HUP INT QUIT ILL ABRT PIPE TERM
161
162 for d in $dirs; do
163 mkdir -p $d
164 mount -t tmpfs tmpfs $d
165 done
166
167 chown postgres:postgres /etc/postgresql ; chmod 755 /etc/postgresql
168 chown postgres:postgres /var/lib/postgresql ; chmod 755 /var/lib/postgresql
169 chown root:postgres /var/log/postgresql ; chmod 1775 /var/log/postgresql
170 chown postgres:postgres /var/run/postgresql ; chmod 2775 /var/run/postgresql /var/backups/postgresql
171 fi
172
173 if [ -d /run/systemd/system ]; then
174 systemctl daemon-reload # poke generator to forget the system's clusters
175 fi
176
177 # the RPM packages enable the logging_collector by default, which the testsuite
178 # doesn't like. We disable it unconditionally here.
179 if ! grep -q logging_collector /etc/postgresql-common/createcluster.conf; then
180 echo "logging_collector = off # by pg-testsuite" >> /etc/postgresql-common/createcluster.conf
181 fi
182
183 # reset core limit for pg_ctl tests
184 ulimit -S -c 0
185
186 # set environment
187 unset TMPDIR
188 unset LC_ALL
189 export LANG=en_US.utf8
190
191 # set variables which cause taint check errors
192 export IFS
193 export CDPATH=/usr
194 export ENV=/nonexisting
195 export BASH_ENV=/nonexisting
196
197 if [ $# -eq 0 ]; then
198 set -- $TESTSDIR/*.t
199 fi
200
201 # dump environment for debugging
202 if [ "${VERBOSE:-}" ]; then
203 echo "Environment:"
204 env | sort
205 echo "Mounts:"
206 cat /proc/mounts
207 echo "Namespaces:"
208 ls -l /proc/self/ns
209 echo
210 fi
211
212 for U in $PG_UMASKS; do
213 echo "====== Running all tests with umask $U ======="
214 umask $U
215 for T; do
216 TBASE=${T##*/}
217 [ "${FROM:-}" ] && [ "${TBASE%%_*}" -lt "${FROM:-}" ] && continue
218 echo "### PostgreSQL test $TBASE ###"
219 perl -I. $T || {
220 EXIT=$?
221 FAILED_TESTS="${FAILED_TESTS:-} $T"
222 if [ "${FAILURE:-}" ]; then
223 echo "*** $TBASE failed with status $EXIT, dropping you into a shell in the testbed ***"
224 ${SHELL:-/bin/sh}
225 fi
226 }
227 echo "### End test $TBASE ###"
228 echo
229 done
230 done
231
232 if [ "${FAILED_TESTS:-}" ]; then
233 echo "Failed tests: $FAILED_TESTS"
234 echo
235 fi
236
237 exit ${EXIT:-0}