diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 093301819..9a496da83 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,6 @@ -include_directories(${CMAKE_SOURCE_DIR}/src/C-interface) +include_directories( + ${CMAKE_SOURCE_DIR}/src/C-interface + ${CMAKE_BINARY_DIR}/src/Fortran-interface) set(SOURCES_TYPED add_matrix_typed.c @@ -76,6 +78,27 @@ if(MPI_C_FOUND AND MPI_C_COMPILE_FLAGS) LINK_FLAGS ${MPI_C_LINK_FLAGS}) endif() +add_executable(bml-test-fortran + test_m.F90 + allocate_matrix.F90 + bml_test.F90) +target_link_libraries(bml-test-fortran bml ${LINK_LIBRARIES}) +set_target_properties(bml-test-fortran + PROPERTIES + LINK_FLAGS "--coverage") +if(OPENMP_FOUND) + set_target_properties(bml-test-fortran + PROPERTIES + COMPILE_FLAGS ${OpenMP_Fortran_FLAGS} + LINK_FLAGS ${OpenMP_Fortran_FLAGS}) +endif() +if(MPI_Fortran_FOUND AND MPI_Fortran_COMPILE_FLAGS) + set_target_properties(bml-test-fortran + PROPERTIES + COMPILE_FLAGS ${MPI_Fortran_COMPILE_FLAGS} + LINK_FLAGS ${MPI_Fortran_LINK_FLAGS}) +endif() + foreach(N add adjacency adjungate_triangle allocate convert copy diagonalize get_element get_sparsity inverse multiply norm normalize scale set_diagonal set_row submatrix threshold trace transpose) @@ -85,6 +108,7 @@ foreach(N add adjacency adjungate_triangle allocate convert copy diagonalize #add_test(${N}-${T}-${P} mpirun -np 1 bml-test -n ${N} -t ${T} -p ${P}) #else() add_test(${N}-${T}-${P} bml-test -n ${N} -t ${T} -p ${P}) + add_test(${N}-${T}-${P}-Fortran bml-test-fortran ${N} ${T} ${P}) #endif() if(NOT BML_MPI AND NOT BML_OPENMP AND VALGRIND) add_test(${N}-${T}-${P}-valgrind ${VALGRIND} --error-exitcode=1 diff --git a/tests/bml_test.F90 b/tests/bml_test.F90 new file mode 100644 index 000000000..522696b3c --- /dev/null +++ b/tests/bml_test.F90 @@ -0,0 +1,35 @@ +program bml_test + + use bml_types_m + + integer :: N = 11 + integer :: M = -1 + character(1000) :: test = "" + character(1000) :: matrix_type = BML_MATRIX_DENSE + character(1000) :: matrix_precision = BML_ELEMENT_REAL + + integer :: n_args + + ! Arguments are interpreted as + ! + ! testname + ! matrix_type + ! precision + + n_args = command_argument_count() + if(n_args /= 3) then + print *, "incorrect number of command line arguments" + error stop + end if + + call get_command_argument(1, test) + call get_command_argument(2, matrix_type) + call get_command_argument(3, matrix_precision) + + select case(test) + case default + print *, "unknown test name "//trim(test) + error stop + end select + +end program bml_test diff --git a/tests/test_driver.F90 b/tests/test_driver.F90 deleted file mode 100644 index 63ddf8a16..000000000 --- a/tests/test_driver.F90 +++ /dev/null @@ -1,20 +0,0 @@ -program test - - ! All tests need the Fortran kinds corresponding to the C floating types. - use, intrinsic :: iso_c_binding, only : C_FLOAT, C_DOUBLE, C_FLOAT_COMPLEX, & - & C_DOUBLE_COMPLEX - use bml - use TEST_MODULE - - implicit none - - integer, parameter :: N = 7, M = 7 - type(TEST_TYPE) :: tester - - write(*, "(A)") "Testing "//MATRIX_TYPE//":"//MATRIX_PRECISION - if(.not. tester%test_function(MATRIX_TYPE, REAL_NAME, REAL_KIND, N, M)) then - write(*, "(A)") "Test failed" - error stop - end if - -end program test diff --git a/tests/test_driver.c b/tests/test_driver.c deleted file mode 100644 index 8675d6e20..000000000 --- a/tests/test_driver.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "bml.h" -#include "bml_test.h" - -#define STRINGIFY2(a) #a -#define STRINGIFY(a) STRINGIFY2(a) - -int -main( - int argc, - char **argv) -{ - const int N = 7; - const int M = 7; - - bml_log(BML_LOG_INFO, "testing %s:%s\n", - STRINGIFY(MATRIX_TYPE_NAME), STRINGIFY(MATRIX_PRECISION)); - if (test_function(N, MATRIX_TYPE_NAME, MATRIX_PRECISION, M) != 0) - { - LOG_ERROR("test failed\n"); - return -1; - } - LOG_INFO("test passed\n"); - return 0; -} diff --git a/tests/test_m.F90 b/tests/test_m.F90 index aa9db2d63..c83c060e8 100644 --- a/tests/test_m.F90 +++ b/tests/test_m.F90 @@ -1,4 +1,5 @@ module test_m + ! All tests need the Fortran kinds corresponding to the C floating types. use, intrinsic :: iso_c_binding, only : C_FLOAT, C_DOUBLE, C_FLOAT_COMPLEX, & & C_DOUBLE_COMPLEX