Skip to content

Commit 1621a37

Browse files
authored
Merge pull request libgit2#4812 from libgit2/ethomson/ci-refactor
CI: refactoring
2 parents 0530d7d + 429c7f1 commit 1621a37

File tree

6 files changed

+76
-58
lines changed

6 files changed

+76
-58
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ OPTION(USE_EXT_HTTP_PARSER "Use system HTTP_Parser if available" ON)
6262
OPTION(DEBUG_POOL "Enable debug pool allocator" OFF)
6363
OPTION(ENABLE_WERROR "Enable compilation with -Werror" OFF)
6464
OPTION(USE_BUNDLED_ZLIB "Use the bundled version of zlib" OFF)
65-
SET(CLAR_XML "OFF" CACHE STRING
66-
"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.")
6765

6866
IF (UNIX AND NOT APPLE)
6967
OPTION(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)

ci/build.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ Write-Host "####################################################################
1818
Write-Host "## Configuring build environment"
1919
Write-Host "##############################################################################"
2020

21-
$TestOutputDirectory = $BuildDirectory -replace "\\", "/"
22-
23-
Invoke-Expression "cmake ${SourceDirectory} -DBUILD_EXAMPLES=ON -DCLAR_XML=${TestOutputDirectory} ${Env:CMAKE_OPTIONS}"
21+
Invoke-Expression "cmake ${SourceDirectory} -DBUILD_EXAMPLES=ON ${Env:CMAKE_OPTIONS}"
2422
if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) }
2523

2624
Write-Host ""

ci/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ echo "##########################################################################
2828
echo "## Configuring build environment"
2929
echo "##############################################################################"
3030

31-
echo cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -DCLAR_XML=\"${BUILD_DIR}\" ${CMAKE_OPTIONS}
32-
cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -DCLAR_XML="${BUILD_DIR}" ${CMAKE_OPTIONS}
31+
echo cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON ${CMAKE_OPTIONS}
32+
cmake ${SOURCE_DIR} -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON ${CMAKE_OPTIONS}
3333

3434
echo ""
3535
echo "##############################################################################"

ci/test.ps1

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,68 @@ $PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
55

66
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
77

8+
$SourceDir = Split-Path (Split-Path (Get-Variable MyInvocation).Value.MyCommand.Path)
9+
$BuildDir = Get-Location
10+
$Success = $true
11+
812
if ($Env:SKIP_TESTS) { exit }
913

14+
# Ask ctest what it would run if we were to invoke it directly. This lets
15+
# us manage the test configuration in a single place (tests/CMakeLists.txt)
16+
# instead of running clar here as well. But it allows us to wrap our test
17+
# harness with a leak checker like valgrind. Append the option to write
18+
# JUnit-style XML files.
19+
function run_test {
20+
$TestName = $args[0]
21+
22+
$TestCommand = (ctest -N -V -R "^$TestName$") -join "`n" -replace "(?ms).*\n^[0-9]*: Test command: ","" -replace "\n.*",""
23+
$TestCommand += " -r${BuildDir}\results_${TestName}.xml"
24+
25+
Write-Host $TestCommand
26+
Invoke-Expression $TestCommand
27+
28+
if ($LastExitCode -ne 0) { $Success = $false }
29+
}
30+
1031
Write-Host "##############################################################################"
1132
Write-Host "## Configuring test environment"
1233
Write-Host "##############################################################################"
1334

14-
Write-Host ""
15-
Write-Host "Starting HTTP proxy..."
16-
Invoke-WebRequest -Method GET -Uri https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy-0.1.0.jar -OutFile poxyproxy.jar
17-
javaw -jar poxyproxy.jar -d --port 8080 --credentials foo:bar
35+
if (-not $Env:SKIP_PROXY_TESTS) {
36+
Write-Host ""
37+
Write-Host "Starting HTTP proxy..."
38+
Invoke-WebRequest -Method GET -Uri https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy-0.1.0.jar -OutFile poxyproxy.jar
39+
javaw -jar poxyproxy.jar -d --port 8080 --credentials foo:bar
40+
}
1841

1942
Write-Host ""
2043
Write-Host "##############################################################################"
2144
Write-Host "## Running (offline) tests"
2245
Write-Host "##############################################################################"
2346

24-
ctest -V -R offline
25-
if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) }
47+
run_test offline
2648

27-
Write-Host ""
28-
Write-Host "##############################################################################"
29-
Write-Host "## Running (online) tests"
30-
Write-Host "##############################################################################"
49+
if (-not $Env:SKIP_ONLINE_TESTS) {
50+
Write-Host ""
51+
Write-Host "##############################################################################"
52+
Write-Host "## Running (online) tests"
53+
Write-Host "##############################################################################"
3154

32-
ctest -V -R online
33-
if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) }
55+
run_test online
56+
}
3457

35-
Write-Host ""
36-
Write-Host "Running proxy tests"
37-
Write-Host ""
58+
if (-not $Env:SKIP_PROXY_TESTS) {
59+
Write-Host ""
60+
Write-Host "Running proxy tests"
61+
Write-Host ""
62+
63+
$Env:GITTEST_REMOTE_PROXY_URL="localhost:8080"
64+
$Env:GITTEST_REMOTE_PROXY_USER="foo"
65+
$Env:GITTEST_REMOTE_PROXY_PASS="bar"
66+
67+
run_test proxy
3868

39-
$Env:GITTEST_REMOTE_PROXY_URL="localhost:8080"
40-
$Env:GITTEST_REMOTE_PROXY_USER="foo"
41-
$Env:GITTEST_REMOTE_PROXY_PASS="bar"
42-
ctest -V -R proxy
43-
if ($LastExitCode -ne 0) { [Environment]::Exit($LastExitCode) }
69+
taskkill /F /IM javaw.exe
70+
}
4471

45-
taskkill /F /IM javaw.exe
72+
if (-not $Success) { exit 1 }

ci/test.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ BUILD_DIR=$(pwd)
1111
TMPDIR=${TMPDIR:-/tmp}
1212
USER=${USER:-$(whoami)}
1313

14+
SUCCESS=1
15+
1416
VALGRIND="valgrind --leak-check=full --show-reachable=yes --error-exitcode=125 --num-callers=50 --suppressions=\"$SOURCE_DIR/libgit2_clar.supp\""
1517
LEAKS="MallocStackLogging=1 MallocScribble=1 leaks -quiet -atExit -- nohup"
1618

@@ -30,18 +32,19 @@ cleanup() {
3032
echo "Done."
3133
}
3234

33-
die() {
35+
failure() {
3436
echo "Test exited with code: $1"
35-
36-
cleanup
37-
exit $1
37+
SUCCESS=0
3838
}
3939

40-
# Ask ctest what it would run if we were to invoke it directly. This lets us manage the
41-
# test configuration in a single place (tests/CMakeLists.txt) instead of running clar
42-
# here as well. But it allows us to wrap our test harness with a leak checker like valgrind.
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.
4345
run_test() {
44-
TEST_CMD=$(ctest -N -V -R $1 | sed -n 's/^[0-9]*: Test command: //p')
46+
TEST_CMD=$(ctest -N -V -R "^${1}$" | sed -n 's/^[0-9]*: Test command: //p')
47+
TEST_CMD="${TEST_CMD} -r${BUILD_DIR}/results_${1}.xml"
4548

4649
if [ "$LEAK_CHECK" = "valgrind" ]; then
4750
RUNNER="$VALGRIND $TEST_CMD"
@@ -51,7 +54,7 @@ run_test() {
5154
RUNNER="$TEST_CMD"
5255
fi
5356

54-
eval $RUNNER || die $?
57+
eval $RUNNER || failure
5558
}
5659

5760
# Configure the test environment; run them early so that we're certain
@@ -191,10 +194,16 @@ if [ -z "$SKIP_FUZZERS" ]; then
191194
echo "##############################################################################"
192195

193196
for fuzzer in fuzzers/*_fuzzer; do
194-
"${fuzzer}" "${SOURCE_DIR}/fuzzers/corpora/$(basename "${fuzzer%_fuzzer}")" || die $?
197+
"${fuzzer}" "${SOURCE_DIR}/fuzzers/corpora/$(basename "${fuzzer%_fuzzer}")" || failure
195198
done
196199
fi
197200

198-
echo "Success."
199201
cleanup
202+
203+
if [ "$SUCCESS" -ne "1" ]; then
204+
echo "Some tests failed."
205+
exit 1
206+
fi
207+
208+
echo "Success."
200209
exit 0

tests/CMakeLists.txt

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,8 @@ IF (MSVC_IDE)
5454
SET_SOURCE_FILES_PROPERTIES("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h")
5555
ENDIF ()
5656

57-
IF (CLAR_XML)
58-
IF (CLAR_XML STREQUAL "ON")
59-
SET(XML_PATH "")
60-
ELSE ()
61-
SET(XML_PATH "${CLAR_XML}/")
62-
ENDIF ()
63-
64-
SET(TESTS_OFFLINE_XML "-r${XML_PATH}results_offline.xml")
65-
SET(TESTS_ONLINE_XML "-r${XML_PATH}results_online.xml")
66-
SET(TESTS_GITDAEMON_XML "-r${XML_PATH}results_gitdaemon.xml")
67-
SET(TESTS_SSH_XML "-r${XML_PATH}results_ssh.xml")
68-
SET(TESTS_PROXY_XML "-r${XML_PATH}results_proxy.xml")
69-
ENDIF ()
70-
71-
ADD_TEST(offline "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_OFFLINE_XML} -xonline)
72-
ADD_TEST(online "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_ONLINE_XML} -sonline)
73-
ADD_TEST(gitdaemon "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_GITDAEMON_XML} -sonline::push)
74-
ADD_TEST(ssh "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_SSH_XML} -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths)
75-
ADD_TEST(proxy "${libgit2_BINARY_DIR}/libgit2_clar" -v ${TESTS_PROXY_XML} -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request)
57+
ADD_TEST(offline "${libgit2_BINARY_DIR}/libgit2_clar" -v -xonline)
58+
ADD_TEST(online "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline)
59+
ADD_TEST(gitdaemon "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::push)
60+
ADD_TEST(ssh "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths)
61+
ADD_TEST(proxy "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request)

0 commit comments

Comments
 (0)