2019-04-07 09:45:52 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
|
|
|
#
|
|
|
|
# Runs a single regressoion test
|
|
|
|
#
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT REGRESSION_TEST)
|
2019-04-07 09:45:52 +00:00
|
|
|
message(FATAL_ERROR "Script needs REGRESSION_TEST defined (tip: use -DREGRESSION_TEST=..)")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT OPENTTD_EXECUTABLE)
|
2019-04-07 09:45:52 +00:00
|
|
|
message(FATAL_ERROR "Script needs OPENTTD_EXECUTABLE defined (tip: use -DOPENTTD_EXECUTABLE=..)")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-04-07 09:45:52 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT EXISTS ai/${REGRESSION_TEST}/test.sav)
|
2019-04-07 09:45:52 +00:00
|
|
|
message(FATAL_ERROR "Regression test ${REGRESSION_TEST} does not exist (tip: check regression folder for the correct spelling)")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-04-07 09:45:52 +00:00
|
|
|
|
|
|
|
# If editbin is given, copy the executable to a new folder, and change the
|
|
|
|
# subsystem to console. The copy is needed as multiple regressions can run
|
|
|
|
# at the same time.
|
2020-09-25 11:55:25 +00:00
|
|
|
if(EDITBIN_EXECUTABLE)
|
2020-12-13 18:00:25 +00:00
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${OPENTTD_EXECUTABLE} regression_${REGRESSION_TEST}.exe)
|
|
|
|
set(OPENTTD_EXECUTABLE "regression_${REGRESSION_TEST}.exe")
|
2019-04-07 09:45:52 +00:00
|
|
|
|
|
|
|
execute_process(COMMAND ${EDITBIN_EXECUTABLE} /nologo /subsystem:console ${OPENTTD_EXECUTABLE})
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-04-07 09:45:52 +00:00
|
|
|
|
|
|
|
# Run the regression test
|
|
|
|
execute_process(COMMAND ${OPENTTD_EXECUTABLE}
|
|
|
|
-x
|
|
|
|
-c regression/regression.cfg
|
|
|
|
-g ai/${REGRESSION_TEST}/test.sav
|
|
|
|
-snull
|
|
|
|
-mnull
|
|
|
|
-vnull:ticks=30000
|
|
|
|
-d script=2
|
|
|
|
-d misc=9
|
|
|
|
OUTPUT_VARIABLE REGRESSION_OUTPUT
|
|
|
|
ERROR_VARIABLE REGRESSION_RESULT
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(REGRESSION_OUTPUT)
|
2019-04-07 09:45:52 +00:00
|
|
|
message(FATAL_ERROR "Unexpected output: ${REGRESSION_OUTPUT}")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-04-07 09:45:52 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT REGRESSION_RESULT)
|
2019-04-07 09:45:52 +00:00
|
|
|
message(FATAL_ERROR "Regression did not output anything; did the compilation fail?")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-04-07 09:45:52 +00:00
|
|
|
|
|
|
|
# For some reason pointer can be printed as '0x(nil)', '0x0000000000000000', or '0x0x0'
|
|
|
|
string(REPLACE "0x(nil)" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
string(REPLACE "0x0000000000000000" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
string(REPLACE "0x0x0" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
|
2021-03-03 21:17:15 +00:00
|
|
|
# Remove timestamps if any
|
|
|
|
string(REGEX REPLACE "\[[0-9-]+ [0-9:]+\] " "" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
|
2019-04-07 09:45:52 +00:00
|
|
|
# Convert the output to a format that is expected (and more readable) by result.txt
|
|
|
|
string(REPLACE "\ndbg: [script]" "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
string(REPLACE "\n " "\nERROR: " REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
string(REPLACE "\nERROR: [1] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
string(REPLACE "\n[P] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
string(REGEX REPLACE "dbg: ([^\n]*)\n?" "" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
|
|
|
|
# Read the expected result
|
|
|
|
file(READ ai/${REGRESSION_TEST}/result.txt REGRESSION_EXPECTED)
|
|
|
|
|
|
|
|
# Convert the string to a list
|
|
|
|
string(REPLACE "\n" ";" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
string(REPLACE "\n" ";" REGRESSION_EXPECTED "${REGRESSION_EXPECTED}")
|
|
|
|
|
|
|
|
set(ARGC 0)
|
|
|
|
set(ERROR NO)
|
|
|
|
|
|
|
|
list(LENGTH REGRESSION_EXPECTED REGRESSION_EXPECTED_LENGTH)
|
|
|
|
|
|
|
|
# Compare the output
|
|
|
|
foreach(RESULT IN LISTS REGRESSION_RESULT)
|
2021-01-09 17:28:51 +00:00
|
|
|
unset(EXPECTED)
|
|
|
|
if(ARGC LESS REGRESSION_EXPECTED_LENGTH)
|
|
|
|
list(GET REGRESSION_EXPECTED ${ARGC} EXPECTED)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
math(EXPR ARGC "${ARGC} + 1")
|
2019-04-07 09:45:52 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT RESULT STREQUAL EXPECTED)
|
2019-04-07 09:45:52 +00:00
|
|
|
message("${ARGC}: - ${EXPECTED}")
|
|
|
|
message("${ARGC}: + ${RESULT}'")
|
|
|
|
set(ERROR YES)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-04-07 09:45:52 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT REGRESSION_EXPECTED_LENGTH EQUAL ARGC)
|
2021-01-09 17:28:51 +00:00
|
|
|
message("(${REGRESSION_EXPECTED_LENGTH} lines were expected but ${ARGC} were found)")
|
2019-04-07 09:45:52 +00:00
|
|
|
set(ERROR YES)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-04-07 09:45:52 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(ERROR)
|
2021-01-09 17:28:51 +00:00
|
|
|
# Ouput the regression result to a file
|
|
|
|
set(REGRESSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/regression_${REGRESSION_TEST}_output.txt")
|
|
|
|
string(REPLACE ";" "\n" REGRESSION_RESULT "${REGRESSION_RESULT}")
|
|
|
|
file(WRITE ${REGRESSION_FILE} "${REGRESSION_RESULT}")
|
|
|
|
|
|
|
|
message(FATAL_ERROR "Regression failed - Output in ${REGRESSION_FILE}")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|