From 869a4e68a4c3490fea5dcc77381c05fb2defa0b2 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sat, 30 Nov 2024 23:39:32 +0000 Subject: [PATCH] Memory safety check for --watchfd. --- tests/Memory_safety_-_Watchfd.test | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 tests/Memory_safety_-_Watchfd.test diff --git a/tests/Memory_safety_-_Watchfd.test b/tests/Memory_safety_-_Watchfd.test new file mode 100755 index 0000000..bb52bde --- /dev/null +++ b/tests/Memory_safety_-_Watchfd.test @@ -0,0 +1,55 @@ +#!/bin/sh +# +# Run valgrind's memory checker against a process using the --watchfd +# option. + +# Dummy assignments for "shellcheck". +sourcePath="${sourcePath:-.}"; testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"; workFile2="${workFile2:-.tmp2}"; workFile3="${workFile3:-.tmp3}"; workFile4="${workFile4:-.tmp4}" + +# Load the valgrind function. +. "${sourcePath}/tests/run-valgrind.sh" + +# Skip the test if "-d" is not available. +if ! "${testSubject}" -h | grep -Fq ' -d'; then + echo "no \`--watchfd' / \`-d' option on this platform" + exit 77 +fi + +# Skip the test if "-d" does not work. +sleep 2 & +sleep 0.1 +"${testSubject}" -d "${pid}" -f -i 0.5 >/dev/null 2>"${workFile1}" +if grep -Fq ' -d: not available' "${workFile1}"; then + echo "no \`--watchfd' / \`-d' option on this platform" + exit 77 +fi + +# Check "--watchfd PID:FD". +# See the "Watchfd" tests for more detail. +seq 1 100 > "${workFile1}" +(export line; sleep 1; read -r line; sleep 1; read -r line; sleep 1) <"${workFile1}" & +pid=$! +sleep 0.1 +{ runWithValgrind -d "${pid}:0" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1 + +# Check "--watchfd PID". +seq 1 100 > "${workFile1}" +seq 1 300 > "${workFile2}" +( +export line +sleep 1 +read -r line +exec 9<"${workFile2}" +sleep 1 +exec 8<"${workFile1}" +exec 7/dev/null 2>&1; } 4>&1 || exit 1 + +exit 0