Skip to content

Commit 31164c2

Browse files
authored
selfcheck.sh: added options VALGRIND_TOOL and SIMPLECPP_PATH / CI-unixish.yml: use selfcheck.sh to run valgrind (#560)
1 parent fba4909 commit 31164c2

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ jobs:
100100
if: matrix.os == 'ubuntu-24.04'
101101
run: |
102102
make clean
103-
make -j$(nproc)
103+
make -j$(nproc) CXXOPTS="-O1"
104104
valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./testrunner
105-
valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./simplecpp simplecpp.cpp -e
105+
# TODO: run Python tests with valgrind
106+
VALGRIND_TOOL=memcheck ./selfcheck.sh
106107
107108
- name: Run with libstdc++ debug mode
108109
if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'g++'
@@ -146,10 +147,13 @@ jobs:
146147
tar xvf 1.5.1.tar.gz
147148
make clean
148149
make -j$(nproc) CXXOPTS="-O2 -g3"
149-
valgrind --tool=callgrind ./simplecpp -e simplecpp-1.5.1/simplecpp.cpp 2>callgrind.log || (cat callgrind.log && false)
150+
VALGRIND_TOOL=callgrind SIMPLECPP_PATH=simplecpp-1.5.1 ./selfcheck.sh >callgrind.log || (cat callgrind.log && false)
150151
cat callgrind.log
151-
callgrind_annotate --auto=no > callgrind.annotated.log
152-
head -50 callgrind.annotated.log
152+
for f in callgrind.out.*;
153+
do
154+
callgrind_annotate --auto=no $f > $f.annotated.log
155+
head -50 $f.annotated.log
156+
done
153157
154158
- uses: actions/upload-artifact@v4
155159
if: matrix.os == 'ubuntu-24.04'

selfcheck.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
#!/bin/bash
22

3-
output=$(./simplecpp simplecpp.cpp -e -f 2>&1)
3+
if [ -z "$SIMPLECPP_PATH" ]; then
4+
SIMPLECPP_PATH=.
5+
fi
6+
7+
if [ -n "$VALGRIND_TOOL" ]; then
8+
if [ "$VALGRIND_TOOL" = "memcheck" ]; then
9+
VALGRIND_OPTS="--error-limit=yes --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42"
10+
elif [ "$VALGRIND_TOOL" = "callgrind" ]; then
11+
VALGRIND_OPTS="--tool=callgrind"
12+
else
13+
echo "unsupported valgrind tool '$VALGRIND_TOOL'"
14+
exit 1
15+
fi
16+
VALGRIND_CMD="valgrind --tool=$VALGRIND_TOOL --log-fd=9 $VALGRIND_OPTS"
17+
VALGRIND_REDIRECT="valgrind_$VALGRIND_TOOL.log"
18+
else
19+
VALGRIND_CMD=
20+
VALGRIND_REDIRECT="/dev/null"
21+
fi
22+
23+
output=$($VALGRIND_CMD ./simplecpp "$SIMPLECPP_PATH/simplecpp.cpp" -e -f 2>&1 9> "$VALGRIND_REDIRECT")
424
ec=$?
25+
cat "$VALGRIND_REDIRECT"
526
errors=$(echo "$output" | grep -v 'Header not found: <')
627
if [ $ec -ne 0 ]; then
728
# only fail if we got errors which do not refer to missing system includes
@@ -104,8 +125,9 @@ else
104125
fi
105126

106127
# run with -std=gnuc++* so __has_include(...) is available
107-
./simplecpp simplecpp.cpp -e -f -std=gnu++11 $defs $inc
128+
$VALGRIND_CMD ./simplecpp "$SIMPLECPP_PATH/simplecpp.cpp" -e -f -std=gnu++11 $defs $inc 9> "$VALGRIND_REDIRECT"
108129
ec=$?
130+
cat "$VALGRIND_REDIRECT"
109131
if [ $ec -ne 0 ]; then
110132
exit $ec
111133
fi

0 commit comments

Comments
 (0)