test.sh 6.58 KB
Newer Older
1
#!/usr/bin/env bash
2 3 4 5

set -e

if [ -n "$SKIP_TESTS" ]; then
6
	exit 0
7 8
fi

9 10 11 12 13
SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
BUILD_DIR=$(pwd)
TMPDIR=${TMPDIR:-/tmp}
USER=${USER:-$(whoami)}

14 15
SUCCESS=1

16 17 18
cleanup() {
	echo "Cleaning up..."

19
	if [ ! -z "$GITDAEMON_PID" ]; then
20
		echo "Stopping git daemon..."
21
		kill $GITDAEMON_PID
22 23 24
	fi

	if [ ! -z "$SSHD_DIR" -a -f "${SSHD_DIR}/pid" ]; then
25
		echo "Stopping SSH..."
26 27
		kill $(cat "${SSHD_DIR}/pid")
	fi
28 29

	echo "Done."
30 31
}

32
run_test() {
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
	if [[ "$GITTEST_FLAKY_RETRY" > 0 ]]; then
		ATTEMPTS_REMAIN=$GITTEST_FLAKY_RETRY
	else
		ATTEMPTS_REMAIN=1
	fi

	FAILED=0
	while [[ "$ATTEMPTS_REMAIN" > 0 ]]; do
		if [ "$FAILED" -eq 1 ]; then
			echo ""
			echo "Re-running flaky ${1} tests..."
			echo ""
		fi

		RETURN_CODE=0
48 49

		CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml" ctest -V -R "^${1}$" || RETURN_CODE=$? && true
50 51 52 53 54 55 56 57 58 59 60 61 62

		if [ "$RETURN_CODE" -eq 0 ]; then
			break
		fi

		echo "Test exited with code: $RETURN_CODE"
		ATTEMPTS_REMAIN="$(($ATTEMPTS_REMAIN-1))"
		FAILED=1
	done

	if [ "$FAILED" -ne 0 ]; then
		SUCCESS=0
	fi
63
}
64

65 66 67
# Configure the test environment; run them early so that we're certain
# that they're started by the time we need them.

68
echo "##############################################################################"
69
echo "## Configuring test environment"
70 71 72 73 74 75
echo "##############################################################################"

if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
	echo "Starting git daemon..."
	GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX`
	git init --bare "${GITDAEMON_DIR}/test.git"
76 77
	git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null &
	GITDAEMON_PID=$!
78 79 80
fi

if [ -z "$SKIP_PROXY_TESTS" ]; then
81 82 83 84 85 86 87 88 89
	curl -L https://github.com/ethomson/poxyproxy/releases/download/v0.7.0/poxyproxy-0.7.0.jar >poxyproxy.jar

	echo ""
	echo "Starting HTTP proxy (Basic)..."
	java -jar poxyproxy.jar --address 127.0.0.1 --port 8080 --credentials foo:bar --auth-type basic --quiet &

	echo ""
	echo "Starting HTTP proxy (NTLM)..."
	java -jar poxyproxy.jar --address 127.0.0.1 --port 8090 --credentials foo:bar --auth-type ntlm --quiet &
90 91 92 93 94 95 96 97
fi

if [ -z "$SKIP_SSH_TESTS" ]; then
	echo "Starting ssh daemon..."
	HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
	SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
	git init --bare "${SSHD_DIR}/test.git"
	cat >"${SSHD_DIR}/sshd_config" <<-EOF
98 99 100 101 102
	Port 2222
	ListenAddress 0.0.0.0
	Protocol 2
	HostKey ${SSHD_DIR}/id_rsa
	PidFile ${SSHD_DIR}/pid
103 104
	AuthorizedKeysFile ${HOME}/.ssh/authorized_keys
	LogLevel DEBUG
105 106 107 108
	RSAAuthentication yes
	PasswordAuthentication yes
	PubkeyAuthentication yes
	ChallengeResponseAuthentication no
109
	StrictModes no
110 111
	# Required here as sshd will simply close connection otherwise
	UsePAM no
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
	EOF
	ssh-keygen -t rsa -f "${SSHD_DIR}/id_rsa" -N "" -q
	/usr/sbin/sshd -f "${SSHD_DIR}/sshd_config" -E "${SSHD_DIR}/log"

	# Set up keys
	mkdir "${HOME}/.ssh"
	ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" -N "" -q
	cat "${HOME}/.ssh/id_rsa.pub" >>"${HOME}/.ssh/authorized_keys"
	while read algorithm key comment; do
		echo "[localhost]:2222 $algorithm $key" >>"${HOME}/.ssh/known_hosts"
	done <"${SSHD_DIR}/id_rsa.pub"

	# Get the fingerprint for localhost and remove the colons so we can
	# parse it as a hex number. Older versions have a different output
	# format.
	if [[ $(ssh -V 2>&1) == OpenSSH_6* ]]; then
		SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -f "${HOME}/.ssh/known_hosts" -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':')
	else
		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 :)
	fi
132 133 134 135
fi

# Run the tests that do not require network connectivity.

136 137 138 139 140
if [ -z "$SKIP_OFFLINE_TESTS" ]; then
	echo ""
	echo "##############################################################################"
	echo "## Running (offline) tests"
	echo "##############################################################################"
141

142
	run_test offline
143
fi
144

145
if [ -n "$RUN_INVASIVE_TESTS" ]; then
146 147 148 149 150 151 152 153 154 155 156 157 158
	echo ""
	echo "Running invasive tests"
	echo ""

	export GITTEST_INVASIVE_FS_SIZE=1
	export GITTEST_INVASIVE_MEMORY=1
	export GITTEST_INVASIVE_SPEED=1
	run_test invasive
	unset GITTEST_INVASIVE_FS_SIZE
	unset GITTEST_INVASIVE_MEMORY
	unset GITTEST_INVASIVE_SPEED
fi

159 160 161 162
if [ -z "$SKIP_ONLINE_TESTS" ]; then
	# Run the various online tests.  The "online" test suite only includes the
	# default online tests that do not require additional configuration.  The
	# "proxy" and "ssh" test suites require further setup.
163

164 165 166 167
	echo ""
	echo "##############################################################################"
	echo "## Running (online) tests"
	echo "##############################################################################"
168

169
	export GITTEST_FLAKY_RETRY=5
170
	run_test online
171
	unset GITTEST_FLAKY_RETRY
172
fi
173

174 175 176 177
if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
	echo ""
	echo "Running gitdaemon tests"
	echo ""
178

179
	export GITTEST_REMOTE_URL="git://localhost/test.git"
180
	run_test gitdaemon
181 182
	unset GITTEST_REMOTE_URL
fi
183

184 185
if [ -z "$SKIP_PROXY_TESTS" ]; then
	echo ""
186
	echo "Running proxy tests (Basic authentication)"
187 188
	echo ""

189
	export GITTEST_REMOTE_PROXY_HOST="localhost:8080"
190 191
	export GITTEST_REMOTE_PROXY_USER="foo"
	export GITTEST_REMOTE_PROXY_PASS="bar"
192
	run_test proxy
193
	unset GITTEST_REMOTE_PROXY_HOST
194 195
	unset GITTEST_REMOTE_PROXY_USER
	unset GITTEST_REMOTE_PROXY_PASS
196 197 198 199 200 201 202 203 204 205 206 207

	echo ""
	echo "Running proxy tests (NTLM authentication)"
	echo ""

	export GITTEST_REMOTE_PROXY_HOST="localhost:8090"
	export GITTEST_REMOTE_PROXY_USER="foo"
	export GITTEST_REMOTE_PROXY_PASS="bar"
	run_test proxy
	unset GITTEST_REMOTE_PROXY_HOST
	unset GITTEST_REMOTE_PROXY_USER
	unset GITTEST_REMOTE_PROXY_PASS
208
fi
209

210 211 212 213 214 215 216 217 218 219 220
if [ -z "$SKIP_SSH_TESTS" ]; then
	echo ""
	echo "Running ssh tests"
	echo ""

	export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
	export GITTEST_REMOTE_USER=$USER
	export GITTEST_REMOTE_SSH_KEY="${HOME}/.ssh/id_rsa"
	export GITTEST_REMOTE_SSH_PUBKEY="${HOME}/.ssh/id_rsa.pub"
	export GITTEST_REMOTE_SSH_PASSPHRASE=""
	export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}"
221
	run_test ssh
222 223 224 225 226 227 228
	unset GITTEST_REMOTE_URL
	unset GITTEST_REMOTE_USER
	unset GITTEST_REMOTE_SSH_KEY
	unset GITTEST_REMOTE_SSH_PUBKEY
	unset GITTEST_REMOTE_SSH_PASSPHRASE
	unset GITTEST_REMOTE_SSH_FINGERPRINT
fi
229

230 231 232 233 234 235
if [ -z "$SKIP_FUZZERS" ]; then
	echo ""
	echo "##############################################################################"
	echo "## Running fuzzers"
	echo "##############################################################################"

236
	ctest -V -R 'fuzzer'
237 238
fi

239
cleanup
240

241
if [ "$SUCCESS" -ne 1 ]; then
242 243 244 245 246
	echo "Some tests failed."
	exit 1
fi

echo "Success."
247
exit 0