find_package(GTest CONFIG REQUIRED)
add_executable(symbian_firmware_tests firmware_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_options(symbian_firmware_tests PRIVATE -fno-exceptions)
target_link_libraries(symbian_firmware_tests PRIVATE
                     symbian_emulator_firmware epoc config drivers GTest::gtest_main)
add_test(NAME symbian_firmware_tests COMMAND symbian_firmware_tests)
add_executable(symbian_e32_oracle e32_oracle_test.cc)
add_executable(symbian_eka1_oracle eka1_oracle_test.cc)
target_compile_features(symbian_eka1_oracle PRIVATE cxx_std_20)
target_compile_options(symbian_eka1_oracle PRIVATE -fno-exceptions)
target_link_libraries(symbian_eka1_oracle PRIVATE
                      epocloader common GTest::gtest_main)
# EKA1 has independent opt-in fixtures. Keep it out of the EKA2 verifier's
# complete four-case suite; skipped cases cannot count as verification.
add_executable(symbian_rom_atomic_oracle rom_atomic_oracle.cc)
target_compile_features(symbian_rom_atomic_oracle PRIVATE cxx_std_20)
target_compile_options(symbian_rom_atomic_oracle PRIVATE -fno-exceptions)
target_link_libraries(symbian_rom_atomic_oracle PRIVATE
                      epocloader epocmem config common)
target_compile_features(symbian_e32_oracle PRIVATE cxx_std_20)
target_compile_options(symbian_e32_oracle PRIVATE -fno-exceptions)
target_link_libraries(symbian_e32_oracle PRIVATE
                      epocloader common GTest::gtest_main)
set(SYMBIAN_E32_TEST_IMAGE
    "${SYMBIAN_PLATFORM_ROOT}/.symbian/e32-probe/e32_probe.exe" CACHE FILEPATH
    "Experimental executable to check with the independent EKA2L1 parser")
enable_testing()
add_test(NAME symbian_e32_oracle COMMAND symbian_e32_oracle)
set_tests_properties(symbian_e32_oracle PROPERTIES
  ENVIRONMENT "SYMBIAN_E32_TEST_IMAGE=${SYMBIAN_E32_TEST_IMAGE}" TIMEOUT 15)

# The checksum implementation stays in the pinned upstream checkout with its
# original EPL license. Keep this oracle separate from the GPL emulator binary.
set(SYMBIAN_CHECKSUM_SOURCE_DIR
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/buildtools/toolsandutils/e32tools/elf2e32/source"
    CACHE PATH "Pinned Nokia elf2e32 checksum source")
add_library(symbian_historical_checksum STATIC
            "${SYMBIAN_CHECKSUM_SOURCE_DIR}/checksum.cpp")
target_compile_options(symbian_historical_checksum PRIVATE -fno-exceptions
  -include "${CMAKE_CURRENT_SOURCE_DIR}/checksum_host_types.h")
target_include_directories(symbian_historical_checksum PUBLIC
                           "${SYMBIAN_CHECKSUM_SOURCE_DIR}")
add_executable(symbian_checksum_oracle checksum_oracle_test.cc)
target_compile_features(symbian_checksum_oracle PRIVATE cxx_std_20)
target_compile_options(symbian_checksum_oracle PRIVATE -fno-exceptions)
target_include_directories(symbian_checksum_oracle PRIVATE
                           "${SYMBIAN_PLATFORM_ROOT}/cpp")
target_link_libraries(symbian_checksum_oracle PRIVATE
                      symbian_historical_checksum GTest::gtest_main)
add_test(NAME symbian_checksum_oracle COMMAND symbian_checksum_oracle)
set_tests_properties(symbian_checksum_oracle PROPERTIES
  ENVIRONMENT "SYMBIAN_E32_TEST_IMAGE=${SYMBIAN_E32_TEST_IMAGE}" TIMEOUT 15)

set(SYMBIAN_KERNEL_SOURCE_DIR
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/kernelhwsrv" CACHE PATH
    "Pinned Nokia kernel and loader headers")
add_executable(symbian_validator_oracle validator_oracle_test.cc)
target_compile_features(symbian_validator_oracle PRIVATE cxx_std_20)
target_compile_options(symbian_validator_oracle PRIVATE
                       -fno-exceptions -Wno-invalid-offsetof)
target_include_directories(symbian_validator_oracle PRIVATE
    "${SYMBIAN_KERNEL_SOURCE_DIR}/kernel/eka/include"
    "${SYMBIAN_KERNEL_SOURCE_DIR}/userlibandfileserver/fileserver/inc")
target_link_libraries(symbian_validator_oracle PRIVATE
                      symbian_historical_checksum GTest::gtest_main)
add_test(NAME symbian_validator_oracle COMMAND symbian_validator_oracle)
set_tests_properties(symbian_validator_oracle PROPERTIES
  ENVIRONMENT "SYMBIAN_E32_TEST_IMAGE=${SYMBIAN_E32_TEST_IMAGE}" TIMEOUT 15)

add_executable(symbian_cpu_probe cpu_probe_test.cc)
target_compile_features(symbian_cpu_probe PRIVATE cxx_std_20)
target_compile_options(symbian_cpu_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_cpu_probe PRIVATE
                      cpu epocloader common GTest::gtest_main)
add_test(NAME symbian_cpu_probe COMMAND symbian_cpu_probe)
set_tests_properties(symbian_cpu_probe PROPERTIES
  ENVIRONMENT "SYMBIAN_E32_TEST_IMAGE=${SYMBIAN_E32_TEST_IMAGE}" TIMEOUT 15)

add_executable(symbian_cpu_strexd cpu_strexd_test.cc)
target_compile_features(symbian_cpu_strexd PRIVATE cxx_std_20)
target_compile_options(symbian_cpu_strexd PRIVATE -fno-exceptions)
target_link_libraries(symbian_cpu_strexd PRIVATE cpu GTest::gtest_main)
add_test(NAME symbian_cpu_strexd COMMAND symbian_cpu_strexd)
set_tests_properties(symbian_cpu_strexd PROPERTIES TIMEOUT 15)

add_executable(symbian_process_probe process_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_process_probe PRIVATE cxx_std_20)
target_compile_options(symbian_process_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_process_probe PRIVATE
                      epoc epockern epocmem epoctiming epocio GTest::gtest_main)
add_test(NAME symbian_process_probe COMMAND symbian_process_probe)
set_tests_properties(symbian_process_probe PROPERTIES
  ENVIRONMENT "SYMBIAN_E32_TEST_IMAGE=${SYMBIAN_E32_TEST_IMAGE}" TIMEOUT 15)

add_executable(symbian_package_probe package_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_package_probe PRIVATE cxx_std_20)
target_compile_options(symbian_package_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_package_probe PRIVATE
                      epoc epockern epocmem epoctiming epocio epocpkg GTest::gtest_main)
set(SYMBIAN_SIS_TEST_PACKAGE
    "${SYMBIAN_PLATFORM_ROOT}/.symbian/package/probe.sis" CACHE FILEPATH
    "Maintained canonical SISX experiment, prevalidated by the native core")
add_test(NAME symbian_package_probe COMMAND symbian_package_probe)
set_tests_properties(symbian_package_probe PROPERTIES
  ENVIRONMENT "SYMBIAN_E32_TEST_IMAGE=${SYMBIAN_E32_TEST_IMAGE};SYMBIAN_SIS_TEST_PACKAGE=${SYMBIAN_SIS_TEST_PACKAGE}"
  TIMEOUT 15)

add_executable(symbian_gui_package_probe gui_package_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_gui_package_probe PRIVATE cxx_std_20)
target_compile_options(symbian_gui_package_probe PRIVATE -fno-exceptions)
target_include_directories(symbian_gui_package_probe PRIVATE
  "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/emu/services/include")
target_link_libraries(symbian_gui_package_probe PRIVATE
                      epoc epockern epocmem epoctiming epocio epocpkg epocloader
                      epocservs GTest::gtest_main)
# The Python verifier supplies a private exact payload and independent hash.
# Direct replay also requires SYMBIAN_E32_TEST_HASH; no default hash is invented.
add_test(NAME symbian_gui_package_probe COMMAND symbian_gui_package_probe)
set_tests_properties(symbian_gui_package_probe PROPERTIES
  ENVIRONMENT "SYMBIAN_E32_TEST_IMAGE=${SYMBIAN_PLATFORM_ROOT}/.symbian/gui-app/gui_app.exe;SYMBIAN_SIS_TEST_PACKAGE=${SYMBIAN_PLATFORM_ROOT}/.symbian/gui-package/gui_app.sis"
  TIMEOUT 15)

# Separate historical EPL oracle; no emulator or production format code linked.
add_executable(symbian_firmware_import_probe firmware_import_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_firmware_import_probe PRIVATE cxx_std_20)
target_compile_options(symbian_firmware_import_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_firmware_import_probe PRIVATE
                      epoc epockern epocmem epoctiming epocio epocloader GTest::gtest_main)
# Opt-in research test with a new explicit output root; no physical transport.

add_executable(symbian_rom_abi_probe rom_abi_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_rom_abi_probe PRIVATE cxx_std_20)
target_compile_options(symbian_rom_abi_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_rom_abi_probe PRIVATE
                      epoc epockern epocmem epoctiming epocio epocloader GTest::gtest_main)
# Opt-in trusted-firmware analysis, excluded from default CTest and the wheel.

add_executable(symbian_svc_profile_probe svc_profile_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_svc_profile_probe PRIVATE cxx_std_20)
target_compile_options(symbian_svc_profile_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_svc_profile_probe PRIVATE
                      epoc epockern epocmem epoctiming epocio epocloader GTest::gtest_main)
add_test(NAME symbian_svc_profile_probe COMMAND symbian_svc_profile_probe)

add_executable(symbian_cpu_register_probe cpu_register_probe_test.cc)
target_compile_features(symbian_cpu_register_probe PRIVATE cxx_std_20)
target_compile_options(symbian_cpu_register_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_cpu_register_probe PRIVATE cpu GTest::gtest_main)
add_test(NAME symbian_cpu_register_probe COMMAND symbian_cpu_register_probe)
set_tests_properties(symbian_cpu_register_probe PROPERTIES TIMEOUT 15)

add_executable(symbian_sis_checksum_oracle sis_checksum_oracle_test.cc)
target_compile_features(symbian_sis_checksum_oracle PRIVATE cxx_std_20)
target_compile_options(symbian_sis_checksum_oracle PRIVATE -fno-exceptions)
target_include_directories(symbian_sis_checksum_oracle PRIVATE
                           "${SYMBIAN_PLATFORM_ROOT}/cpp")
target_link_libraries(symbian_sis_checksum_oracle PRIVATE
                      symbian_historical_checksum GTest::gtest_main)
add_test(NAME symbian_sis_checksum_oracle COMMAND symbian_sis_checksum_oracle)
set_tests_properties(symbian_sis_checksum_oracle PROPERTIES
  ENVIRONMENT "SYMBIAN_SIS_TEST_PACKAGE=${SYMBIAN_SIS_TEST_PACKAGE}" TIMEOUT 15)

# Trusted development DLL fixture, separate from the production wheel.
add_executable(symbian_dll_fixture dll_fixture.cc)
target_compile_features(symbian_dll_fixture PRIVATE cxx_std_20)
target_compile_options(symbian_dll_fixture PRIVATE -fno-exceptions
                       -Wno-invalid-offsetof)
target_include_directories(symbian_dll_fixture PRIVATE
    "${SYMBIAN_KERNEL_SOURCE_DIR}/kernel/eka/include"
    "${SYMBIAN_KERNEL_SOURCE_DIR}/userlibandfileserver/fileserver/inc")
target_link_libraries(symbian_dll_fixture PRIVATE symbian_historical_checksum)

add_executable(symbian_import_probe import_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_import_probe PRIVATE cxx_std_20)
target_compile_options(symbian_import_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_import_probe PRIVATE
                      epoc epockern epocmem epoctiming epocio epocloader GTest::gtest_main)
add_test(NAME symbian_import_probe COMMAND symbian_import_probe)
set_tests_properties(symbian_import_probe PROPERTIES
  ENVIRONMENT "SYMBIAN_E32_TEST_IMAGE=${SYMBIAN_PLATFORM_ROOT}/.symbian/import-probe/import_probe.exe;SYMBIAN_DLL_TEST_IMAGE=${SYMBIAN_PLATFORM_ROOT}/.symbian/native-dll/probe.dll"
  TIMEOUT 15)

add_executable(symbian_import_data_probe import_data_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_import_data_probe PRIVATE cxx_std_20)
target_compile_options(symbian_import_data_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_import_data_probe PRIVATE
                      epoc epockern epocmem epoctiming epocio epocloader GTest::gtest_main)

add_executable(symbian_pointer_probe pointer_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_pointer_probe PRIVATE cxx_std_20)
target_compile_options(symbian_pointer_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_pointer_probe PRIVATE
                      epoc epockern epocmem epoctiming epocio epocloader GTest::gtest_main)
add_test(NAME symbian_pointer_probe COMMAND symbian_pointer_probe)
set_tests_properties(symbian_pointer_probe PROPERTIES
  ENVIRONMENT "SYMBIAN_E32_TEST_IMAGE=${SYMBIAN_PLATFORM_ROOT}/.symbian/pointer-probe/pointer_probe.exe"
  TIMEOUT 15)

add_executable(symbian_control_probe control_probe_test.cc
    "${SYMBIAN_PLATFORM_ROOT}/research/upstream/EKA2L1/src/tests/platform.cpp")
target_compile_features(symbian_control_probe PRIVATE cxx_std_20)
target_compile_options(symbian_control_probe PRIVATE -fno-exceptions)
target_link_libraries(symbian_control_probe PRIVATE
                      symbian_emulator_control epoc epockern epocmem epoctiming epocio
                      GTest::gtest_main)
add_test(NAME symbian_control_probe COMMAND symbian_control_probe)
set_tests_properties(symbian_control_probe PROPERTIES TIMEOUT 15)

# These GPL integration TUs include original emulator throwing templates.
# Their foreign-library boundary needs exceptions; SDK native libraries do not.
file(GLOB symbian_eka2l1_boundary_sources CONFIGURE_DEPENDS
     "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
set_source_files_properties(${symbian_eka2l1_boundary_sources}
  PROPERTIES COMPILE_OPTIONS -fexceptions)
