Allow tests to run their own driver

Tests can now specify a DRIVER option pointing to a shell script that
will run instead of the default driver. It allows tests to run any
commands and run the emulator several times or with different
environment variables.

The full path of the test program is available in the OVNI_TEST_PATH
environment variable.
This commit is contained in:
Rodrigo Arias 2023-10-18 11:27:15 +02:00 committed by Rodrigo Arias Mallo
parent 7b4ebca002
commit d1bf4e7520
2 changed files with 28 additions and 17 deletions

View File

@ -5,7 +5,7 @@ include(CMakeParseArguments)
function(ovni_test source)
set(switches MP SHOULD_FAIL NOEMU SORT BREAKDOWN DISABLED)
set(single NPROC REGEX NAME)
set(single NPROC REGEX NAME DRIVER)
set(multi ENV)
cmake_parse_arguments(
@ -61,6 +61,11 @@ function(ovni_test source)
list(APPEND OVNI_TEST_ENV "OVNI_EMU_ARGS=-b")
endif()
if(OVNI_TEST_DRIVER)
list(APPEND OVNI_TEST_ENV
"OVNI_DRIVER=${CMAKE_CURRENT_SOURCE_DIR}/${OVNI_TEST_DRIVER}")
endif()
include_directories(
"${CMAKE_SOURCE_DIR}/src/include"
"${CMAKE_SOURCE_DIR}/src/emu"

View File

@ -12,8 +12,9 @@ dir=$(readlink -f "${OVNI_CURRENT_DIR}")
testname="$dir/$1"
workdir="${testname}.dir"
tracedir="${workdir}/ovni"
emubin="${OVNI_BUILD_DIR}/ovniemu"
sortbin="${OVNI_BUILD_DIR}/ovnisort"
export PATH="${OVNI_BUILD_DIR}:$PATH"
export OVNI_TEST_BIN="$testname"
rm -rf "${workdir}"
mkdir -p "${workdir}"
@ -23,23 +24,28 @@ if [ -z "$OVNI_NPROCS" ]; then
OVNI_NPROCS=1
fi
if [ "$OVNI_NPROCS" -gt 1 ]; then
for i in $(seq 1 "$OVNI_NPROCS"); do
# Run the test in the background
OVNI_RANK=$(($i-1)) OVNI_NRANKS=$OVNI_NPROCS "$testname" &
done
wait
# Let the test run its own driver
if [ -n "$OVNI_DRIVER" ]; then
. "$OVNI_DRIVER"
else
"$testname"
fi
if [ "$OVNI_NPROCS" -gt 1 ]; then
for i in $(seq 1 "$OVNI_NPROCS"); do
# Run the test in the background
OVNI_RANK=$(($i-1)) OVNI_NRANKS=$OVNI_NPROCS "$testname" &
done
wait
else
"$testname"
fi
if [ -n "$OVNI_DO_SORT" ]; then
"$sortbin" "$tracedir"
fi
if [ -n "$OVNI_DO_SORT" ]; then
ovnisort "$tracedir"
fi
if [ -z "$OVNI_NOEMU" ]; then
# 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
ovniemu $OVNI_EMU_ARGS -l "$tracedir"
fi
fi
# Run any post script that was generated