# BozoEngine's tests.
#
# Instruction tests: bozo-test-gen recompiles the cases of instr/cases.cpp into C++ (through the real analysis and
# emitter); bozo-instr-tests compiles that C++ with the stub runtime, runs each case and checks the results.
#   cmake --build build && ctest --test-dir build

set(gen_dir ${CMAKE_CURRENT_BINARY_DIR}/instr_gen)
set(gen_files ${gen_dir}/instr_000.cpp ${gen_dir}/instr_table.cpp ${gen_dir}/instr_functions.h)

add_executable(bozo-test-gen instr/gen_main.cpp instr/cases.cpp)
target_include_directories(bozo-test-gen PRIVATE instr support)
target_link_libraries(bozo-test-gen PRIVATE bozo_recomp_lib bozo_runtime_headers)

add_custom_command(
  OUTPUT ${gen_files}
  COMMAND bozo-test-gen ${gen_dir}
  DEPENDS bozo-test-gen
  COMMENT "Recompiling the instruction test cases")

add_executable(bozo-instr-tests instr/run_main.cpp instr/cases.cpp support/stub_runtime.cpp
  ${gen_dir}/instr_000.cpp ${gen_dir}/instr_table.cpp)
target_include_directories(bozo-instr-tests PRIVATE instr support ${gen_dir})
target_link_libraries(bozo-instr-tests PRIVATE bozo_runtime_headers)
set_source_files_properties(${gen_dir}/instr_000.cpp PROPERTIES COMPILE_OPTIONS "-Wno-unused-label;-Wno-unused-variable")

if(MINGW)
  target_link_options(bozo-test-gen PRIVATE -static)
  target_link_options(bozo-instr-tests PRIVATE -static)
endif()

add_test(NAME instructions COMMAND bozo-instr-tests)

# Optional: with -DBOZO_TEST_ELF=<a game's executable> (never part of the repository), check that every word of its
# code decodes.
if(BOZO_TEST_ELF)
  add_test(NAME elf_decodes COMMAND bozo-recomp ${BOZO_TEST_ELF} --census)
endif()

# The sampling profiler (bozo/app/profiler.h): a spinning thread's function named first.
add_executable(bozo-profiler-tests app/profiler_tests.cpp)
target_link_libraries(bozo-profiler-tests PRIVATE bozo_profiler)
if(MINGW)
  target_link_options(bozo-profiler-tests PRIVATE -static)
endif()
add_test(NAME profiler COMMAND bozo-profiler-tests)

# The runtime core (runtime/): guest memory views, the function table and overrides, COP0 Status.
add_executable(bozo-runtime-tests runtime/runtime_tests.cpp)
target_link_libraries(bozo-runtime-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-runtime-tests PRIVATE -static)
endif()
add_test(NAME runtime COMMAND bozo-runtime-tests)
add_executable(bozo-vu0-simd-tests runtime/vu0_simd_tests.cpp)
target_link_libraries(bozo-vu0-simd-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-vu0-simd-tests PRIVATE -static)
endif()
add_test(NAME vu0_simd COMMAND bozo-vu0-simd-tests)

# The native libraries (runtime/libs): what no call log checks yet (the memory card's save path), and the heap and
# rand rules.
add_executable(bozo-libs-tests libs/libs_tests.cpp)
target_link_libraries(bozo-libs-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-libs-tests PRIVATE -static)
endif()
add_test(NAME libs COMMAND bozo-libs-tests)

# The native mixer and libsd (runtime/audio): the voice-status rules, the clock, libsd's entries, and the reference's
# samples for a fixed scenario (audio/mixer_scenario.h).
add_executable(bozo-audio-tests audio/audio_tests.cpp)
target_link_libraries(bozo-audio-tests PRIVATE bozo_audio)
if(MINGW)
  target_link_options(bozo-audio-tests PRIVATE -static)
endif()
add_test(NAME audio COMMAND bozo-audio-tests)
add_executable(bozo-compiled-library-tests native/compiled_libraries_tests.cpp)
target_link_libraries(bozo-compiled-library-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-compiled-library-tests PRIVATE -static)
endif()
add_test(NAME compiled_libraries COMMAND bozo-compiled-library-tests)
add_executable(bozo-library-semaphore-tests native/library_semaphore_tests.cpp)
target_link_libraries(bozo-library-semaphore-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-semaphore-tests PRIVATE -static)
endif()
add_test(NAME library_semaphores COMMAND bozo-library-semaphore-tests)
set_tests_properties(library_semaphores PROPERTIES TIMEOUT 10)
add_executable(bozo-kernel-services-tests runtime/kernel_services_tests.cpp)
target_link_libraries(bozo-kernel-services-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-kernel-services-tests PRIVATE -static)
endif()
add_test(NAME kernel_services COMMAND bozo-kernel-services-tests)
add_executable(bozo-syscall-tests runtime/syscall_tests.cpp)
target_link_libraries(bozo-syscall-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-syscall-tests PRIVATE -static)
endif()
add_test(NAME syscalls COMMAND bozo-syscall-tests)
add_executable(bozo-thread-sleep-tests runtime/thread_sleep_tests.cpp)
target_link_libraries(bozo-thread-sleep-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-thread-sleep-tests PRIVATE -static)
endif()
add_test(NAME thread_sleep COMMAND bozo-thread-sleep-tests)
add_executable(bozo-deadline-tests runtime/deadline_tests.cpp)
target_link_libraries(bozo-deadline-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-deadline-tests PRIVATE -static)
endif()
add_test(NAME deadlines COMMAND bozo-deadline-tests)
set_tests_properties(deadlines PROPERTIES TIMEOUT 10)
add_executable(bozo-handler-stack-tests runtime/handler_stack_tests.cpp)
target_link_libraries(bozo-handler-stack-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-handler-stack-tests PRIVATE -static)
endif()
add_test(NAME handler_stacks COMMAND bozo-handler-stack-tests)
add_executable(bozo-timer-tests libs/timer_tests.cpp)
target_link_libraries(bozo-timer-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-timer-tests PRIVATE -static)
endif()
add_test(NAME timers COMMAND bozo-timer-tests)
set_tests_properties(timers PROPERTIES TIMEOUT 10)
add_executable(bozo-cd-callback-tests libs/cd_callback_tests.cpp)
target_link_libraries(bozo-cd-callback-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-cd-callback-tests PRIVATE -static)
endif()
add_test(NAME cd_callbacks COMMAND bozo-cd-callback-tests)
set_tests_properties(cd_callbacks PROPERTIES TIMEOUT 10)
add_executable(bozo-mpeg-callbacks-tests libs/mpeg_callbacks_tests.cpp)
target_link_libraries(bozo-mpeg-callbacks-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-mpeg-callbacks-tests PRIVATE -static)
endif()
add_test(NAME mpeg_callbacks COMMAND bozo-mpeg-callbacks-tests)
set_tests_properties(mpeg_callbacks PROPERTIES TIMEOUT 10)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
add_executable(bozo-colour-level-tests render/colour_levels_tests.cpp)
target_link_libraries(bozo-colour-level-tests PRIVATE bozo_render)
if(MINGW)
  target_link_options(bozo-colour-level-tests PRIVATE -static)
endif()
add_test(NAME native_colour_levels COMMAND bozo-colour-level-tests)
add_executable(bozo-draw-in-place-tests render/draw_in_place_tests.cpp)
target_link_libraries(bozo-draw-in-place-tests PRIVATE bozo_render)
if(MINGW)
  target_link_options(bozo-draw-in-place-tests PRIVATE -static)
endif()
add_test(NAME native_draw_in_place COMMAND bozo-draw-in-place-tests)
add_executable(bozo-image-processing-tests render/image_processing_tests.cpp)
target_link_libraries(bozo-image-processing-tests PRIVATE bozo_render)
if(MINGW)
  target_link_options(bozo-image-processing-tests PRIVATE -static)
endif()
add_test(NAME native_image_processing COMMAND bozo-image-processing-tests)
add_test(NAME reference_records COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/native/test_reference.py)
add_test(NAME data_objects_in_code COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/native/test_data_objects.py $<TARGET_FILE:bozo-recomp>)
add_test(NAME delay_slot_labels COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/native/test_delay_slot_labels.py $<TARGET_FILE:bozo-recomp>)
add_test(NAME explicit_entries COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/native/test_entries.py $<TARGET_FILE:bozo-recomp>)
add_test(NAME overrides_take_jumps COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/native/test_overrides_take_jumps.py $<TARGET_FILE:bozo-recomp>)
set(entry_gen "${CMAKE_CURRENT_BINARY_DIR}/explicit_entry_gen")
add_custom_command(
  OUTPUT "${entry_gen}/entries_000.cpp" "${entry_gen}/entries_table.cpp" "${entry_gen}/entries_functions.h"
  COMMAND ${Python3_EXECUTABLE} -I "${CMAKE_CURRENT_SOURCE_DIR}/native/test_entries.py" --emit "${entry_gen}"
  COMMAND $<TARGET_FILE:bozo-recomp> "${entry_gen}/fixture.elf" "${entry_gen}" --prefix entries --files 1
    --entries "${entry_gen}/entries.txt" --patches "${entry_gen}/patches.txt" --no-comments
  DEPENDS bozo-recomp "${CMAKE_CURRENT_SOURCE_DIR}/native/test_entries.py")
add_executable(bozo-entry-tests instr/entries_run.cpp "${entry_gen}/entries_000.cpp" "${entry_gen}/entries_table.cpp")
target_include_directories(bozo-entry-tests PRIVATE "${entry_gen}")
target_link_libraries(bozo-entry-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-entry-tests PRIVATE -static)
endif()
add_test(NAME explicit_entries_adaptations COMMAND bozo-entry-tests "${entry_gen}/fixture.elf")
add_test(NAME function_discovery COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/native/test_discovery.py
  $<TARGET_FILE:bozo-recomp> ${CMAKE_CURRENT_SOURCE_DIR}/../tools/discovery/bozo_discovery_score.py)
set(discovery_gen "${CMAKE_CURRENT_BINARY_DIR}/discovery_gen")
add_custom_command(
  OUTPUT "${discovery_gen}/discovery_000.cpp" "${discovery_gen}/discovery_table.cpp" "${discovery_gen}/discovery_functions.h"
  COMMAND ${Python3_EXECUTABLE} -I "${CMAKE_CURRENT_SOURCE_DIR}/native/test_discovery.py" --emit "${discovery_gen}"
  COMMAND $<TARGET_FILE:bozo-recomp> "${discovery_gen}/fixture.elf" "${discovery_gen}" --prefix discovery --files 1 --no-comments
  DEPENDS bozo-recomp "${CMAKE_CURRENT_SOURCE_DIR}/native/test_discovery.py")
add_executable(bozo-discovery-tests native/discovery_run.cpp "${discovery_gen}/discovery_000.cpp" "${discovery_gen}/discovery_table.cpp")
target_include_directories(bozo-discovery-tests PRIVATE "${discovery_gen}")
target_link_libraries(bozo-discovery-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-discovery-tests PRIVATE -static)
endif()
add_test(NAME function_discovery_runs COMMAND bozo-discovery-tests "${discovery_gen}/fixture.elf")
add_test(NAME strict_irx_generation COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/native/test_irx.py)
add_test(NAME symbol_maps COMMAND ${Python3_EXECUTABLE} -I ${CMAKE_CURRENT_SOURCE_DIR}/native/test_symbol_map.py
  $<TARGET_FILE:bozo-externals> $<TARGET_FILE:bozo-recomp> ${CMAKE_CURRENT_SOURCE_DIR}/../tools/symbolmap/bozo_symbolmap.py)
add_executable(bozo-symbol-map-host-tests native/symbol_map_host_tests.cpp)
target_link_libraries(bozo-symbol-map-host-tests PRIVATE bozo_host)
if(MINGW)
  target_link_options(bozo-symbol-map-host-tests PRIVATE -static)
endif()
add_test(NAME symbol_map_host COMMAND bozo-symbol-map-host-tests)
set_tests_properties(symbol_map_host PROPERTIES TIMEOUT 10)

add_executable(bozo-mipmap-tests render/mipmap_tests.cpp)
target_link_libraries(bozo-mipmap-tests PRIVATE bozo_render)
if(MINGW)
  target_link_options(bozo-mipmap-tests PRIVATE -static)
endif()
add_test(NAME render_mipmap COMMAND bozo-mipmap-tests)
add_executable(bozo-texture-upscale-tests render/texture_upscale_tests.cpp)
target_link_libraries(bozo-texture-upscale-tests PRIVATE bozo_render)
if(MINGW)
  target_link_options(bozo-texture-upscale-tests PRIVATE -static)
endif()
add_test(NAME render_texture_upscale COMMAND bozo-texture-upscale-tests)
set_tests_properties(render_texture_upscale PROPERTIES TIMEOUT 30)
add_executable(bozo-texture-replace-tests render/texture_replace_tests.cpp)
target_link_libraries(bozo-texture-replace-tests PRIVATE bozo_render)
if(MINGW)
  target_link_options(bozo-texture-replace-tests PRIVATE -static)
endif()
add_test(NAME render_texture_replace COMMAND bozo-texture-replace-tests)
set_tests_properties(render_texture_replace PROPERTIES TIMEOUT 30)

if(BOZO_APP)
  add_executable(bozo-image-processing-gpu-tests render/image_processing_gpu_tests.cpp)
  target_link_libraries(bozo-image-processing-gpu-tests PRIVATE bozo_render SDL3::SDL3-static)
  if(MINGW)
    target_link_options(bozo-image-processing-gpu-tests PRIVATE -static)
  endif()
  add_test(NAME native_image_processing_gpu COMMAND bozo-image-processing-gpu-tests)
  set_tests_properties(native_image_processing_gpu PROPERTIES LABELS "gpu")
  add_executable(bozo-render-target-tests render/render_targets_tests.cpp)
  target_link_libraries(bozo-render-target-tests PRIVATE bozo_render SDL3::SDL3-static)
  if(MINGW)
    target_link_options(bozo-render-target-tests PRIVATE -static)
  endif()
  add_test(NAME native_render_targets COMMAND bozo-render-target-tests)
  set_tests_properties(native_render_targets PROPERTIES LABELS "gpu")
  add_executable(bozo-picture-readback-gpu-tests render/picture_readback_gpu_tests.cpp)
  target_link_libraries(bozo-picture-readback-gpu-tests PRIVATE bozo_render SDL3::SDL3-static)
  if(MINGW)
    target_link_options(bozo-picture-readback-gpu-tests PRIVATE -static)
  endif()
  add_test(NAME native_picture_readback_gpu COMMAND bozo-picture-readback-gpu-tests)
  set_tests_properties(native_picture_readback_gpu PROPERTIES LABELS "gpu")
  add_executable(bozo-image-readback-gpu-tests render/image_readback_gpu_tests.cpp)
  target_link_libraries(bozo-image-readback-gpu-tests PRIVATE bozo_render SDL3::SDL3-static)
  if(MINGW)
    target_link_options(bozo-image-readback-gpu-tests PRIVATE -static)
  endif()
  add_test(NAME native_image_readback_gpu COMMAND bozo-image-readback-gpu-tests)
  set_tests_properties(native_image_readback_gpu PROPERTIES LABELS "gpu")
endif()

# Unused native image definitions must not write packets; generic SDK output is retained.
add_executable(bozo-image-builders-tests libs/image_builders_tests.cpp)
target_link_libraries(bozo-image-builders-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-image-builders-tests PRIVATE -static)
endif()
add_test(NAME native_image_builders COMMAND bozo-image-builders-tests)

# Native graphics services retain no GS register/transfer bank or packet readers.
add_executable(bozo-port-hooks-tests native/port_hooks_tests.cpp)
target_link_libraries(bozo-port-hooks-tests PRIVATE bozo_host)
if(MINGW)
  target_link_options(bozo-port-hooks-tests PRIVATE -static)
endif()
add_test(NAME port_hooks COMMAND bozo-port-hooks-tests)
set_tests_properties(port_hooks PROPERTIES TIMEOUT 10)
add_executable(bozo-native-graphics-tests libs/native_graphics_tests.cpp)
target_link_libraries(bozo-native-graphics-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-native-graphics-tests PRIVATE -static)
endif()
add_test(NAME native_graphics_boundary COMMAND bozo-native-graphics-tests)

# Validate the whole adaptation batch before changing the offline analysis image.
add_executable(bozo-instruction-patch-tests instr/patch_tests.cpp)
target_link_libraries(bozo-instruction-patch-tests PRIVATE bozo_recomp_lib)
if(MINGW)
  target_link_options(bozo-instruction-patch-tests PRIVATE -static)
endif()
add_test(NAME guarded_instruction_adaptations COMMAND bozo-instruction-patch-tests)
add_executable(bozo-library-binding-tests native/library_binding_tests.cpp)
target_link_libraries(bozo-library-binding-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-binding-tests PRIVATE -static)
endif()
add_test(NAME library_bindings COMMAND bozo-library-binding-tests)
set_tests_properties(library_bindings PROPERTIES TIMEOUT 10)
add_executable(bozo-library-memory-tests native/library_memory_tests.cpp)
target_link_libraries(bozo-library-memory-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-memory-tests PRIVATE -static)
endif()
add_test(NAME library_memory COMMAND bozo-library-memory-tests)
set_tests_properties(library_memory PROPERTIES TIMEOUT 10)
add_executable(bozo-library-sysclib-words-tests native/library_sysclib_words_tests.cpp)
target_link_libraries(bozo-library-sysclib-words-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-sysclib-words-tests PRIVATE -static)
endif()
add_test(NAME library_sysclib_words COMMAND bozo-library-sysclib-words-tests)
set_tests_properties(library_sysclib_words PROPERTIES TIMEOUT 10)
add_executable(bozo-library-rpc-context-tests native/library_rpc_context_tests.cpp)
target_link_libraries(bozo-library-rpc-context-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-rpc-context-tests PRIVATE -static)
endif()
add_test(NAME library_rpc_context COMMAND bozo-library-rpc-context-tests)
set_tests_properties(library_rpc_context PROPERTIES TIMEOUT 10)
add_executable(bozo-library-rpc-blocking-tests native/library_rpc_blocking_tests.cpp)
target_link_libraries(bozo-library-rpc-blocking-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-rpc-blocking-tests PRIVATE -static)
endif()
add_test(NAME library_rpc_blocking COMMAND bozo-library-rpc-blocking-tests)
set_tests_properties(library_rpc_blocking PROPERTIES TIMEOUT 10)
add_executable(bozo-library-cpu-interrupt-tests native/library_cpu_interrupt_tests.cpp)
target_link_libraries(bozo-library-cpu-interrupt-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-cpu-interrupt-tests PRIVATE -static)
endif()
add_test(NAME library_cpu_interrupts COMMAND bozo-library-cpu-interrupt-tests)
set_tests_properties(library_cpu_interrupts PROPERTIES TIMEOUT 10)
add_executable(bozo-library-exclusion-tests native/library_exclusion_tests.cpp)
target_link_libraries(bozo-library-exclusion-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-exclusion-tests PRIVATE -static)
endif()
add_test(NAME library_exclusion COMMAND bozo-library-exclusion-tests)
set_tests_properties(library_exclusion PROPERTIES TIMEOUT 10)
add_executable(bozo-library-bulk-copy-tests native/library_bulk_copy_tests.cpp)
target_link_libraries(bozo-library-bulk-copy-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-bulk-copy-tests PRIVATE -static)
endif()
add_test(NAME library_bulk_copy COMMAND bozo-library-bulk-copy-tests)
set_tests_properties(library_bulk_copy PROPERTIES TIMEOUT 10)
add_executable(bozo-library-priority-semaphore-tests native/library_priority_semaphore_tests.cpp)
target_link_libraries(bozo-library-priority-semaphore-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-priority-semaphore-tests PRIVATE -static)
endif()
add_test(NAME library_priority_semaphores COMMAND bozo-library-priority-semaphore-tests)
set_tests_properties(library_priority_semaphores PROPERTIES TIMEOUT 10)
add_executable(bozo-ready-audio-completion-tests native/ready_audio_completion_tests.cpp)
target_link_libraries(bozo-ready-audio-completion-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-ready-audio-completion-tests PRIVATE -static)
endif()
add_test(NAME ready_audio_completions COMMAND bozo-ready-audio-completion-tests)
set_tests_properties(ready_audio_completions PROPERTIES TIMEOUT 10)
add_executable(bozo-library-timer-handler-tests native/library_timer_handler_tests.cpp)
target_link_libraries(bozo-library-timer-handler-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-timer-handler-tests PRIVATE -static)
endif()
add_test(NAME library_timer_handlers COMMAND bozo-library-timer-handler-tests)
set_tests_properties(library_timer_handlers PROPERTIES TIMEOUT 10)
add_executable(bozo-library-alarm-tests native/library_alarm_tests.cpp)
target_link_libraries(bozo-library-alarm-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-alarm-tests PRIVATE -static)
endif()
add_test(NAME library_alarms COMMAND bozo-library-alarm-tests)
set_tests_properties(library_alarms PROPERTIES TIMEOUT 10)
add_executable(bozo-library-block-ring-tests native/library_block_ring_tests.cpp)
target_link_libraries(bozo-library-block-ring-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-block-ring-tests PRIVATE -static)
endif()
add_test(NAME library_block_ring COMMAND bozo-library-block-ring-tests)
set_tests_properties(library_block_ring PROPERTIES TIMEOUT 10)
add_executable(bozo-library-host-services-tests native/library_host_services_tests.cpp)
target_link_libraries(bozo-library-host-services-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-host-services-tests PRIVATE -static)
endif()
add_test(NAME library_host_services COMMAND bozo-library-host-services-tests)
set_tests_properties(library_host_services PROPERTIES TIMEOUT 10)
add_executable(bozo-library-event-flags-tests native/library_event_flags_tests.cpp)
target_link_libraries(bozo-library-event-flags-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-event-flags-tests PRIVATE -static)
endif()
add_test(NAME library_event_flags COMMAND bozo-library-event-flags-tests)
set_tests_properties(library_event_flags PROPERTIES TIMEOUT 10)
add_executable(bozo-library-ee-rpc-tests native/library_ee_rpc_tests.cpp)
target_link_libraries(bozo-library-ee-rpc-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-ee-rpc-tests PRIVATE -static)
endif()
add_test(NAME library_ee_rpc COMMAND bozo-library-ee-rpc-tests)
set_tests_properties(library_ee_rpc PROPERTIES TIMEOUT 10)
add_executable(bozo-library-frame-listener-tests native/library_frame_listener_tests.cpp)
target_link_libraries(bozo-library-frame-listener-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-frame-listener-tests PRIVATE -static)
endif()
add_test(NAME library_frame_listeners COMMAND bozo-library-frame-listener-tests)
set_tests_properties(library_frame_listeners PROPERTIES TIMEOUT 10)
add_executable(bozo-library-command-tests native/library_command_tests.cpp)
target_link_libraries(bozo-library-command-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-command-tests PRIVATE -static)
endif()
add_test(NAME library_user_commands COMMAND bozo-library-command-tests)
set_tests_properties(library_user_commands PROPERTIES TIMEOUT 10)
add_executable(bozo-library-sreg-tests native/library_sreg_tests.cpp)
target_link_libraries(bozo-library-sreg-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-sreg-tests PRIVATE -static)
endif()
add_test(NAME library_sregs COMMAND bozo-library-sreg-tests)
set_tests_properties(library_sregs PROPERTIES TIMEOUT 10)
add_executable(bozo-library-allocation-tests native/library_allocation_tests.cpp)
target_link_libraries(bozo-library-allocation-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-allocation-tests PRIVATE -static)
endif()
add_test(NAME library_allocation_views COMMAND bozo-library-allocation-tests)
set_tests_properties(library_allocation_views PROPERTIES TIMEOUT 10)
add_executable(bozo-library-reply-tests native/library_reply_tests.cpp)
target_link_libraries(bozo-library-reply-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-reply-tests PRIVATE -static)
endif()
add_test(NAME library_command_replies COMMAND bozo-library-reply-tests)
set_tests_properties(library_command_replies PROPERTIES TIMEOUT 10)
add_executable(bozo-library-disc-files-tests native/library_disc_files_tests.cpp)
target_link_libraries(bozo-library-disc-files-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-disc-files-tests PRIVATE -static)
endif()
add_test(NAME library_disc_files COMMAND bozo-library-disc-files-tests)
set_tests_properties(library_disc_files PROPERTIES TIMEOUT 10)
add_executable(bozo-library-disc-commands-tests native/library_disc_commands_tests.cpp)
target_link_libraries(bozo-library-disc-commands-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-disc-commands-tests PRIVATE -static)
endif()
add_test(NAME library_disc_commands COMMAND bozo-library-disc-commands-tests)
set_tests_properties(library_disc_commands PROPERTIES TIMEOUT 10)
add_executable(bozo-library-disc-stream-tests native/library_disc_stream_tests.cpp)
target_link_libraries(bozo-library-disc-stream-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-disc-stream-tests PRIVATE -static)
endif()
add_test(NAME library_disc_stream COMMAND bozo-library-disc-stream-tests)
set_tests_properties(library_disc_stream PROPERTIES TIMEOUT 10)
add_executable(bozo-library-heap-queries-tests native/library_heap_queries_tests.cpp)
target_link_libraries(bozo-library-heap-queries-tests PRIVATE bozo_libs)
if(MINGW)
  target_link_options(bozo-library-heap-queries-tests PRIVATE -static)
endif()
add_test(NAME library_heap_queries COMMAND bozo-library-heap-queries-tests)
set_tests_properties(library_heap_queries PROPERTIES TIMEOUT 10)

# Save states (bozo/state.h): archives, files, a dispatcher saved and loaded.
add_executable(bozo-state-tests runtime/state_tests.cpp)
target_link_libraries(bozo-state-tests PRIVATE bozo_runtime_core)
if(MINGW)
  target_link_options(bozo-state-tests PRIVATE -static)
endif()
add_test(NAME state COMMAND bozo-state-tests)
