From c257405060cd628c95e66a12645102abbb3bdb70 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Tue, 25 Jul 2023 16:25:13 +0200 Subject: [PATCH] Define unit_test() macro with ovni_test() This allows unit tests to be executed in a individual directory where they can create new files in $PWD. --- test/macros.cmake | 55 ++++------------------------------------ test/ovni-driver.sh | 8 +++--- test/unit/CMakeLists.txt | 4 +++ 3 files changed, 14 insertions(+), 53 deletions(-) diff --git a/test/macros.cmake b/test/macros.cmake index 5e879bc..85f0e65 100644 --- a/test/macros.cmake +++ b/test/macros.cmake @@ -3,57 +3,8 @@ include(CMakeParseArguments) -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/emu" - "${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}") - - list(APPEND OVNI_TEST_ENV - "OVNI_CONFIG_DIR=${CMAKE_SOURCE_DIR}/cfg") - - set_tests_properties("${OVNI_TEST_NAME}" - PROPERTIES - RUN_SERIAL TRUE - ENVIRONMENT "${OVNI_TEST_ENV}" - WORKING_DIRECTORY "${OVNI_TEST_BUILD_DIR}") -endfunction(unit_test) - function(ovni_test source) - set(switches MP SHOULD_FAIL SORT UNIT BREAKDOWN DISABLED) + set(switches MP SHOULD_FAIL NOEMU SORT BREAKDOWN DISABLED) set(single NPROC REGEX NAME) set(multi ENV) @@ -102,6 +53,10 @@ function(ovni_test source) list(APPEND OVNI_TEST_ENV "OVNI_DO_SORT=1") endif() + if(OVNI_TEST_NOEMU) + list(APPEND OVNI_TEST_ENV "OVNI_NOEMU=1") + endif() + if(OVNI_TEST_BREAKDOWN) list(APPEND OVNI_TEST_ENV "OVNI_EMU_ARGS=-b") endif() diff --git a/test/ovni-driver.sh b/test/ovni-driver.sh index 41ddf84..5cb8ffd 100755 --- a/test/ovni-driver.sh +++ b/test/ovni-driver.sh @@ -10,7 +10,7 @@ fi dir=$(readlink -f "${OVNI_CURRENT_DIR}") testname="$dir/$1" -workdir="${testname}.trace" +workdir="${testname}.dir" tracedir="${workdir}/ovni" emubin="${OVNI_BUILD_DIR}/ovniemu" sortbin="${OVNI_BUILD_DIR}/ovnisort" @@ -37,8 +37,10 @@ if [ -n "$OVNI_DO_SORT" ]; then "$sortbin" "$tracedir" fi -# Then launch the emulator in lint mode -"$emubin" $OVNI_EMU_ARGS -l "$tracedir" +if [ -z "$OVNI_NOEMU" ]; then + # Then launch the emulator in lint mode + "$emubin" $OVNI_EMU_ARGS -l "$tracedir" +fi # Run any post script that was generated ls -1 *.sh | while read sh; do diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 031796a..d2ac78f 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -1,6 +1,10 @@ # Copyright (c) 2022-2023 Barcelona Supercomputing Center (BSC) # SPDX-License-Identifier: GPL-3.0-or-later +function(unit_test) + ovni_test(${ARGN} NOEMU) +endfunction() + #unit_test(bay-hash-speed.c) unit_test(bay.c) unit_test(cfg.c)