Skip to content

Commit 1ba0985

Browse files
Merge branch 'ci-fix-asan-detection' into 'dev'
Fix run with ASAN script See merge request objectbox/objectbox-java!123
2 parents 26a9c03 + 7c95370 commit 1ba0985

File tree

4 files changed

+66
-35
lines changed

4 files changed

+66
-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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
# ASAN shared library (gcc or clang setup)
9+
if [ -z "$ASAN_LIB_SO" ]; then # If not supplied (e.g. by CI script), try to locate the lib:
10+
ASAN_ARCH=$(uname -m) # x86_64 or aarch64
11+
echo "No ASAN_LIB_SO defined, trying to locate dynamically..."
12+
# Approach via https://stackoverflow.com/a/54386573/551269
13+
ASAN_LIB_SO_GCC=$(gcc -print-file-name=libasan.so || true)
14+
ASAN_LIB_SO_CLANG=$(clang -print-file-name=libclang_rt.asan-${ASAN_ARCH}.so || true)
15+
# Find in the typical llvm directory (using `tail` for latest version; `head` would be oldest")
16+
ASAN_LIB_SO_CLANG_LATEST=$(find /usr/lib/llvm-*/ -name libclang_rt.asan-${ASAN_ARCH}.so | tail -1)
17+
echo " gcc asan lib: ${ASAN_LIB_SO_GCC}"
18+
echo " clang asan lib: ${ASAN_LIB_SO_CLANG}"
19+
echo "clang latest asan lib: ${ASAN_LIB_SO_CLANG_LATEST}"
20+
if [ -f "${ASAN_LIB_SO_CLANG_LATEST}" ]; then # prefer this so version matches with llvm-symbolizer below
21+
export ASAN_LIB_SO="${ASAN_LIB_SO_CLANG_LATEST}"
22+
elif [ -f "${ASAN_LIB_SO_CLANG}" ]; then
23+
export ASAN_LIB_SO="${ASAN_LIB_SO_CLANG}"
24+
elif [ -f "${ASAN_LIB_SO_GCC}" ]; then
25+
export ASAN_LIB_SO="${ASAN_LIB_SO_GCC}"
26+
else
27+
echo "No asan lib found; please specify via ASAN_LIB_SO"
28+
exit 1
29+
fi
30+
fi
31+
32+
# llvm-symbolizer (clang setup only)
33+
# Rocky Linux 8 (buildenv-core)
34+
if [ -z "$ASAN_SYMBOLIZER_PATH" ]; then
35+
export ASAN_SYMBOLIZER_PATH="$(find /usr/local/bin/ -name llvm-symbolizer | tail -1 )"
36+
fi
37+
# Ubuntu 22.04
38+
if [ -z "$ASAN_SYMBOLIZER_PATH" ]; then
39+
export ASAN_SYMBOLIZER_PATH="$(find /usr/lib/llvm-*/ -name llvm-symbolizer | tail -1)"
40+
fi
41+
42+
if [ -z "$ASAN_OPTIONS" ]; then
43+
export ASAN_OPTIONS="detect_leaks=0"
44+
fi
45+
46+
echo "ASAN_LIB_SO: $ASAN_LIB_SO"
47+
echo "ASAN_SYMBOLIZER_PATH: $ASAN_SYMBOLIZER_PATH"
48+
echo "ASAN_OPTIONS: $ASAN_OPTIONS"
49+
ls -l $ASAN_LIB_SO
50+
ls -l $ASAN_SYMBOLIZER_PATH
51+
52+
if [[ $# -eq 0 ]] ; then
53+
args=test
54+
else
55+
args=$@
56+
fi
57+
echo "Starting Gradle for target(s) \"$args\"..."
58+
pwd
59+
60+
LD_PRELOAD=${ASAN_LIB_SO} ./gradlew ${args}

0 commit comments

Comments
 (0)