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

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

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

setup_file() {
	PKG="Boost/MPI"
	TASKS=$(tasks_count 16)
	check_rms

	export PKG TASKS
}

@test "[$PKG] all_gather_test under resource manager (${RESOURCE_MANAGER}/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
	test=all_gather_test
	if [ ! -x $test ]; then
		flunk "$test does not exist"
	fi
	run_mpi_binary ./$test atest 2 "${TASKS}"
	assert_success
}

@test "[$PKG] all_reduce_test under resource manager (${RESOURCE_MANAGER}/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
	test=all_reduce_test
	if [ ! -x $test ]; then
		flunk "$test does not exist"
	fi
	run_mpi_binary ./$test atest 2 "${TASKS}"
	assert_success
}

@test "[$PKG] all_to_all_test under resource manager (${RESOURCE_MANAGER}/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
	test=all_to_all_test
	if [ ! -x $test ]; then
		flunk "$test does not exist"
	fi
	run_mpi_binary ./$test atest 2 "${TASKS}"
	assert_success
}

@test "[$PKG] groups_test under resource manager (${RESOURCE_MANAGER}/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
	test=groups_test
	if [ ! -x $test ]; then
		flunk "$test does not exist"
	fi
	run_mpi_binary ./$test atest 2 "${TASKS}"
	assert_success
}

@test "[$PKG] broadcast_test under resource manager (${RESOURCE_MANAGER}/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
	test=broadcast_test
	if [ ! -x $test ]; then
		flunk "$test does not exist"
	fi
	run_mpi_binary ./$test atest 2 "${TASKS}"
	assert_success
}

@test "[$PKG] ring_test under resource manager (${RESOURCE_MANAGER}/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
	test=ring_test
	if [ ! -x $test ]; then
		flunk "$test does not exist"
	fi
	# Use retry logic as this test can sometimes timeout
	run_with_retry run_mpi_binary ./$test atest 2 "${TASKS}"
	assert_success
}

@test "[$PKG] pointer_test under resource manager (${RESOURCE_MANAGER}/$LMOD_FAMILY_COMPILER/$LMOD_FAMILY_MPI)" {
	test=pointer_test
	if [ ! -x $test ]; then
		flunk "$test does not exist"
	fi
	run_mpi_binary ./$test atest 2 "${TASKS}"
	assert_success
}
