#!/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 ../../common/TEST_ENV ];then
    source ../../common/TEST_ENV
fi

check_rms
RMS=$RESOURCE_MANAGER

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

@test "[MPI] C   binary runs on two nodes under resource manager ($RMS/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
    if [ ! -s C_test ];then
	flunk "C_test binary does not exist"
    fi
    
    run run_mpi_binary ./C_test $ARGS $NODES $TASKS
    assert_success
}

@test "[MPI] C++ binary runs on two nodes under resource manager ($RMS/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
    if [[ "$LMOD_FAMILY_MPI" == "openmpi5" ]];then
        skip "C++ not available with openmpi5"
    fi
    if [ ! -s CXX_test ];then
	flunk "CXX_test binary does not exist"
    fi

    run run_mpi_binary ./CXX_test $ARGS $NODES $TASKS
    assert_success
}

@test "[MPI] F90 binary runs on two nodes under resource manager ($RMS/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
    if [ ! -s F90_test ];then
	flunk "F90_test binary does not exist"
    fi

    run run_mpi_binary ./F90_test $ARGS $NODES $TASKS
    assert_success
}
