#!/usr/bin/env -S bats --report-formatter junit --formatter tap
# -*-sh-*-

load ../../../common/test_helper_functions || exit 1
source ../../../common/functions || exit 1

if [ -s ../../../TEST_ENV ];then
    source ../../../TEST_ENV
fi

check_rms
rm=$RESOURCE_MANAGER

NODES=2
TASKS=`tasks_count 8`
ARGS=8

TIMEOUT="00:05:00"

@test "[libs/FFTW] Serial C binary runs under resource manager ($rm/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
    if [ ! -s C_test ];then
	flunk "C_test binary does not exist"
    fi
    
    run run_serial_binary -t ${TIMEOUT} ./C_test
    assert_success
}

@test "[libs/FFTW] MPI C binary runs under resource manager ($rm/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
    if [ ! -s C_mpi_test ];then
	flunk "C_mpi_test binary does not exist"
    fi

    # choose specific pml for openmpi5
    if [[ "$LMOD_FAMILY_MPI" == "openmpi5" ]];then
	export OMPI_MCA_pml=ob1
    fi

    run run_mpi_binary -t ${TIMEOUT} ./C_mpi_test $ARGS $NODES $TASKS
    assert_success
}

@test "[libs/FFTW] Serial Fortran binary runs under resource manager ($rm/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
    if [ ! -s F_test ];then
	flunk "F_test binary does not exist"
    fi

    run run_serial_binary -t ${TIMEOUT} ./F_test
    assert_success
}



