include(AddFdbTest)

# We need some variables to configure the test setup
set(ENABLE_BUGGIFY ON CACHE BOOL "Enable buggify for tests")
set(RUN_IGNORED_TESTS OFF CACHE BOOL "Run tests that are marked for ignore")
set(TEST_KEEP_LOGS "FAILED" CACHE STRING "Which locks to keep (NONE, FAILED, ALL)")
set(TEST_KEEP_SIMDIR "NONE" CACHE STRING "Which simfdb directories to keep (NONE, FAILED, ALL)")
set(TEST_AGGREGATE_TRACES "NONE" CACHE STRING "Create aggregated trace files (NONE, FAILED, ALL)")

# for the restart test we optimally want to use the last stable fdbserver
# to test upgrades

find_program(OLD_FDBSERVER_BINARY
  fdbserver
  HINTS /usr/sbin /usr/libexec /usr/local/sbin /usr/local/libexec)
if(OLD_FDBSERVER_BINARY)
  message(STATUS "Use old fdb at ${OLD_FDBSERVER_BINARY}")
else()
  set(fdbserver_location ${CMAKE_BINARY_DIR}/bin/fdbserver)
  set(OLD_FDBSERVER_BINARY ${fdbserver_location} CACHE FILEPATH "Old fdbserver binary" FORCE)
  message(WARNING "\
No old fdbserver binary found - using ${fdbserver_location} \
It is recommended to install the current stable version from https://www.foundationdb.org/download/ \
Or provide a path to another fdbserver")
endif()

set(TestRunner "${PROJECT_SOURCE_DIR}/tests/TestRunner/TestRunner.py")

configure_file(${PROJECT_SOURCE_DIR}/tests/CTestCustom.ctest ${PROJECT_BINARY_DIR}/CTestCustom.ctest @ONLY)

configure_testing(TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
                  ERROR_ON_ADDITIONAL_FILES
                  IGNORE_PATTERNS ".*/CMakeLists.txt")

add_fdb_test(TEST_FILES AsyncFileCorrectness.txt UNIT IGNORE)
add_fdb_test(TEST_FILES AsyncFileMix.txt UNIT IGNORE)
add_fdb_test(TEST_FILES AsyncFileRead.txt UNIT IGNORE)
add_fdb_test(TEST_FILES AsyncFileReadRandom.txt UNIT IGNORE)
add_fdb_test(TEST_FILES AsyncFileWrite.txt UNIT IGNORE)
add_fdb_test(TEST_FILES BackupContainers.txt IGNORE)
add_fdb_test(TEST_FILES BandwidthThrottle.txt IGNORE)
add_fdb_test(TEST_FILES BigInsert.txt IGNORE)
add_fdb_test(TEST_FILES BlobStore.txt IGNORE)
add_fdb_test(TEST_FILES ConsistencyCheck.txt IGNORE)
add_fdb_test(TEST_FILES DiskDurability.txt IGNORE)
add_fdb_test(TEST_FILES FileSystem.txt IGNORE)
add_fdb_test(TEST_FILES Happy.txt IGNORE)
add_fdb_test(TEST_FILES IncrementalDelete.txt IGNORE)
add_fdb_test(TEST_FILES KillRegionCycle.txt IGNORE)
add_fdb_test(TEST_FILES KVStoreMemTest.txt UNIT IGNORE)
add_fdb_test(TEST_FILES KVStoreReadMostly.txt UNIT IGNORE)
add_fdb_test(TEST_FILES KVStoreTest.txt UNIT IGNORE)
add_fdb_test(TEST_FILES KVStoreTestRead.txt UNIT IGNORE)
add_fdb_test(TEST_FILES KVStoreTestWrite.txt UNIT IGNORE)
add_fdb_test(TEST_FILES KVStoreValueSize.txt UNIT IGNORE)
add_fdb_test(TEST_FILES LayerStatusMerge.txt IGNORE)
add_fdb_test(TEST_FILES PureNetwork.txt IGNORE)
add_fdb_test(TEST_FILES RRW2500.txt IGNORE)
add_fdb_test(TEST_FILES RandomRead.txt IGNORE)
add_fdb_test(TEST_FILES RandomReadWrite.txt IGNORE)
add_fdb_test(TEST_FILES ReadAbsent.txt IGNORE)
add_fdb_test(TEST_FILES ReadHalfAbsent.txt IGNORE)
add_fdb_test(TEST_FILES RedwoodCorrectness.txt IGNORE)
add_fdb_test(TEST_FILES RedwoodPerfTests.txt IGNORE)
add_fdb_test(TEST_FILES SlowTask.txt IGNORE)
add_fdb_test(TEST_FILES SpecificUnitTest.txt IGNORE)
add_fdb_test(TEST_FILES StreamingWrite.txt IGNORE)
add_fdb_test(TEST_FILES ThreadSafety.txt IGNORE)
add_fdb_test(TEST_FILES TraceEventMetrics.txt IGNORE)
add_fdb_test(TEST_FILES default.txt IGNORE)
add_fdb_test(TEST_FILES errors.txt IGNORE)
add_fdb_test(TEST_FILES fail.txt IGNORE)
add_fdb_test(TEST_FILES killall.txt IGNORE)
add_fdb_test(TEST_FILES latency.txt IGNORE)
add_fdb_test(TEST_FILES performance-fs.txt IGNORE)
add_fdb_test(TEST_FILES performance.txt IGNORE)
add_fdb_test(TEST_FILES ping.TXT IGNORE)
add_fdb_test(TEST_FILES pingServers.TXT IGNORE)
add_fdb_test(TEST_FILES pt.TXT IGNORE)
add_fdb_test(TEST_FILES randomSelector.txt IGNORE)
add_fdb_test(TEST_FILES selectorCorrectness.txt IGNORE)
add_fdb_test(TEST_FILES fast/AtomicBackupCorrectness.txt)
add_fdb_test(TEST_FILES fast/AtomicBackupToDBCorrectness.txt)
add_fdb_test(TEST_FILES fast/AtomicOps.txt)
add_fdb_test(TEST_FILES fast/AtomicOpsApiCorrectness.txt)
add_fdb_test(TEST_FILES fast/BackupCorrectness.txt)
add_fdb_test(TEST_FILES fast/BackupCorrectnessClean.txt)
add_fdb_test(TEST_FILES fast/BackupToDBCorrectness.txt)
add_fdb_test(TEST_FILES fast/BackupToDBCorrectnessClean.txt)
add_fdb_test(TEST_FILES fast/CloggedSideband.txt)
add_fdb_test(TEST_FILES fast/ConstrainedRandomSelector.txt)
add_fdb_test(TEST_FILES fast/CycleAndLock.txt)
add_fdb_test(TEST_FILES fast/CycleTest.txt)
add_fdb_test(TEST_FILES fast/FuzzApiCorrectness.txt)
add_fdb_test(TEST_FILES fast/FuzzApiCorrectnessClean.txt)
add_fdb_test(TEST_FILES fast/IncrementTest.txt)
add_fdb_test(TEST_FILES fast/InventoryTestAlmostReadOnly.txt)
add_fdb_test(TEST_FILES fast/InventoryTestSomeWrites.txt)
add_fdb_test(TEST_FILES fast/LongStackWriteDuringRead.txt)
add_fdb_test(TEST_FILES fast/LowLatency.txt)
add_fdb_test(TEST_FILES fast/MemoryLifetime.txt)
add_fdb_test(TEST_FILES fast/MoveKeysCycle.txt)
add_fdb_test(TEST_FILES fast/RandomSelector.txt)
add_fdb_test(TEST_FILES fast/RandomUnitTests.txt)
add_fdb_test(TEST_FILES fast/SelectorCorrectness.txt)
add_fdb_test(TEST_FILES fast/Sideband.txt)
add_fdb_test(TEST_FILES fast/SidebandWithStatus.txt)
add_fdb_test(TEST_FILES fast/SwizzledRollbackSideband.txt)
add_fdb_test(TEST_FILES fast/SystemRebootTestCycle.txt)
add_fdb_test(TEST_FILES fast/TaskBucketCorrectness.txt)
add_fdb_test(TEST_FILES fast/TimeKeeperCorrectness.txt)
add_fdb_test(TEST_FILES fast/Unreadable.txt)
add_fdb_test(TEST_FILES fast/VersionStamp.txt)
add_fdb_test(TEST_FILES fast/Watches.txt)
add_fdb_test(TEST_FILES fast/WriteDuringRead.txt)
add_fdb_test(TEST_FILES fast/WriteDuringReadClean.txt)
add_fdb_test(TEST_FILES rare/CheckRelocation.txt)
add_fdb_test(TEST_FILES rare/ClogUnclog.txt)
add_fdb_test(TEST_FILES rare/CloggedCycleWithKills.txt)
add_fdb_test(TEST_FILES rare/ConflictRangeCheck.txt)
add_fdb_test(TEST_FILES rare/ConflictRangeRYOWCheck.txt)
add_fdb_test(TEST_FILES rare/CycleRollbackClogged.txt)
add_fdb_test(TEST_FILES rare/CycleWithKills.txt)
add_fdb_test(TEST_FILES rare/FuzzTest.txt)
add_fdb_test(TEST_FILES rare/InventoryTestHeavyWrites.txt)
add_fdb_test(TEST_FILES rare/LargeApiCorrectness.txt)
add_fdb_test(TEST_FILES rare/LargeApiCorrectnessStatus.txt)
add_fdb_test(TEST_FILES rare/RYWDisable.txt)
add_fdb_test(TEST_FILES rare/RandomReadWriteTest.txt)
add_fdb_test(TEST_FILES rare/SwizzledLargeApiCorrectness.txt)
add_fdb_test(
  TEST_FILES restarting/CycleTestRestart-1.txt
             restarting/CycleTestRestart-2.txt)
add_fdb_test(
  TEST_FILES restarting/StorefrontTestRestart-1.txt
             restarting/StorefrontTestRestart-2.txt)
add_fdb_test(
  TEST_FILES restarting/from_5.1.7/DrUpgradeRestart-1.txt
             restarting/from_5.1.7/DrUpgradeRestart-2.txt IGNORE)
add_fdb_test(
  TEST_FILES restarting/from_5.2.0/ClientTransactionProfilingCorrectness-1.txt
             restarting/from_5.2.0/ClientTransactionProfilingCorrectness-2.txt IGNORE)
add_fdb_test(TEST_FILES slow/ApiCorrectness.txt)
add_fdb_test(TEST_FILES slow/ApiCorrectnessAtomicRestore.txt)
add_fdb_test(TEST_FILES slow/ApiCorrectnessSwitchover.txt)
add_fdb_test(TEST_FILES slow/ClogWithRollbacks.txt)
add_fdb_test(TEST_FILES slow/CloggedCycleTest.txt)
add_fdb_test(TEST_FILES slow/CloggedStorefront.txt)
add_fdb_test(TEST_FILES slow/CommitBug.txt)
add_fdb_test(TEST_FILES slow/ConfigureTest.txt)
add_fdb_test(TEST_FILES slow/CycleRollbackPlain.txt)
add_fdb_test(TEST_FILES slow/DDBalanceAndRemove.txt)
add_fdb_test(TEST_FILES slow/DDBalanceAndRemoveStatus.txt)
add_fdb_test(TEST_FILES slow/FastTriggeredWatches.txt)
add_fdb_test(TEST_FILES slow/LowLatencyWithFailures.txt)
add_fdb_test(TEST_FILES slow/MoveKeysClean.txt)
add_fdb_test(TEST_FILES slow/MoveKeysSideband.txt)
add_fdb_test(TEST_FILES slow/RyowCorrectness.txt)
add_fdb_test(TEST_FILES slow/Serializability.txt)
add_fdb_test(TEST_FILES slow/SharedBackupCorrectness.txt)
add_fdb_test(TEST_FILES slow/SharedBackupToDBCorrectness.txt)
add_fdb_test(TEST_FILES slow/StorefrontTest.txt)
add_fdb_test(TEST_FILES slow/SwizzledApiCorrectness.txt)
add_fdb_test(TEST_FILES slow/SwizzledCycleTest.txt)
add_fdb_test(TEST_FILES slow/SwizzledDdBalance.txt)
add_fdb_test(TEST_FILES slow/SwizzledRollbackTimeLapse.txt)
add_fdb_test(TEST_FILES slow/SwizzledRollbackTimeLapseIncrement.txt)
add_fdb_test(TEST_FILES slow/VersionStampBackupToDB.txt)
add_fdb_test(TEST_FILES slow/VersionStampSwitchover.txt)
add_fdb_test(TEST_FILES slow/WriteDuringReadAtomicRestore.txt)
add_fdb_test(TEST_FILES slow/WriteDuringReadSwitchover.txt)
add_fdb_test(TEST_FILES slow/ddbalance.txt)
# Note that status tests are not deterministic.
add_fdb_test(TEST_FILES status/invalid_proc_addresses.txt)
add_fdb_test(TEST_FILES status/local_6_machine_no_replicas_remain.txt)
add_fdb_test(TEST_FILES status/separate_1_of_3_coordinators_remain.txt)
add_fdb_test(TEST_FILES status/separate_2_of_3_coordinators_remain.txt)
add_fdb_test(TEST_FILES status/separate_cannot_write_cluster_file.txt)
add_fdb_test(TEST_FILES status/separate_idle.txt)
add_fdb_test(TEST_FILES status/separate_initializing.txt)
add_fdb_test(TEST_FILES status/separate_no_coordinators.txt)
add_fdb_test(TEST_FILES status/separate_no_database.txt)
add_fdb_test(TEST_FILES status/separate_no_servers.txt)
add_fdb_test(TEST_FILES status/separate_not_enough_servers.txt)
add_fdb_test(TEST_FILES status/single_process_too_many_config_params.txt)

verify_testing()
