#!/bin/bash
set -e

pkg=simka

if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # shellcheck disable=SC2064
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

cp -a /usr/share/doc/${pkg}/example "${AUTOPKGTEST_TMP}"
cp -a /usr/share/doc/${pkg}min/example "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"/example
find . -name "*.gz" -exec gunzip \{\} \;
ls && ls simkaMin

echo "Testing simka"
# capping number of concurrent threads due to bug #986256
NR_CPUS="$(
	lscpu \
	| awk '/^CPU\(s\):/{print$2}'
)"
if [ "$NR_CPUS" -gt 8 ]
then
	echo "NOTE: found $NR_CPUS cores, capping tests to 8 threads."
	NR_CPUS=8
fi
bash simple_test.sh -nb-cores "$NR_CPUS"
python3 simple_test.py
echo "FIXME: Testing simkaMin does not work - needs more investigation"
echo "FIXME: The test suite slows dramatically down when exceeding 8 cores."
# python3 simkaMin/test_simkaMin.py
