#!/bin/sh

set -e

test_name=$(basename $0 | tr '-' '_')
echo "Building"
gcc -DOS_LINUX -Wall -o "${AUTOPKGTEST_TMP}/tests_${test_name}" "subprojects/libinsane/tests/tests_${test_name}.c" subprojects/libinsane/tests/main.c -lcunit -linsane

# limit the number of file descriptors in case the autopkgtest system set it
# to the hard value which is very high and exhausts ressources and/or timeouts
echo "Reducing file descriptors limit"
ulimit -Sn 1024

if [ $(command -v valgrind) ]; then
	echo "Running test with valgrind"
	valgrind --trace-children=yes --leak-check=full --error-exitcode=10 "${AUTOPKGTEST_TMP}/tests_${test_name}"
else
	echo "Runing test without valgrind"
	"${AUTOPKGTEST_TMP}/tests_${test_name}"
fi
