# Host tests for the shim's trace/compare infrastructure (src/shim/trace). The Python
# oracle (sots-re/verify/harness/compare) is used when SOTS_TRACECMP_DIR points at it;
# the tests skip those steps cleanly otherwise.
set(SOTS_TRACECMP_DIR "$ENV{HOME}/sots-re/verify/harness/compare" CACHE PATH
    "Directory holding tracecmp.py + mkfixture.py (python oracle for the trace tests)")

set(_out ${CMAKE_CURRENT_BINARY_DIR}/out)
file(MAKE_DIRECTORY ${_out})

foreach(_t sha256 emitter diff hook coverage)
  add_executable(shim_trace_test_${_t} test_${_t}.cpp)
  target_link_libraries(shim_trace_test_${_t} PRIVATE shim_trace)
  target_compile_options(shim_trace_test_${_t} PRIVATE -Wall -Wextra -Werror)
  target_compile_definitions(shim_trace_test_${_t} PRIVATE SOTS_TRACECMP_DIR="${SOTS_TRACECMP_DIR}")
endforeach()
target_link_libraries(shim_trace_test_hook PRIVATE pthread)

add_test(NAME shim_trace_sha256 COMMAND shim_trace_test_sha256)
add_test(NAME shim_trace_emitter COMMAND shim_trace_test_emitter ${_out}/emitter_oracle.jsonl
         ${CMAKE_CURRENT_SOURCE_DIR}/oracle_emit.py)
add_test(NAME shim_trace_diff COMMAND shim_trace_test_diff)
# Every hook descriptor's coverage declaration, checked on the host (the descriptors themselves
# only compile on the MinGW cross build, so this is where an unaudited hook gets caught).
target_link_libraries(shim_trace_test_coverage PRIVATE shim_techfx)
add_test(NAME shim_trace_coverage COMMAND shim_trace_test_coverage)
add_test(NAME shim_trace_hook COMMAND shim_trace_test_hook ${_out})
