Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 9998fbd

Browse files
author
Hendrik van Antwerpen
committed
Custom valgrind runner to allow capturing logs
1 parent e3b1afe commit 9998fbd

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,16 @@ jobs:
4747
run: ${{ env.CARGO_HACK }} test
4848
- name: Run test suite with all optimizations (default features)
4949
run: cargo test --release
50-
- name: Install cargo-valgrind
50+
- name: Install valgrind
5151
run: |
5252
sudo apt-get update
5353
sudo apt-get install -y valgrind
54-
cargo install cargo-valgrind
5554
- name: Run test suite under valgrind (default features)
55+
id: valgrind
5656
# We only need to use valgrind to test the crates that have C bindings.
57-
run: cargo valgrind test -p stack-graphs
58-
env:
59-
# Since Rust 1.83, Valgrind reports some possible leaks that cargo-valgrind
60-
# treats as fatal. The given suppressions file makes sure these are ignored.
61-
VALGRINDFLAGS: --suppressions=valgrind.supp --gen-suppressions=all --log-file=${{ runner.temp }}/valgrind.log
57+
run: script/ci-test-valgrind -p stack-graphs
6258
- name: Upload valgrind log
63-
if: ${{ failure() }}
59+
if: ${{ failure() && steps.valgrind.outcome == 'failure' }}
6460
uses: actions/upload-artifact@v4
6561
with:
6662
name: valgrind logs

script/ci-test-valgrind

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
5+
# Start by building the test binary, before we try to get its filename
6+
cargo test "$@" --no-run
7+
8+
# Cargo does not have a clean way to get the test binary, so we do some text processing here to get it
9+
test="$(cargo test "$@" --no-run 2>&1 | grep 'Executable' | head -1 | sed -e 's/[^(]*(\(.*\)).*$/\1/')"
10+
log="${RUNNER_TEMP-.}/valgrind.log"
11+
12+
# Run the test binary under valgrind
13+
if ! valgrind \
14+
--leak-check=full \
15+
--show-leak-kinds=all \
16+
--error-exitcode=1 \
17+
--suppressions=valgrind.supp \
18+
--gen-suppressions=all \
19+
--log-file="$log" \
20+
"$test"; then
21+
echo "Valgrind detected errors! See logs: $log"
22+
exit 1
23+
fi
File renamed without changes.

0 commit comments

Comments
 (0)