# This file is part of GTI (Generic Tool Infrastructure)
#
# Copyright (C)
#   2008-2019 ZIH, Technische Universitaet Dresden, Federal Republic of Germany
#   2008-2019 Lawrence Livermore National Laboratories, United States of America
#   2013-2023 RWTH Aachen University, Federal Republic of Germany
#
# See the LICENSE file in the package base directory for details

configure_file(test_errhandler.sh.in test_errhandler.sh.gen @ONLY)
file(GENERATE OUTPUT test_errhandler.sh INPUT ${CMAKE_CURRENT_BINARY_DIR}/test_errhandler.sh.gen)

add_executable(CommErrorhandlerTest Comm.c)
target_link_libraries(CommErrorhandlerTest "${PnMPI_C_LIBRARIES}")
add_test(
        NAME Errhandler/comm_errhandler
        COMMAND ${BASH} test_errhandler.sh $<TARGET_FILE:CommErrorhandlerTest>
)
set_tests_properties(Errhandler/comm_errhandler
        PROPERTIES
        PASS_REGULAR_EXPRESSION "caught MPI error nr 0.*MyCommErrhandler was called!"
        PROCESSORS 3
)

if (GTI_ENABLE_SESSIONS)
    add_executable(SessionErrorhandlerTest Session.c)
    target_link_libraries(SessionErrorhandlerTest "${PnMPI_C_LIBRARIES}")
    add_test(
            NAME Errhandler/session_errhandler
            COMMAND ${BASH} test_errhandler.sh $<TARGET_FILE:SessionErrorhandlerTest>
    )
    set_tests_properties(Errhandler/session_errhandler
            PROPERTIES
            PASS_REGULAR_EXPRESSION "caught MPI error nr 0.*MySessionErrhandler was called!"
            PROCESSORS 3
    )
endif ()
