]> git.proxmox.com Git - libgit2.git/blame - ci/test.sh
New upstream version 0.28.4+dfsg.1
[libgit2.git] / ci / test.sh
CommitLineData
6c7cee42
RD
1#!/usr/bin/env bash
2
3set -e
4
5if [ -n "$SKIP_TESTS" ]; then
6 exit 0
7fi
8
9SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
10BUILD_DIR=$(pwd)
11TMPDIR=${TMPDIR:-/tmp}
12USER=${USER:-$(whoami)}
13
14SUCCESS=1
15
16VALGRIND="valgrind --leak-check=full --show-reachable=yes --error-exitcode=125 --num-callers=50 --suppressions=\"$SOURCE_DIR/libgit2_clar.supp\""
ac3d33df 17LEAKS="MallocStackLogging=1 MallocScribble=1 MallocLogFile=/dev/null CLAR_AT_EXIT=\"leaks -quiet \$PPID\""
6c7cee42
RD
18
19cleanup() {
20 echo "Cleaning up..."
21
22 if [ ! -z "$GITDAEMON_DIR" -a -f "${GITDAEMON_DIR}/pid" ]; then
23 echo "Stopping git daemon..."
24 kill $(cat "${GITDAEMON_DIR}/pid")
25 fi
26
27 if [ ! -z "$SSHD_DIR" -a -f "${SSHD_DIR}/pid" ]; then
28 echo "Stopping SSH..."
29 kill $(cat "${SSHD_DIR}/pid")
30 fi
31
32 echo "Done."
33}
34
35failure() {
36 echo "Test exited with code: $1"
37 SUCCESS=0
38}
39
40# Ask ctest what it would run if we were to invoke it directly. This lets
41# us manage the test configuration in a single place (tests/CMakeLists.txt)
42# instead of running clar here as well. But it allows us to wrap our test
43# harness with a leak checker like valgrind. Append the option to write
44# JUnit-style XML files.
45run_test() {
46 TEST_CMD=$(ctest -N -V -R "^${1}$" | sed -n 's/^[0-9]*: Test command: //p')
ac3d33df
JK
47
48 if [ -z "$TEST_CMD" ]; then
49 echo "Could not find tests: $1"
50 exit 1
51 fi
52
6c7cee42
RD
53 TEST_CMD="${TEST_CMD} -r${BUILD_DIR}/results_${1}.xml"
54
55 if [ "$LEAK_CHECK" = "valgrind" ]; then
56 RUNNER="$VALGRIND $TEST_CMD"
57 elif [ "$LEAK_CHECK" = "leaks" ]; then
58 RUNNER="$LEAKS $TEST_CMD"
59 else
60 RUNNER="$TEST_CMD"
61 fi
62
63 eval $RUNNER || failure
64}
65
66# Configure the test environment; run them early so that we're certain
67# that they're started by the time we need them.
68
69echo "##############################################################################"
70echo "## Configuring test environment"
71echo "##############################################################################"
72
73if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
74 echo "Starting git daemon..."
75 GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX`
76 git init --bare "${GITDAEMON_DIR}/test.git"
77 git daemon --listen=localhost --export-all --enable=receive-pack --pid-file="${GITDAEMON_DIR}/pid" --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null &
78fi
79
80if [ -z "$SKIP_PROXY_TESTS" ]; then
81 echo "Starting HTTP proxy..."
ac3d33df
JK
82 curl -L https://github.com/ethomson/poxyproxy/releases/download/v0.4.0/poxyproxy-0.4.0.jar >poxyproxy.jar
83 java -jar poxyproxy.jar -d --address 127.0.0.1 --port 8080 --credentials foo:bar --quiet &
6c7cee42
RD
84fi
85
86if [ -z "$SKIP_SSH_TESTS" ]; then
87 echo "Starting ssh daemon..."
88 HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
89 SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
90 git init --bare "${SSHD_DIR}/test.git"
91 cat >"${SSHD_DIR}/sshd_config" <<-EOF
92 Port 2222
93 ListenAddress 0.0.0.0
94 Protocol 2
95 HostKey ${SSHD_DIR}/id_rsa
96 PidFile ${SSHD_DIR}/pid
97 AuthorizedKeysFile ${HOME}/.ssh/authorized_keys
98 LogLevel DEBUG
99 RSAAuthentication yes
100 PasswordAuthentication yes
101 PubkeyAuthentication yes
102 ChallengeResponseAuthentication no
103 StrictModes no
104 # Required here as sshd will simply close connection otherwise
105 UsePAM no
106 EOF
107 ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q
108 /usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" -E "${SSHD_DIR}/log"
109
110 # Set up keys
111 mkdir "${HOME}/.ssh"
112 ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" -N "" -q
113 cat "${HOME}/.ssh/id_rsa.pub" >>"${HOME}/.ssh/authorized_keys"
114 while read algorithm key comment; do
115 echo "[localhost]:2222 $algorithm $key" >>"${HOME}/.ssh/known_hosts"
116 done <"${SSHD_DIR}/id_rsa.pub"
117
118 # Get the fingerprint for localhost and remove the colons so we can
119 # parse it as a hex number. Older versions have a different output
120 # format.
121 if [[ $(ssh -V 2>&1) == OpenSSH_6* ]]; then
122 SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':')
123 else
124 SSH_FINGERPRINT=$(ssh-keygen -E md5 -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 3 | cut -d : -f2- | tr -d :)
125 fi
126fi
127
128# Run the tests that do not require network connectivity.
129
130if [ -z "$SKIP_OFFLINE_TESTS" ]; then
131 echo ""
132 echo "##############################################################################"
133 echo "## Running (offline) tests"
134 echo "##############################################################################"
135
136 run_test offline
137fi
138
ac3d33df
JK
139if [ -n "$RUN_INVASIVE_TESTS" ]; then
140 echo ""
141 echo "Running invasive tests"
142 echo ""
143
144 export GITTEST_INVASIVE_FS_SIZE=1
145 export GITTEST_INVASIVE_MEMORY=1
146 export GITTEST_INVASIVE_SPEED=1
147 run_test invasive
148 unset GITTEST_INVASIVE_FS_SIZE
149 unset GITTEST_INVASIVE_MEMORY
150 unset GITTEST_INVASIVE_SPEED
151fi
152
6c7cee42
RD
153if [ -z "$SKIP_ONLINE_TESTS" ]; then
154 # Run the various online tests. The "online" test suite only includes the
155 # default online tests that do not require additional configuration. The
156 # "proxy" and "ssh" test suites require further setup.
157
158 echo ""
159 echo "##############################################################################"
160 echo "## Running (online) tests"
161 echo "##############################################################################"
162
163 run_test online
164fi
165
166if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
167 echo ""
168 echo "Running gitdaemon tests"
169 echo ""
170
171 export GITTEST_REMOTE_URL="git://localhost/test.git"
172 run_test gitdaemon
173 unset GITTEST_REMOTE_URL
174fi
175
176if [ -z "$SKIP_PROXY_TESTS" ]; then
177 echo ""
178 echo "Running proxy tests"
179 echo ""
180
ac3d33df 181 export GITTEST_REMOTE_PROXY_HOST="localhost:8080"
6c7cee42
RD
182 export GITTEST_REMOTE_PROXY_USER="foo"
183 export GITTEST_REMOTE_PROXY_PASS="bar"
184 run_test proxy
ac3d33df 185 unset GITTEST_REMOTE_PROXY_HOST
6c7cee42
RD
186 unset GITTEST_REMOTE_PROXY_USER
187 unset GITTEST_REMOTE_PROXY_PASS
188fi
189
190if [ -z "$SKIP_SSH_TESTS" ]; then
191 echo ""
192 echo "Running ssh tests"
193 echo ""
194
195 export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
196 export GITTEST_REMOTE_USER=$USER
197 export GITTEST_REMOTE_SSH_KEY="${HOME}/.ssh/id_rsa"
198 export GITTEST_REMOTE_SSH_PUBKEY="${HOME}/.ssh/id_rsa.pub"
199 export GITTEST_REMOTE_SSH_PASSPHRASE=""
200 export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}"
201 run_test ssh
202 unset GITTEST_REMOTE_URL
203 unset GITTEST_REMOTE_USER
204 unset GITTEST_REMOTE_SSH_KEY
205 unset GITTEST_REMOTE_SSH_PUBKEY
206 unset GITTEST_REMOTE_SSH_PASSPHRASE
207 unset GITTEST_REMOTE_SSH_FINGERPRINT
208fi
209
ac3d33df
JK
210if [ -z "$SKIP_FUZZERS" ]; then
211 echo ""
212 echo "##############################################################################"
213 echo "## Running fuzzers"
214 echo "##############################################################################"
215
216 for fuzzer in fuzzers/*_fuzzer; do
217 "${fuzzer}" "${SOURCE_DIR}/fuzzers/corpora/$(basename "${fuzzer%_fuzzer}")" || failure
218 done
219fi
220
6c7cee42
RD
221cleanup
222
223if [ "$SUCCESS" -ne "1" ]; then
224 echo "Some tests failed."
225 exit 1
226fi
227
228echo "Success."
229exit 0