Skip to content

Commit b524f6e

Browse files
Scripts: fix and make ASAN detection work for more cases.
Also move ASAN script to make clear it's also for dev machines.
1 parent 26a9c03 commit b524f6e

File tree

4 files changed

+60
-35
lines changed

4 files changed

+60
-35
lines changed

.gitlab-ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Default image for linux builds
2+
# Using core instead of base to get access to ASAN from clang.
23
image: objectboxio/buildenv-core:2023-07-28
34

45
# Assumes these environment variables are configured in GitLab CI/CD Settings:
@@ -44,7 +45,7 @@ test:
4445
# "|| true" for an OK exit code if no file is found
4546
- rm **/hs_err_pid*.log || true
4647
script:
47-
- ./ci/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean build
48+
- ./scripts/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean build
4849
artifacts:
4950
when: always
5051
paths:
@@ -89,7 +90,7 @@ test-macos:
8990
LC_ALL: "C.UTF-8"
9091
script:
9192
# Note: do not run check task as it includes SpotBugs.
92-
- ./ci/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean :tests:objectbox-java-test:test
93+
- ./scripts/test-with-asan.sh $GITLAB_REPO_ARGS $VERSION_ARGS clean :tests:objectbox-java-test:test
9394

9495
# Test oldest supported and a recent JDK.
9596
# Note: can not run these in parallel using a matrix configuration as Gradle would step over itself.

Jenkinsfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pipeline {
5656

5757
stage('build-java') {
5858
steps {
59-
sh "./ci/test-with-asan.sh $gradleArgs $signingArgs $gitlabRepoArgs clean build"
59+
sh "./scripts/test-with-asan.sh $gradleArgs $signingArgs $gitlabRepoArgs clean build"
6060
}
6161
post {
6262
always {
@@ -78,7 +78,7 @@ pipeline {
7878
// "|| true" for an OK exit code if no file is found
7979
sh 'rm tests/objectbox-java-test/hs_err_pid*.log || true'
8080
// Note: do not run check task as it includes SpotBugs.
81-
sh "./ci/test-with-asan.sh $gradleArgs $gitlabRepoArgs clean :tests:objectbox-java-test:test"
81+
sh "./scripts/test-with-asan.sh $gradleArgs $gitlabRepoArgs clean :tests:objectbox-java-test:test"
8282
}
8383
post {
8484
always {
@@ -95,7 +95,7 @@ pipeline {
9595
// "|| true" for an OK exit code if no file is found
9696
sh 'rm tests/objectbox-java-test/hs_err_pid*.log || true'
9797
// Note: do not run check task as it includes SpotBugs.
98-
sh "./ci/test-with-asan.sh $gradleArgs $gitlabRepoArgs clean :tests:objectbox-java-test:test"
98+
sh "./scripts/test-with-asan.sh $gradleArgs $gitlabRepoArgs clean :tests:objectbox-java-test:test"
9999
}
100100
post {
101101
always {

ci/test-with-asan.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

scripts/test-with-asan.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Runs Gradle with address sanitizer enabled. Arguments are passed directly to Gradle.
5+
# If no arguments are specified runs the test task.
6+
# The ASAN detection is known to work with the buildenv-core image or Ubuntu 22.04 with a clang setup.
7+
8+
if [ -z "$ASAN_LIB_SO" ]; then # If not supplied (e.g. by CI script), try to locate the lib:
9+
ASAN_ARCH=$(uname -m) # x86_64 or aarch64
10+
echo "No ASAN_LIB_SO defined, trying to locate dynamically..."
11+
# Approach via https://stackoverflow.com/a/54386573/551269
12+
ASAN_LIB_SO_GCC=$(gcc -print-file-name=libasan.so || true)
13+
ASAN_LIB_SO_CLANG=$(clang -print-file-name=libclang_rt.asan-${ASAN_ARCH}.so || true)
14+
# Find in the typical llvm directory (using `tail` for latest version; `head` would be oldest")
15+
ASAN_LIB_SO_CLANG_LATEST=$(find /usr/lib/llvm-*/ -name libclang_rt.asan-${ASAN_ARCH}.so | tail -1)
16+
echo " gcc asan lib: ${ASAN_LIB_SO_GCC}"
17+
echo " clang asan lib: ${ASAN_LIB_SO_CLANG}"
18+
echo "clang latest asan lib: ${ASAN_LIB_SO_CLANG_LATEST}"
19+
if [ -f "${ASAN_LIB_SO_CLANG_LATEST}" ]; then # prefer this so version matches with llvm-symbolizer below
20+
export ASAN_LIB_SO="${ASAN_LIB_SO_CLANG_LATEST}"
21+
elif [ -f "${ASAN_LIB_SO_CLANG}" ]; then
22+
export ASAN_LIB_SO="${ASAN_LIB_SO_CLANG}"
23+
elif [ -f "${ASAN_LIB_SO_GCC}" ]; then
24+
export ASAN_LIB_SO="${ASAN_LIB_SO_GCC}"
25+
else
26+
echo "No asan lib found; please specify via ASAN_LIB_SO"
27+
exit 1
28+
fi
29+
fi
30+
31+
if [ -z "$ASAN_SYMBOLIZER_PATH" ]; then
32+
## TODO what to look for when using gcc's lib?
33+
export ASAN_SYMBOLIZER_PATH="$(find /usr/lib/llvm-*/ -name llvm-symbolizer | tail -1)"
34+
fi
35+
36+
if [ -z "$ASAN_OPTIONS" ]; then
37+
export ASAN_OPTIONS="detect_leaks=0"
38+
fi
39+
40+
echo "ASAN_LIB_SO: $ASAN_LIB_SO"
41+
echo "ASAN_SYMBOLIZER_PATH: $ASAN_SYMBOLIZER_PATH"
42+
echo "ASAN_OPTIONS: $ASAN_OPTIONS"
43+
ls -l $ASAN_LIB_SO
44+
ls -l $ASAN_SYMBOLIZER_PATH
45+
46+
if [[ $# -eq 0 ]] ; then
47+
args=test
48+
else
49+
args=$@
50+
fi
51+
echo "Starting Gradle for target(s) \"$args\"..."
52+
pwd
53+
54+
LD_PRELOAD=${ASAN_LIB_SO} ./gradlew ${args}

0 commit comments

Comments
 (0)