Fix cTest script

This commit is contained in:
olszomal 2023-05-08 13:21:14 +02:00 committed by Michał Trojnara
parent b00ceee310
commit c90166ba8d
2 changed files with 64 additions and 52 deletions

View File

@ -7,11 +7,11 @@ option(STOP_SERVER "Stop HTTP server after tests" ON)
include(FindPython3) include(FindPython3)
set(TEST_DIR "${PROJECT_BINARY_DIR}/Testing/") set(TEST_DIR "${PROJECT_BINARY_DIR}/Testing")
file(COPY file(COPY
"${CMAKE_CURRENT_SOURCE_DIR}/tests/files" "${CMAKE_CURRENT_SOURCE_DIR}/tests/files"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/conf" "${CMAKE_CURRENT_SOURCE_DIR}/tests/conf"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/client_http.py" "${CMAKE_CURRENT_SOURCE_DIR}/tests/client_http.py"
DESTINATION "${TEST_DIR}/") DESTINATION "${TEST_DIR}/")
file(MAKE_DIRECTORY "${TEST_DIR}/logs") file(MAKE_DIRECTORY "${TEST_DIR}/logs")
@ -22,30 +22,37 @@ set(CONF "${TEST_DIR}/conf")
set(LOGS "${TEST_DIR}/logs") set(LOGS "${TEST_DIR}/logs")
set(CLIENT_HTTP "${TEST_DIR}/client_http.py") set(CLIENT_HTTP "${TEST_DIR}/client_http.py")
if(CMAKE_HOST_UNIX) if(UNIX)
file(COPY file(COPY
"${CMAKE_CURRENT_SOURCE_DIR}/tests/server_http.py" "${CMAKE_CURRENT_SOURCE_DIR}/tests/server_http.py"
DESTINATION "${TEST_DIR}/") DESTINATION "${TEST_DIR}/")
set(SERVER_HTTP "${TEST_DIR}/server_http.py") set(SERVER_HTTP "${TEST_DIR}/server_http.py")
else(CMAKE_HOST_UNIX) else(UNIX)
file(COPY file(COPY
"${CMAKE_CURRENT_SOURCE_DIR}/tests/server_http.pyw" "${CMAKE_CURRENT_SOURCE_DIR}/tests/server_http.pyw"
DESTINATION "${TEST_DIR}/") DESTINATION "${TEST_DIR}/")
set(SERVER_HTTP "${TEST_DIR}/server_http.pyw") set(SERVER_HTTP "${TEST_DIR}/server_http.pyw")
endif(CMAKE_HOST_UNIX) endif(UNIX)
file(COPY file(COPY
"${CMAKE_CURRENT_SOURCE_DIR}/tests/certs/ca-bundle.crt" "${CMAKE_CURRENT_SOURCE_DIR}/tests/certs/ca-bundle.crt"
DESTINATION "${CONF}") DESTINATION "${CONF}")
# Stop server if running if(WIN32 OR APPLE)
if(CMAKE_HOST_UNIX) if(WIN32)
if(Python3_FOUND) message(STATUS "Use pythonw to start HTTP server: \"pythonw.exe Testing\\server_http.pyw\"")
if(EXISTS ${LOGS}/port.log) else(WIN32)
# Try to kill HTTP server message(STATUS "Use python3 to start HTTP server: \"python3 Testing/server_http.py --port 19254\"")
message(STATUS "Try to kill HTTP server") endif(WIN32)
set(default_certs 1)
else(WIN32 OR APPLE)
if(Python3_FOUND)
if(EXISTS ${LOGS}/port.log)
# Stop HTTP server if running
message(STATUS "Try to kill HTTP server")
execute_process( execute_process(
COMMAND ${Python3_EXECUTABLE} "${CLIENT_HTTP}" COMMAND ${Python3_EXECUTABLE} "${CLIENT_HTTP}"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
OUTPUT_VARIABLE client_output OUTPUT_VARIABLE client_output
RESULT_VARIABLE client_result) RESULT_VARIABLE client_result)
if(NOT client_result) if(NOT client_result)
@ -55,50 +62,55 @@ if(CMAKE_HOST_UNIX)
endif(EXISTS ${LOGS}/port.log) endif(EXISTS ${LOGS}/port.log)
# Start Time Stamping Authority and CRL distribution point HTTP server # Start Time Stamping Authority and CRL distribution point HTTP server
execute_process( execute_process(
COMMAND ${Python3_EXECUTABLE} "${SERVER_HTTP}" COMMAND ${Python3_EXECUTABLE} "${SERVER_HTTP}"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
OUTPUT_FILE ${LOGS}/server.log OUTPUT_FILE ${LOGS}/server.log
ERROR_FILE ${LOGS}/server.log ERROR_FILE ${LOGS}/server.log
RESULT_VARIABLE server_error) RESULT_VARIABLE server_error)
endif(Python3_FOUND) if(server_error)
message(STATUS "HTTP server failed: ${server_error}")
else(server_error)
# Check if file exists and is no-empty
while(NOT EXISTS ${LOGS}/port.log)
execute_process(COMMAND sleep 1)
endwhile(NOT EXISTS ${LOGS}/port.log)
file(READ ${LOGS}/port.log PORT)
while(NOT PORT)
execute_process(COMMAND sleep 1)
file(READ ${LOGS}/port.log PORT)
endwhile(NOT PORT)
file(STRINGS ${LOGS}/server.log server_log)
message(STATUS "${server_log}")
if(NOT EXISTS ${LOGS}/port.log OR server_error) # Generate new cTest certificates
# Failed to start HTTP server if(NOT SED_EXECUTABLE)
set(PORT 19254) find_program(SED_EXECUTABLE sed)
message(STATUS "Fail to start HTTP server, CTest skips some tests") mark_as_advanced(SED_EXECUTABLE)
else(NOT EXISTS ${LOGS}/port.log OR server_error) endif(NOT SED_EXECUTABLE)
file(READ ${LOGS}/port.log PORT) execute_process(
message(STATUS "HTTP server started, URL http://127.0.0.1:${PORT}") COMMAND ${SED_EXECUTABLE}
endif(NOT EXISTS ${LOGS}/port.log OR server_error) -i.bak s/:19254/:${PORT}/ "${CONF}/openssl_intermediate_crldp.cnf"
COMMAND ${SED_EXECUTABLE}
-i.bak s/:19254/:${PORT}/ "${CONF}/openssl_tsa_root.cnf")
execute_process(
COMMAND "${CONF}/makecerts.sh"
WORKING_DIRECTORY ${CONF}
OUTPUT_VARIABLE makecerts_output
RESULT_VARIABLE default_certs)
message(STATUS "${makecerts_output}")
endif(server_error)
endif(Python3_FOUND)
# Generate new test certificates endif(WIN32 OR APPLE)
if(NOT SED_EXECUTABLE)
find_program(SED_EXECUTABLE sed)
mark_as_advanced(SED_EXECUTABLE)
endif(NOT SED_EXECUTABLE)
execute_process(
COMMAND ${SED_EXECUTABLE} "-i" "s/:19254/:${PORT}/" "${CONF}/openssl_intermediate_crldp.cnf"
COMMAND ${SED_EXECUTABLE} "-i" "s/:19254/:${PORT}/" "${CONF}/openssl_tsa_root.cnf")
execute_process(
COMMAND "${CONF}/makecerts.sh"
WORKING_DIRECTORY ${CONF}
OUTPUT_VARIABLE makecerts_output
RESULT_VARIABLE makecerts_result)
else(CMAKE_HOST_UNIX)
message(STATUS "To start HTTP server, URL http://127.0.0.1:19254, run: \"pythonw.exe Testing\\server_http.pyw\"")
set(PORT 19254)
set(makecerts_result 1)
endif(CMAKE_HOST_UNIX)
# If makecerts.sh failed copy the set of default certificates # Copy the set of default certificates
if(makecerts_result) if(default_certs)
message(STATUS "makecerts.sh failed") message(STATUS "Default certificates used by cTest")
if(makecerts_output) set(PORT 19254)
message(STATUS "${makecerts_output}")
endif(makecerts_output)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests/certs" file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests/certs"
DESTINATION "${TEST_DIR}") DESTINATION "${TEST_DIR}")
endif(makecerts_result) endif(default_certs)
# Compute a SHA256 hash of the leaf certificate (in DER form) # Compute a SHA256 hash of the leaf certificate (in DER form)
execute_process( execute_process(
@ -388,7 +400,7 @@ foreach(file ${files})
endforeach(ext ${extensions_3}) endforeach(ext ${extensions_3})
endforeach(file ${files}) endforeach(file ${files})
if(Python3_FOUND) if(Python3_FOUND OR server_error)
### Sign with Time-Stamp Authority ### ### Sign with Time-Stamp Authority ###
@ -566,9 +578,9 @@ if(Python3_FOUND)
message(STATUS "Keep HTTP server after tests") message(STATUS "Keep HTTP server after tests")
endif(STOP_SERVER) endif(STOP_SERVER)
else(Python3_FOUND) else(Python3_FOUND OR server_error)
message(STATUS "CTest skips some tests") message(STATUS "CTest skips some tests")
endif(Python3_FOUND) endif(Python3_FOUND OR server_error)
# Test 112 # Test 112

View File

@ -391,9 +391,9 @@ make_certs() {
then then
mkdir -p "../certs" mkdir -p "../certs"
cp tmp/* ../certs cp tmp/* ../certs
printf "%s" "keys & certificates successfully generated" printf "%s" "Keys & certificates successfully generated"
else else
printf "%s" "error logs ${result_path}/makecerts.log" printf "%s" "Error logs ${result_path}/makecerts.log"
result=1 result=1
fi fi