chore(gpu): fix sanitizer script

This commit is contained in:
Agnes Leroy
2025-11-21 11:09:00 +01:00
committed by Agnès Leroy
parent 97214f801e
commit 1ed8710868

View File

@@ -1,10 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail
RUN_VALGRIND=0 RUN_VALGRIND=0
RUN_COMPUTE_SANITIZER=0 RUN_COMPUTE_SANITIZER=0
while [ -n "$1" ] while [ -n "${1:-}" ]; do
do
case "$1" in case "$1" in
"--cpu" ) "--cpu" )
RUN_VALGRIND=1 RUN_VALGRIND=1
@@ -32,7 +33,8 @@ RUSTFLAGS="$RUSTFLAGS" cargo "${CARGO_RS_BUILD_TOOLCHAIN}" nextest list --cargo-
--features=integer,internal-keycache,gpu-debug,zk-pok -p "${TFHE_SPEC}" &> /tmp/test_list.txt --features=integer,internal-keycache,gpu-debug,zk-pok -p "${TFHE_SPEC}" &> /tmp/test_list.txt
# Filter the tests to get only the HL ones # Filter the tests to get only the HL ones
TESTS_HL=$(sed -e $'s/\x1b\[[0-9;]*m//g' < /tmp/test_list.txt | grep 'high_level_api::.*gpu.*' ) TESTS_HL=$(sed -e $'s/\x1b\[[0-9;]*m//g' < /tmp/test_list.txt | grep 'high_level_api::booleans::tests::.*gpu.*' | grep -v 'array')
if [[ "${RUN_VALGRIND}" == "1" ]]; then if [[ "${RUN_VALGRIND}" == "1" ]]; then
# Build the tests but don't run them # Build the tests but don't run them
@@ -43,21 +45,19 @@ if [[ "${RUN_VALGRIND}" == "1" ]]; then
EXECUTABLE=target/release/deps/$(find target/release/deps/ -type f -executable -name "tfhe-*" -printf "%T@ %f\n" |sort -nr|sed 's/^.* //; q;') EXECUTABLE=target/release/deps/$(find target/release/deps/ -type f -executable -name "tfhe-*" -printf "%T@ %f\n" |sort -nr|sed 's/^.* //; q;')
# shellcheck disable=SC2181 # shellcheck disable=SC2181
RESULT=0 && \ RESULT=0
while read -r t; do \ while read -r t; do
echo valgrind --leak-check=full --show-leak-kinds=definite "$(pwd)"/"${EXECUTABLE}" -- "${t}" && \ [ -z "$t" ] && continue
valgrind --leak-check=full --show-leak-kinds=definite "$(pwd)"/"${EXECUTABLE}" -- "${t}" && \ echo "Running valgrind on: $t"
if [[ $? != "0" ]]; then \ VALGRIND_EXIT=0
RESULT=1; \ valgrind --leak-check=full --show-leak-kinds=definite "$EXECUTABLE" -- "$t" || VALGRIND_EXIT=$?
fi; \ if [[ $VALGRIND_EXIT -ne 0 ]]; then
done <<< "${TESTS_HL}" RESULT=1
fi
if [ $RESULT -ne 0 ]; then \ done <<< "$TESTS_HL"
exit $RESULT; \
fi;
fi fi
TESTS_HL=$(sed -e $'s/\x1b\[[0-9;]*m//g' < /tmp/test_list.txt | grep 'high_level_api::.*gpu.*' ) TESTS_HL=$(sed -e $'s/\x1b\[[0-9;]*m//g' < /tmp/test_list.txt | grep 'high_level_api::booleans::tests::.*gpu.*' | grep -v 'array')
if [[ "${RUN_COMPUTE_SANITIZER}" == "1" ]]; then if [[ "${RUN_COMPUTE_SANITIZER}" == "1" ]]; then
# Build the tests but don't run them # Build the tests but don't run them
@@ -67,20 +67,18 @@ if [[ "${RUN_COMPUTE_SANITIZER}" == "1" ]]; then
# Find the test executable -> last one to have been modified # Find the test executable -> last one to have been modified
EXECUTABLE=target/release/deps/$(find target/release/deps/ -type f -executable -name "tfhe-*" -printf "%T@ %f\n" |sort -nr|sed 's/^.* //; q;') EXECUTABLE=target/release/deps/$(find target/release/deps/ -type f -executable -name "tfhe-*" -printf "%T@ %f\n" |sort -nr|sed 's/^.* //; q;')
# Run compute sanitizer on each test individually RESULT=0
# shellcheck disable=SC2181 while read -r t; do
RESULT=0 && \ [ -z "$t" ] && continue
while read -r t; do \ echo "Running compute-sanitizer on: $t"
echo compute-sanitizer --tool memcheck --target-processes=all "$(pwd)"/"${EXECUTABLE}" -- "${t}" && \ CS_EXIT=0
compute-sanitizer --tool memcheck --leak-check=full --error-exitcode=1 --target-processes=all "$(pwd)"/"${EXECUTABLE}" -- "${t}" && \ compute-sanitizer --tool memcheck --leak-check=full \
if [[ $? != "0" ]]; then \ --error-exitcode=1 --target-processes=all \
RESULT=1; \ "$EXECUTABLE" -- "$t" || CS_EXIT=$?
fi; \ if [[ $CS_EXIT -ne 0 ]]; then
done <<< "${TESTS_HL}" RESULT=1
fi
if [ $RESULT -ne 0 ]; then \ done <<< "$TESTS_HL"
exit $RESULT; \
fi;
fi fi
exit 0 exit $RESULT