Files
FemLite/tests/cmake/run_cclite_worker_mock.cmake
T
shenw 0440ed5a64
FemLite CI / build-test (push) Has been cancelled
Release FemLite 0.6.4
2026-07-05 17:23:34 +08:00

125 lines
4.0 KiB
CMake

if(NOT DEFINED FEMLITE_EXE)
message(FATAL_ERROR "FEMLITE_EXE is required")
endif()
if(NOT DEFINED SOURCE_DIR)
message(FATAL_ERROR "SOURCE_DIR is required")
endif()
if(NOT DEFINED OUT_DIR)
message(FATAL_ERROR "OUT_DIR is required")
endif()
if(NOT DEFINED STEPS)
set(STEPS 100)
endif()
function(check_seq_ack LOG_PATH)
file(READ "${LOG_PATH}" _content)
string(REPLACE "\r\n" "\n" _content "${_content}")
string(REPLACE "\n" ";" _lines "${_content}")
set(_prev_seq 0)
set(_done_seen FALSE)
foreach(_line IN LISTS _lines)
if(_line MATCHES "^[0-9]+,")
string(REPLACE "," ";" _fields "${_line}")
list(GET _fields 0 _seq)
list(GET _fields 1 _ack)
list(GET _fields 6 _state)
if(_state EQUAL 2)
if(NOT _ack EQUAL _prev_seq)
message(FATAL_ERROR "worker running ack mismatch in ${_line}")
endif()
else()
if(NOT _ack EQUAL _seq)
message(FATAL_ERROR "worker completed ack mismatch in ${_line}")
endif()
endif()
if(_state EQUAL 3)
set(_done_seen TRUE)
endif()
set(_prev_seq "${_seq}")
endif()
endforeach()
if(NOT _done_seen)
message(FATAL_ERROR "worker STOP/DONE state was not observed")
endif()
endfunction()
file(REMOVE_RECURSE "${OUT_DIR}")
file(MAKE_DIRECTORY "${OUT_DIR}/results")
set(_log "${OUT_DIR}/worker_mock.log")
execute_process(
COMMAND "${FEMLITE_EXE}"
--cclite-worker
--case "${SOURCE_DIR}/examples/c3d4_one_element.inp"
--ipc-name mock
--log "${_log}"
--output-dir "${OUT_DIR}/results"
--mock-steps "${STEPS}"
WORKING_DIRECTORY "${SOURCE_DIR}"
RESULT_VARIABLE _rv
OUTPUT_VARIABLE _stdout
ERROR_VARIABLE _stderr
)
if(NOT _rv EQUAL 0)
message(FATAL_ERROR "worker mock failed: ${_stdout}\n${_stderr}")
endif()
file(READ "${_log}" _log_text)
if(NOT _log_text MATCHES "ipc_name,mock")
message(FATAL_ERROR "worker log missed ipc_name")
endif()
if(NOT _log_text MATCHES "mock_steps,${STEPS}")
message(FATAL_ERROR "worker log missed mock_steps")
endif()
if(NOT _log_text MATCHES "1,1,1,0,0,0,1,0")
message(FATAL_ERROR "worker READY state after INIT was not observed")
endif()
if(NOT _log_text MATCHES ",8,${STEPS},0,0,3,0")
message(FATAL_ERROR "worker STOP row was not observed")
endif()
if(NOT EXISTS "${OUT_DIR}/results/results.pvd")
message(FATAL_ERROR "worker did not write PVD output")
endif()
if(NOT EXISTS "${OUT_DIR}/results/femlite_cclite_load_report.csv")
message(FATAL_ERROR "worker did not write coupling load report")
endif()
if(NOT EXISTS "${OUT_DIR}/results/femlite_cclite_surface_report.csv")
message(FATAL_ERROR "worker did not write coupling surface report")
endif()
file(READ "${OUT_DIR}/results/femlite_cclite_load_report.csv" _load_report)
if(NOT _load_report MATCHES "index,node_id,source_id,load_mode,fx,fy,fz,mx,my,mz")
message(FATAL_ERROR "coupling load report header mismatch")
endif()
file(READ "${OUT_DIR}/results/femlite_cclite_surface_report.csv" _surface_report)
if(NOT _surface_report MATCHES "source_id,count,fx,fy,fz,mx,my,mz")
message(FATAL_ERROR "coupling surface report header mismatch")
endif()
check_seq_ack("${_log}")
set(_bad_log "${OUT_DIR}/worker_error.log")
execute_process(
COMMAND "${FEMLITE_EXE}"
--cclite-worker
--case "${SOURCE_DIR}/tests/data/does_not_exist.inp"
--ipc-name mock_error
--log "${_bad_log}"
--output-dir "${OUT_DIR}/bad_results"
--mock-steps 1
WORKING_DIRECTORY "${SOURCE_DIR}"
RESULT_VARIABLE _bad_rv
OUTPUT_VARIABLE _bad_stdout
ERROR_VARIABLE _bad_stderr
)
if(_bad_rv EQUAL 0)
message(FATAL_ERROR "worker error path unexpectedly succeeded")
endif()
file(READ "${_bad_log}" _bad_text)
if(NOT _bad_text MATCHES ",2,0,0,0,-1,")
message(FATAL_ERROR "worker error row was not observed")
endif()