#!/bin/sh
set -e

if ! which valgrind >/dev/null; then
    printf '\e[36mNo valgrind, no fail.\e[0m\n'
    exit 0
fi

cc -Wall -O3 -g -o "$AUTOPKGTEST_TMP"/⁊ debian/tests/threaded.c -pthread

err=0
for TOOL in memcheck drd helgrind; do
    printf '\e[36mChecking \e[96m%s\e[0m\n' "$TOOL"
    ret=0; valgrind --tool="$TOOL" "$AUTOPKGTEST_TMP"/⁊ || ret=$?
    # postpone failing until the end
    : $(( err += ret ))
done

exit $err
