#!/bin/bash

set -e

# compile the tests
[[ ! -d Debug ]] && mkdir Debug
pushd Debug
../build --root-dir=.. --build=Debug \
         --with-examples=no --with-benchmarks=no --with-tools=no --with-python=no --with-doc=no \
         --with-tests=yes --run-tests=no \
         --with-clang=yes --with-cuda=yes --with-coverage=yes
popd

tests=(
   AllocatorsTest-dbg
   AssertTest-dbg
   AssertCudaTest-dbg
   FileNameTest-dbg
   FileTest-dbg
   ObjectTest-dbg
#   ParallelForTest-dbg  # FIXME: too slow
   StringTest-dbg
   TimerTest-dbg
   TypeInfoTest-dbg

   # Containers
   ArrayOperationsTest-dbg
   ArrayTest-dbg
   ArrayTestCuda-dbg
   ArrayViewTest-dbg
   VectorTest-dbg
   VectorPrefixSumTest-dbg
   VectorEvaluateAndReduceTest-dbg
   VectorBinaryOperationsTest-dbg
   VectorUnaryOperationsTest-dbg
   VectorVerticalOperationsTest-dbg
   StaticArrayTest-dbg
   StaticVectorTest-dbg
   StaticVectorOperationsTest-dbg
   NDArrayTest-dbg
   NDSubarrayTest-dbg
   SlicedNDArrayTest-dbg
   StaticNDArrayTest-dbg
   StaticNDArrayCudaTest-dbg
   MultireductionTest-dbg
   ListTest-dbg
   MultimapTest-dbg
   StaticMultimapTest-dbg
   "DistributedArrayTest-dbg                     :: mpirun -np 4 DistributedArrayTest-dbg"
   "DistributedVectorTest-dbg                    :: mpirun -np 4 DistributedVectorTest-dbg"
   "DistributedVectorBinaryOperationsTest-dbg    :: mpirun -np 4 DistributedVectorBinaryOperationsTest-dbg"
   "DistributedVectorUnaryOperationsTest-dbg     :: mpirun -np 4 DistributedVectorUnaryOperationsTest-dbg"
   "DistributedVectorVerticalOperationsTest-dbg  :: mpirun -np 4 DistributedVectorVerticalOperationsTest-dbg"
   "DistributedNDArray_1D_test-dbg               :: mpirun -np 4 DistributedNDArray_1D_test-dbg"
   "DistributedNDArray_semi1D_test-dbg           :: mpirun -np 4 DistributedNDArray_semi1D_test-dbg"
   "DistributedNDArrayOverlaps_1D_test-dbg       :: mpirun -np 4 DistributedNDArrayOverlaps_1D_test-dbg"
   "DistributedNDArrayOverlaps_semi1D_test-dbg   :: mpirun -np 4 DistributedNDArrayOverlaps_semi1D_test-dbg"

   # Functions
   BoundaryMeshFunctionTest-dbg
   MeshFunctionTest-dbg

   # Matrices
   DenseMatrixTest-dbg
   SparseMatrixCopyTest-dbg
   SparseMatrixTest_AdEllpack-dbg
   SparseMatrixTest_BiEllpack-dbg
   SparseMatrixTest_ChunkedEllpack-dbg
   SparseMatrixTest_CSR-dbg
   SparseMatrixTest_Ellpack-dbg
   SparseMatrixTest_SlicedEllpack-dbg
   "DistributedMatrixTest-dbg   :: mpirun -np 4 DistributedMatrixTest-dbg"

   # Meshes
   BoundaryTagsTest-dbg
#   MeshEntityTest-dbg
#   MeshOrderingTest-dbg
#   MeshReaderTest-dbg
#   MeshTest-dbg
)

# run the programs and create coverage reports
./scripts/code_coverage/coverage.py -b Debug -o coverage_report/ --ignore-filename-regex="^\/tmp\/tmpxft_.*" "${tests[@]}"
