Skip to content

Commit 5449a48

Browse files
committed
test the script with valgrind in docker too
1 parent bc7503f commit 5449a48

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

.github/workflows/zhook.yml

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ jobs:
4747
set -o pipefail
4848
set -o xtrace
4949
pip install --user --upgrade --requirement ./requirements.txt
50-
sudo mkdir -m0777 ${{ github.workspace }}/cores
51-
sudo sysctl -w kernel.core_pattern='${{ github.workspace }}/cores/core.%e.%p.%t'
52-
ulimit -c unlimited
53-
valgrind --verbose --log-file=/tmp/zook.py-valgrind-%p-%n.log --leak-check=full python ./zhook.py
50+
# in case valgrind catches a segfault, it will write a core file in ./vgcore.%p
51+
valgrind \
52+
--verbose \
53+
--log-file=${GITHUB_WORKSPACE}/direct-valgrind-%p-%n.log \
54+
--leak-check=yes \
55+
python ./zhook.py
5456
5557
- name: Run in Docker with Core Dumps
5658
if: |
@@ -76,19 +78,28 @@ jobs:
7678
INPUT_SENDERUSERNAME="${INPUT_SENDERUSERNAME}"
7779
INPUT_SENDERICONURL="${INPUT_SENDERICONURL}"
7880
INPUT_ZITILOGLEVEL="${INPUT_ZITILOGLEVEL}"
81+
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}"
7982
EOF
8083
84+
# configure the kernel to write core dumps to the workspace directory that is writable by the container
85+
sudo sysctl -w kernel.core_pattern="${GITHUB_WORKSPACE}/core.%e.%p.%t"
86+
87+
# build the action's container image so we can source it for the debug image
8188
docker build -t zhook-action .
8289
docker build -t zhook-action-dbg -f debug.Dockerfile .
8390
docker run --rm \
84-
-v "${{ github.workspace }}:${{ github.workspace }}" \
85-
-w "${{ github.workspace }}" \
91+
--volume "${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE}" \
92+
--workdir "${GITHUB_WORKSPACE}" \
8693
--env-file /tmp/docker.env \
87-
--entrypoint /bin/bash \
88-
zhook-action-dbg -xc "
89-
ulimit -c unlimited
90-
exec /app/zhook.py
91-
"
94+
--entrypoint=/bin/bash \
95+
zhook-action-dbg -euxo pipefail -c '
96+
ulimit -c unlimited;
97+
exec valgrind \
98+
--verbose \
99+
--log-file=${GITHUB_WORKSPACE}/docker-valgrind-%p-%n.log \
100+
--leak-check=yes \
101+
python /app/zhook.py;
102+
'
92103
93104
- uses: ./
94105
name: Run as a GH Action from the Local Checkout
@@ -113,19 +124,36 @@ jobs:
113124
echo "DEBUG: PYTHONPATH=${PYTHONPATH:-}"
114125
echo "DEBUG: PATH=${PATH:-}"
115126
echo "DEBUG: LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}"
127+
# list non-git files in the two uppermost levels of the workspace directory hierarchy
128+
find . -maxdepth 2 -path './.git' -prune -o -print
116129
find $(python -c "import site; print(site.USER_SITE)") -path "*/openziti*" -name "*.so*" -type f -print0 | xargs -0r ldd
117-
cat /tmp/zook.py-valgrind-*.log
130+
118131
shopt -s nullglob
119-
typeset -a CORES=(${{ github.workspace }}/cores/core.*)
120-
shopt -u nullglob
121-
if [ ${#CORES[@]} -eq 0 ]; then
122-
echo "DEBUG: No core dumps found"
132+
# find valgrind logs from both execution steps
133+
typeset -a VALGRIND_LOGS=(${GITHUB_WORKSPACE}/*-valgrind-*.log)
134+
if (( ${#VALGRIND_LOGS[@]} )); then
135+
for LOG in "${VALGRIND_LOGS[@]}"; do
136+
if [ -s "$LOG" ]; then
137+
echo "DEBUG: Valgrind log: $LOG"
138+
cat "$LOG"
139+
echo "--- End of $(basename "$LOG") ---"
140+
fi
141+
done
123142
else
143+
echo "DEBUG: No Valgrind logs found"
144+
fi
145+
146+
# find core dumps produced by the kernel and valgrind
147+
typeset -a CORES=(${GITHUB_WORKSPACE}/core.* ${GITHUB_WORKSPACE}/vgcore.*)
148+
shopt -u nullglob
149+
if (( ${#CORES[@]} )); then
124150
for CORE in "${CORES[@]}"; do
125151
if [ -s "$CORE" ]; then
126-
echo "DEBUG: Core dump found: $CORE"
152+
echo "DEBUG: Core dump: $CORE"
127153
EXECUTABLE=$(basename "$CORE" | cut -d. -f2)
128154
gdb -q $(realpath $(which "$EXECUTABLE")) -c "$CORE" --ex bt --ex exit
129155
fi
130156
done
157+
else
158+
echo "DEBUG: No core dumps found"
131159
fi

debug.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ FROM python:3-slim AS debug
44

55
COPY --from=distroless /app /app
66

7-
RUN apt-get update && apt-get install --yes bash
7+
RUN apt-get update && apt-get install -y valgrind

0 commit comments

Comments
 (0)