Skip to content

Commit 9d9b557

Browse files
committed
selfcheck.sh: added options VALGRIND_TOOL and SIMPLECPP_PATH / CI-unixish.yml: use selfcheck.sh to run valgrind
1 parent e5b6182 commit 9d9b557

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
@@ -98,9 +98,10 @@ jobs:
9898
if: matrix.os == 'ubuntu-24.04'
9999
run: |
100100
make clean
101-
make -j$(nproc)
101+
make -j$(nproc) CXXOPTS="-O1"
102102
valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./testrunner
103-
valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./simplecpp simplecpp.cpp -e
103+
# TODO: run Python tests with valgrind
104+
VALGRIND_TOOL=memcheck ./selfcheck.sh
104105
105106
- name: Run with libstdc++ debug mode
106107
if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'g++'
@@ -144,10 +145,13 @@ jobs:
144145
tar xvf 1.5.1.tar.gz
145146
make clean
146147
make -j$(nproc) CXXOPTS="-O2 -g3"
147-
valgrind --tool=callgrind ./simplecpp -e simplecpp-1.5.1/simplecpp.cpp 2>callgrind.log || (cat callgrind.log && false)
148+
VALGRIND_TOOL=callgrind SIMPLECPP_PATH=simplecpp-1.5.1 ./selfcheck.sh 2>callgrind.log || (cat callgrind.log && false)
148149
cat callgrind.log
149-
callgrind_annotate --auto=no > callgrind.annotated.log
150-
head -50 callgrind.annotated.log
150+
for f in callgrind.out.*;
151+
do
152+
callgrind_annotate --auto=no $f > $f.annotated.log
153+
head -50 $f.annotated.log
154+
done
151155
152156
- uses: actions/upload-artifact@v4
153157
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)