summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2022-09-23 12:13:25 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-12-08 22:45:27 -0500
commit5d0a311f28b96e8be2e051ae8cb08cc654d0b63e (patch)
treec94eb0eaa3fe7b8dff68a3845de144729f6c606e
parent216deefd377cf495f07f05a9b355e8d842ccb5b6 (diff)
downloadhaskell-5d0a311f28b96e8be2e051ae8cb08cc654d0b63e.tar.gz
ci: Add job to test interface file determinism guarantees
In this job we can run on every commit we add a test which builds the Cabal library twice and checks that the ABI hash and interface hash is stable across the two builds. * We run the test 20 times to try to weed out any race conditions due to `-j` * We run the builds in different temporary directories to try to weed out anything related to build directory affecting ABI or interface file hash. Fixes #22180
-rw-r--r--.gitlab-ci.yml40
-rwxr-xr-x.gitlab/ci.sh60
2 files changed, 100 insertions, 0 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f19c78c561..f6ef3e2c3f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -753,6 +753,46 @@ perf:
rules:
- if: '$CI_MERGE_REQUEST_LABELS !~ /.*fast-ci.*/'
+############################################################
+# ABI testing
+############################################################
+
+abi-test:
+ stage: testing
+ needs:
+ - job: x86_64-linux-fedora33-release
+ optional: true
+ - job: nightly-x86_64-linux-fedora33-release
+ optional: true
+ - job: release-x86_64-linux-fedora33-release
+ optional: true
+ dependencies: null
+ image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-fedora33:$DOCKER_REV"
+ rules:
+ - if: $CI_MERGE_REQUEST_ID
+ - if: '$CI_COMMIT_BRANCH == "master"'
+ - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/'
+ tags:
+ - x86_64-linux
+ script:
+ - root=$(pwd)/ghc
+ - |
+ mkdir tmp
+ tar -xf ghc-x86_64-linux-fedora33-release.tar.xz -C tmp
+ pushd tmp/ghc-*/
+ ./configure --prefix=$root
+ make install
+ popd
+ rm -Rf tmp
+ - export BOOT_HC=$(which ghc)
+ - export HC=$root/bin/ghc
+ - .gitlab/ci.sh abi_test
+ artifacts:
+ paths:
+ - out
+ rules:
+ - if: '$CI_MERGE_REQUEST_LABELS !~ /.*fast-ci.*/'
+
############################################################
# Documentation deployment via GitLab Pages
diff --git a/.gitlab/ci.sh b/.gitlab/ci.sh
index b840500aa4..5a9097aaab 100755
--- a/.gitlab/ci.sh
+++ b/.gitlab/ci.sh
@@ -663,6 +663,36 @@ function test_hadrian() {
}
+function summarise_hi_files() {
+ for iface in $(find . -type f -name "*.hi" | sort); do echo "$iface $($HC --show-iface $iface | grep " ABI hash:")"; done | tee $OUT/abis
+ for iface in $(find . -type f -name "*.hi" | sort); do echo "$iface $($HC --show-iface $iface | grep " interface hash:")"; done | tee $OUT/interfaces
+ for iface in $(find . -type f -name "*.hi" | sort); do
+ fname="$OUT/$(dirname $iface)"
+ mkdir -p $fname
+ $HC --show-iface $iface > "$OUT/$iface"
+ done
+}
+
+function cabal_abi_test() {
+ if [ -z "$OUT" ]; then
+ fail "OUT not set"
+ fi
+
+ cp -r libraries/Cabal $DIR
+ pushd $DIR
+ echo $PWD
+
+ start_section "Cabal test: $OUT"
+ mkdir -p "$OUT"
+ run "$HC" \
+ -hidir tmp -odir tmp -fforce-recomp -haddock \
+ -iCabal/Cabal/src -XNoPolyKinds Distribution.Simple -j"$cores" \
+ "$@" 2>&1 | tee $OUT/log
+ summarise_hi_files
+ popd
+ end_section "Cabal test: $OUT"
+}
+
function cabal_test() {
if [ -z "$OUT" ]; then
fail "OUT not set"
@@ -693,6 +723,35 @@ function run_perf_test() {
OUT=out/Cabal-O2 cabal_test -O2
}
+function check_interfaces(){
+ difference=$(diff "$1/$3" "$2/$3") || warn "diff failed"
+ if [ -z "$difference" ]
+ then
+ info "$1 and $2 $3 match"
+ else
+ echo $difference
+ for line in $(echo "$difference" | tr ' ' '\n' | grep ".hi" | sort | uniq); do
+ diff "$1/$line" "$2/$line"
+ done
+ fail "$3"
+ fi
+}
+
+function abi_test() {
+ for i in {1..20}; do info "iteration $i"; run_abi_test; done
+}
+
+function run_abi_test() {
+ if [ -z "$HC" ]; then
+ fail "HC not set"
+ fi
+ mkdir -p out
+ OUT="$PWD/out/run1" DIR=$(mktemp -d XXXX-looooooooong) cabal_abi_test -O0
+ OUT="$PWD/out/run2" DIR=$(mktemp -d XXXX-short) cabal_abi_test -O0
+ check_interfaces out/run1 out/run2 abis "Mismatched ABI hash"
+ check_interfaces out/run1 out/run2 interfaces "Mismatched interface hashes"
+}
+
function save_cache () {
info "Storing cabal cache from $CABAL_DIR to $CABAL_CACHE..."
rm -Rf "$CABAL_CACHE"
@@ -837,6 +896,7 @@ case $1 in
exit $res ;;
run_hadrian) shift; run_hadrian "$@" ;;
perf_test) run_perf_test ;;
+ abi_test) abi_test ;;
cabal_test) cabal_test ;;
lint_author) shift; lint_author "$@" ;;
clean) clean ;;