2022-09-19 12:39:02 +02:00
|
|
|
# Copyright (c) 2022 Barcelona Supercomputing Center (BSC)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2022-08-22 16:40:08 +02:00
|
|
|
include(CMakeParseArguments)
|
|
|
|
|
2022-12-16 12:11:46 +01:00
|
|
|
function(unit_test source)
|
|
|
|
set(switches "")
|
|
|
|
set(single "" NAME)
|
|
|
|
set(multi "")
|
|
|
|
|
|
|
|
cmake_parse_arguments(
|
|
|
|
OVNI_TEST "${switches}" "${single}" "${multi}" ${ARGN})
|
|
|
|
|
|
|
|
if(OVNI_TEST_NAME)
|
|
|
|
set(test_name "${OVNI_TEST_NAME}")
|
|
|
|
else()
|
|
|
|
set(test_name "${source}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Compute the test name from the source and path
|
|
|
|
cmake_path(RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR
|
|
|
|
BASE_DIRECTORY "${OVNI_TEST_SOURCE_DIR}"
|
|
|
|
OUTPUT_VARIABLE name_prefix)
|
|
|
|
set(full_path "${name_prefix}/${test_name}")
|
|
|
|
string(REGEX REPLACE "\.c$" "" full_path_noext "${full_path}")
|
|
|
|
string(REPLACE "/" "-" name "${full_path_noext}")
|
|
|
|
|
|
|
|
set(OVNI_TEST_NAME ${name})
|
|
|
|
set(OVNI_TEST_NAME ${OVNI_TEST_NAME} PARENT_SCOPE)
|
|
|
|
set(OVNI_TEST_SOURCE ${source})
|
|
|
|
|
|
|
|
include_directories(
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/include"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src"
|
|
|
|
"${CMAKE_SOURCE_DIR}/include"
|
|
|
|
)
|
|
|
|
add_executable("${OVNI_TEST_NAME}" "${OVNI_TEST_SOURCE}")
|
|
|
|
target_link_libraries("${OVNI_TEST_NAME}" PRIVATE ovni emu)
|
|
|
|
|
|
|
|
add_test(NAME "${OVNI_TEST_NAME}"
|
|
|
|
COMMAND "${OVNI_TEST_NAME}"
|
|
|
|
WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}")
|
|
|
|
|
|
|
|
set_tests_properties("${OVNI_TEST_NAME}"
|
|
|
|
PROPERTIES
|
|
|
|
RUN_SERIAL TRUE
|
|
|
|
WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}")
|
|
|
|
endfunction(unit_test)
|
|
|
|
|
2022-08-25 19:30:44 +02:00
|
|
|
function(ovni_test source)
|
2022-12-16 12:11:46 +01:00
|
|
|
set(switches MP SHOULD_FAIL SORT UNIT)
|
2022-09-27 15:41:43 +02:00
|
|
|
set(single NPROC REGEX NAME)
|
2022-08-25 19:30:44 +02:00
|
|
|
set(multi ENV)
|
|
|
|
|
2022-09-27 15:41:43 +02:00
|
|
|
cmake_parse_arguments(
|
|
|
|
OVNI_TEST "${switches}" "${single}" "${multi}" ${ARGN})
|
|
|
|
|
|
|
|
if(OVNI_TEST_NAME)
|
|
|
|
set(test_name "${OVNI_TEST_NAME}")
|
|
|
|
else()
|
|
|
|
set(test_name "${source}")
|
|
|
|
endif()
|
|
|
|
|
2022-08-25 19:30:44 +02:00
|
|
|
# Compute the test name from the source and path
|
|
|
|
cmake_path(RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR
|
2022-09-27 15:41:43 +02:00
|
|
|
BASE_DIRECTORY "${OVNI_TEST_SOURCE_DIR}"
|
2022-08-25 19:30:44 +02:00
|
|
|
OUTPUT_VARIABLE name_prefix)
|
2022-09-27 15:41:43 +02:00
|
|
|
set(full_path "${name_prefix}/${test_name}")
|
2022-08-25 19:30:44 +02:00
|
|
|
string(REGEX REPLACE "\.c$" "" full_path_noext "${full_path}")
|
|
|
|
string(REPLACE "/" "-" name "${full_path_noext}")
|
2022-08-22 16:40:08 +02:00
|
|
|
|
2022-08-25 19:30:44 +02:00
|
|
|
set(OVNI_TEST_NAME ${name})
|
2022-09-27 15:41:43 +02:00
|
|
|
set(OVNI_TEST_NAME ${OVNI_TEST_NAME} PARENT_SCOPE)
|
2022-08-25 19:30:44 +02:00
|
|
|
set(OVNI_TEST_SOURCE ${source})
|
2022-08-22 16:40:08 +02:00
|
|
|
|
|
|
|
if(NOT OVNI_TEST_NPROC)
|
|
|
|
if(NOT OVNI_TEST_MP)
|
|
|
|
set(OVNI_TEST_NPROC 1)
|
|
|
|
else()
|
|
|
|
set(OVNI_TEST_NPROC 4)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
list(APPEND OVNI_TEST_ENV
|
|
|
|
"OVNI_NPROCS=${OVNI_TEST_NPROC}")
|
|
|
|
|
|
|
|
list(APPEND OVNI_TEST_ENV
|
2022-12-16 11:56:43 +01:00
|
|
|
"OVNI_BUILD_DIR=${CMAKE_BINARY_DIR}/src/emu")
|
2022-08-22 16:40:08 +02:00
|
|
|
|
|
|
|
list(APPEND OVNI_TEST_ENV
|
|
|
|
"OVNI_CURRENT_DIR=${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
|
2022-11-09 14:34:40 +01:00
|
|
|
list(APPEND OVNI_TEST_ENV
|
|
|
|
"OVNI_CONFIG_DIR=${CMAKE_SOURCE_DIR}/cfg")
|
|
|
|
|
2022-10-07 11:26:32 +02:00
|
|
|
if(OVNI_TEST_SORT)
|
|
|
|
list(APPEND OVNI_TEST_ENV "OVNI_DO_SORT=1")
|
|
|
|
endif()
|
|
|
|
|
2022-12-16 11:56:43 +01:00
|
|
|
include_directories(
|
|
|
|
"${CMAKE_SOURCE_DIR}/src/include"
|
|
|
|
"${CMAKE_SOURCE_DIR}/src"
|
|
|
|
"${CMAKE_SOURCE_DIR}/include"
|
|
|
|
)
|
2022-08-22 16:40:08 +02:00
|
|
|
add_executable("${OVNI_TEST_NAME}" "${OVNI_TEST_SOURCE}")
|
2022-10-04 19:54:55 +02:00
|
|
|
target_link_libraries("${OVNI_TEST_NAME}" PRIVATE ovni)
|
2022-08-22 16:40:08 +02:00
|
|
|
|
|
|
|
set(driver "${OVNI_TEST_SOURCE_DIR}/ovni-driver.sh")
|
|
|
|
|
|
|
|
if(OVNI_TEST_SHOULD_FAIL)
|
|
|
|
if(NOT OVNI_TEST_REGEX)
|
|
|
|
message(FATAL_ERROR "You must provide a REGEX for a failing test")
|
|
|
|
endif()
|
|
|
|
# Custom error handler, as ctest doesn't behave as one would expect.
|
|
|
|
add_test(NAME "${OVNI_TEST_NAME}"
|
|
|
|
COMMAND
|
|
|
|
"${OVNI_TEST_SOURCE_DIR}/match-error.sh"
|
|
|
|
"${OVNI_TEST_REGEX}"
|
|
|
|
"${driver}"
|
|
|
|
"${OVNI_TEST_NAME}"
|
|
|
|
WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}")
|
|
|
|
else()
|
2022-10-07 13:08:14 +02:00
|
|
|
if(OVNI_TEST_REGEX)
|
|
|
|
# Custom error handler for ok too
|
|
|
|
add_test(NAME "${OVNI_TEST_NAME}"
|
|
|
|
COMMAND
|
|
|
|
"${OVNI_TEST_SOURCE_DIR}/match-ok.sh"
|
|
|
|
"${OVNI_TEST_REGEX}"
|
|
|
|
"${driver}"
|
|
|
|
"${OVNI_TEST_NAME}"
|
|
|
|
WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}")
|
|
|
|
else()
|
|
|
|
add_test(NAME "${OVNI_TEST_NAME}"
|
|
|
|
COMMAND
|
|
|
|
"${driver}"
|
|
|
|
"${OVNI_TEST_NAME}"
|
|
|
|
WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}")
|
|
|
|
endif()
|
2022-08-22 16:40:08 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set_tests_properties("${OVNI_TEST_NAME}"
|
|
|
|
PROPERTIES
|
|
|
|
RUN_SERIAL TRUE
|
|
|
|
ENVIRONMENT "${OVNI_TEST_ENV}"
|
|
|
|
WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}")
|
|
|
|
endfunction(ovni_test)
|