#!/bin/sh
set -e

export OMPI_MCA_rmaps_base_oversubscribe=yes

MPI_TEST_FILE=`pwd`/debian/tests/test_file_mpi.py

for py in $(py3versions -r 2>/dev/null);
do
    cd "$AUTOPKGTEST_TMP"

    echo "\n=== Testing with $py ==="
    $py -c "import h5py; h5py.run_tests('-v')"

    echo "\n=== Testing with $py-dbg ==="
    $py-dbg -c "import h5py; h5py.run_tests('-v')"

    echo "\n=== Testing MPI support with $py ==="
    #mpirun -n 5 $py -c "import h5py; h5py.run_tests('-v')"
    echo "MPI testing with h5py.run_tests() is broken in h5py 2.10.0, see https://github.com/h5py/h5py/issues/1364"
    echo "running manual MPI tests instead"
    if mpirun -n 4 $py ${MPI_TEST_FILE}; then
	echo "MPIO tests passed"
    else
	test_return=$?
	echo "MPIO tests failed with return value ${test_return}"
	(exit ${test_return})
    fi

done
