/pkg-postgresql/postgresql-common/trunk

To get this branch, use:
bzr branch https://alioth.debian.org/scm/loggerhead/pkg-postgresql/postgresql-common/trunk
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
1
#!/bin/sh
384.1.23 by martin at piware
add testsuite control program
2
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
3
# Run integration tests (on the installed package). This happens on unshared
4
# tmpfses, so does not interfere with installed clusters.
973 by Martin Pitt
Add standard license headers to all programs, and update copyright.
5
#
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
6
# (C) 2005-2012 Martin Pitt <mpitt@debian.org>
1433 by Christoph Berg
testsuite: Always umount the tmpfs overlays.
7
# (C) 2012-2014 Christoph Berg <myon@debian.org>
973 by Martin Pitt
Add standard license headers to all programs, and update copyright.
8
#
9
#  This program is free software; you can redistribute it and/or modify
10
#  it under the terms of the GNU General Public License as published by
11
#  the Free Software Foundation; either version 2 of the License, or
12
#  (at your option) any later version.
13
#
14
#  This program is distributed in the hope that it will be useful,
15
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
#  GNU General Public License for more details.
18
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
19
set -e
20
1205 by Christoph Berg
testsuite: Add getopt handling, and make the list of umasks to loop
21
# default config
22
TESTSDIR="$(dirname $0)/t"
1267 by Christoph Berg
testsuite: The default list of umasks to test (022 077) can be overridden
23
: ${PG_UMASKS="022 077"}
1205 by Christoph Berg
testsuite: Add getopt handling, and make the list of umasks to loop
24
25
help ()
26
{
27
    echo "postgresql-common testsuite"
28
    echo "Syntax: $0 [options] [test ...]"
1515 by Christoph Berg
testsuite: -f nnn starts tests at this sequence number.
29
    echo "    -f number        run tests starting at this number"
1465 by Christoph Berg
testsuite -v -i will install packages needed for these versions.
30
    echo "    -i               install packages for versions specified by -v"
1486 by Christoph Berg
testsuite -s opens a shell on failure
31
    echo "    -s               start a shell in the testbed on failure"
1344 by Christoph Berg
testsuite: Allow overriding the list of versions to test (-v).
32
    echo "    -u 'umask ...'   umasks to run testsuite with [default: 022 077]"
33
    echo "    -v 'version ...' PostgreSQL versions to test [default: client versions installed]"
1205 by Christoph Berg
testsuite: Add getopt handling, and make the list of umasks to loop
34
    exit ${1:-0}
35
}
36
37
# option parsing
1515 by Christoph Berg
testsuite: -f nnn starts tests at this sequence number.
38
while getopts "hf:isu:v:" opt ; do
1205 by Christoph Berg
testsuite: Add getopt handling, and make the list of umasks to loop
39
    case $opt in
1515 by Christoph Berg
testsuite: -f nnn starts tests at this sequence number.
40
        f) FROM="$OPTARG" ;;
1465 by Christoph Berg
testsuite -v -i will install packages needed for these versions.
41
        i) INSTALL=1 ;;
1205 by Christoph Berg
testsuite: Add getopt handling, and make the list of umasks to loop
42
        h) help ;;
1486 by Christoph Berg
testsuite -s opens a shell on failure
43
        s) RUN_SHELL=1 ;;
1267 by Christoph Berg
testsuite: The default list of umasks to test (022 077) can be overridden
44
        u) PG_UMASKS="$OPTARG" ;;
1344 by Christoph Berg
testsuite: Allow overriding the list of versions to test (-v).
45
        v) export PG_VERSIONS="$OPTARG" ;; # used in t/TestLib.pm
1205 by Christoph Berg
testsuite: Add getopt handling, and make the list of umasks to loop
46
        *) help 1 ;;
47
    esac
48
done
384.1.23 by martin at piware
add testsuite control program
49
1515 by Christoph Berg
testsuite: -f nnn starts tests at this sequence number.
50
if [ "$(id -u)" != 0 ]; then
51
    echo "Error: this test suite needs to be run as root" >&2
52
    exit 1
53
fi
54
1465 by Christoph Berg
testsuite -v -i will install packages needed for these versions.
55
# install packages for versions specified by -v
1479 by Christoph Berg
Fix testsuite -i to install packages before invoking unshare so apt still
56
# needs network for apt, so run before unshare
57
if [ "${INSTALL:-}" ] && [ -z "${UNSHARED:-}" ]; then
1465 by Christoph Berg
testsuite -v -i will install packages needed for these versions.
58
    for v in $PG_VERSIONS; do
59
        apt-get install -y postgresql-contrib-$v \
60
            postgresql-plperl-$v \
61
            postgresql-plpython-$v \
62
            postgresql-plpython3-$v \
63
            postgresql-pltcl-$v \
64
            postgresql-server-dev-$v
65
    done
66
    apt-get install -y libecpg-dev \
67
        locales \
68
        logrotate \
69
        procps \
70
        netcat-openbsd \
71
        hunspell-en-us
72
fi
1493 by Christoph Berg
Start porting the postgresql-common framework to RedHat, backed by the
73
# requirements on RedHat:
1529 by Christoph Berg
rpm: install /etc/postgresql and other directories; relax dependency on lsb by also implementing log_failure_msg
74
# perl-Test-Simple perl-Time-HiRes
1465 by Christoph Berg
testsuite -v -i will install packages needed for these versions.
75
1479 by Christoph Berg
Fix testsuite -i to install packages before invoking unshare so apt still
76
# re-exec ourselves through unshare
77
if [ -z "$UNSHARED" ]; then
78
    UNSHARED=1 exec unshare -uimn -- "$0" "$@"
79
fi
80
81
# shift away args
82
shift $(($OPTIND - 1))
83
1261 by Christoph Berg
testsuite: Move locale generation here from debian/tests/system
84
# install locales; this happens differently on Debian and Ubuntu
85
if [ -e /etc/locale.gen ]; then
86
    # Debian
87
    while read locale ; do
88
	if ! grep -q "^$locale\$" /etc/locale.gen ; then
89
	    echo "$locale" >> /etc/locale.gen
90
	    run=1
91
	fi
92
    done <<-EOF
93
	en_US.UTF-8 UTF-8
94
	ru_RU ISO-8859-5
95
	ru_RU.UTF-8 UTF-8
96
EOF
97
    [ "$run" ] && locale-gen
1493 by Christoph Berg
Start porting the postgresql-common framework to RedHat, backed by the
98
elif [ -x /usr/sbin/locale-gen ]; then
1261 by Christoph Berg
testsuite: Move locale generation here from debian/tests/system
99
    # Ubuntu
100
    # locale-gen will skip existing locales, so just call it for all here
101
    locale-gen en_US.UTF-8 ru_RU ru_RU.UTF-8
102
fi
103
1237 by Martin Pitt
testsuite: Stop currently running clusters, just as the script has done
104
# stop currently running clusters
105
if [ -x "/etc/init.d/postgresql" ]; then
106
    /etc/init.d/postgresql stop
107
fi
108
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
109
# let everything happen in overlay tmpfses to avoid interfering with already
110
# existing clusters; this also speeds up testing
1445 by Christoph Berg
Suppress mount --make-rprivate errors
111
mount --make-rprivate / 2> /dev/null || : # reset / to private mounts (systemd changes this to shared)
1491 by Christoph Berg
testsuite: Also mount /dev/shm; with -s, open shell on failure.
112
dirs="/etc/postgresql /etc/postgresql-common /var/lib/postgresql /var/log/postgresql /var/run/postgresql /dev/shm"
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
113
created_dirs=""
1433 by Christoph Berg
testsuite: Always umount the tmpfs overlays.
114
for d in $dirs; do
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
115
    if ! [ -d $d ]; then
116
        created_dirs="$created_dirs $d"
117
        mkdir -p $d
384.1.23 by martin at piware
add testsuite control program
118
    fi
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
119
    mount -n -t tmpfs -o mode=755 tmpfs $d
384.1.23 by martin at piware
add testsuite control program
120
done
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
121
# clean up created directories after us
1433 by Christoph Berg
testsuite: Always umount the tmpfs overlays.
122
cleanup () {
123
    umount $dirs
124
    if [ "$created_dirs" ]; then
125
        rmdir --ignore-fail-on-non-empty -p $created_dirs
126
    fi
127
}
128
trap "cleanup" 0 HUP INT QUIT ILL ABRT PIPE TERM
1232 by Martin Pitt
testsuite: Run with overlaid tmpfses on the postgresql /etc/ and /var
129
chown root:postgres /var/log/postgresql
130
chmod 1775 /var/log/postgresql
131
chown postgres:postgres /var/run/postgresql
132
chmod 2775 /var/run/postgresql
1491 by Christoph Berg
testsuite: Also mount /dev/shm; with -s, open shell on failure.
133
chmod 1777 /dev/shm
384.1.23 by martin at piware
add testsuite control program
134
1512 by Christoph Berg
Document the RPM port; disable OOM killer protection; disable logging_collector for tests; create postgres user using the commands from the RPM packages
135
# the RPM packages enable the logging_collector by default, which the testsuite
136
# doesn't like. We disable it unconditionally here.
137
echo "logging_collector = off" >> /etc/postgresql-common/createcluster.conf
138
1184 by Peter Eisentraut
testsuite: Reset core limit for pg_ctl tests.
139
# reset core limit for pg_ctl tests
140
ulimit -S -c 0
141
1236 by Christoph Berg
testsuite: start localhost interface which is down after unshare -n.
142
# start localhost interface
1410 by Martin Pitt
testsuite, pg_virtualenv: Don't fail if ifconfig is not installed. We
143
ifconfig lo up || true
1236 by Christoph Berg
testsuite: start localhost interface which is down after unshare -n.
144
1261 by Christoph Berg
testsuite: Move locale generation here from debian/tests/system
145
# set environment
146
unset TMPDIR
147
unset LC_ALL
148
export LANG=en_US.utf8
149
582 by martin at piware
* testsuite: Set all variables that potentially cause Perl taint check
150
# set variables which cause taint check errors
151
export IFS=' '
152
export CDPATH=/usr
153
export ENV=/nonexisting
154
export BASH_ENV=/nonexisting
155
1185 by Peter Eisentraut
testsuite: Allow running individual tests by passing them on the
156
if [ $# -eq 0 ]; then
157
    set -- $TESTSDIR/*.t
158
fi
159
1267 by Christoph Berg
testsuite: The default list of umasks to test (022 077) can be overridden
160
for U in $PG_UMASKS; do
1205 by Christoph Berg
testsuite: Add getopt handling, and make the list of umasks to loop
161
    case $U in
162
        022) TYPE="default" ;;
163
        077) TYPE="tight" ;;
164
        *) TYPE="custom" ;;
165
    esac
166
167
    echo "====== Running all tests with $TYPE umask $U ======="
168
    umask $U
169
    for T; do
1515 by Christoph Berg
testsuite: -f nnn starts tests at this sequence number.
170
        TBASE=${T##*/}
171
        [ "$FROM" ] && [ "${TBASE%%_*}" -lt "$FROM" ] && continue
172
        echo "=== Running test $TBASE ... ==="
1486 by Christoph Berg
testsuite -s opens a shell on failure
173
        perl $T || {
174
            EXIT=$?
175
            if [ "${RUN_SHELL:-}" ]; then
1515 by Christoph Berg
testsuite: -f nnn starts tests at this sequence number.
176
                echo "*** $TBASE failed with status $EXIT, dropping you into a shell in the testbed ***"
1486 by Christoph Berg
testsuite -s opens a shell on failure
177
                ${SHELL:-/bin/sh}
178
            fi
179
            exit $EXIT
180
        }
1205 by Christoph Berg
testsuite: Add getopt handling, and make the list of umasks to loop
181
    done
384.1.23 by martin at piware
add testsuite control program
182
done