Commit 09335809 authored by Hans-Nikolai Viessmann's avatar Hans-Nikolai Viessmann
Browse files

Merge branch 'unit-test-directories' into 'develop'

Unit test directories

See merge request !62
parents 401924f8 36042fd7
CMAKE_MINIMUM_REQUIRED (VERSION 3.4)
SET (TESTS_SRC_DIR ${PROJECT_SOURCE_DIR}/tests)
SET (TESTS_BIN_DIR ${PROJECT_BINARY_DIR}/tests)
MACRO (REGISTER_TEST sac_file)
GET_FILENAME_COMPONENT (namewe "${sac_file}" NAME_WE)
SET (test_name "test-${namewe}")
ADD_TEST (
NAME ${test_name}
COMMAND ${PROJECT_BINARY_DIR}/tests/scripts/run.sh ${sac_file})
COMMAND
${PROJECT_BINARY_DIR}/tests/scripts/run.sh
${sac_file} ${TESTS_BIN_DIR})
ENDMACRO ()
SET (SAC2C_EXEC "${PROJECT_BINARY_DIR}/sac2c${BUILD_TYPE_POSTFIX}")
SET (SCRIPT_LIST common.sh run.sh grep-command-output.sh
check-return-status.sh isalloptionson.sh)
check-return-status.sh isalloptionson.sh)
FOREACH (script ${SCRIPT_LIST})
CONFIGURE_FILE(
"${PROJECT_SOURCE_DIR}/tests/scripts/${script}.in"
"${PROJECT_BINARY_DIR}/tests/scripts/${script}" @ONLY)
"${TESTS_SRC_DIR}/scripts/${script}.in"
"${TESTS_BIN_DIR}/scripts/${script}" @ONLY)
ENDFOREACH ()
CONFIGURE_FILE (
"${PROJECT_SOURCE_DIR}/tests/common.mk.in"
"${PROJECT_BINARY_DIR}/tests/common.mk" @ONLY)
CONFIGURE_FILE (
"${PROJECT_SOURCE_DIR}/tests/ut-optional-packages.h.in"
"${PROJECT_BINARY_DIR}/tests/ut-optional-packages.h" COPYONLY)
CONFIGURE_FILE (
"${PROJECT_SOURCE_DIR}/tests/ut-flags.mk.in"
"${PROJECT_BINARY_DIR}/tests/ut-flags.mk" COPYONLY)
FILE (GLOB sac_test_files "${PROJECT_SOURCE_DIR}/tests/*.sac")
#FILE (GLOB scripts "${PROJECT_SOURCE_DIR}/tests/*.sh")
FILE (GLOB mk "${PROJECT_SOURCE_DIR}/tests/*.mk")
"${TESTS_SRC_DIR}/common.mk.in"
"${TESTS_BIN_DIR}/common.mk" @ONLY)
FILE (GLOB_RECURSE sac_test_files
RELATIVE "${TESTS_SRC_DIR}" "*.sac")
FILE (GLOB_RECURSE headers
RELATIVE "${TESTS_SRC_DIR}" "*.h")
FILE (GLOB_RECURSE mk
RELATIVE "${TESTS_SRC_DIR}" "*.mk")
FOREACH (f ${sac_test_files} ${headers} ${mk})
GET_FILENAME_COMPONENT (localdir "${f}" DIRECTORY)
FILE (COPY ${TESTS_SRC_DIR}/${f}
DESTINATION "${TESTS_BIN_DIR}/${localdir}")
ENDFOREACH ()
FILE (COPY ${sac_test_files} ${mk} DESTINATION "${PROJECT_BINARY_DIR}/tests")
FILE (GLOB tests "${PROJECT_BINARY_DIR}/tests/test-*.sac")
FILE (GLOB_RECURSE tests
RELATIVE "${TESTS_SRC_DIR}" "test-*.sac")
FOREACH (test ${tests})
REGISTER_TEST ("${test}")
......
SAC2C := @SAC2C_EXEC@
SAC2C_FLAGS := -v0
SAC2C_FLAGS := -v0 -cppI@TESTS_BIN_DIR@
# Name wrapper around shell script taking two arguments
# specifying a grep string and wc for same
# on the stdout.
GREP_COMMAND_OUTPUT := ./scripts/grep-command-output.sh
GREP_COMMAND_OUTPUT := @TESTS_BIN_DIR@/scripts/grep-command-output.sh
# Namewrapper for predicate script that returns true if
# all sac2c optional packages are enabled
ISALLOPTIONSON := ./scripts/isalloptionson.sh
ISALLOPTIONSON := @TESTS_BIN_DIR@/scripts/isalloptionson.sh
# Namewrapper for a script of two arguments `binary' and `ret'
# that verifies that return status of executing $binary is $ret.
CHECK_RETURN_STATUS := ./scripts/check-return-status.sh
CHECK_RETURN_STATUS := @TESTS_BIN_DIR@/scripts/check-return-status.sh
%:%.sac
$(SAC2C) $(SAC2C_FLAGS) -o $@ $<
// TEMPORARY LOCATION UNTIL ARTEM GETS SUBDIR SUPPORT WORKING.
// THIS IS FOR POGO ONLY... other subdirs need different flags
// gitlab unit test flag definitions for POGO
// unit test template for POGO
// Caller must define GREP_STR and GREP_COUNT;
// GREP_STR is the string to look for in the compiler output,
// e.g., GREP_STR="val_l"
// GREP_COUNT is the number of occurrences of that string if all goes well,
// e.g., GREP_COUNT=42
//echo GREP_STR is $GREP_STR and GREP_COUNT is $GREP_COUNT
// GREP_STR
// is the string to look for in the compiler
// output, e.g., GREP_STR="val_l"
// GREP_COUNT
// is the number of occurrences of that string
// if all goes well, e.g., GREP_COUNT=42
// SAC_TEST|include common.mk
// Compile and execute unit test; save exit code
// SAC_TEST|SAC2C_FLAGS += -check c -dopogo -noggs -dolacsi -dowlf -nopwlf -noctz -norelcf -noainl -doplur
// SAC_TEST|SAC2C_BREAKPOINT := $(SAC2C_FLAGS) -bopt:wlbscnf2 -printfun main
// SAC_TEST|CALL_SAC2C := $(SAC2C) $(SAC2C_FLAGS)
// SAC_TEST|ifeq ($(shell ./scripts/isalloptionson.sh $(SAC2C) "ISL" "BARVINOK"),yes)
// SAC_TEST|ifeq ($(shell $(ISALLOPTIONSON) $(SAC2C) "ISL" "BARVINOK"),yes)
// SAC_TEST|all: <file-name>
// SAC_TEST|<tab>@$(SAC2C) $(SAC2C_FLAGS) $< -o <file-name-we>
// SAC_TEST|<tab>@$(CALL_SAC2C) $< -o <file-name-we>
// SAC_TEST|<tab>$(CHECK_RETURN_STATUS) <file-name-we> 0
// Compile unit test with breakpoint
// SAC_TEST|<tab>@$(CALL_SAC2C) $(SAC2C_BREAKPOINT) $< | $(GREP_COMMAND_OUTPUT) $(GREP_STR) $(GREP_COUNT)
......
......@@ -3,10 +3,10 @@
# predicate: return true(0) if all script arguments are configured ON in sac2c,
# and print yes/no on stdout. Caller decisions are driven by the stdout value.
# Arguments are: sac2c name, optionalpackage1, optionalpackage2,...
# Arguments are: <sac2c> <optionalpackage1> <optionalpackage2> ...
sac=$1
shift
shift
for i in $@; do
res=$($sac -VV | grep $i:)
......@@ -16,6 +16,7 @@ for i in $@; do
echo "no"; exit 1
fi
done
# All arguments were configured ON in sac2c
echo "yes"; exit 0
echo "yes"; exit 0
......@@ -9,9 +9,15 @@ function namewe () {
# Source file that we are about to run tests on.
SAC_FILE=$1
# Location of the toplevel tests directory.
TOP_DIR=$2
# Cut the path off.
base_fname=$(basename $SAC_FILE)
# Cut the filename off.
dir_name=$(dirname $SAC_FILE)
# Generate the name for the extracted makefile.
makefile=${base_fname}.mk
......@@ -25,13 +31,13 @@ base_fname_we=$(namewe "$base_fname")
-e 's/<tab>/\t/g' \
-e "s/<file-name>/$base_fname/g" \
-e "s/<file-name-we>/$base_fname_we/g" \
-e 's/<nlslash>/\\/g' > $makefile
-e 's/<nlslash>/\\/g' > ${dir_name}/$makefile
if test $? -ne 0; then
die "cannot parse SAC_TEST specification in $SAC_FILE"
fi
if ! make -f $makefile; then
if ! (cd ${dir_name}; make -I$TOP_DIR -f $makefile); then
die "test $SAC_FILE failed"
fi
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment