#!/bin/bash
# -*-sh-*-

TEST_LOGS=""
MAKEFLAGS=""
status=0

source ./common/TEST_ENV  || exit 1
source ./common/functions || exit 1

cd apps/miniDFT || exit 1
export BATS_JUNIT_CLASS=MiniDFT

# bootstrap the local autotools project

./bootstrap || exit 1

rm -f tests/test/miniDFT.*.out tests/log.miniDFT >& /dev/null

make_check_failure=0

for compiler in $COMPILER_FAMILIES ; do
    for mpi in $MPI_FAMILIES ; do

	if [[ "${compiler}" == "gnu" && "${mpi}" == "impi" ]];then
	    continue
	fi
	
	echo " "
	echo " "
	echo "-------------------------------------------------------"
	echo "Apps: MiniDFT tests: $compiler-$mpi"
	echo "-------------------------------------------------------"

	module purge          || exit 1
	module load prun      || exit 1
	module load $compiler || exit 1
	module load $mpi      || exit 1

    if test "x$LMOD_FAMILY_COMPILER" = "xgnu"; then
        if test "x$LMOD_MPI_COMPILER" != "ximpi"; then
            module load fftw      || exit 1
            module load openblas  || exit 1
            module load scalapack || exit 1
        fi
    fi

	./configure           || exit 1
	make clean            || exit 1
	make -k check         || status=1

        save_logs_mpi_family tests $compiler $mpi

	make distclean
    done
done

echo " "
echo " "
echo "-------------------------------------------------------"
echo "Apps: MiniDFT tests: Results Summary"
echo "-------------------------------------------------------"
printf "%-24s %-10s %-10s %16s %16s\n" \
Run_ID Compiler MPI_Stack Reference_Time Current_Time
cat tests/log.miniDFT

exit ${status}
