Merge pull request #4812 from libgit2/ethomson/ci-refactor CI: refactoring
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8aaa61d..c3f3e40 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -62,8 +62,6 @@ OPTION(USE_EXT_HTTP_PARSER "Use system HTTP_Parser if available" ON)
OPTION(DEBUG_POOL "Enable debug pool allocator" OFF)
OPTION(ENABLE_WERROR "Enable compilation with -Werror" OFF)
OPTION(USE_BUNDLED_ZLIB "Use the bundled version of zlib" OFF)
- SET(CLAR_XML "OFF" CACHE STRING
- "Writes test results in XML format. One of ON, OFF or the directory to write to; this does not affect the output executables, this only affects the behavior of the ctest command.")
IF (UNIX AND NOT APPLE)
OPTION(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)
diff --git a/ci/build.ps1 b/ci/build.ps1
index c74717d..159c1dd 100644
--- a/ci/build.ps1
+++ b/ci/build.ps1
@@ -18,9 +18,7 @@ Write-Host "####################################################################
Write-Host "## Configuring build environment"
Write-Host "##############################################################################"
-$TestOutputDirectory = $BuildDirectory -replace "\\", "/"
-
-Invoke-Expression "cmake ${SourceDirectory} -DBUILD_EXAMPLES=ON -DCLAR_XML=${TestOutputDirectory} ${Env:CMAKE_OPTIONS}"
+Invoke-Expression "cmake ${SourceDirectory} -DBUILD_EXAMPLES=ON ${Env:CMAKE_OPTIONS}"
if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) }
Write-Host ""
diff --git a/ci/build.sh b/ci/build.sh
index b4f0a6f..49e7330 100755
--- a/ci/build.sh
+++ b/ci/build.sh
@@ -28,8 +28,8 @@ echo "##########################################################################
echo "## Configuring build environment"
echo "##############################################################################"
-echo cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -DCLAR_XML=\"${BUILD_DIR}\" ${CMAKE_OPTIONS}
-cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -DCLAR_XML="${BUILD_DIR}" ${CMAKE_OPTIONS}
+echo cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON ${CMAKE_OPTIONS}
+cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON ${CMAKE_OPTIONS}
echo ""
echo "##############################################################################"
diff --git a/ci/test.ps1 b/ci/test.ps1
index 843df70..7a55bff 100644
--- a/ci/test.ps1
+++ b/ci/test.ps1
@@ -5,41 +5,68 @@ $PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+$SourceDir = Split-Path (Split-Path (Get-Variable MyInvocation).Value.MyCommand.Path)
+$BuildDir = Get-Location
+$Success = $true
+
if ($Env:SKIP_TESTS) { exit }
+# Ask ctest what it would run if we were to invoke it directly. This lets
+# us manage the test configuration in a single place (tests/CMakeLists.txt)
+# instead of running clar here as well. But it allows us to wrap our test
+# harness with a leak checker like valgrind. Append the option to write
+# JUnit-style XML files.
+function run_test {
+ $TestName = $args[0]
+
+ $TestCommand = (ctest -N -V -R "^$TestName$") -join "`n" -replace "(?ms).*\n^[0-9]*: Test command: ","" -replace "\n.*",""
+ $TestCommand += " -r${BuildDir}\results_${TestName}.xml"
+
+ Write-Host $TestCommand
+ Invoke-Expression $TestCommand
+
+ if ($LastExitCode -ne 0) { $Success = $false }
+}
+
Write-Host "##############################################################################"
Write-Host "## Configuring test environment"
Write-Host "##############################################################################"
-Write-Host ""
-Write-Host "Starting HTTP proxy..."
-Invoke-WebRequest -Method GET -Uri https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy-0.1.0.jar -OutFile poxyproxy.jar
-javaw -jar poxyproxy.jar -d --port 8080 --credentials foo:bar
+if (-not $Env:SKIP_PROXY_TESTS) {
+ Write-Host ""
+ Write-Host "Starting HTTP proxy..."
+ Invoke-WebRequest -Method GET -Uri https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy-0.1.0.jar -OutFile poxyproxy.jar
+ javaw -jar poxyproxy.jar -d --port 8080 --credentials foo:bar
+}
Write-Host ""
Write-Host "##############################################################################"
Write-Host "## Running (offline) tests"
Write-Host "##############################################################################"
-ctest -V -R offline
-if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) }
+run_test offline
-Write-Host ""
-Write-Host "##############################################################################"
-Write-Host "## Running (online) tests"
-Write-Host "##############################################################################"
+if (-not $Env:SKIP_ONLINE_TESTS) {
+ Write-Host ""
+ Write-Host "##############################################################################"
+ Write-Host "## Running (online) tests"
+ Write-Host "##############################################################################"
-ctest -V -R online
-if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) }
+ run_test online
+}
-Write-Host ""
-Write-Host "Running proxy tests"
-Write-Host ""
+if (-not $Env:SKIP_PROXY_TESTS) {
+ Write-Host ""
+ Write-Host "Running proxy tests"
+ Write-Host ""
+
+ $Env:GITTEST_REMOTE_PROXY_URL="localhost:8080"
+ $Env:GITTEST_REMOTE_PROXY_USER="foo"
+ $Env:GITTEST_REMOTE_PROXY_PASS="bar"
+
+ run_test proxy
-$Env:GITTEST_REMOTE_PROXY_URL="localhost:8080"
-$Env:GITTEST_REMOTE_PROXY_USER="foo"
-$Env:GITTEST_REMOTE_PROXY_PASS="bar"
-ctest -V -R proxy
-if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) }
+ taskkill /F /IM javaw.exe
+}
-taskkill /F /IM javaw.exe
+if (-not $Success) { exit 1 }
diff --git a/ci/test.sh b/ci/test.sh
index a9a8537..e50e6fa 100755
--- a/ci/test.sh
+++ b/ci/test.sh
@@ -11,6 +11,8 @@ BUILD_DIR=$(pwd)
TMPDIR=${TMPDIR:-/tmp}
USER=${USER:-$(whoami)}
+SUCCESS=1
+
VALGRIND="valgrind --leak-check=full --show-reachable=yes --error-exitcode=125 --num-callers=50 --suppressions=\"$SOURCE_DIR/libgit2_clar.supp\""
LEAKS="MallocStackLogging=1 MallocScribble=1 leaks -quiet -atExit -- nohup"
@@ -30,18 +32,19 @@ cleanup() {
echo "Done."
}
-die() {
+failure() {
echo "Test exited with code: $1"
-
- cleanup
- exit $1
+ SUCCESS=0
}
-# Ask ctest what it would run if we were to invoke it directly. This lets us manage the
-# test configuration in a single place (tests/CMakeLists.txt) instead of running clar
-# here as well. But it allows us to wrap our test harness with a leak checker like valgrind.
+# Ask ctest what it would run if we were to invoke it directly. This lets
+# us manage the test configuration in a single place (tests/CMakeLists.txt)
+# instead of running clar here as well. But it allows us to wrap our test
+# harness with a leak checker like valgrind. Append the option to write
+# JUnit-style XML files.
run_test() {
- TEST_CMD=$(ctest -N -V -R $1 | sed -n 's/^[0-9]*: Test command: //p')
+ TEST_CMD=$(ctest -N -V -R "^${1}$" | sed -n 's/^[0-9]*: Test command: //p')
+ TEST_CMD="${TEST_CMD} -r${BUILD_DIR}/results_${1}.xml"
if [ "$LEAK_CHECK" = "valgrind" ]; then
RUNNER="$VALGRIND $TEST_CMD"
@@ -51,7 +54,7 @@ run_test() {
RUNNER="$TEST_CMD"
fi
- eval $RUNNER || die $?
+ eval $RUNNER || failure
}
# Configure the test environment; run them early so that we're certain
@@ -191,10 +194,16 @@ if [ -z "$SKIP_FUZZERS" ]; then
echo "##############################################################################"
for fuzzer in fuzzers/*_fuzzer; do
- "${fuzzer}" "${SOURCE_DIR}/fuzzers/corpora/$(basename "${fuzzer%_fuzzer}")" || die $?
+ "${fuzzer}" "${SOURCE_DIR}/fuzzers/corpora/$(basename "${fuzzer%_fuzzer}")" || failure
done
fi
-echo "Success."
cleanup
+
+if [ "$SUCCESS" -ne "1" ]; then
+ echo "Some tests failed."
+ exit 1
+fi
+
+echo "Success."
exit 0
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 792e6b5..9502504 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -54,22 +54,8 @@ IF (MSVC_IDE)
SET_SOURCE_FILES_PROPERTIES("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h")
ENDIF ()
-IF (CLAR_XML)
- IF (CLAR_XML STREQUAL "ON")
- SET(XML_PATH "")
- ELSE ()
- SET(XML_PATH "${CLAR_XML}/")
- ENDIF ()
-
- SET(TESTS_OFFLINE_XML "-r${XML_PATH}results_offline.xml")
- SET(TESTS_ONLINE_XML "-r${XML_PATH}results_online.xml")
- SET(TESTS_GITDAEMON_XML "-r${XML_PATH}results_gitdaemon.xml")
- SET(TESTS_SSH_XML "-r${XML_PATH}results_ssh.xml")
- SET(TESTS_PROXY_XML "-r${XML_PATH}results_proxy.xml")
-ENDIF ()
-
-ADD_TEST(offline "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_OFFLINE_XML} -xonline)
-ADD_TEST(online "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_ONLINE_XML} -sonline)
-ADD_TEST(gitdaemon "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_GITDAEMON_XML} -sonline::push)
-ADD_TEST(ssh "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_SSH_XML} -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths)
-ADD_TEST(proxy "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_PROXY_XML} -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request)
+ADD_TEST(offline "${libgit2_BINARY_DIR}/libgit2_clar" -v -xonline)
+ADD_TEST(online "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline)
+ADD_TEST(gitdaemon "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::push)
+ADD_TEST(ssh "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths)
+ADD_TEST(proxy "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request)