if(BUILD_TESTING)
    add_test_executable(guest_owned_memory_tests ${LIBS_INCLUDE_DIR}/tests/GuestOwnedMemory.cpp)
    target_include_directories(guest_owned_memory_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_owned_memory_tests PRIVATE libc)
    configure_windows_unwind(guest_owned_memory_tests)
    add_test(NAME guest_owned_memory COMMAND guest_owned_memory_tests)
    set_tests_properties(guest_owned_memory PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_owned_memory PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    if(WIN32)
        add_test_executable(guest_owned_memory_limits_tests ${LIBS_INCLUDE_DIR}/tests/GuestOwnedMemoryLimits.cpp)
        target_include_directories(guest_owned_memory_limits_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_compile_definitions(guest_owned_memory_limits_tests PRIVATE GUEST_OWNED_LIMIT_TEST=1)
        configure_host_test_executable(guest_owned_memory_limits_tests)
        add_test(NAME guest_owned_memory_limits COMMAND guest_owned_memory_limits_tests)
        set_tests_properties(guest_owned_memory_limits PROPERTIES TIMEOUT 30)

        add_test_executable(windows_mappings_release_tests ${LIBS_INCLUDE_DIR}/tests/WindowsMappingsRelease.cpp)
        target_include_directories(windows_mappings_release_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(windows_mappings_release_tests PRIVATE libc)
        configure_windows_unwind(windows_mappings_release_tests)
        add_test(NAME windows_mappings_release COMMAND windows_mappings_release_tests)
        set_tests_properties(windows_mappings_release PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        foreach(mode 0 1 2)
            add_test(NAME windows_mappings_release_mismatch_${mode} COMMAND windows_mappings_release_tests ${mode})
            set_tests_properties(windows_mappings_release_mismatch_${mode} PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endforeach()

        add_test_executable(windows_mappings_lock_tests ${LIBS_INCLUDE_DIR}/tests/WindowsMappingsLock.cpp)
        target_include_directories(windows_mappings_lock_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(windows_mappings_lock_tests PRIVATE libc)
        configure_windows_unwind(windows_mappings_lock_tests)
        add_test(NAME windows_mappings_lock COMMAND windows_mappings_lock_tests)
        add_test(NAME windows_mappings_lock_pthread COMMAND windows_mappings_lock_tests)
        set_tests_properties(windows_mappings_lock windows_mappings_lock_pthread PROPERTIES TIMEOUT 60
            ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        set_tests_properties(windows_mappings_lock_pthread PROPERTIES ENVIRONMENT "APS5_MAPPINGS_PTHREAD_LOCK=1")
    endif()

    add_test_executable(guest_memmove_snapshot_tests ${LIBS_INCLUDE_DIR}/tests/GuestMemmoveSnapshot.cpp)
    target_include_directories(guest_memmove_snapshot_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_memmove_snapshot_tests PRIVATE libc)
    configure_windows_unwind(guest_memmove_snapshot_tests)
    add_test(NAME guest_memmove_snapshot COMMAND guest_memmove_snapshot_tests)
    set_tests_properties(guest_memmove_snapshot PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_memmove_snapshot PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_binary_word_tests ${LIBS_INCLUDE_DIR}/tests/GuestBinaryWord.cpp)
    target_include_directories(guest_binary_word_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_binary_word_tests PRIVATE libc)
    configure_windows_unwind(guest_binary_word_tests)
    add_test(NAME guest_binary_word COMMAND guest_binary_word_tests guest_binary_word.tmp)
    set_tests_properties(guest_binary_word PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_binary_word PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_strndup_guarded_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrndupGuarded.cpp)
    target_include_directories(guest_strndup_guarded_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strndup_guarded_tests PRIVATE libc)
    configure_windows_unwind(guest_strndup_guarded_tests)
    add_test(NAME guest_strndup_guarded COMMAND guest_strndup_guarded_tests)
    set_tests_properties(guest_strndup_guarded PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strndup_guarded PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_stream_purge_tests ${LIBS_INCLUDE_DIR}/tests/GuestStreamPurge.cpp)
    target_include_directories(guest_stream_purge_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_stream_purge_tests PRIVATE libc)
    configure_windows_unwind(guest_stream_purge_tests)
    add_test(NAME guest_stream_purge COMMAND guest_stream_purge_tests)
    set_tests_properties(guest_stream_purge PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_stream_purge PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_bsearch_packed_tests ${LIBS_INCLUDE_DIR}/tests/GuestBsearchPacked.cpp)
    target_include_directories(guest_bsearch_packed_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_bsearch_packed_tests PRIVATE libc)
    configure_windows_unwind(guest_bsearch_packed_tests)
    add_test(NAME guest_bsearch_packed COMMAND guest_bsearch_packed_tests)
    set_tests_properties(guest_bsearch_packed PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_bsearch_packed PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_safe_error_tests ${LIBS_INCLUDE_DIR}/tests/GuestSafeErrors.cpp)
    target_include_directories(guest_safe_error_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_safe_error_tests PRIVATE libc)
    configure_windows_unwind(guest_safe_error_tests)
    add_test(NAME guest_safe_errors COMMAND guest_safe_error_tests)
    set_tests_properties(guest_safe_errors PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_safe_errors PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_radix64_tests ${LIBS_INCLUDE_DIR}/tests/GuestRadix64.cpp)
    target_include_directories(guest_radix64_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_radix64_tests PRIVATE libc)
    configure_windows_unwind(guest_radix64_tests)
    add_test(NAME guest_radix64 COMMAND guest_radix64_tests)
    set_tests_properties(guest_radix64 PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_radix64 PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_queue_tests ${LIBS_INCLUDE_DIR}/tests/GuestQueue.cpp)
    target_include_directories(guest_queue_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_queue_tests PRIVATE libc)
    configure_windows_unwind(guest_queue_tests)
    add_test(NAME guest_queue COMMAND guest_queue_tests)
    set_tests_properties(guest_queue PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_queue PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(BUILD_TESTING)
    add_test_executable(guest_bounded_search_guards_tests ${LIBS_INCLUDE_DIR}/tests/GuestBoundedSearchGuards.cpp)
    target_include_directories(guest_bounded_search_guards_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_bounded_search_guards_tests PRIVATE libc)
    configure_windows_unwind(guest_bounded_search_guards_tests)
    add_test(NAME guest_bounded_search_guards COMMAND guest_bounded_search_guards_tests)
    set_tests_properties(guest_bounded_search_guards PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_bounded_search_guards PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_bounded_copy_blocks_tests ${LIBS_INCLUDE_DIR}/tests/GuestBoundedCopyBlocks.cpp)
    target_include_directories(guest_bounded_copy_blocks_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_bounded_copy_blocks_tests PRIVATE libc)
    configure_windows_unwind(guest_bounded_copy_blocks_tests)
    add_test(NAME guest_bounded_copy_blocks COMMAND guest_bounded_copy_blocks_tests)
    if(WIN32)
        set_tests_properties(guest_bounded_copy_blocks PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

target_sources(libc PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/Export.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/General.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/PreciseWait.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/AppArchive.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/AppArchiveBacking.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/CreationMask.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/FailureReport.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LogFilePlatform.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LogFile.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/RunReport.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/specifics/gcc/StackGuard.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/specifics/windows/CrashReport.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/specifics/windows/GuestGs.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/specifics/x86_64/CallTrace.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/specifics/linux/CrashReport.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/specifics/linux/DlIteratePhdr.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/specifics/linux/GuestFaultCopy.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/specifics/macos/GuestGs.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/specifics/macos/GuestImages.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Strings.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/AllocatingStrings.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/WideConversion.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/BoundsChecking.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Multibyte.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/RuneLocale.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/CLocaleHelpers.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/StringExtensions.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxStringSearch.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/GetSubOpt.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/VectorAlgorithms.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Math.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/MathExact.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/VersionedExtendedPrecision.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Bessel.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/J0f.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/J1f.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/TrueGamma.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Jnf.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Random.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/VersionedMultiprecision.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/FloatBuiltins.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/FloatingPrefix.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/HostEntropy.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Backtrace.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/DinkumwareAtomics.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/DinkumwareInternals.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxNextPrime.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxSort.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxThreadState.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Time.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/TimeExtras.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Fmtmsg.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Getwd.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxIntegerToString.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/AtomicBuiltins.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/FileAndHeap.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/HashSearch.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/SearchTree.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Mergesort.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Heapsort.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/HostErrno.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/FileLock.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/StdioExtras.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/StandardStreams.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/StreamPurge.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/VersionedStreamInit.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/GuestAllocations.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/MemoryResource.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/GuestArena.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/GuestStacks.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/GuestWriteWatch.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Interfaces.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/GuestHeap.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/HeapDiagnostics.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Mspace.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/ApplicationHeap.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/ApplicationProcessParameters.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/JumpBuffer.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Formatting.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/ScanWideField.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/FormattingWide.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/ScanningWide.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/RuntimeSupport.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/IntegerBuiltins.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LocaleSupport.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/SonyCrt.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Process.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Hostname.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/DeviceName.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Environment.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Directory.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Filesystem.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/VersionedFilesystem.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/VersionedFilesystemCalls.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/AtomicWait.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxMutex.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Rename.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Errors.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Syslog.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/RealPath.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/CxxAbiSupport.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Threads.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxCondition.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Backtrace.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/exception/Exports.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Radix64.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/Queue.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxStringErase.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/LibcxxPlainMutex.cpp
        ${CMAKE_CURRENT_SOURCE_DIR}/src/NumericLimits.cpp
)

find_package(Git QUIET)
set(runReportRevisionRoot ${CMAKE_CURRENT_BINARY_DIR}/run_report_generated)
add_custom_target(run_report_revision
        COMMAND ${CMAKE_COMMAND} -DGIT=${GIT_EXECUTABLE} -DSOURCE=${CMAKE_SOURCE_DIR} -DOUTPUT=${runReportRevisionRoot}/RunReportRevision.hpp -P ${CMAKE_CURRENT_SOURCE_DIR}/run_report_revision.cmake
        BYPRODUCTS ${runReportRevisionRoot}/RunReportRevision.hpp
        VERBATIM
)
add_dependencies(libc run_report_revision)
target_include_directories(libc PRIVATE ${runReportRevisionRoot})

function(run_report_stamp_components root)
    foreach(component libkernel libSceVideoOut libSceAgcDriver)
        if(TARGET ${component})
            target_include_directories(${component} PRIVATE ${root})
            add_dependencies(${component} run_report_revision)
        endif()
    endforeach()
endfunction()
cmake_language(EVAL CODE "cmake_language(DEFER DIRECTORY [[${CMAKE_SOURCE_DIR}]] CALL run_report_stamp_components [[${runReportRevisionRoot}]])")

set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/MathExact.cpp
        TARGET_DIRECTORY libc PROPERTIES COMPILE_OPTIONS "-frounding-math")
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/VersionedExtendedPrecision.cpp
        TARGET_DIRECTORY libc PROPERTIES COMPILE_OPTIONS "-frounding-math")

if(ANYPS5_ENABLE_TSAN)
    set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/exception/Exports.cpp
            TARGET_DIRECTORY libc PROPERTIES COMPILE_OPTIONS "-fno-sanitize=thread")
endif()

target_sources(libc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryWordIo.cpp)
target_sources(libc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/LegacySignals.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/SigvecExport.cpp)

if(BUILD_TESTING)
    add_test_executable(guest_libcxx_condition_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcxxCondition.cpp)
    target_include_directories(guest_libcxx_condition_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libcxx_condition_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_libcxx_condition_tests)
    add_test(NAME guest_libcxx_condition COMMAND guest_libcxx_condition_tests)
    set_tests_properties(guest_libcxx_condition PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libcxx_condition PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>;PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
    endif()
    add_test_executable(guest_sigvec_tests ${LIBS_INCLUDE_DIR}/tests/GuestSigvec.cpp)
    target_include_directories(guest_sigvec_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sigvec_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_sigvec_tests)
    add_test(NAME guest_sigvec COMMAND guest_sigvec_tests)
    set_tests_properties(guest_sigvec PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_sigvec PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_std_atomic_wait_tests ${LIBS_INCLUDE_DIR}/tests/GuestStdAtomicWait.cpp)
    target_include_directories(guest_std_atomic_wait_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_std_atomic_wait_tests PRIVATE libc)
    configure_windows_unwind(guest_std_atomic_wait_tests)
    add_test(NAME guest_std_atomic_wait COMMAND guest_std_atomic_wait_tests)
    add_test_executable(guest_std_atomic_wait_kernel_tests ${LIBS_INCLUDE_DIR}/tests/GuestStdAtomicWaitKernel.cpp)
    target_include_directories(guest_std_atomic_wait_kernel_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_std_atomic_wait_kernel_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_std_atomic_wait_kernel_tests)
    add_test(NAME guest_std_atomic_wait_kernel COMMAND guest_std_atomic_wait_kernel_tests)
    set_tests_properties(guest_std_atomic_wait_kernel PROPERTIES TIMEOUT 20)
    add_test_executable(guest_libcxx_recursive_mutex_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcxxRecursiveMutex.cpp)
    target_include_directories(guest_libcxx_recursive_mutex_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libcxx_recursive_mutex_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_libcxx_recursive_mutex_tests)
    add_test(NAME guest_libcxx_recursive_mutex COMMAND guest_libcxx_recursive_mutex_tests)
    set_tests_properties(guest_libcxx_recursive_mutex PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_std_atomic_wait guest_std_atomic_wait_kernel guest_libcxx_recursive_mutex PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>;PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
    endif()
endif()

target_include_directories(libc PRIVATE
        ${LIBS_INCLUDE_DIR}
)

target_link_libraries(libc PRIVATE zarchive)

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
    target_compile_options(libc PRIVATE -ffp-contract=off $<$<CXX_COMPILER_ID:Clang,AppleClang>:-fno-slp-vectorize>)
    if(BUILD_TESTING AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64)$" AND NOT MSVC)
        add_test(NAME libc_floating_point_contraction
                COMMAND ${CMAKE_COMMAND} -DCOMPILER=${CMAKE_CXX_COMPILER}
                    "-DARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}"
                    "-DOPTIONS=$<JOIN:$<TARGET_PROPERTY:libc,COMPILE_OPTIONS>, >"
                    -DWORK=${CMAKE_CURRENT_BINARY_DIR}/libc_floating_point_contraction
                    -P ${LIBS_INCLUDE_DIR}/tests/LibcFloatingPointContraction.cmake)
    endif()
endif()

if(WIN32)
    target_link_libraries(libc PRIVATE shell32)
endif()

if(BUILD_TESTING)
    add_test_executable(run_report_tests ${LIBS_INCLUDE_DIR}/tests/RunReport.cpp)
    target_include_directories(run_report_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(run_report_tests PRIVATE libc)
    if(WIN32)
        target_link_libraries(run_report_tests PRIVATE shell32)
    endif()
    configure_windows_unwind(run_report_tests)
    add_test(NAME run_report COMMAND run_report_tests)
    set_tests_properties(run_report PROPERTIES TIMEOUT 60)
    find_package(Python3 QUIET COMPONENTS Interpreter)
    if(Python3_Interpreter_FOUND)
        execute_process(COMMAND ${Python3_EXECUTABLE} -c "import jsonschema" RESULT_VARIABLE runReportHasJsonschema OUTPUT_QUIET ERROR_QUIET)
        if(runReportHasJsonschema EQUAL 0)
            add_test(NAME run_report_schema COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/tests/validate_run_report_dump.py $<TARGET_FILE:run_report_tests>)
            set_tests_properties(run_report_schema PROPERTIES TIMEOUT 60)
            if(WIN32)
                set_tests_properties(run_report_schema PROPERTIES ENVIRONMENT_MODIFICATION
                    "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
            endif()
        endif()
    endif()
    if(GIT_FOUND)
        add_test(NAME run_report_revision COMMAND ${CMAKE_COMMAND} -DGIT=${GIT_EXECUTABLE}
                -DSCRIPT=${CMAKE_CURRENT_SOURCE_DIR}/run_report_revision.cmake
                -DWORK=${CMAKE_CURRENT_BINARY_DIR}/run_report_revision_test
                -P ${CMAKE_CURRENT_SOURCE_DIR}/tests_run_report_revision.cmake)
        set_tests_properties(run_report_revision PROPERTIES TIMEOUT 120)
    endif()
    if(WIN32)
        set_tests_properties(run_report PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_memcmp_protected_tests ${LIBS_INCLUDE_DIR}/tests/GuestMemcmpProtected.cpp)
    target_include_directories(guest_memcmp_protected_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_memcmp_protected_tests PRIVATE libc)
    configure_windows_unwind(guest_memcmp_protected_tests)
    add_test(NAME guest_memcmp_protected COMMAND guest_memcmp_protected_tests)
    set_tests_properties(guest_memcmp_protected PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_memcmp_protected PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_env_probe_tests NO_RUNTIME_DLL_STAGING ${LIBS_INCLUDE_DIR}/tests/GuestUpdateEnv.cpp)
    target_include_directories(guest_env_probe_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_env_probe_tests PRIVATE libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_env_probe_tests)
    add_test(NAME guest_update_env COMMAND guest_env_probe_tests $<TARGET_FILE:libc>)
    foreach(bit RANGE 0 5)
        foreach(source RANGE 0 2)
            add_test(NAME guest_update_env_pending_${bit}_${source} COMMAND guest_env_probe_tests $<TARGET_FILE:libc> ${bit} ${source})
            set_tests_properties(guest_update_env_pending_${bit}_${source} PROPERTIES TIMEOUT 10 SKIP_RETURN_CODE 77)
            if(WIN32)
                set_tests_properties(guest_update_env_pending_${bit}_${source} PROPERTIES ENVIRONMENT_MODIFICATION
                    "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
            endif()
        endforeach()
    endforeach()
    if(WIN32)
        set_tests_properties(guest_update_env PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

target_sources(libc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/FloatingPoint.cpp)
target_sources(libc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/CodecvtUtf.cpp)

if(BUILD_TESTING)
    add_test_executable(guest_memset_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestMemsetExtent.cpp)
    target_include_directories(guest_memset_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_memset_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_memset_extent_tests)
    add_test(NAME guest_memset_extent COMMAND guest_memset_extent_tests)
    add_test_executable(guest_atomic_2_tests ${LIBS_INCLUDE_DIR}/tests/GuestAtomic2.cpp)
    target_include_directories(guest_atomic_2_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_atomic_2_tests PRIVATE libc)
    configure_windows_unwind(guest_atomic_2_tests)
    add_test(NAME guest_atomic_2 COMMAND guest_atomic_2_tests)
    set_tests_properties(guest_atomic_2 PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_atomic_2 PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    set_tests_properties(guest_memset_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_memset_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_raise_except_tests NO_RUNTIME_DLL_STAGING ${LIBS_INCLUDE_DIR}/tests/GuestRaiseExcept.cpp)
    target_include_directories(guest_raise_except_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_raise_except_tests PRIVATE libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_raise_except_tests)
    add_test(NAME guest_raise_except COMMAND guest_raise_except_tests $<TARGET_FILE:libc>)
    set(raiseExceptTests guest_raise_except)
    foreach(exceptionBit RANGE 0 5)
        add_test(NAME guest_raise_except_trap_${exceptionBit} COMMAND guest_raise_except_tests $<TARGET_FILE:libc> ${exceptionBit})
        list(APPEND raiseExceptTests guest_raise_except_trap_${exceptionBit})
    endforeach()
    set_tests_properties(${raiseExceptTests} PROPERTIES TIMEOUT 10 SKIP_RETURN_CODE 77)
    if(WIN32)
        set_tests_properties(${raiseExceptTests} PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_floating_point_tests NO_RUNTIME_DLL_STAGING ${LIBS_INCLUDE_DIR}/tests/GuestFloatingPoint.cpp)
    target_include_directories(guest_floating_point_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_floating_point_tests PRIVATE libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_floating_point_tests)
    add_test(NAME guest_floating_point COMMAND guest_floating_point_tests $<TARGET_FILE:libc>)
    set_tests_properties(guest_floating_point PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_floating_point PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(MINGW OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
        enable_language(ASM)
        add_test_executable(guest_sce_v2_exceptions_tests
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.cpp
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.S)
        target_include_directories(guest_sce_v2_exceptions_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_sce_v2_exceptions_tests PRIVATE libc)
        configure_windows_unwind(guest_sce_v2_exceptions_tests)
        add_test(NAME guest_sce_v2_exceptions COMMAND guest_sce_v2_exceptions_tests)
        set_tests_properties(guest_sce_v2_exceptions PROPERTIES TIMEOUT 10)
        if(WIN32)
            set_tests_properties(guest_sce_v2_exceptions PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
        add_test_executable(guest_sce_v2_locale_basics_tests
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2LocaleBasics.cpp
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.S)
        target_include_directories(guest_sce_v2_locale_basics_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_sce_v2_locale_basics_tests PRIVATE libc)
        configure_windows_unwind(guest_sce_v2_locale_basics_tests)
        add_test(NAME guest_sce_v2_locale_basics COMMAND guest_sce_v2_locale_basics_tests)
        set_tests_properties(guest_sce_v2_locale_basics PROPERTIES TIMEOUT 10)
        if(WIN32)
            set_tests_properties(guest_sce_v2_locale_basics PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
        add_test_executable(guest_sce_v2_locimp_references_tests
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2LocimpReferences.cpp
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.S)
        target_include_directories(guest_sce_v2_locimp_references_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_sce_v2_locimp_references_tests PRIVATE libc)
        configure_windows_unwind(guest_sce_v2_locimp_references_tests)
        add_test(NAME guest_sce_v2_locimp_references COMMAND guest_sce_v2_locimp_references_tests)
        set_tests_properties(guest_sce_v2_locimp_references PROPERTIES TIMEOUT 10)
        if(WIN32)
            set_tests_properties(guest_sce_v2_locimp_references PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
        add_test_executable(guest_sce_v2_makeloc_tests
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Makeloc.cpp
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.S)
        target_include_directories(guest_sce_v2_makeloc_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_sce_v2_makeloc_tests PRIVATE libc)
        configure_windows_unwind(guest_sce_v2_makeloc_tests)
        add_test(NAME guest_sce_v2_makeloc COMMAND guest_sce_v2_makeloc_tests)
        set_tests_properties(guest_sce_v2_makeloc PROPERTIES TIMEOUT 10)
        if(WIN32)
            set_tests_properties(guest_sce_v2_makeloc PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
        add_test_executable(guest_filesystem_error_tests
            ${LIBS_INCLUDE_DIR}/tests/GuestFilesystemError.cpp
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.S)
        target_include_directories(guest_filesystem_error_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_filesystem_error_tests PRIVATE libc)
        configure_windows_unwind(guest_filesystem_error_tests)
        add_test(NAME guest_filesystem_error COMMAND guest_filesystem_error_tests)
        set_tests_properties(guest_filesystem_error PROPERTIES TIMEOUT 10)
        if(WIN32)
            set_tests_properties(guest_filesystem_error PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
        add_test_executable(guest_bad_any_cast_node_access_tests
            ${LIBS_INCLUDE_DIR}/tests/GuestBadAnyCastNodeAccess.cpp
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.S)
        target_include_directories(guest_bad_any_cast_node_access_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_bad_any_cast_node_access_tests PRIVATE libc)
        configure_windows_unwind(guest_bad_any_cast_node_access_tests)
        add_test(NAME guest_bad_any_cast_node_access COMMAND guest_bad_any_cast_node_access_tests)
        set_tests_properties(guest_bad_any_cast_node_access PROPERTIES TIMEOUT 10)
        if(WIN32)
            set_tests_properties(guest_bad_any_cast_node_access PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endif()

    add_test_executable(guest_sce_v2_filesystem_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Filesystem.cpp)
    target_include_directories(guest_sce_v2_filesystem_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_filesystem_tests PRIVATE libc libkernel zarchive)
    configure_windows_unwind(guest_sce_v2_filesystem_tests)
    add_test(NAME guest_sce_v2_filesystem COMMAND guest_sce_v2_filesystem_tests)
    set_tests_properties(guest_sce_v2_filesystem PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_sce_v2_filesystem PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_exp_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exp.cpp)
    target_include_directories(guest_sce_v2_exp_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_exp_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_exp_tests)
    add_test(NAME guest_sce_v2_exp COMMAND guest_sce_v2_exp_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_exp PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_sce_v2_filesystem_calls_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2FilesystemCalls.cpp)
    target_include_directories(guest_sce_v2_filesystem_calls_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_filesystem_calls_tests PRIVATE libc libkernel zarchive)
    configure_windows_unwind(guest_sce_v2_filesystem_calls_tests)
    add_test(NAME guest_sce_v2_filesystem_calls COMMAND guest_sce_v2_filesystem_calls_tests)
    set_tests_properties(guest_sce_v2_filesystem_calls PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_sce_v2_filesystem_calls PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_pmsw_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Pmsw.cpp)
    target_include_directories(guest_sce_v2_pmsw_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_pmsw_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_pmsw_tests)
    add_test(NAME guest_sce_v2_pmsw COMMAND guest_sce_v2_pmsw_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_pmsw PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(WIN32)
    target_link_libraries(libc PRIVATE advapi32 ws2_32 iphlpapi)
endif()

if(BUILD_TESTING)
    if(UNIX)
        add_test_executable(guest_atomic_assert_tests ${LIBS_INCLUDE_DIR}/tests/GuestAtomicAssert.cpp)
        target_include_directories(guest_atomic_assert_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_atomic_assert_tests PRIVATE libc)
        add_test(NAME guest_atomic_assert COMMAND guest_atomic_assert_tests)
        set_tests_properties(guest_atomic_assert PROPERTIES TIMEOUT 10)
    endif()

    add_test_executable(guest_fopen_errors_tests ${LIBS_INCLUDE_DIR}/tests/GuestFopenErrors.cpp)
    target_include_directories(guest_fopen_errors_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_fopen_errors_tests PRIVATE libc)
    add_test(NAME guest_fopen_errors COMMAND guest_fopen_errors_tests)
    set_tests_properties(guest_fopen_errors PROPERTIES TIMEOUT 20 SKIP_RETURN_CODE 77)
    if(WIN32)
        set_tests_properties(guest_fopen_errors PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    if(MINGW OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
        enable_language(ASM)
        add_test_executable(guest_memory_resource_tests
            ${LIBS_INCLUDE_DIR}/tests/GuestMemoryResource.cpp
            ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Exceptions.S)
        target_include_directories(guest_memory_resource_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_memory_resource_tests PRIVATE libc)
        configure_windows_unwind(guest_memory_resource_tests)
        add_test(NAME guest_memory_resource COMMAND guest_memory_resource_tests)
        set_tests_properties(guest_memory_resource PROPERTIES TIMEOUT 10)
        if(WIN32)
            set_tests_properties(guest_memory_resource PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endif()

    add_test_executable(guest_index_tests NO_RUNTIME_DLL_STAGING ${LIBS_INCLUDE_DIR}/tests/GuestIndex.cpp)
    target_include_directories(guest_index_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_index_tests PRIVATE libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_index_tests)
    add_test(NAME guest_index COMMAND guest_index_tests $<TARGET_FILE:libc>)
    if(WIN32)
        set_tests_properties(guest_index PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_fwide_tests NO_RUNTIME_DLL_STAGING ${LIBS_INCLUDE_DIR}/tests/GuestFwide.cpp)
    target_include_directories(guest_fwide_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_fwide_tests PRIVATE libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_fwide_tests)
    add_test(NAME guest_fwide COMMAND guest_fwide_tests $<TARGET_FILE:libc> guest_fwide.tmp)
    set_tests_properties(guest_fwide PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_fwide PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_memccpy_bounds_tests ${LIBS_INCLUDE_DIR}/tests/GuestMemccpyBounds.cpp)
    target_include_directories(guest_memccpy_bounds_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_memccpy_bounds_tests PRIVATE libc)
    configure_windows_unwind(guest_memccpy_bounds_tests)
    add_test(NAME guest_memccpy_bounds COMMAND guest_memccpy_bounds_tests)
    set_tests_properties(guest_memccpy_bounds PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_memccpy_bounds PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_memrchr_blocks_tests ${LIBS_INCLUDE_DIR}/tests/GuestMemrchrBlocks.cpp)
    target_include_directories(guest_memrchr_blocks_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_memrchr_blocks_tests PRIVATE libc)
    configure_windows_unwind(guest_memrchr_blocks_tests)
    add_test(NAME guest_memrchr_blocks COMMAND guest_memrchr_blocks_tests)
    if(WIN32)
        set_tests_properties(guest_memrchr_blocks PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_explicit_memset_tests ${LIBS_INCLUDE_DIR}/tests/GuestExplicitMemset.cpp)
    target_include_directories(guest_explicit_memset_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_explicit_memset_tests PRIVATE libc)
    configure_windows_unwind(guest_explicit_memset_tests)
    foreach(mode empty values ranges guard_pages)
        add_test(NAME guest_explicit_memset_${mode} COMMAND guest_explicit_memset_tests ${mode})
        set_tests_properties(guest_explicit_memset_${mode} PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_explicit_memset_${mode} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()

    add_test_executable(guest_allocating_strings_tests ${LIBS_INCLUDE_DIR}/tests/GuestAllocatingStrings.cpp)
    target_include_directories(guest_allocating_strings_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_allocating_strings_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_allocating_strings_tests)
    add_test(NAME guest_allocating_strings COMMAND guest_allocating_strings_tests)
    if(WIN32)
        set_tests_properties(guest_allocating_strings PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_wide_substring_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideSubstringBoundary.cpp)
    target_include_directories(guest_wide_substring_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_substring_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_substring_boundary_tests)
    add_test(NAME guest_wide_substring_boundary COMMAND guest_wide_substring_boundary_tests)
    set_tests_properties(guest_wide_substring_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wide_substring_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_app_archive_tests ${LIBS_INCLUDE_DIR}/tests/GuestAppArchive.cpp)
    target_include_directories(guest_app_archive_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_app_archive_tests PRIVATE libc zarchive)
    configure_windows_unwind(guest_app_archive_tests)
    foreach(mode present absent damaged invalid)
        add_test(NAME guest_app_archive_${mode} COMMAND guest_app_archive_tests ${mode})
        set_tests_properties(guest_app_archive_${mode} PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_app_archive_${mode} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()

    add_test_executable(guest_array_callbacks_tests ${LIBS_INCLUDE_DIR}/tests/GuestArrayCallbacks.cpp)
    target_include_directories(guest_array_callbacks_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_array_callbacks_tests PRIVATE libc)
    configure_windows_unwind(guest_array_callbacks_tests)
    add_test(NAME guest_array_callbacks COMMAND guest_array_callbacks_tests)
    set_tests_properties(guest_array_callbacks PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_array_callbacks PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_strncmp_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrncmpBoundary.cpp)
    target_include_directories(guest_strncmp_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strncmp_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_strncmp_boundary_tests)
    add_test(NAME guest_strncmp_boundary COMMAND guest_strncmp_boundary_tests)
    set_tests_properties(guest_strncmp_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strncmp_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_dynamic_cast_tests ${LIBS_INCLUDE_DIR}/tests/GuestDynamicCast.cpp)
    target_include_directories(guest_dynamic_cast_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_dynamic_cast_tests PRIVATE libc)
    configure_windows_unwind(guest_dynamic_cast_tests)
    add_test(NAME guest_dynamic_cast COMMAND guest_dynamic_cast_tests)
    if(WIN32)
        set_tests_properties(guest_dynamic_cast PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(WIN32)
        add_test_executable(windows_guest_main_stack_tests ${LIBS_INCLUDE_DIR}/tests/WindowsGuestMainStack.cpp)
        target_include_directories(windows_guest_main_stack_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(windows_guest_main_stack_tests PRIVATE libc)
        configure_windows_unwind(windows_guest_main_stack_tests)
        add_test_executable(windows_guest_main_stack_failure_tests
            ${LIBS_INCLUDE_DIR}/tests/WindowsGuestMainStackFailure.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/GuestStacks.cpp)
        target_include_directories(windows_guest_main_stack_failure_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(windows_guest_main_stack_failure_tests PRIVATE libc)
        configure_windows_unwind(windows_guest_main_stack_failure_tests)
        add_test(NAME windows_guest_main_stack_failure COMMAND windows_guest_main_stack_failure_tests)
        set_tests_properties(windows_guest_main_stack_failure PROPERTIES TIMEOUT 20 ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        add_test(NAME windows_guest_main_stack COMMAND windows_guest_main_stack_tests)
        set_tests_properties(windows_guest_main_stack PROPERTIES TIMEOUT 20 ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        if(Python3_Interpreter_FOUND)
            add_test(NAME windows_guest_main_stack_entry COMMAND ${Python3_EXECUTABLE}
                ${LIBS_INCLUDE_DIR}/tests/test_windows_guest_main_stack.py $<TARGET_FILE:relinker> $<TARGET_FILE_DIR:libc>)
            set(relinkerTestTemp ${CMAKE_BINARY_DIR}/core/relinker/test-temp)
            file(MAKE_DIRECTORY ${relinkerTestTemp})
            set_tests_properties(windows_guest_main_stack_entry PROPERTIES TIMEOUT 20 ENVIRONMENT_MODIFICATION
                "TMPDIR=set:${relinkerTestTemp};TEMP=set:${relinkerTestTemp};TMP=set:${relinkerTestTemp};PYTHONUTF8=set:1")
        endif()
    endif()
    add_test_executable(guest_time_conversion_tests ${LIBS_INCLUDE_DIR}/tests/GuestTimeConversion.cpp)
    target_include_directories(guest_time_conversion_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_time_conversion_tests PRIVATE libc)
    configure_windows_unwind(guest_time_conversion_tests)
    add_test(NAME guest_time_conversion COMMAND guest_time_conversion_tests)
    set_tests_properties(guest_time_conversion PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_time_conversion PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
        add_test(NAME guest_time_startup_errno COMMAND guest_time_conversion_tests --startup-errno)
        set_tests_properties(guest_time_startup_errno PROPERTIES TIMEOUT 20 ENVIRONMENT
            "TZ=:${CMAKE_CURRENT_BINARY_DIR}/anyps5-missing-startup-time-zone;APS5_NO_WRITE_WATCH=1;APS5_REPORT=0")
    endif()
    add_test_executable(guest_timespec_get_tests ${LIBS_INCLUDE_DIR}/tests/GuestTimespecGet.cpp)
    target_include_directories(guest_timespec_get_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_timespec_get_tests PRIVATE libc)
    configure_windows_unwind(guest_timespec_get_tests)
    add_test(NAME guest_timespec_get COMMAND guest_timespec_get_tests)
    if(WIN32)
        set_tests_properties(guest_timespec_get PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_mktime_tests ${LIBS_INCLUDE_DIR}/tests/GuestMktime.cpp)
    target_include_directories(guest_mktime_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_mktime_tests PRIVATE libc)
    configure_windows_unwind(guest_mktime_tests)
    add_test(NAME guest_mktime COMMAND guest_mktime_tests)
    set_tests_properties(guest_mktime PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_mktime PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_strcpy_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrcpyExtent.cpp)
    target_include_directories(guest_strcpy_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strcpy_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_strcpy_extent_tests)
    add_test(NAME guest_strcpy_extent COMMAND guest_strcpy_extent_tests)
    set_tests_properties(guest_strcpy_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strcpy_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_time_return_tests ${LIBS_INCLUDE_DIR}/tests/GuestTimeReturn.cpp)
    target_include_directories(guest_time_return_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_time_return_tests PRIVATE libc)
    configure_windows_unwind(guest_time_return_tests)
    add_test(NAME guest_time_return COMMAND guest_time_return_tests)
    set_tests_properties(guest_time_return PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_time_return PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libcxx_plain_mutex_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcxxPlainMutex.cpp)
    target_include_directories(guest_libcxx_plain_mutex_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libcxx_plain_mutex_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_libcxx_plain_mutex_tests)
    add_test(NAME guest_libcxx_plain_mutex COMMAND guest_libcxx_plain_mutex_tests)
    set_tests_properties(guest_libcxx_plain_mutex PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libcxx_plain_mutex PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>;PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
    endif()
    add_test_executable(guest_libcxx_to_time_t_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcxxToTimeT.cpp)
    target_include_directories(guest_libcxx_to_time_t_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libcxx_to_time_t_tests PRIVATE libc)
    configure_windows_unwind(guest_libcxx_to_time_t_tests)
    add_test(NAME guest_libcxx_to_time_t COMMAND guest_libcxx_to_time_t_tests)
    set_tests_properties(guest_libcxx_to_time_t PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_libcxx_to_time_t PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_set_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideSetBoundary.cpp)
    target_include_directories(guest_wide_set_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_set_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_set_boundary_tests)
    add_test(NAME guest_wide_set_boundary COMMAND guest_wide_set_boundary_tests)
    set_tests_properties(guest_wide_set_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wide_set_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_time_extras_tests ${LIBS_INCLUDE_DIR}/tests/GuestTimeExtras.cpp)
    target_include_directories(guest_time_extras_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_time_extras_tests PRIVATE libc)
    configure_windows_unwind(guest_time_extras_tests)
    add_test(NAME guest_time_extras COMMAND guest_time_extras_tests)
    set_tests_properties(guest_time_extras PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_time_extras PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(precise_wait_tests ${LIBS_INCLUDE_DIR}/tests/PreciseWait.cpp)
    target_include_directories(precise_wait_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(precise_wait_tests PRIVATE libc)
    configure_windows_unwind(precise_wait_tests)
    add_test(NAME precise_wait COMMAND precise_wait_tests)
    set_tests_properties(precise_wait PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(precise_wait PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_substring_protected_tests ${LIBS_INCLUDE_DIR}/tests/GuestSubstringProtected.cpp)
    target_include_directories(guest_substring_protected_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_substring_protected_tests PRIVATE libc)
    configure_windows_unwind(guest_substring_protected_tests)
    add_test(NAME guest_substring_protected COMMAND guest_substring_protected_tests)
    set_tests_properties(guest_substring_protected PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_substring_protected PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_scan_count_tests ${LIBS_INCLUDE_DIR}/tests/GuestScanCount.cpp)
    target_include_directories(guest_scan_count_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_scan_count_tests PRIVATE libc)
    configure_windows_unwind(guest_scan_count_tests)
    add_test(NAME guest_scan_count COMMAND guest_scan_count_tests)
    if(WIN32)
        set_tests_properties(guest_scan_count PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wcsncat_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestWcsncatExtent.cpp)
    target_include_directories(guest_wcsncat_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wcsncat_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_wcsncat_extent_tests)
    add_test(NAME guest_wcsncat_extent COMMAND guest_wcsncat_extent_tests)
    set_tests_properties(guest_wcsncat_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wcsncat_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_access_tests ${LIBS_INCLUDE_DIR}/tests/GuestAccess.cpp)
    target_include_directories(guest_access_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_access_tests PRIVATE libc)
    configure_windows_unwind(guest_access_tests)
    add_test(NAME guest_access COMMAND guest_access_tests)
    if(WIN32)
        target_link_libraries(guest_access_tests PRIVATE advapi32)
        set_tests_properties(guest_access PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(file_position_tests ${LIBS_INCLUDE_DIR}/tests/FilePosition.cpp)
    target_include_directories(file_position_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(file_position_tests PRIVATE libc)
    configure_windows_unwind(file_position_tests)
    add_test(NAME file_position COMMAND file_position_tests)
    if(WIN32)
        set_tests_properties(file_position PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(WIN32)
        add_test_executable(guest_fopen_long_host_path_tests ${LIBS_INCLUDE_DIR}/tests/GuestFopenLongHostPath.cpp)
        target_include_directories(guest_fopen_long_host_path_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_fopen_long_host_path_tests PRIVATE libc)
        configure_windows_unwind(guest_fopen_long_host_path_tests)
        add_test(NAME guest_fopen_long_host_path COMMAND guest_fopen_long_host_path_tests)
        set_tests_properties(guest_fopen_long_host_path PROPERTIES TIMEOUT 20 ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_char_search_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestCharSearchBoundary.cpp)
    target_include_directories(guest_char_search_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_char_search_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_char_search_boundary_tests)
    add_test(NAME guest_char_search_boundary COMMAND guest_char_search_boundary_tests)
    set_tests_properties(guest_char_search_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_char_search_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_formatting_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideFormatting.cpp)
    target_include_directories(guest_wide_formatting_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_formatting_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_formatting_tests)
    add_test(NAME guest_wide_formatting COMMAND guest_wide_formatting_tests)
    if(WIN32)
        set_tests_properties(guest_wide_formatting PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_strncat_protected_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrncatProtected.cpp)
    target_include_directories(guest_strncat_protected_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strncat_protected_tests PRIVATE libc)
    configure_windows_unwind(guest_strncat_protected_tests)
    add_test(NAME guest_strncat_protected COMMAND guest_strncat_protected_tests)
    set_tests_properties(guest_strncat_protected PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strncat_protected PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_string_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideStrings.cpp)
    target_include_directories(guest_wide_string_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_string_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_string_tests)
    add_test(NAME guest_wide_strings COMMAND guest_wide_string_tests)
    if(WIN32)
        set_tests_properties(guest_wide_strings PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_atomic_builtins_tests ${LIBS_INCLUDE_DIR}/tests/GuestAtomicBuiltins.cpp)
    target_include_directories(guest_atomic_builtins_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_atomic_builtins_tests PRIVATE libc)
    configure_windows_unwind(guest_atomic_builtins_tests)
    add_test(NAME guest_atomic_builtins COMMAND guest_atomic_builtins_tests)
    if(WIN32)
        set_tests_properties(guest_atomic_builtins PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_strpbrk_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrpbrkBoundary.cpp)
    target_include_directories(guest_strpbrk_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strpbrk_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_strpbrk_boundary_tests)
    add_test(NAME guest_strpbrk_boundary COMMAND guest_strpbrk_boundary_tests)
    set_tests_properties(guest_strpbrk_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strpbrk_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_multibyte_locale_tests ${LIBS_INCLUDE_DIR}/tests/GuestMultibyteLocale.cpp)
    target_include_directories(guest_multibyte_locale_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_multibyte_locale_tests PRIVATE libc)
    configure_windows_unwind(guest_multibyte_locale_tests)
    add_test(NAME guest_multibyte_locale COMMAND guest_multibyte_locale_tests)
    if(WIN32)
        set_tests_properties(guest_multibyte_locale PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libc_mbstate_tls_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcMbstateTls.cpp)
    target_include_directories(guest_libc_mbstate_tls_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_mbstate_tls_tests PRIVATE libc)
    configure_windows_unwind(guest_libc_mbstate_tls_tests)
    add_test(NAME guest_libc_mbstate_tls COMMAND guest_libc_mbstate_tls_tests)
    set_tests_properties(guest_libc_mbstate_tls PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_libc_mbstate_tls PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_span_protected_tests ${LIBS_INCLUDE_DIR}/tests/GuestSpanProtected.cpp)
    target_include_directories(guest_span_protected_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_span_protected_tests PRIVATE libc)
    configure_windows_unwind(guest_span_protected_tests)
    add_test(NAME guest_span_protected COMMAND guest_span_protected_tests)
    set_tests_properties(guest_span_protected PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_span_protected PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_conversion_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideConversion.cpp)
    target_include_directories(guest_wide_conversion_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_conversion_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_conversion_tests)
    add_test(NAME guest_wide_conversion COMMAND guest_wide_conversion_tests)
    if(WIN32)
        set_tests_properties(guest_wide_conversion PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wmemmove_snapshot_tests ${LIBS_INCLUDE_DIR}/tests/GuestWmemmoveSnapshot.cpp)
    target_include_directories(guest_wmemmove_snapshot_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wmemmove_snapshot_tests PRIVATE libc)
    configure_windows_unwind(guest_wmemmove_snapshot_tests)
    add_test(NAME guest_wmemmove_snapshot COMMAND guest_wmemmove_snapshot_tests)
    set_tests_properties(guest_wmemmove_snapshot PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wmemmove_snapshot PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_one_runs_tests ${LIBS_INCLUDE_DIR}/tests/GuestOneRuns.cpp)
    target_include_directories(guest_one_runs_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_one_runs_tests PRIVATE libc)
    configure_windows_unwind(guest_one_runs_tests)
    foreach(direction leading trailing)
        foreach(width uc us ui ul ull)
            add_test(NAME guest_one_runs_${direction}_${width} COMMAND guest_one_runs_tests ${direction}_${width})
            set_tests_properties(guest_one_runs_${direction}_${width} PROPERTIES TIMEOUT 20)
            if(WIN32)
                set_tests_properties(guest_one_runs_${direction}_${width} PROPERTIES ENVIRONMENT_MODIFICATION
                    "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
            endif()
        endforeach()
    endforeach()
    add_test_executable(guest_wmemcpy_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestWmemcpyExtent.cpp)
    target_include_directories(guest_wmemcpy_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wmemcpy_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_wmemcpy_extent_tests)
    add_test(NAME guest_wmemcpy_extent COMMAND guest_wmemcpy_extent_tests)
    set_tests_properties(guest_wmemcpy_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wmemcpy_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_bounds_checking_tests ${LIBS_INCLUDE_DIR}/tests/GuestBoundsChecking.cpp)
    target_include_directories(guest_bounds_checking_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_bounds_checking_tests PRIVATE libc)
    configure_windows_unwind(guest_bounds_checking_tests)
    add_test(NAME guest_bounds_checking COMMAND guest_bounds_checking_tests guest_bounds_checking.tmp)
    set_tests_properties(guest_bounds_checking PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_bounds_checking PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_timingsafe_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestTimingsafeBoundary.cpp)
    target_include_directories(guest_timingsafe_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_timingsafe_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_timingsafe_boundary_tests)
    add_test(NAME guest_timingsafe_boundary COMMAND guest_timingsafe_boundary_tests)
    set_tests_properties(guest_timingsafe_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_timingsafe_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_zero_runs_tests ${LIBS_INCLUDE_DIR}/tests/GuestZeroRuns.cpp)
    target_include_directories(guest_zero_runs_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_zero_runs_tests PRIVATE libc)
    configure_windows_unwind(guest_zero_runs_tests)
    foreach(direction leading trailing)
        foreach(width uc us ui ul ull)
            add_test(NAME guest_zero_runs_${direction}_${width} COMMAND guest_zero_runs_tests ${direction}_${width})
            set_tests_properties(guest_zero_runs_${direction}_${width} PROPERTIES TIMEOUT 20)
            if(WIN32)
                set_tests_properties(guest_zero_runs_${direction}_${width} PROPERTIES ENVIRONMENT_MODIFICATION
                    "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
            endif()
        endforeach()
    endforeach()
    add_test_executable(guest_float_builtins_tests ${LIBS_INCLUDE_DIR}/tests/GuestFloatBuiltins.cpp)
    target_include_directories(guest_float_builtins_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_float_builtins_tests PRIVATE libc)
    configure_windows_unwind(guest_float_builtins_tests)
    add_test(NAME guest_float_builtins COMMAND guest_float_builtins_tests)
    if(WIN32)
        set_tests_properties(guest_float_builtins PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_length_protected_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideLengthProtected.cpp)
    target_include_directories(guest_wide_length_protected_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_length_protected_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_length_protected_tests)
    add_test(NAME guest_wide_length_protected COMMAND guest_wide_length_protected_tests)
    set_tests_properties(guest_wide_length_protected PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wide_length_protected PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_character_tests ${LIBS_INCLUDE_DIR}/tests/GuestCharacter.cpp)
    target_include_directories(guest_character_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_character_tests PRIVATE libc)
    configure_windows_unwind(guest_character_tests)
    add_test(NAME guest_character COMMAND guest_character_tests)
    if(WIN32)
        set_tests_properties(guest_character PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_set_env_tests NO_RUNTIME_DLL_STAGING ${LIBS_INCLUDE_DIR}/tests/GuestSetEnv.cpp)
    target_include_directories(guest_set_env_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_set_env_tests PRIVATE libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_set_env_tests)
    add_test(NAME guest_set_env COMMAND guest_set_env_tests $<TARGET_FILE:libc>)
    foreach(bit RANGE 0 5)
        add_test(NAME guest_set_env_pending_${bit} COMMAND guest_set_env_tests $<TARGET_FILE:libc> ${bit})
        set_tests_properties(guest_set_env_pending_${bit} PROPERTIES TIMEOUT 10 SKIP_RETURN_CODE 77)
        if(WIN32)
            set_tests_properties(guest_set_env_pending_${bit} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()
    if(WIN32)
        set_tests_properties(guest_set_env PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_lgamma_poles_tests ${LIBS_INCLUDE_DIR}/tests/GuestLgammaPoles.cpp)
    target_include_directories(guest_lgamma_poles_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_lgamma_poles_tests PRIVATE libc)
    configure_windows_unwind(guest_lgamma_poles_tests)
    add_test(NAME guest_lgamma_poles COMMAND guest_lgamma_poles_tests)
    set_tests_properties(guest_lgamma_poles PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_lgamma_poles PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_math_tests ${LIBS_INCLUDE_DIR}/tests/GuestMath.cpp)
    target_include_directories(guest_math_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_math_tests PRIVATE libc)
    configure_windows_unwind(guest_math_tests)
    add_test(NAME guest_math COMMAND guest_math_tests)
    if(WIN32)
        set_tests_properties(guest_math PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_math_elementary_tests ${LIBS_INCLUDE_DIR}/tests/GuestMathElementary.cpp)
    target_include_directories(guest_math_elementary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_math_elementary_tests PRIVATE libc)
    configure_windows_unwind(guest_math_elementary_tests)
    add_test(NAME guest_math_elementary COMMAND guest_math_elementary_tests)
    if(WIN32)
        set_tests_properties(guest_math_elementary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_dsign_tests ${LIBS_INCLUDE_DIR}/tests/GuestDsign.cpp)
    target_include_directories(guest_dsign_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_dsign_tests PRIVATE libc)
    configure_windows_unwind(guest_dsign_tests)
    add_test(NAME guest_dsign COMMAND guest_dsign_tests)
    if(WIN32)
        set_tests_properties(guest_dsign PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_strtod_subnormal_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrtodSubnormal.cpp)
    target_include_directories(guest_strtod_subnormal_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strtod_subnormal_tests PRIVATE libc)
    configure_windows_unwind(guest_strtod_subnormal_tests)
    add_test(NAME guest_strtod_subnormal COMMAND guest_strtod_subnormal_tests)
    if(WIN32)
        set_tests_properties(guest_strtod_subnormal PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_strnstr_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrnstrBoundary.cpp)
    target_include_directories(guest_strnstr_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strnstr_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_strnstr_boundary_tests)
    add_test(NAME guest_strnstr_boundary COMMAND guest_strnstr_boundary_tests)
    set_tests_properties(guest_strnstr_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strnstr_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_random_state_tests ${LIBS_INCLUDE_DIR}/tests/GuestRandomState.cpp)
    target_include_directories(guest_random_state_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_random_state_tests PRIVATE libc)
    configure_windows_unwind(guest_random_state_tests)
    add_test(NAME guest_random_state COMMAND guest_random_state_tests)
    if(WIN32)
        set_tests_properties(guest_random_state PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libc_random_seeding_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcRandomSeeding.cpp)
    target_include_directories(guest_libc_random_seeding_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_random_seeding_tests PRIVATE libc)
    configure_windows_unwind(guest_libc_random_seeding_tests)
    add_test(NAME guest_libc-random-seeding COMMAND guest_libc_random_seeding_tests)
    if(WIN32)
        set_tests_properties(guest_libc-random-seeding PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wmemcmp_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWmemcmpBoundary.cpp)
    target_include_directories(guest_wmemcmp_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wmemcmp_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wmemcmp_boundary_tests)
    add_test(NAME guest_wmemcmp_boundary COMMAND guest_wmemcmp_boundary_tests)
    set_tests_properties(guest_wmemcmp_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wmemcmp_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_random_device_seed_tests ${LIBS_INCLUDE_DIR}/tests/GuestRandomDeviceSeed.cpp src/Random.cpp)
    target_include_directories(guest_random_device_seed_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_random_device_seed_tests PRIVATE libc libSceLibcInternal)
    configure_windows_unwind(guest_random_device_seed_tests)
    add_test(NAME guest_random_device_seed COMMAND guest_random_device_seed_tests)
    if(WIN32)
        set_tests_properties(guest_random_device_seed PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_stream_init_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2StreamInit.cpp)
    target_include_directories(guest_sce_v2_stream_init_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_stream_init_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_stream_init_tests)
    add_test(NAME guest_sce_v2_stream_init COMMAND guest_sce_v2_stream_init_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_stream_init PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_memcpy_protected_tests ${LIBS_INCLUDE_DIR}/tests/GuestMemcpyProtected.cpp)
    target_include_directories(guest_memcpy_protected_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_memcpy_protected_tests PRIVATE libc)
    configure_windows_unwind(guest_memcpy_protected_tests)
    add_test(NAME guest_memcpy_protected COMMAND guest_memcpy_protected_tests)
    set_tests_properties(guest_memcpy_protected PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_memcpy_protected PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_float_constants_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2FloatConstants.cpp)
    target_include_directories(guest_sce_v2_float_constants_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_float_constants_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_float_constants_tests)
    add_test(NAME guest_sce_v2_float_constants COMMAND guest_sce_v2_float_constants_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_float_constants PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_count_ones_tests ${LIBS_INCLUDE_DIR}/tests/GuestCountOnes.cpp)
    target_include_directories(guest_count_ones_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_count_ones_tests PRIVATE libc)
    configure_windows_unwind(guest_count_ones_tests)
    foreach(width uc us ui ul ull)
        add_test(NAME guest_count_ones_${width} COMMAND guest_count_ones_tests ${width})
        set_tests_properties(guest_count_ones_${width} PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_count_ones_${width} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()
    add_test_executable(guest_c23_bits_tests ${LIBS_INCLUDE_DIR}/tests/GuestC23Bits.cpp)
    target_include_directories(guest_c23_bits_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_c23_bits_tests PRIVATE libc)
    configure_windows_unwind(guest_c23_bits_tests)
    foreach(operation first_leading_zero first_leading_one first_trailing_zero first_trailing_one has_single_bit bit_width bit_floor bit_ceil)
        foreach(width uc us ui ul ull)
            add_test(NAME guest_c23_bits_${operation}_${width} COMMAND guest_c23_bits_tests ${operation}_${width})
            set_tests_properties(guest_c23_bits_${operation}_${width} PROPERTIES TIMEOUT 20)
            if(WIN32)
                set_tests_properties(guest_c23_bits_${operation}_${width} PROPERTIES ENVIRONMENT_MODIFICATION
                    "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
            endif()
        endforeach()
    endforeach()
    add_test_executable(guest_integer_builtins_tests ${LIBS_INCLUDE_DIR}/tests/GuestIntegerBuiltins.cpp)
    target_include_directories(guest_integer_builtins_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_integer_builtins_tests PRIVATE libc)
    configure_windows_unwind(guest_integer_builtins_tests)
    add_test(NAME guest_integer_builtins COMMAND guest_integer_builtins_tests)
    if(WIN32)
        set_tests_properties(guest_integer_builtins PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wcsncmp_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWcsncmpBoundary.cpp)
    target_include_directories(guest_wcsncmp_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wcsncmp_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wcsncmp_boundary_tests)
    add_test(NAME guest_wcsncmp_boundary COMMAND guest_wcsncmp_boundary_tests)
    set_tests_properties(guest_wcsncmp_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wcsncmp_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_count_zeros_tests ${LIBS_INCLUDE_DIR}/tests/GuestCountZeros.cpp)
    target_include_directories(guest_count_zeros_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_count_zeros_tests PRIVATE libc)
    configure_windows_unwind(guest_count_zeros_tests)
    foreach(width uc us ui ul ull)
        add_test(NAME guest_count_zeros_${width} COMMAND guest_count_zeros_tests ${width})
        set_tests_properties(guest_count_zeros_${width} PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_count_zeros_${width} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()
    add_test_executable(guest_strcoll_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrcollBoundary.cpp)
    target_include_directories(guest_strcoll_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strcoll_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_strcoll_boundary_tests)
    add_test(NAME guest_strcoll_boundary COMMAND guest_strcoll_boundary_tests)
    set_tests_properties(guest_strcoll_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strcoll_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_stream_scan_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideStreamScan.cpp)
    target_include_directories(guest_wide_stream_scan_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_stream_scan_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_stream_scan_tests)
    add_test(NAME guest_wide_stream_scan COMMAND guest_wide_stream_scan_tests)
    if(WIN32)
        set_tests_properties(guest_wide_stream_scan PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_stdio_variadic_tests ${LIBS_INCLUDE_DIR}/tests/GuestStdioVariadic.cpp)
    target_include_directories(guest_stdio_variadic_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_stdio_variadic_tests PRIVATE libc)
    configure_windows_unwind(guest_stdio_variadic_tests)
    add_test(NAME guest_stdio_variadic COMMAND guest_stdio_variadic_tests)
    if(WIN32)
        set_tests_properties(guest_stdio_variadic PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_strncpy_protected_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrncpyProtected.cpp)
    target_include_directories(guest_strncpy_protected_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strncpy_protected_tests PRIVATE libc)
    configure_windows_unwind(guest_strncpy_protected_tests)
    add_test(NAME guest_strncpy_protected COMMAND guest_strncpy_protected_tests)
    set_tests_properties(guest_strncpy_protected PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strncpy_protected PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_execute_once_tests ${LIBS_INCLUDE_DIR}/tests/GuestExecuteOnce.cpp)
    target_include_directories(guest_execute_once_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_execute_once_tests PRIVATE libc)
    configure_windows_unwind(guest_execute_once_tests)
    add_test(NAME guest_execute_once COMMAND guest_execute_once_tests)
    set_tests_properties(guest_execute_once PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_execute_once PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_token_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideTokenBoundary.cpp)
    target_include_directories(guest_wide_token_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_token_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_token_boundary_tests)
    add_test(NAME guest_wide_token_boundary COMMAND guest_wide_token_boundary_tests)
    set_tests_properties(guest_wide_token_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wide_token_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_std_execute_once_tests ${LIBS_INCLUDE_DIR}/tests/GuestStdExecuteOnce.cpp)
    target_include_directories(guest_std_execute_once_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_std_execute_once_tests PRIVATE libc)
    configure_windows_unwind(guest_std_execute_once_tests)
    add_test(NAME guest_std_execute_once COMMAND guest_std_execute_once_tests)
    set_tests_properties(guest_std_execute_once PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_std_execute_once PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_execute_once_concurrency_tests ${LIBS_INCLUDE_DIR}/tests/GuestExecuteOnceConcurrency.cpp)
    target_include_directories(guest_execute_once_concurrency_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_execute_once_concurrency_tests PRIVATE libc)
    configure_windows_unwind(guest_execute_once_concurrency_tests)
    foreach(onceEntry IN ITEMS mangled plain)
        add_test(NAME guest_execute_once_concurrency_${onceEntry} COMMAND guest_execute_once_concurrency_tests ${onceEntry})
        set_tests_properties(guest_execute_once_concurrency_${onceEntry} PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_execute_once_concurrency_${onceEntry} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()
    add_test_executable(guest_tokenizer_protected_tests ${LIBS_INCLUDE_DIR}/tests/GuestTokenizerProtected.cpp)
    target_include_directories(guest_tokenizer_protected_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_tokenizer_protected_tests PRIVATE libc)
    configure_windows_unwind(guest_tokenizer_protected_tests)
    add_test(NAME guest_tokenizer_protected COMMAND guest_tokenizer_protected_tests)
    set_tests_properties(guest_tokenizer_protected PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_tokenizer_protected PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_math_exact_tests ${LIBS_INCLUDE_DIR}/tests/GuestMathExact.cpp)
    target_include_directories(guest_math_exact_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_math_exact_tests PRIVATE libc)
    configure_windows_unwind(guest_math_exact_tests)
    add_test(NAME guest_math_exact COMMAND guest_math_exact_tests)
    if(WIN32)
        set_tests_properties(guest_math_exact PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_multiprecision_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Multiprecision.cpp)
    target_include_directories(guest_sce_v2_multiprecision_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_multiprecision_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_multiprecision_tests)
    add_test(NAME guest_sce_v2_multiprecision COMMAND guest_sce_v2_multiprecision_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_multiprecision PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_dinkumware_float_bits_tests ${LIBS_INCLUDE_DIR}/tests/GuestDinkumwareFloatBits.cpp)
    target_include_directories(guest_dinkumware_float_bits_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_dinkumware_float_bits_tests PRIVATE libc)
    configure_windows_unwind(guest_dinkumware_float_bits_tests)
    add_test(NAME guest_dinkumware_float_bits COMMAND guest_dinkumware_float_bits_tests)
    if(WIN32)
        set_tests_properties(guest_dinkumware_float_bits PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_log_gamma_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2LogGamma.cpp)
    target_include_directories(guest_sce_v2_log_gamma_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_log_gamma_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_log_gamma_tests)
    add_test(NAME guest_sce_v2_log_gamma COMMAND guest_sce_v2_log_gamma_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_log_gamma PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_float_helpers_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2FloatHelpers.cpp)
    target_include_directories(guest_sce_v2_float_helpers_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_float_helpers_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_float_helpers_tests)
    add_test(NAME guest_sce_v2_float_helpers COMMAND guest_sce_v2_float_helpers_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_float_helpers PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_xtime_diff_to_millis_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2XtimeDiffToMillis.cpp)
    target_include_directories(guest_sce_v2_xtime_diff_to_millis_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_xtime_diff_to_millis_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_xtime_diff_to_millis_tests)
    add_test(NAME guest_sce_v2_xtime_diff_to_millis COMMAND guest_sce_v2_xtime_diff_to_millis_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_xtime_diff_to_millis PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_bessel_tests ${LIBS_INCLUDE_DIR}/tests/GuestBessel.cpp)
    target_include_directories(guest_bessel_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_bessel_tests PRIVATE libc)
    configure_windows_unwind(guest_bessel_tests)
    add_test(NAME guest_bessel COMMAND guest_bessel_tests)
    if(WIN32)
        set_tests_properties(guest_bessel PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wcslen_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWcslenBoundary.cpp)
    target_include_directories(guest_wcslen_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wcslen_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wcslen_boundary_tests)
    add_test(NAME guest_wcslen_boundary COMMAND guest_wcslen_boundary_tests)
    set_tests_properties(guest_wcslen_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wcslen_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libc_threads_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcThreads.cpp)
    target_include_directories(guest_libc_threads_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_threads_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_libc_threads_tests)
    add_test(NAME guest_libc_threads COMMAND guest_libc_threads_tests)
    set_tests_properties(guest_libc_threads PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_threads PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_thrd_start_tests ${LIBS_INCLUDE_DIR}/tests/GuestThrdStart.cpp)
    target_include_directories(guest_thrd_start_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_thrd_start_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_thrd_start_tests)
    add_test(NAME guest_thrd_start COMMAND guest_thrd_start_tests)
    set_tests_properties(guest_thrd_start PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(guest_thrd_start PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_cnd_at_thread_exit_tests ${LIBS_INCLUDE_DIR}/tests/GuestCndAtThreadExit.cpp)
    target_include_directories(guest_cnd_at_thread_exit_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cnd_at_thread_exit_tests PRIVATE libc)
    configure_windows_unwind(guest_cnd_at_thread_exit_tests)
    add_test(NAME guest_cnd_at_thread_exit COMMAND guest_cnd_at_thread_exit_tests)
    set_tests_properties(guest_cnd_at_thread_exit PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cnd_at_thread_exit PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_std_thread_hardware_concurrency_tests ${LIBS_INCLUDE_DIR}/tests/GuestStdThreadHardwareConcurrency.cpp)
    target_include_directories(guest_std_thread_hardware_concurrency_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_std_thread_hardware_concurrency_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_std_thread_hardware_concurrency_tests)
    add_test(NAME guest_std_thread_hardware_concurrency COMMAND guest_std_thread_hardware_concurrency_tests)
    set_tests_properties(guest_std_thread_hardware_concurrency PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_std_thread_hardware_concurrency PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libcxx_thread_state_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcxxThreadState.cpp)
    target_include_directories(guest_libcxx_thread_state_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libcxx_thread_state_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_libcxx_thread_state_tests)
    add_test(NAME guest_libcxx_thread_state COMMAND guest_libcxx_thread_state_tests)
    set_tests_properties(guest_libcxx_thread_state PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libcxx_thread_state PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libc_shared_mutex_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcSharedMutex.cpp)
    target_include_directories(guest_libc_shared_mutex_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_shared_mutex_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_libc_shared_mutex_tests)
    add_test(NAME guest_libc_shared_mutex COMMAND guest_libc_shared_mutex_tests)
    set_tests_properties(guest_libc_shared_mutex PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_shared_mutex PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_timespec64_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Timespec64.cpp)
    target_include_directories(guest_sce_v2_timespec64_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_timespec64_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_timespec64_tests)
    add_test(NAME guest_sce_v2_timespec64 COMMAND guest_sce_v2_timespec64_tests)
    set_tests_properties(guest_sce_v2_timespec64 PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_sce_v2_timespec64 PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libc_static_imports_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcStaticImports.cpp)
    target_include_directories(guest_libc_static_imports_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_static_imports_tests PRIVATE libc)
    configure_windows_unwind(guest_libc_static_imports_tests)
    add_test(NAME guest_libc_static_imports COMMAND guest_libc_static_imports_tests)
    set_tests_properties(guest_libc_static_imports PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_static_imports PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_at_thread_exit_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2AtThreadExit.cpp)
    target_include_directories(guest_sce_v2_at_thread_exit_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_at_thread_exit_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_sce_v2_at_thread_exit_tests)
    add_test(NAME guest_sce_v2_at_thread_exit COMMAND guest_sce_v2_at_thread_exit_tests)
    set_tests_properties(guest_sce_v2_at_thread_exit PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_sce_v2_at_thread_exit PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wcscmp_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWcscmpBoundary.cpp)
    target_include_directories(guest_wcscmp_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wcscmp_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wcscmp_boundary_tests)
    add_test(NAME guest_wcscmp_boundary COMMAND guest_wcscmp_boundary_tests)
    set_tests_properties(guest_wcscmp_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wcscmp_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_compare_blocks_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideCompareBlocks.cpp)
    target_include_directories(guest_wide_compare_blocks_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_compare_blocks_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_compare_blocks_tests)
    add_test(NAME guest_wide_compare_blocks COMMAND guest_wide_compare_blocks_tests)
    if(WIN32)
        set_tests_properties(guest_wide_compare_blocks PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_fiopen_tests ${LIBS_INCLUDE_DIR}/tests/GuestFiopen.cpp)
    target_include_directories(guest_fiopen_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_fiopen_tests PRIVATE libc)
    configure_windows_unwind(guest_fiopen_tests)
    add_test(NAME guest_fiopen COMMAND guest_fiopen_tests)
    set_tests_properties(guest_fiopen PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_fiopen PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_working_directory_tests ${LIBS_INCLUDE_DIR}/tests/GuestWorkingDirectory.cpp)
    target_include_directories(guest_working_directory_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_working_directory_tests PRIVATE libc)
    configure_windows_unwind(guest_working_directory_tests)
    add_test(NAME guest_working_directory COMMAND guest_working_directory_tests)
    if(WIN32)
        set_tests_properties(guest_working_directory PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_strlcat_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrlcatBoundary.cpp)
    target_include_directories(guest_strlcat_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strlcat_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_strlcat_boundary_tests)
    add_test(NAME guest_strlcat_boundary COMMAND guest_strlcat_boundary_tests)
    set_tests_properties(guest_strlcat_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strlcat_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_realpath_tests ${LIBS_INCLUDE_DIR}/tests/GuestRealpath.cpp)
    target_include_directories(guest_realpath_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_realpath_tests PRIVATE libc)
    configure_windows_unwind(guest_realpath_tests)
    add_test(NAME guest_realpath COMMAND guest_realpath_tests)
    set_tests_properties(guest_realpath PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_realpath PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_strxfrm_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrxfrmBoundary.cpp)
    target_include_directories(guest_strxfrm_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strxfrm_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_strxfrm_boundary_tests)
    add_test(NAME guest_strxfrm_boundary COMMAND guest_strxfrm_boundary_tests)
    set_tests_properties(guest_strxfrm_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strxfrm_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_path_case_tests ${LIBS_INCLUDE_DIR}/tests/GuestPathCase.cpp)
    target_include_directories(guest_path_case_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_path_case_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_path_case_tests)
    add_test(NAME guest_path_case COMMAND guest_path_case_tests)
    if(WIN32)
        set_tests_properties(guest_path_case PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_path_drive_component_tests ${LIBS_INCLUDE_DIR}/tests/GuestPathDriveComponent.cpp)
    target_include_directories(guest_path_drive_component_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_path_drive_component_tests PRIVATE libc)
    configure_windows_unwind(guest_path_drive_component_tests)
    add_test(NAME guest_path_drive_component COMMAND guest_path_drive_component_tests)
    set_tests_properties(guest_path_drive_component PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_path_drive_component PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wcsncpy_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestWcsncpyExtent.cpp)
    target_include_directories(guest_wcsncpy_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wcsncpy_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_wcsncpy_extent_tests)
    add_test(NAME guest_wcsncpy_extent COMMAND guest_wcsncpy_extent_tests)
    set_tests_properties(guest_wcsncpy_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wcsncpy_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_directory_tests ${LIBS_INCLUDE_DIR}/tests/GuestDirectory.cpp)
    target_include_directories(guest_directory_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_directory_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_directory_tests)
    add_test(NAME guest_directory COMMAND guest_directory_tests)
    if(WIN32)
        set_tests_properties(guest_directory PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_decimal_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestDecimalBoundary.cpp)
    target_include_directories(guest_decimal_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_decimal_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_decimal_boundary_tests)
    add_test(NAME guest_decimal_boundary COMMAND guest_decimal_boundary_tests)
    set_tests_properties(guest_decimal_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_decimal_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_environment_tests ${LIBS_INCLUDE_DIR}/tests/GuestEnvironment.cpp)
    target_include_directories(guest_environment_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_environment_tests PRIVATE libc)
    configure_windows_unwind(guest_environment_tests)
    add_test(NAME guest_environment COMMAND guest_environment_tests)
    if(WIN32)
        set_tests_properties(guest_environment PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_dinkumware_atomics_tests ${LIBS_INCLUDE_DIR}/tests/GuestDinkumwareAtomics.cpp)
    target_include_directories(guest_dinkumware_atomics_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_dinkumware_atomics_tests PRIVATE libc)
    configure_windows_unwind(guest_dinkumware_atomics_tests)
    add_test(NAME guest_dinkumware_atomics COMMAND guest_dinkumware_atomics_tests)
    if(WIN32)
        set_tests_properties(guest_dinkumware_atomics PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libc_atomic_cas_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcAtomicCas.cpp)
    target_include_directories(guest_libc_atomic_cas_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_atomic_cas_tests PRIVATE libc)
    configure_windows_unwind(guest_libc_atomic_cas_tests)
    add_test(NAME guest_libc_atomic_cas COMMAND guest_libc_atomic_cas_tests)
    if(WIN32)
        set_tests_properties(guest_libc_atomic_cas PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_dinkumware_division_tests ${LIBS_INCLUDE_DIR}/tests/GuestDinkumwareDivision.cpp)
    target_include_directories(guest_dinkumware_division_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_dinkumware_division_tests PRIVATE libc)
    configure_windows_unwind(guest_dinkumware_division_tests)
    add_test(NAME guest_dinkumware_division COMMAND guest_dinkumware_division_tests)
    if(MINGW)
        set_tests_properties(guest_dinkumware_division PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_dinkumware_internals_tests ${LIBS_INCLUDE_DIR}/tests/GuestDinkumwareInternals.cpp)
    target_include_directories(guest_dinkumware_internals_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_dinkumware_internals_tests PRIVATE libc)
    configure_windows_unwind(guest_dinkumware_internals_tests)
    add_test(NAME guest_dinkumware_internals COMMAND guest_dinkumware_internals_tests)
    if(WIN32)
        set_tests_properties(guest_dinkumware_internals PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_string_to_integer_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2StringToInteger.cpp)
    target_include_directories(guest_sce_v2_string_to_integer_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_string_to_integer_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_string_to_integer_tests)
    add_test(NAME guest_sce_v2_string_to_integer COMMAND guest_sce_v2_string_to_integer_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_string_to_integer PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_device_name_tests ${LIBS_INCLUDE_DIR}/tests/GuestDeviceName.cpp)
    target_include_directories(guest_device_name_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_device_name_tests PRIVATE libc)
    configure_windows_unwind(guest_device_name_tests)
    add_test(NAME guest_device_name COMMAND guest_device_name_tests)
    set_tests_properties(guest_device_name PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_device_name PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_hostname_tests ${LIBS_INCLUDE_DIR}/tests/GuestHostname.cpp)
    target_include_directories(guest_hostname_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_hostname_tests PRIVATE libc)
    configure_windows_unwind(guest_hostname_tests)
    add_test(NAME guest_hostname COMMAND guest_hostname_tests)
    set_tests_properties(guest_hostname PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_hostname PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_vector_algorithms_tests ${LIBS_INCLUDE_DIR}/tests/GuestVectorAlgorithms.cpp)
    target_include_directories(guest_vector_algorithms_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_vector_algorithms_tests PRIVATE libc)
    configure_windows_unwind(guest_vector_algorithms_tests)
    add_test(NAME guest_vector_algorithms COMMAND guest_vector_algorithms_tests)
    if(WIN32)
        set_tests_properties(guest_vector_algorithms PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_find_last_trivial_tests ${LIBS_INCLUDE_DIR}/tests/GuestFindLastTrivial.cpp)
    target_include_directories(guest_find_last_trivial_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_find_last_trivial_tests PRIVATE libc)
    configure_windows_unwind(guest_find_last_trivial_tests)
    foreach(width 1 2 4 8)
        foreach(mode empty positions values guard_pages)
            add_test(NAME guest_find_last_trivial_${width}_${mode} COMMAND guest_find_last_trivial_tests ${width} ${mode})
            set_tests_properties(guest_find_last_trivial_${width}_${mode} PROPERTIES TIMEOUT 20)
            if(WIN32)
                set_tests_properties(guest_find_last_trivial_${width}_${mode} PROPERTIES ENVIRONMENT_MODIFICATION
                    "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
            endif()
        endforeach()
    endforeach()
    add_test_executable(guest_memrchr_tests ${LIBS_INCLUDE_DIR}/tests/GuestMemrchr.cpp)
    target_include_directories(guest_memrchr_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_memrchr_tests PRIVATE libc)
    configure_windows_unwind(guest_memrchr_tests)
    add_test(NAME guest_memrchr COMMAND guest_memrchr_tests)
    if(WIN32)
        set_tests_properties(guest_memrchr PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_string_compare_tests ${LIBS_INCLUDE_DIR}/tests/GuestStringCompare.cpp)
    target_include_directories(guest_string_compare_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_string_compare_tests PRIVATE libc)
    configure_windows_unwind(guest_string_compare_tests)
    add_test(NAME guest_string_compare COMMAND guest_string_compare_tests)
    if(WIN32)
        set_tests_properties(guest_string_compare PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_case_compare_random_tests ${LIBS_INCLUDE_DIR}/tests/GuestCaseCompareRandom.cpp)
    target_include_directories(guest_case_compare_random_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_case_compare_random_tests PRIVATE libc)
    configure_windows_unwind(guest_case_compare_random_tests)
    add_test(NAME guest_case_compare_random COMMAND guest_case_compare_random_tests)
    if(WIN32)
        set_tests_properties(guest_case_compare_random PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_daemon_tests ${LIBS_INCLUDE_DIR}/tests/GuestDaemon.cpp)
    target_include_directories(guest_daemon_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_daemon_tests PRIVATE libc)
    configure_windows_unwind(guest_daemon_tests)
    add_test(NAME guest_daemon COMMAND guest_daemon_tests)
    if(WIN32)
        set_tests_properties(guest_daemon PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_lifecycle_tests ${LIBS_INCLUDE_DIR}/tests/GuestLifecycle.cpp)
    target_include_directories(guest_lifecycle_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_lifecycle_tests PRIVATE libc)
    configure_windows_unwind(guest_lifecycle_tests)
    add_test(NAME guest_lifecycle COMMAND guest_lifecycle_tests)
    if(WIN32)
        set_tests_properties(guest_lifecycle PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_thread_callback_abi_tests ${LIBS_INCLUDE_DIR}/tests/GuestThreadCallbackAbi.cpp)
    target_include_directories(guest_thread_callback_abi_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_thread_callback_abi_tests PRIVATE libc)
    configure_windows_unwind(guest_thread_callback_abi_tests)
    add_test(NAME guest_thread_callback_abi COMMAND guest_thread_callback_abi_tests)
    set_tests_properties(guest_thread_callback_abi PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_thread_callback_abi PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libcxx_sleep_for_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcxxSleepFor.cpp)
    target_include_directories(guest_libcxx_sleep_for_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libcxx_sleep_for_tests PRIVATE libc)
    configure_windows_unwind(guest_libcxx_sleep_for_tests)
    add_test(NAME guest_libcxx_sleep_for COMMAND guest_libcxx_sleep_for_tests)
    set_tests_properties(guest_libcxx_sleep_for PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_libcxx_sleep_for PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_interface_tests ${LIBS_INCLUDE_DIR}/tests/GuestInterfaces.cpp)
    target_include_directories(guest_interface_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_interface_tests PRIVATE libc)
    configure_windows_unwind(guest_interface_tests)
    add_test(NAME guest_interfaces COMMAND guest_interface_tests)
    if(WIN32)
        target_link_libraries(guest_interface_tests PRIVATE ws2_32 iphlpapi)
        set_tests_properties(guest_interfaces PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_binary_scaling_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2BinaryScaling.cpp)
    target_include_directories(guest_sce_v2_binary_scaling_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_binary_scaling_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_binary_scaling_tests)
    add_test(NAME guest_sce_v2_binary_scaling COMMAND guest_sce_v2_binary_scaling_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_binary_scaling PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_sce_v2_extended_precision_tests ${LIBS_INCLUDE_DIR}/tests/GuestSceV2ExtendedPrecision.cpp)
    target_include_directories(guest_sce_v2_extended_precision_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_sce_v2_extended_precision_tests PRIVATE libc)
    configure_windows_unwind(guest_sce_v2_extended_precision_tests)
    add_test(NAME guest_sce_v2_extended_precision COMMAND guest_sce_v2_extended_precision_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_extended_precision PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_qsort_tests ${LIBS_INCLUDE_DIR}/tests/GuestQsort.cpp)
    target_include_directories(guest_qsort_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_qsort_tests PRIVATE libc)
    configure_windows_unwind(guest_qsort_tests)
    add_test(NAME guest_qsort COMMAND guest_qsort_tests)
    set_tests_properties(guest_qsort PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_qsort PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libcxx_sort_unsigned_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcxxSortUnsigned.cpp)
    target_include_directories(guest_libcxx_sort_unsigned_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libcxx_sort_unsigned_tests PRIVATE libc)
    configure_windows_unwind(guest_libcxx_sort_unsigned_tests)
    add_test(NAME guest_libcxx_sort_unsigned COMMAND guest_libcxx_sort_unsigned_tests)
    set_tests_properties(guest_libcxx_sort_unsigned PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_libcxx_sort_unsigned PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_cxa_guard_tests ${LIBS_INCLUDE_DIR}/tests/GuestCxaGuard.cpp)
    target_include_directories(guest_cxa_guard_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_cxa_guard_tests PRIVATE libc)
    configure_windows_unwind(guest_cxa_guard_tests)
    add_test(NAME guest_cxa_guard COMMAND guest_cxa_guard_tests)
    set_tests_properties(guest_cxa_guard PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_cxa_guard PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_timespec_getres_tests ${LIBS_INCLUDE_DIR}/tests/GuestTimespecGetres.cpp)
    target_include_directories(guest_timespec_getres_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_timespec_getres_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_timespec_getres_tests)
    foreach(mode unsupported forwarding errors integration)
        add_test(NAME guest_timespec_getres_${mode} COMMAND guest_timespec_getres_tests ${mode})
        set_tests_properties(guest_timespec_getres_${mode} PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_timespec_getres_${mode} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()

    add_test_executable(guest_crt_setup_tests ${LIBS_INCLUDE_DIR}/tests/GuestCrtSetup.cpp)
    target_include_directories(guest_crt_setup_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_crt_setup_tests PRIVATE libc)
    configure_windows_unwind(guest_crt_setup_tests)
    foreach(mode table abutting constants)
        add_test(NAME guest_crt_setup_${mode} COMMAND guest_crt_setup_tests ${mode})
        set_tests_properties(guest_crt_setup_${mode} PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_crt_setup_${mode} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()

    add_test_executable(guest_shared_mutex_instance_tests ${LIBS_INCLUDE_DIR}/tests/GuestSharedMutexInstance.cpp)
    target_include_directories(guest_shared_mutex_instance_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_shared_mutex_instance_tests PRIVATE libc libkernel)
    configure_windows_unwind(guest_shared_mutex_instance_tests)
    foreach(mode identity refcount exclusion shared unknown reacquire)
        add_test(NAME guest_shared_mutex_instance_${mode} COMMAND guest_shared_mutex_instance_tests ${mode})
        set_tests_properties(guest_shared_mutex_instance_${mode} PROPERTIES TIMEOUT 20)
        if(WIN32)
            set_tests_properties(guest_shared_mutex_instance_${mode} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()

    add_test_executable(guest_strftime_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrftime.cpp)
    target_include_directories(guest_strftime_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strftime_tests PRIVATE libc)
    configure_windows_unwind(guest_strftime_tests)
    add_test(NAME guest_strftime COMMAND guest_strftime_tests)
    set_tests_properties(guest_strftime PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strftime PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_atoi_tests ${LIBS_INCLUDE_DIR}/tests/GuestAtoi.cpp)
    target_include_directories(guest_atoi_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_atoi_tests PRIVATE libc)
    configure_windows_unwind(guest_atoi_tests)
    add_test(NAME guest_atoi COMMAND guest_atoi_tests)
    set_tests_properties(guest_atoi PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_atoi PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_reallocalign_tests ${LIBS_INCLUDE_DIR}/tests/GuestReallocalign.cpp)
    target_include_directories(guest_reallocalign_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_reallocalign_tests PRIVATE libc)
    configure_windows_unwind(guest_reallocalign_tests)
    add_test(NAME guest_reallocalign COMMAND guest_reallocalign_tests)
    if(WIN32)
        set_tests_properties(guest_reallocalign PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_standard_stream_tests ${LIBS_INCLUDE_DIR}/tests/GuestStandardStreams.cpp)
    target_include_directories(guest_standard_stream_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_standard_stream_tests PRIVATE libc)
    configure_windows_unwind(guest_standard_stream_tests)
    add_test(NAME guest_standard_streams COMMAND guest_standard_stream_tests)
    add_test(NAME guest_standard_streams_closed_stdout COMMAND guest_standard_stream_tests --closed-stdout)
    add_test(NAME guest_standard_streams_exclusive_stdout COMMAND guest_standard_stream_tests --exclusive-stdout)
    add_test(NAME guest_standard_streams_reopen_closed_stdout COMMAND guest_standard_stream_tests --reopen-closed-stdout)
    if(WIN32)
        set_tests_properties(guest_standard_streams guest_standard_streams_closed_stdout guest_standard_streams_exclusive_stdout guest_standard_streams_reopen_closed_stdout PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test(NAME guest_standard_streams_update_stdout COMMAND guest_standard_stream_tests --update-stdout)
    if(WIN32)
        set_tests_properties(guest_standard_streams_update_stdout PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_gets_tests NO_RUNTIME_DLL_STAGING ${LIBS_INCLUDE_DIR}/tests/GuestGets.cpp)
    target_include_directories(guest_gets_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_gets_tests PRIVATE libc ${CMAKE_DL_LIBS})
    configure_windows_unwind(guest_gets_tests)
    add_test(NAME guest_gets COMMAND guest_gets_tests $<TARGET_FILE:libc> guest_gets_error.tmp)
    set_tests_properties(guest_gets PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_gets PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(file_stream_status_tests ${LIBS_INCLUDE_DIR}/tests/FileStreamStatus.cpp)
    target_include_directories(file_stream_status_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(file_stream_status_tests PRIVATE libc)
    configure_windows_unwind(file_stream_status_tests)
    add_test(NAME file_stream_status COMMAND file_stream_status_tests)
    set_tests_properties(file_stream_status PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(file_stream_status PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(file_streams_tests ${LIBS_INCLUDE_DIR}/tests/FileStreams.cpp)
    target_include_directories(file_streams_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(file_streams_tests PRIVATE libc)
    configure_windows_unwind(file_streams_tests)
    add_test(NAME file_streams COMMAND file_streams_tests file_streams.tmp)
    set_tests_properties(file_streams PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(file_streams PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        add_test_executable(guest_stream_buffer_host_write_tests ${LIBS_INCLUDE_DIR}/tests/GuestStreamBufferHostWrite.cpp)
        target_include_directories(guest_stream_buffer_host_write_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_stream_buffer_host_write_tests PRIVATE libkernel libc)
        configure_windows_unwind(guest_stream_buffer_host_write_tests)
        add_test(NAME guest_stream_buffer_host_write COMMAND guest_stream_buffer_host_write_tests)
        set_tests_properties(guest_stream_buffer_host_write PROPERTIES TIMEOUT 20 ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libc_file_lock_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcFileLock.cpp)
    target_include_directories(guest_libc_file_lock_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libc_file_lock_tests PRIVATE libc)
    configure_windows_unwind(guest_libc_file_lock_tests)
    add_test(NAME guest_libc_file_lock COMMAND guest_libc_file_lock_tests)
    set_tests_properties(guest_libc_file_lock PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libc_file_lock PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_freopen_host_standard_tests ${LIBS_INCLUDE_DIR}/tests/GuestFreopenHostStandard.cpp)
    target_include_directories(guest_freopen_host_standard_tests PRIVATE ${LIBS_INCLUDE_DIR})
    if(WIN32)
        target_link_libraries(guest_freopen_host_standard_tests PRIVATE libkernel libc)
    else()
        target_link_libraries(guest_freopen_host_standard_tests PRIVATE libc)
    endif()
    configure_windows_unwind(guest_freopen_host_standard_tests)
    add_test(NAME guest_freopen_host_standard COMMAND guest_freopen_host_standard_tests)
    set_tests_properties(guest_freopen_host_standard PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_freopen_host_standard PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_freopen_host_log_tests ${LIBS_INCLUDE_DIR}/tests/GuestFreopenHostLog.cpp)
    target_include_directories(guest_freopen_host_log_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_freopen_host_log_tests PRIVATE libc)
    configure_windows_unwind(guest_freopen_host_log_tests)
    add_test(NAME guest_freopen_host_log COMMAND guest_freopen_host_log_tests)
    set_tests_properties(guest_freopen_host_log PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_freopen_host_log PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
        add_test(NAME guest_freopen_host_log_keep_failure COMMAND guest_freopen_host_log_tests keep-failure)
        set_tests_properties(guest_freopen_host_log_keep_failure PROPERTIES TIMEOUT 20)
    endif()
    add_test_executable(guest_error_tests ${LIBS_INCLUDE_DIR}/tests/GuestErrors.cpp)
    target_include_directories(guest_error_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_error_tests PRIVATE libc)
    configure_windows_unwind(guest_error_tests)
    add_test(NAME guest_errors COMMAND guest_error_tests)
    if(WIN32)
        set_tests_properties(guest_errors PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
        add_test_executable(guest_call_trace_tests ${LIBS_INCLUDE_DIR}/tests/GuestCallTrace.cpp)
        target_include_directories(guest_call_trace_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_call_trace_tests PRIVATE libc)
        configure_windows_unwind(guest_call_trace_tests)
        add_test(NAME guest_call_trace COMMAND guest_call_trace_tests)
        add_test(NAME guest_call_trace_abort COMMAND guest_call_trace_tests abort)
        if(WIN32)
            set_tests_properties(guest_call_trace guest_call_trace_abort PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
        set_tests_properties(guest_call_trace_abort PROPERTIES TIMEOUT 20 PASS_REGULAR_EXPRESSION
            "last traced system library calls[^~]*#1 thread [0-9]+ libTraced.prx Integers from [^~]*guest_call_trace_tests${CMAKE_EXECUTABLE_SUFFIX}[^~]*#2 thread [0-9]+ libOther.prx Blocks from[^~]*last traced calls of thread [0-9]+:[^~]*#1 libTraced.prx Integers from[^~]*#2 libOther.prx Blocks from[^~]*most called traced imports \\(2 calls in total\\):[^~]* 1 libTraced.prx Integers[^~]* 1 libOther.prx Blocks")
        if(NOT WIN32)
            add_test(NAME guest_call_trace_abort_race COMMAND guest_call_trace_tests abort-race)
            set_tests_properties(guest_call_trace_abort_race PROPERTIES TIMEOUT 20 PASS_REGULAR_EXPRESSION
                "last traced system library calls[^~]*#102 thread [0-9]+ libTraced.prx Integers from[^~]*most called traced imports \\(102 calls in total\\):[^~]* 101 libTraced.prx Integers[^~]* 1 libOther.prx Blocks")
        endif()
        if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
            add_test_executable(guest_call_trace_fixed_base_tests ${LIBS_INCLUDE_DIR}/tests/GuestCallTrace.cpp)
            target_include_directories(guest_call_trace_fixed_base_tests PRIVATE ${LIBS_INCLUDE_DIR})
            target_link_libraries(guest_call_trace_fixed_base_tests PRIVATE libc)
            set_target_properties(guest_call_trace_fixed_base_tests PROPERTIES POSITION_INDEPENDENT_CODE OFF)
            target_compile_options(guest_call_trace_fixed_base_tests PRIVATE -fno-pie)
            target_link_options(guest_call_trace_fixed_base_tests PRIVATE -no-pie -fuse-ld=bfd)
            add_test(NAME guest_call_trace_fixed_base_abort COMMAND guest_call_trace_fixed_base_tests abort)
            set_tests_properties(guest_call_trace_fixed_base_abort PROPERTIES TIMEOUT 20 PASS_REGULAR_EXPRESSION
                "#1 thread [0-9]+ libTraced.prx Integers from 0x00000000004[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f] guest_call_trace_fixed_base_tests\\+0x[0-9a-f]?[0-9a-f]?[0-9a-f]?[0-9a-f]?[0-9a-f][^0-9a-f]")
        endif()
    endif()
    add_test_executable(guest_syslog_tests ${LIBS_INCLUDE_DIR}/tests/GuestSyslog.cpp)
    target_include_directories(guest_syslog_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_syslog_tests PRIVATE libkernel libc)
    configure_windows_unwind(guest_syslog_tests)
    add_test(NAME guest_syslog COMMAND guest_syslog_tests)
    if(WIN32)
        add_test_executable(guest_syslog_reload_tests ${LIBS_INCLUDE_DIR}/tests/GuestSyslog.cpp)
        target_include_directories(guest_syslog_reload_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_compile_definitions(guest_syslog_reload_tests PRIVATE SYSLOG_RELOAD_TEST)
        target_link_libraries(guest_syslog_reload_tests PRIVATE libc)
        add_dependencies(guest_syslog_reload_tests libkernel)
        configure_windows_unwind(guest_syslog_reload_tests)
        add_test(NAME guest_syslog_reload COMMAND guest_syslog_reload_tests $<TARGET_FILE:libkernel>)
        set_tests_properties(guest_syslog guest_syslog_reload PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(mspace_tests ${LIBS_INCLUDE_DIR}/tests/Mspace.cpp)
    target_include_directories(mspace_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(mspace_tests PRIVATE libc)
    configure_windows_unwind(mspace_tests)
    add_test(NAME mspace COMMAND mspace_tests)
    if(WIN32)
        set_tests_properties(mspace PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_formatting_tests ${LIBS_INCLUDE_DIR}/tests/Formatting.cpp)
    target_include_directories(guest_formatting_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_formatting_tests PRIVATE libc)
    configure_windows_unwind(guest_formatting_tests)
    add_test(NAME guest_formatting COMMAND guest_formatting_tests)
    add_test(NAME guest_sprintf_s_constraints COMMAND guest_formatting_tests --terminated-only)
    if(WIN32)
        set_tests_properties(guest_formatting guest_sprintf_s_constraints PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_new_handler_tests ${LIBS_INCLUDE_DIR}/tests/GuestNewHandler.cpp)
    target_include_directories(guest_new_handler_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_new_handler_tests PRIVATE libc)
    configure_windows_unwind(guest_new_handler_tests)
    add_test_executable(guest_generic_category_tests ${LIBS_INCLUDE_DIR}/tests/GuestGenericCategory.cpp)
    target_include_directories(guest_generic_category_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_generic_category_tests PRIVATE libc)
    configure_windows_unwind(guest_generic_category_tests)
    add_test(NAME guest_generic_category COMMAND guest_generic_category_tests)
    set_tests_properties(guest_generic_category PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_generic_category PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_future_category_tests ${LIBS_INCLUDE_DIR}/tests/GuestFutureCategory.cpp)
    target_include_directories(guest_future_category_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_future_category_tests PRIVATE libc)
    configure_windows_unwind(guest_future_category_tests)
    configure_macos_unwind(guest_future_category_tests)
    add_test(NAME guest_future_category COMMAND guest_future_category_tests)
    set_tests_properties(guest_future_category PROPERTIES TIMEOUT 10)
    if(WIN32)
        set_tests_properties(guest_future_category PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test(NAME guest_new_handler COMMAND guest_new_handler_tests)
    if(WIN32)
        set_tests_properties(guest_new_handler PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test(NAME guest_new_handler_default_heap COMMAND guest_new_handler_tests default)
    if(WIN32)
        set_tests_properties(guest_new_handler_default_heap PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_bzero_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestBzeroExtent.cpp)
    target_include_directories(guest_bzero_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_bzero_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_bzero_extent_tests)
    add_test(NAME guest_bzero_extent COMMAND guest_bzero_extent_tests)
    set_tests_properties(guest_bzero_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_bzero_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_search_tests ${LIBS_INCLUDE_DIR}/tests/GuestSearch.cpp)
    target_include_directories(guest_search_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_search_tests PRIVATE libc)
    configure_windows_unwind(guest_search_tests)
    add_test(NAME guest_search COMMAND guest_search_tests)
    if(WIN32)
        set_tests_properties(guest_search PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wmemchr_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWmemchrBoundary.cpp)
    target_include_directories(guest_wmemchr_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wmemchr_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wmemchr_boundary_tests)
    add_test(NAME guest_wmemchr_boundary COMMAND guest_wmemchr_boundary_tests)
    set_tests_properties(guest_wmemchr_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wmemchr_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_demangle_tests ${LIBS_INCLUDE_DIR}/tests/GuestDemangle.cpp)
    target_include_directories(guest_demangle_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_demangle_tests PRIVATE libc)
    configure_windows_unwind(guest_demangle_tests)
    add_test(NAME guest_demangle COMMAND guest_demangle_tests)
    if(WIN32)
        set_tests_properties(guest_demangle PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(unwind_cursor_tests ${LIBS_INCLUDE_DIR}/tests/UnwindCursor.cpp)
    target_include_directories(unwind_cursor_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(unwind_cursor_tests PRIVATE libc)
    set_target_properties(unwind_cursor_tests PROPERTIES ENABLE_EXPORTS ON)
    configure_windows_unwind(unwind_cursor_tests)
    add_test(NAME unwind_cursor COMMAND unwind_cursor_tests)
    set(unwindCursorTests unwind_cursor)
    if(WIN32)
        add_test_executable(unwind_import_queries_tests ${LIBS_INCLUDE_DIR}/tests/UnwindImportQueries.cpp)
        target_include_directories(unwind_import_queries_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(unwind_import_queries_tests PRIVATE libc)
        configure_windows_unwind(unwind_import_queries_tests)
        add_test(NAME unwind_import_queries COMMAND unwind_import_queries_tests)
        set_tests_properties(unwind_import_queries PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    foreach(operation IN ITEMS get set)
        add_test(NAME unwind_cursor_${operation}_register COMMAND unwind_cursor_tests ${operation}-register)
        set_tests_properties(unwind_cursor_${operation}_register PROPERTIES TIMEOUT 20
            PASS_REGULAR_EXPRESSION "libunwind: ${operation}Register - unsupported x86_64 register")
        add_test(NAME unwind_cursor_${operation}_float_register COMMAND unwind_cursor_tests ${operation}-float-register)
        set_tests_properties(unwind_cursor_${operation}_float_register PROPERTIES TIMEOUT 20
            PASS_REGULAR_EXPRESSION "libunwind: ${operation}FloatRegister - no x86_64 float registers")
        list(APPEND unwindCursorTests unwind_cursor_${operation}_register unwind_cursor_${operation}_float_register)
    endforeach()
    if(WIN32)
        set_tests_properties(${unwindCursorTests} PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_string_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrings.cpp)
    target_include_directories(guest_string_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_string_tests PRIVATE libc libScePosixForWebKit)
    configure_windows_unwind(guest_string_tests)
    add_test(NAME guest_strings COMMAND guest_string_tests)
    if(WIN32)
        set_tests_properties(guest_strings PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wcsrtombs_tests ${LIBS_INCLUDE_DIR}/tests/GuestWcsrtombs.cpp)
    target_include_directories(guest_wcsrtombs_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wcsrtombs_tests PRIVATE libc)
    configure_windows_unwind(guest_wcsrtombs_tests)
    add_test(NAME guest_wcsrtombs COMMAND guest_wcsrtombs_tests)
    if(WIN32)
        set_tests_properties(guest_wcsrtombs PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_span_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideSpanBoundary.cpp)
    target_include_directories(guest_wide_span_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_span_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_span_boundary_tests)
    add_test(NAME guest_wide_span_boundary COMMAND guest_wide_span_boundary_tests)
    set_tests_properties(guest_wide_span_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wide_span_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wcsrtombs_s_tests ${LIBS_INCLUDE_DIR}/tests/GuestWcsrtombsS.cpp)
    target_include_directories(guest_wcsrtombs_s_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wcsrtombs_s_tests PRIVATE libc)
    configure_windows_unwind(guest_wcsrtombs_s_tests)
    add_test(NAME guest_wcsrtombs_s COMMAND guest_wcsrtombs_s_tests)
    if(WIN32)
        set_tests_properties(guest_wcsrtombs_s PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_char_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideCharBoundary.cpp)
    target_include_directories(guest_wide_char_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_char_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_char_boundary_tests)
    add_test(NAME guest_wide_char_boundary COMMAND guest_wide_char_boundary_tests)
    set_tests_properties(guest_wide_char_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wide_char_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_scan_blocks_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideScanBlocks.cpp)
    target_include_directories(guest_wide_scan_blocks_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_scan_blocks_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_scan_blocks_tests)
    add_test(NAME guest_wide_scan_blocks COMMAND guest_wide_scan_blocks_tests)
    if(WIN32)
        set_tests_properties(guest_wide_scan_blocks PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(unwind_callback_abi_tests ${LIBS_INCLUDE_DIR}/tests/UnwindCallbackAbi.cpp)
    target_include_directories(unwind_callback_abi_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(unwind_callback_abi_tests PRIVATE libc)
    configure_windows_unwind(unwind_callback_abi_tests)
    configure_macos_unwind(unwind_callback_abi_tests)
    foreach(callback IN ITEMS backtrace forced_unwind delete_exception end_catch end_catch_gnu)
        add_test(NAME unwind_callback_abi_${callback} COMMAND unwind_callback_abi_tests ${callback})
        if(WIN32)
            set_tests_properties(unwind_callback_abi_${callback} PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endforeach()
    add_test_executable(guest_memmem_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestMemmemBoundary.cpp)
    target_include_directories(guest_memmem_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_memmem_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_memmem_boundary_tests)
    add_test(NAME guest_memmem_boundary COMMAND guest_memmem_boundary_tests)
    set_tests_properties(guest_memmem_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_memmem_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_overflow_error_tests ${LIBS_INCLUDE_DIR}/tests/GuestOverflowError.cpp)
    target_include_directories(guest_overflow_error_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_overflow_error_tests PRIVATE libc)
    configure_windows_unwind(guest_overflow_error_tests)
    add_test(NAME guest_overflow_error COMMAND guest_overflow_error_tests)
    if(WIN32)
        set_tests_properties(guest_overflow_error PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_bad_optional_access_tests ${LIBS_INCLUDE_DIR}/tests/GuestBadOptionalAccess.cpp)
    target_include_directories(guest_bad_optional_access_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_bad_optional_access_tests PRIVATE libc)
    configure_windows_unwind(guest_bad_optional_access_tests)
    configure_macos_unwind(guest_bad_optional_access_tests)
    add_test(NAME guest_bad_optional_access COMMAND guest_bad_optional_access_tests)
    if(WIN32)
        set_tests_properties(guest_bad_optional_access PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_unwind_accessors_tests ${LIBS_INCLUDE_DIR}/tests/GuestUnwindAccessors.cpp)
    target_include_directories(guest_unwind_accessors_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_unwind_accessors_tests PRIVATE libc)
    configure_windows_unwind(guest_unwind_accessors_tests)
    add_test(NAME guest_unwind_accessors COMMAND guest_unwind_accessors_tests)
    if(WIN32)
        set_tests_properties(guest_unwind_accessors PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_libcxx_exception_pointer_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcxxExceptionPointer.cpp)
    target_include_directories(guest_libcxx_exception_pointer_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_libcxx_exception_pointer_tests PRIVATE libc)
    configure_windows_unwind(guest_libcxx_exception_pointer_tests)
    add_test(NAME guest_libcxx_exception_pointer COMMAND guest_libcxx_exception_pointer_tests)
    set_tests_properties(guest_libcxx_exception_pointer PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_libcxx_exception_pointer PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_underflow_error_tests ${LIBS_INCLUDE_DIR}/tests/GuestUnderflowError.cpp)
    target_include_directories(guest_underflow_error_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_underflow_error_tests PRIVATE libc)
    configure_windows_unwind(guest_underflow_error_tests)
    add_test(NAME guest_underflow_error COMMAND guest_underflow_error_tests)
    if(WIN32)
        set_tests_properties(guest_underflow_error PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_stpcpy_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestStpcpyExtent.cpp)
    target_include_directories(guest_stpcpy_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_stpcpy_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_stpcpy_extent_tests)
    add_test(NAME guest_stpcpy_extent COMMAND guest_stpcpy_extent_tests)
    set_tests_properties(guest_stpcpy_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_stpcpy_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_throw_bad_array_new_length_tests ${LIBS_INCLUDE_DIR}/tests/GuestThrowBadArrayNewLength.cpp)
    target_include_directories(guest_throw_bad_array_new_length_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_throw_bad_array_new_length_tests PRIVATE libc)
    configure_windows_unwind(guest_throw_bad_array_new_length_tests)
    add_test(NAME guest_throw_bad_array_new_length COMMAND guest_throw_bad_array_new_length_tests)
    if(WIN32)
        set_tests_properties(guest_throw_bad_array_new_length PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(NOT APPLE)
        add_test_executable(guest_libc_rethrow_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcRethrow.cpp)
        target_include_directories(guest_libc_rethrow_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_libc_rethrow_tests PRIVATE libc)
        configure_windows_unwind(guest_libc_rethrow_tests)
        add_test(NAME guest_libc_rethrow COMMAND guest_libc_rethrow_tests)
        if(WIN32)
            set_tests_properties(guest_libc_rethrow PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endif()
    add_test_executable(guest_exception_pointer_tests ${LIBS_INCLUDE_DIR}/tests/GuestExceptionPointer.cpp)
    target_include_directories(guest_exception_pointer_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_exception_pointer_tests PRIVATE libc)
    configure_windows_unwind(guest_exception_pointer_tests)
    add_test(NAME guest_exception_pointer COMMAND guest_exception_pointer_tests)
    set_tests_properties(guest_exception_pointer PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_exception_pointer PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(NOT APPLE)
        add_test_executable(guest_libc_doraise_system_error_tests ${LIBS_INCLUDE_DIR}/tests/GuestLibcDoraiseSystemError.cpp)
        target_include_directories(guest_libc_doraise_system_error_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_libc_doraise_system_error_tests PRIVATE libc)
        configure_windows_unwind(guest_libc_doraise_system_error_tests)
        add_test(NAME guest_libc_doraise_system_error COMMAND guest_libc_doraise_system_error_tests)
        if(WIN32)
            set_tests_properties(guest_libc_doraise_system_error PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endif()
    if(WIN32)
        add_test_executable(exception_personality_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionPersonality.cpp)
        target_include_directories(exception_personality_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(exception_personality_tests PRIVATE libc)
        configure_windows_unwind(exception_personality_tests)
        add_test(NAME exception_personality COMMAND exception_personality_tests)
        set_tests_properties(exception_personality PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(UNIX)
        add_test_executable(exception_personality_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionPersonality.cpp)
        target_include_directories(exception_personality_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(exception_personality_tests PRIVATE libc)
        add_test(NAME exception_personality COMMAND exception_personality_tests)
        add_test_executable(exception_compact_unwind_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionCompactUnwind.cpp)
        target_include_directories(exception_compact_unwind_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(exception_compact_unwind_tests PRIVATE libc)
        add_test(NAME exception_compact_unwind COMMAND exception_compact_unwind_tests)
        add_test_executable(guest_exit_order_tests ${LIBS_INCLUDE_DIR}/tests/GuestExitOrder.cpp)
        target_include_directories(guest_exit_order_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_exit_order_tests PRIVATE libc)
        add_test(NAME guest_exit_order COMMAND guest_exit_order_tests)
        add_test_executable(guest_cxa_finalize_handles_tests ${LIBS_INCLUDE_DIR}/tests/GuestCxaFinalizeHandles.cpp)
        target_include_directories(guest_cxa_finalize_handles_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_cxa_finalize_handles_tests PRIVATE libc)
        add_test(NAME guest_cxa_finalize_handles COMMAND guest_cxa_finalize_handles_tests)
        add_test_executable(guest_path_lifetime_tests ${LIBS_INCLUDE_DIR}/tests/GuestPathLifetime.cpp)
        target_include_directories(guest_path_lifetime_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_path_lifetime_tests PRIVATE libc)
        add_test(NAME guest_path_lifetime COMMAND guest_path_lifetime_tests)
        set_tests_properties(guest_path_lifetime PROPERTIES TIMEOUT 20)
        add_test_executable(guest_atomic_4_tests ${LIBS_INCLUDE_DIR}/tests/GuestAtomic4.cpp)
        target_include_directories(guest_atomic_4_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_atomic_4_tests PRIVATE libc)
        add_test(NAME guest_atomic_4 COMMAND guest_atomic_4_tests)
        add_test_executable(guest_heap_lifetime_tests ${LIBS_INCLUDE_DIR}/tests/GuestHeapLifetime.cpp)
        target_include_directories(guest_heap_lifetime_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_heap_lifetime_tests PRIVATE libc)
        add_test(NAME guest_heap_lifetime COMMAND guest_heap_lifetime_tests)
        add_test_executable(guest_math_nan_classifiers_tests ${LIBS_INCLUDE_DIR}/tests/GuestMathNanClassifiers.cpp)
        target_include_directories(guest_math_nan_classifiers_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_math_nan_classifiers_tests PRIVATE libc)
        add_test(NAME guest_math_nan_classifiers COMMAND guest_math_nan_classifiers_tests)
        set_tests_properties(guest_heap_lifetime PROPERTIES TIMEOUT 20)
        if(NOT APPLE)
            add_test_executable(exception_runtime_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionRuntime.cpp)
            target_include_directories(exception_runtime_tests PRIVATE ${LIBS_INCLUDE_DIR})
            target_link_libraries(exception_runtime_tests PRIVATE libc)
            add_test(NAME exception_runtime COMMAND exception_runtime_tests)
            enable_language(C)
            add_test_executable(exception_c_cleanup_tests ${LIBS_INCLUDE_DIR}/tests/ExceptionCCleanup.cpp ${LIBS_INCLUDE_DIR}/tests/ExceptionCCleanup.c)
            target_include_directories(exception_c_cleanup_tests PRIVATE ${LIBS_INCLUDE_DIR})
            set_source_files_properties(${LIBS_INCLUDE_DIR}/tests/ExceptionCCleanup.c PROPERTIES COMPILE_OPTIONS -fexceptions)
            target_link_libraries(exception_c_cleanup_tests PRIVATE libc)
            add_test(NAME exception_c_cleanup COMMAND exception_c_cleanup_tests)
            add_test_executable(guest_image_anonymous_tests ${LIBS_INCLUDE_DIR}/tests/GuestImageAnonymous.cpp)
            target_include_directories(guest_image_anonymous_tests PRIVATE ${LIBS_INCLUDE_DIR})
            target_link_libraries(guest_image_anonymous_tests PRIVATE libc)
            add_test(NAME guest_image_anonymous COMMAND guest_image_anonymous_tests)
        endif()
    endif()

    add_test_executable(unwind_enclosing_function_tests ${LIBS_INCLUDE_DIR}/tests/EnclosingFunction.cpp)
    target_include_directories(unwind_enclosing_function_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(unwind_enclosing_function_tests PRIVATE libc)
    configure_windows_unwind(unwind_enclosing_function_tests)
    configure_macos_unwind(unwind_enclosing_function_tests)
    add_test(NAME unwind_enclosing_function COMMAND unwind_enclosing_function_tests)
    set_tests_properties(unwind_enclosing_function PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(unwind_enclosing_function PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_collate_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestCollate.cpp)
target_include_directories(guest_collate_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_collate_tests PRIVATE libc)
configure_windows_unwind(guest_collate_tests)
set_target_properties(guest_collate_tests PROPERTIES CXX_EXTENSIONS OFF)
if(BUILD_TESTING)
    set_target_properties(guest_collate_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_collate COMMAND guest_collate_tests)
    if(WIN32)
        set_tests_properties(guest_collate PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(application_heap_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/ApplicationHeap.cpp)
target_include_directories(application_heap_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(application_heap_tests PRIVATE libc)
configure_windows_unwind(application_heap_tests)
set_target_properties(application_heap_tests PROPERTIES CXX_EXTENSIONS OFF)
if(BUILD_TESTING)
    set_target_properties(application_heap_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME application_heap_replacement COMMAND application_heap_tests)
    add_test(NAME application_heap_invalid_metadata COMMAND application_heap_tests invalid)
    add_test(NAME application_heap_default COMMAND application_heap_tests default)
    add_test(NAME application_heap_exit_order COMMAND application_heap_tests exit-order)
    add_test(NAME application_heap_scripting COMMAND application_heap_tests scripting)
    add_test(NAME application_heap_lazy COMMAND application_heap_tests lazy)
    add_test(NAME application_heap_threads COMMAND application_heap_tests threads)
    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
        add_library(guest_sdk_heap_fixture MODULE ${LIBS_INCLUDE_DIR}/tests/GuestSdkHeap.cpp)
        add_library(guest_sdk_heap_partial_fixture MODULE ${LIBS_INCLUDE_DIR}/tests/GuestSdkHeap.cpp)
        target_compile_definitions(guest_sdk_heap_partial_fixture PRIVATE SDK_HEAP_PARTIAL)
        set_target_properties(application_heap_tests PROPERTIES ENABLE_EXPORTS ON)
        add_dependencies(application_heap_tests guest_sdk_heap_fixture guest_sdk_heap_partial_fixture)
        add_test(NAME application_heap_guest_sdk COMMAND application_heap_tests sdk $<TARGET_FILE:guest_sdk_heap_fixture>)
        add_test(NAME application_heap_guest_sdk_partial COMMAND application_heap_tests sdk-partial $<TARGET_FILE:guest_sdk_heap_partial_fixture>)
        add_test(NAME application_heap_guest_sdk_default COMMAND application_heap_tests sdk-default $<TARGET_FILE:guest_sdk_heap_fixture>)
    endif()
    if(WIN32)
        set_tests_properties(application_heap_replacement application_heap_invalid_metadata application_heap_default application_heap_exit_order application_heap_scripting application_heap_lazy application_heap_threads
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        add_test(NAME application_heap_without_parameters COMMAND application_heap_tests none)
        set_tests_properties(application_heap_without_parameters
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wide_copy_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestWideCopyExtent.cpp)
    target_include_directories(guest_wide_copy_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wide_copy_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_wide_copy_extent_tests)
    add_test(NAME guest_wide_copy_extent COMMAND guest_wide_copy_extent_tests)
    set_tests_properties(guest_wide_copy_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wide_copy_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_allocator_failures_tests ${LIBS_INCLUDE_DIR}/tests/GuestAllocatorFailures.cpp)
    target_include_directories(guest_allocator_failures_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_allocator_failures_tests PRIVATE libc)
    configure_windows_unwind(guest_allocator_failures_tests)
    add_test(NAME guest_allocator_failures COMMAND guest_allocator_failures_tests)
    set_tests_properties(guest_allocator_failures PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_allocator_failures PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_wmemset_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestWmemsetExtent.cpp)
    target_include_directories(guest_wmemset_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_wmemset_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_wmemset_extent_tests)
    add_test(NAME guest_wmemset_extent COMMAND guest_wmemset_extent_tests)
    set_tests_properties(guest_wmemset_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_wmemset_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_malloc_lifecycle_tests ${LIBS_INCLUDE_DIR}/tests/GuestMallocLifecycle.cpp)
    target_include_directories(guest_malloc_lifecycle_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_malloc_lifecycle_tests PRIVATE libc)
    configure_windows_unwind(guest_malloc_lifecycle_tests)
    add_test(NAME guest_malloc_lifecycle COMMAND guest_malloc_lifecycle_tests)
    set_tests_properties(guest_malloc_lifecycle PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_malloc_lifecycle PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(application_heap_stats_tests ${LIBS_INCLUDE_DIR}/tests/ApplicationHeapStats.cpp)
    target_include_directories(application_heap_stats_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(application_heap_stats_tests PRIVATE libc)
    configure_windows_unwind(application_heap_stats_tests)
    add_test(NAME application_heap_stats COMMAND application_heap_stats_tests)
    add_test(NAME application_heap_stats_default COMMAND application_heap_stats_tests default)
    add_test(NAME application_heap_stats_missing COMMAND application_heap_stats_tests missing)
    if(WIN32)
        set_tests_properties(application_heap_stats application_heap_stats_default application_heap_stats_missing
            PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
        add_test_executable(cpu_topology_tests ${LIBS_INCLUDE_DIR}/tests/CpuTopology.cpp)
        target_include_directories(cpu_topology_tests PRIVATE ${LIBS_INCLUDE_DIR})
        add_test(NAME cpu_topology COMMAND cpu_topology_tests)
        if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64)$")
            add_test_executable(linux_crash_report_tests ${LIBS_INCLUDE_DIR}/tests/LinuxCrashReport.cpp)
            target_include_directories(linux_crash_report_tests PRIVATE ${LIBS_INCLUDE_DIR})
            target_link_libraries(linux_crash_report_tests PRIVATE ${CMAKE_DL_LIBS})
            target_link_options(linux_crash_report_tests PRIVATE "-Wl,--export-dynamic-symbol=write" "-Wl,--export-dynamic-symbol=sigaltstack")
            add_dependencies(linux_crash_report_tests libc)
            add_test(NAME linux_crash_report COMMAND linux_crash_report_tests $<TARGET_FILE:libc> basic)
            add_test(NAME linux_crash_report_handlers COMMAND linux_crash_report_tests $<TARGET_FILE:libc> handlers)
            add_test(NAME linux_crash_report_logging COMMAND linux_crash_report_tests $<TARGET_FILE:libc> logging)
            set_tests_properties(linux_crash_report linux_crash_report_handlers linux_crash_report_logging PROPERTIES TIMEOUT 30)
            foreach(test linux_crash_report linux_crash_report_handlers linux_crash_report_logging)
                add_asan_test_options(${test} handle_segv=0:handle_sigbus=0:handle_sigfpe=0:use_sigaltstack=0:detect_stack_use_after_return=0)
            endforeach()
        endif()
    endif()
    if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR APPLE OR WIN32)
        add_test_executable(guest_backtrace_tests ${LIBS_INCLUDE_DIR}/tests/GuestBacktrace.cpp)
        target_include_directories(guest_backtrace_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_backtrace_tests PRIVATE libc)
        configure_windows_unwind(guest_backtrace_tests)
        add_test(NAME guest_backtrace COMMAND guest_backtrace_tests)
        if(NOT WIN32)
            set_target_properties(guest_backtrace_tests PROPERTIES ENABLE_EXPORTS ON)
        endif()
        if(WIN32)
            set_tests_properties(guest_backtrace PROPERTIES ENVIRONMENT_MODIFICATION
                "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endif()
    endif()
    add_test_executable(host_region_index_tests ${LIBS_INCLUDE_DIR}/tests/HostRegionIndex.cpp)
    target_include_directories(host_region_index_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(host_region_index_tests PRIVATE libc)
    configure_windows_unwind(host_region_index_tests)
    add_test(NAME host_region_index COMMAND host_region_index_tests)
    set_tests_properties(host_region_index PROPERTIES TIMEOUT 60)
    if(WIN32)
        set_tests_properties(host_region_index PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_strcat_extent_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrcatExtent.cpp)
    target_include_directories(guest_strcat_extent_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strcat_extent_tests PRIVATE libc)
    configure_windows_unwind(guest_strcat_extent_tests)
    add_test(NAME guest_strcat_extent COMMAND guest_strcat_extent_tests)
    set_tests_properties(guest_strcat_extent PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strcat_extent PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(log_macros_tests ${LIBS_INCLUDE_DIR}/tests/LogMacros.cpp)
    target_include_directories(log_macros_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(log_macros_tests PRIVATE libc)
    configure_windows_unwind(log_macros_tests)
    add_test(NAME log_macros COMMAND log_macros_tests)
    add_test(NAME log_macros_timestamps COMMAND log_macros_tests timestamps)
    add_test_executable(log_file_tests ${LIBS_INCLUDE_DIR}/tests/LogFile.cpp)
    target_include_directories(log_file_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(log_file_tests PRIVATE libc)
    configure_windows_unwind(log_file_tests)
    add_test(NAME log_file COMMAND log_file_tests)
    set_tests_properties(log_file PROPERTIES TIMEOUT 30)
    if(WIN32)
        set_tests_properties(log_macros log_macros_timestamps log_file PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        add_test_executable(thread_name_tests ${LIBS_INCLUDE_DIR}/tests/ThreadName.cpp)
        target_include_directories(thread_name_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(thread_name_tests PRIVATE libc)
        configure_windows_unwind(thread_name_tests)
        add_test(NAME thread_name COMMAND thread_name_tests)
        set_tests_properties(thread_name PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()

    add_test_executable(guest_strcmp_boundary_tests ${LIBS_INCLUDE_DIR}/tests/GuestStrcmpBoundary.cpp)
    target_include_directories(guest_strcmp_boundary_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_strcmp_boundary_tests PRIVATE libc)
    configure_windows_unwind(guest_strcmp_boundary_tests)
    add_test(NAME guest_strcmp_boundary COMMAND guest_strcmp_boundary_tests)
    set_tests_properties(guest_strcmp_boundary PROPERTIES TIMEOUT 20)
    if(WIN32)
        set_tests_properties(guest_strcmp_boundary PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
    add_test_executable(guest_heap_report_for_game_tests ${LIBS_INCLUDE_DIR}/tests/GuestHeapReportForGame.cpp)
    target_include_directories(guest_heap_report_for_game_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_heap_report_for_game_tests PRIVATE libc)
    configure_windows_unwind(guest_heap_report_for_game_tests)
    add_test(NAME guest_heap_report_for_game COMMAND guest_heap_report_for_game_tests)
    if(WIN32)
        set_tests_properties(guest_heap_report_for_game PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(WIN32)
    add_test_executable(guest_heap_rounding_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestHeapRounding.cpp)
    target_include_directories(guest_heap_rounding_tests PRIVATE ${LIBS_INCLUDE_DIR})
    target_link_libraries(guest_heap_rounding_tests PRIVATE libc)
    configure_windows_unwind(guest_heap_rounding_tests)
    set_target_properties(guest_heap_rounding_tests PROPERTIES CXX_EXTENSIONS OFF)
    if(BUILD_TESTING)
        set_target_properties(guest_heap_rounding_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
        add_test(NAME guest_heap_rounding_overflow COMMAND guest_heap_rounding_tests)
        set_tests_properties(guest_heap_rounding_overflow PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(NOT WIN32)
    add_test_executable(guest_allocations_oom_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestAllocationsOom.cpp)
    target_include_directories(guest_allocations_oom_tests PRIVATE ${LIBS_INCLUDE_DIR})
    set_target_properties(guest_allocations_oom_tests PROPERTIES CXX_EXTENSIONS OFF)
    target_link_libraries(guest_allocations_oom_tests PRIVATE libc)
    if(BUILD_TESTING)
        set_target_properties(guest_allocations_oom_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
        add_test(NAME guest_allocations_oom COMMAND guest_allocations_oom_tests)
        set_tests_properties(guest_allocations_oom PROPERTIES TIMEOUT 60)
    endif()
endif()

add_test_executable(guest_allocations_changes_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestAllocationsChanges.cpp)
target_include_directories(guest_allocations_changes_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_allocations_changes_tests PRIVATE libc)
configure_windows_unwind(guest_allocations_changes_tests)
if(BUILD_TESTING)
    set_target_properties(guest_allocations_changes_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_allocations_changes COMMAND guest_allocations_changes_tests)
    set_tests_properties(guest_allocations_changes PROPERTIES TIMEOUT 60)
    if(WIN32)
        set_tests_properties(guest_allocations_changes PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_sce_v2_facet_ids_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestSceV2FacetIds.cpp)
target_include_directories(guest_sce_v2_facet_ids_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_sce_v2_facet_ids_tests PRIVATE libc)
configure_windows_unwind(guest_sce_v2_facet_ids_tests)
if(BUILD_TESTING)
    set_target_properties(guest_sce_v2_facet_ids_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_sce_v2_facet_ids COMMAND guest_sce_v2_facet_ids_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_facet_ids PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_locale_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestLocale.cpp)
target_include_directories(guest_locale_tests PRIVATE ${LIBS_INCLUDE_DIR})
set_target_properties(guest_locale_tests PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(guest_locale_tests PRIVATE libc)
configure_windows_unwind(guest_locale_tests)
if(BUILD_TESTING)
    set_target_properties(guest_locale_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_locale COMMAND guest_locale_tests)
    if(WIN32)
        set_tests_properties(guest_locale PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_numpunct_facet_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestNumpunctFacet.cpp)
target_include_directories(guest_numpunct_facet_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_numpunct_facet_tests PRIVATE libc)
configure_windows_unwind(guest_numpunct_facet_tests)
if(BUILD_TESTING)
    set_target_properties(guest_numpunct_facet_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_numpunct_facet COMMAND guest_numpunct_facet_tests)
    if(WIN32)
        set_tests_properties(guest_numpunct_facet PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_libc_numpunct_char_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestLibcNumpunctChar.cpp)
target_include_directories(guest_libc_numpunct_char_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libc_numpunct_char_tests PRIVATE libc)
configure_windows_unwind(guest_libc_numpunct_char_tests)
if(BUILD_TESTING)
    set_target_properties(guest_libc_numpunct_char_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_libc_numpunct_char COMMAND guest_libc_numpunct_char_tests)
    if(WIN32)
        set_tests_properties(guest_libc_numpunct_char PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_rune_locale_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestRuneLocale.cpp)
target_include_directories(guest_rune_locale_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_rune_locale_tests PRIVATE libc)
configure_windows_unwind(guest_rune_locale_tests)
if(BUILD_TESTING)
    set_target_properties(guest_rune_locale_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_rune_locale COMMAND guest_rune_locale_tests)
    if(WIN32)
        set_tests_properties(guest_rune_locale PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_sce_v2_locale_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Locale.cpp)
target_include_directories(guest_sce_v2_locale_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_sce_v2_locale_tests PRIVATE libc)
configure_windows_unwind(guest_sce_v2_locale_tests)
if(BUILD_TESTING)
    set_target_properties(guest_sce_v2_locale_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_sce_v2_locale COMMAND guest_sce_v2_locale_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_locale PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_sce_v2_iomanip_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Iomanip.cpp)
target_include_directories(guest_sce_v2_iomanip_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_sce_v2_iomanip_tests PRIVATE libc)
configure_windows_unwind(guest_sce_v2_iomanip_tests)
if(BUILD_TESTING)
    set_target_properties(guest_sce_v2_iomanip_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_sce_v2_iomanip COMMAND guest_sce_v2_iomanip_tests)
    if(WIN32)
        set_tests_properties(guest_sce_v2_iomanip PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_libc_mutex_init_with_name_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestLibcMutexInitWithName.cpp)
target_include_directories(guest_libc_mutex_init_with_name_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libc_mutex_init_with_name_tests PRIVATE libc)
configure_windows_unwind(guest_libc_mutex_init_with_name_tests)
if(BUILD_TESTING)
    set_target_properties(guest_libc_mutex_init_with_name_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_libc_mutex_init_with_name COMMAND guest_libc_mutex_init_with_name_tests)
    if(WIN32)
        set_tests_properties(guest_libc_mutex_init_with_name PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_libc_cnd_init_default_name_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestLibcCndInitDefaultName.cpp)
target_include_directories(guest_libc_cnd_init_default_name_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libc_cnd_init_default_name_tests PRIVATE libc)
configure_windows_unwind(guest_libc_cnd_init_default_name_tests)
if(BUILD_TESTING)
    set_target_properties(guest_libc_cnd_init_default_name_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_libc_cnd_init_default_name COMMAND guest_libc_cnd_init_default_name_tests)
    if(WIN32)
        set_tests_properties(guest_libc_cnd_init_default_name PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_libc_named_exports_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestLibcNamedExports.cpp)
target_include_directories(guest_libc_named_exports_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libc_named_exports_tests PRIVATE libc)
configure_windows_unwind(guest_libc_named_exports_tests)
if(BUILD_TESTING)
    set_target_properties(guest_libc_named_exports_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_libc_named_exports COMMAND guest_libc_named_exports_tests)
    if(WIN32)
        set_tests_properties(guest_libc_named_exports PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_libc_cnd_timed_wait_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestLibcCndTimedWait.cpp)
target_include_directories(guest_libc_cnd_timed_wait_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_libc_cnd_timed_wait_tests PRIVATE libc)
configure_windows_unwind(guest_libc_cnd_timed_wait_tests)
if(BUILD_TESTING)
    set_target_properties(guest_libc_cnd_timed_wait_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_libc_cnd_timed_wait COMMAND guest_libc_cnd_timed_wait_tests)
    if(WIN32)
        set_tests_properties(guest_libc_cnd_timed_wait PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

add_test_executable(guest_heap_trace_info_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/GuestHeapTraceInfo.cpp)
target_include_directories(guest_heap_trace_info_tests PRIVATE ${LIBS_INCLUDE_DIR})
target_link_libraries(guest_heap_trace_info_tests PRIVATE libc)
configure_windows_unwind(guest_heap_trace_info_tests)
if(BUILD_TESTING)
    set_target_properties(guest_heap_trace_info_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
    add_test(NAME guest_heap_trace_info COMMAND guest_heap_trace_info_tests)
    if(WIN32)
        set_tests_properties(guest_heap_trace_info PROPERTIES ENVIRONMENT_MODIFICATION
            "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
    endif()
endif()

if(MINGW)
    if(BUILD_TESTING)
        enable_language(ASM)
        add_test_executable(guest_message_destructor_abi_tests
            ${LIBS_INCLUDE_DIR}/tests/GuestMessageDestructorAbi.cpp
            ${LIBS_INCLUDE_DIR}/tests/GuestMessageDestructorAbi.S)
        target_include_directories(guest_message_destructor_abi_tests PRIVATE ${LIBS_INCLUDE_DIR})
        target_link_libraries(guest_message_destructor_abi_tests PRIVATE libc)
        configure_windows_unwind(guest_message_destructor_abi_tests)
        foreach(mode IN ITEMS control hybrid decoy zero release regex-decoy regex-zero
                runtime-decoy runtime-zero doraise-decoy doraise-zero
                unshared-decoy unshared-zero regex-unshared-decoy regex-unshared-zero)
            add_test(NAME guest_message_destructor_${mode} COMMAND guest_message_destructor_abi_tests ${mode})
            set_tests_properties(guest_message_destructor_${mode} PROPERTIES TIMEOUT 10
                ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        endforeach()
        foreach(kind IN ITEMS message plain)
            foreach(operation IN ITEMS what destroy delete)
                foreach(register IN ITEMS decoy zero)
                    set(mode "vtable-${kind}-${operation}-${register}")
                    add_test(NAME guest_exception_${mode} COMMAND guest_message_destructor_abi_tests ${mode})
                    set_tests_properties(guest_exception_${mode} PROPERTIES TIMEOUT 10
                        ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
                endforeach()
            endforeach()
        endforeach()
    endif()
    foreach(runtimeLinkFlag IN ITEMS -static-libgcc -static-libstdc++ -static)
        string(REPLACE "${runtimeLinkFlag}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
    endforeach()
    add_test_executable(windows_exception_tests EXCLUDE_FROM_ALL ${LIBS_INCLUDE_DIR}/tests/WindowsExceptions.cpp)
    set_target_properties(windows_exception_tests PROPERTIES CXX_EXTENSIONS OFF)
    target_link_libraries(windows_exception_tests PRIVATE libc)
    configure_windows_unwind(windows_exception_tests)
    if(BUILD_TESTING)
        set_target_properties(windows_exception_tests PROPERTIES EXCLUDE_FROM_ALL FALSE)
        add_test(NAME windows_exceptions COMMAND windows_exception_tests)
        set_tests_properties(windows_exceptions PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>")
        add_test_executable(windows_backtrace_report_tests ${LIBS_INCLUDE_DIR}/tests/WindowsBacktraceReport.cpp)
        target_link_libraries(windows_backtrace_report_tests PRIVATE libc)
        target_include_directories(windows_backtrace_report_tests PRIVATE ${LIBS_INCLUDE_DIR})
        add_test(NAME windows_backtrace_report COMMAND windows_backtrace_report_tests)
        set_tests_properties(windows_backtrace_report PROPERTIES TIMEOUT 20
            ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>"
            PASS_REGULAR_EXPRESSION "aborting[^~]*SIGABRT. on thread[^~]*stack return address candidates:[^~]*rsp[+]0x")
        foreach(guardedFault IN ITEMS destination expected outside)
            add_test(NAME windows_guarded_read_wild_${guardedFault} COMMAND windows_backtrace_report_tests guarded-${guardedFault})
            set_tests_properties(windows_guarded_read_wild_${guardedFault} PROPERTIES TIMEOUT 20
                ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>"
                PASS_REGULAR_EXPRESSION "FATAL: unhandled exception 0xc0000005")
        endforeach()
        add_test(NAME windows_backtrace_failure_report COMMAND windows_backtrace_report_tests report)
        set_tests_properties(windows_backtrace_failure_report PROPERTIES TIMEOUT 20
            ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>"
            PASS_REGULAR_EXPRESSION "aborting[^~]*SIGABRT. on thread[^~]*all threads:[^~]*kept failure report ran"
            FAIL_REGULAR_EXPRESSION "dropped failure report ran;kept failure report ran[^~]*kept failure report ran")
        add_test(NAME windows_backtrace_failure_report_once COMMAND windows_backtrace_report_tests report-once)
        set_tests_properties(windows_backtrace_failure_report_once PROPERTIES TIMEOUT 20
            ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>"
            PASS_REGULAR_EXPRESSION "kept failure report ran[^~]*aborting[^~]*SIGABRT. on thread[^~]*all threads:"
            FAIL_REGULAR_EXPRESSION "kept failure report ran[^~]*kept failure report ran")
        add_test(NAME windows_crash_stack_words COMMAND windows_backtrace_report_tests fault)
        set_tests_properties(windows_crash_stack_words PROPERTIES TIMEOUT 20
            ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>;APS5_CRASH_STACK_BYTES=set:2048"
            PASS_REGULAR_EXPRESSION "FATAL: unhandled exception 0xc0000005.*stack words from rsp.*data at stack words that point outside the stack.*c0ffee0000000000 c0ffee0000000001 c0ffee0000000002 c0ffee0000000003 c0ffee0000000004 c0ffee0000000005 c0ffee0000000006 c0ffee0000000007")
        add_test(NAME windows_crash_without_stack_words COMMAND windows_backtrace_report_tests fault)
        set_tests_properties(windows_crash_without_stack_words PROPERTIES TIMEOUT 20
            ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:libc>;APS5_CRASH_STACK_BYTES=unset:"
            PASS_REGULAR_EXPRESSION "FATAL: unhandled exception 0xc0000005"
            FAIL_REGULAR_EXPRESSION "stack words from rsp;data at stack words")
    endif()
endif()

file(GLOB libcTestFragments CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/cmake/*.cmake)
list(SORT libcTestFragments)
foreach(libcTestFragment IN LISTS libcTestFragments)
    include(${libcTestFragment})
endforeach()
