################################################################################
# Copyright 2018-2025, Barcelona Supercomputing Center (BSC), Spain            #
# Copyright 2015-2025, Johannes Gutenberg Universitaet Mainz, Germany          #
#                                                                              #
# This software was partially supported by the                                 #
# EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).    #
#                                                                              #
# This software was partially supported by the                                 #
# ADA-FS project under the SPPEXA project funded by the DFG.                   #
#                                                                              #
# This file is part of GekkoFS.                                                #
#                                                                              #
# GekkoFS is free software: you can redistribute it and/or modify              #
# it under the terms of the GNU General Public License as published by         #
# the Free Software Foundation, either version 3 of the License, or            #
# (at your option) any later version.                                          #
#                                                                              #
# GekkoFS is distributed in the hope that it will be useful,                   #
# but WITHOUT ANY WARRANTY; without even the implied warranty of               #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
# GNU General Public License for more details.                                 #
#                                                                              #
# You should have received a copy of the GNU General Public License            #
# along with GekkoFS.  If not, see <https://www.gnu.org/licenses/>.            #
#                                                                              #
# SPDX-License-Identifier: GPL-3.0-or-later                                    #
################################################################################

# --- Common Test Properties ---
set(DEFAULT_TEST_TIMEOUT 9000)
set(DEFAULT_TEST_LABELS "apps::all")
set(DEFAULT_TEST_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR})

# --- Helper Function to Add Tests with Common Properties ---
# This function simplifies adding new tests that share common properties.
# Usage: gekko_add_test(<test_name> <script_name.sh> [EXTRA_PROPERTIES <prop1> <val1> ...])
function(gekko_add_test TEST_NAME SCRIPT_FILENAME)
    add_test(
        NAME ${TEST_NAME}
        COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${SCRIPT_FILENAME}
        WORKING_DIRECTORY ${DEFAULT_TEST_WORKING_DIR} 
    )

    set_tests_properties(${TEST_NAME}
        PROPERTIES
            TIMEOUT ${DEFAULT_TEST_TIMEOUT}
            LABELS ${DEFAULT_TEST_LABELS}
    )
endfunction()


# --- Test Definitions ---
gekko_add_test(s3d_io_test s3d-io.sh)
# To add the specific environment for this test (if needed):
# set_tests_properties(s3d_io_test APPEND PROPERTIES ENVIRONMENT "${FORTRAN_TEST_ENV}")

gekko_add_test(s3d_io_test_environment s3d-io-env.sh)

gekko_add_test(s3d_io_test_large s3d-io-large.sh)

gekko_add_test(wacomm wacomm.sh)

gekko_add_test(lockfile lockfile.sh)

gekko_add_test(flex_mmap_local flex-mmap-local.sh)


# --- Installation of Test Scripts ---
if(GKFS_INSTALL_TESTS)
    install(
        DIRECTORY apps # Installs files from the current source directory
        DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/gkfs/tests
        FILE_PERMISSIONS OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
        FILES_MATCHING
            PATTERN "*.sh" # Only install .sh files

    )
endif()