# run MPI tests are set up to run on no more than 3 processes
NPROC=$( nproc )
if [[ $NPROC > 2 ]]; then
  N_MPI=3
else
  N_MPI=2
fi
# and only 2 processes for unit tests
N_MPI_UNITTEST=2

export OMPI_MCA_plm_rsh_agent=/bin/false
export OMPI_MCA_rmaps_base_oversubscribe=1
export OMPI_MCA_btl_base_warn_component_unused=0

echo "== running python tests =="

mkdir -p ${AUTOPKGTEST_TMP}/python/dist-packages
cp -ra python/dolfinx_utils ${AUTOPKGTEST_TMP}/python/dist-packages
export PYTHONPATH=${PYTHONPATH}:${AUTOPKGTEST_TMP}/python/dist-packages

# help CI tests run a little faster
export DOLFINX_JIT_CFLAGS="-g0 -O0"

echo "=== python unit test (serial) ==="
python3 -m pytest python/test/unit/
echo "=== python unit test (MPI using ${N_MPI_UNITTEST} processors out of $NPROC) ==="
mpirun -n ${N_MPI_UNITTEST} python3 -m pytest python/test/unit/ --color=no

export DOLFINX_JIT_CFLAGS="-g0 -O2"

python3 python/demo/generate-demo-files.py
echo "=== python demo test (serial) ==="
python3 -m pytest -v -k 'not demo_gmsh' python/demo/test.py
echo "=== python demo test (MPI using ${N_MPI} processors out of $NPROC)) ==="
python3 -m pytest -v -m mpi -k 'not demo_gmsh' python/demo/test.py --mpiexec=mpiexec --num-proc=${N_MPI}
