Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions build/sanitizer-java/bin/java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,54 @@
# This special Java executable is specified to the "jvm" configuration of the
# the surefire plugin to intercept forking the processes for tests. Then
# the tests will run with the compute-sanitizer tool.
exec compute-sanitizer --tool memcheck \
log_token="${BASHPID:-$$}_${RANDOM}_${RANDOM}"
log_basename="sanitizer_for_pid_${log_token}"
sanitizer_pid=""
forwarded_status=""

# forward_signal is invoked from the trap handlers below.
# shellcheck disable=SC2329
forward_signal() {
local signal="$1"
local status_after_signal="$2"
forwarded_status="$status_after_signal"
if [[ -n "$sanitizer_pid" ]]; then
kill "-$signal" "$sanitizer_pid" 2>/dev/null || true
fi
}

trap 'forward_signal TERM 143' TERM
Comment thread
WilliamK112 marked this conversation as resolved.
Outdated
trap 'forward_signal INT 130' INT
trap 'forward_signal HUP 129' HUP

compute-sanitizer --tool memcheck \
--launch-timeout 600 \
--error-exitcode -2 \
--log-file "./sanitizer_for_pid_%p.log" \
java "$@"
--log-file "./${log_basename}_%p.log" \
Comment thread
WilliamK112 marked this conversation as resolved.
Outdated
java "$@" &
sanitizer_pid=$!

wait "$sanitizer_pid"
status=$?
Comment thread
WilliamK112 marked this conversation as resolved.
if [[ -n "$forwarded_status" && $status -gt 128 ]]; then
wait "$sanitizer_pid" 2>/dev/null || true
status="$forwarded_status"
fi
trap - TERM INT HUP

if [[ $status -ne 0 ]]; then
echo "compute-sanitizer failed with exit code $status." >&2

found_logs=false
while IFS= read -r sanitizer_log; do
found_logs=true
echo "===== Last 80 lines of $sanitizer_log =====" >&2
tail -n 80 "$sanitizer_log" >&2
done < <(find . -maxdepth 1 -type f -name "${log_basename}_*.log" | sort)

if [[ $found_logs == false ]]; then
echo "No sanitizer_for_pid_*.log files were created for this fork." >&2
fi
fi

exit $status