diff --git a/.github/workflows/unit-test-all.yml b/.github/workflows/unit-test-all.yml new file mode 100644 index 0000000000..a46f9eee18 --- /dev/null +++ b/.github/workflows/unit-test-all.yml @@ -0,0 +1,52 @@ +name: Run Unit Tests + +on: + workflow_dispatch: + pull_request: + branches: [ main ] + +jobs: + unit-tests: + runs-on: ubuntu-latest + container: + image: ghcr.io/glemieux/containers/unit-testing:latest + options: --hostname fatestestcontainer + + steps: + + - name: Preserve $HOME set in the container + run: echo HOME=/root/ >> "$GITHUB_ENV" + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Activate Spack environment and run tests + run: | + . /opt/spack-environment/activate.sh + python -m pip install matplotlib + echo "HOSTNAME: $HOSTNAME" + echo "HOME: $HOME" + echo "CIMEROOT: $CIMEROOT" + echo "NETCDF_FORTRAN_PATH: $NETCDF_FORTRAN_PATH" + echo "NETCDF_C_PATH: $NETCDF_C_PATH" + cd testing/ + python run_unit_tests.py --make-j 2 --test-list all + + # cd /cime/CIME + # echo "get cime root" + # python -c 'from utils import get_cime_root; print(get_cime_root())' + # echo "get config path" + # python -c 'from utils import get_config_path; print(get_config_path())' + # echo "get schema path" + # python -c 'from utils import get_schema_path; print(get_schema_path())' + + + # cd testing/ + # echo "path_to_cime:" + # python -c 'from path_utils import path_to_cime; print(path_to_cime())' + # python run_unit_tests.py --make-j 2 --test-list all + + # - name: Run FATES unit tests + # working-directory: ./testing/ + # run: | + # python run_unit_tests.py --make-j 2 --test-list all \ No newline at end of file diff --git a/testing/build_fortran_tests.py b/testing/build_fortran_tests.py index 509755eb2d..3803b53ac0 100644 --- a/testing/build_fortran_tests.py +++ b/testing/build_fortran_tests.py @@ -3,6 +3,7 @@ """ import os import shutil +from socket import gethostname from path_utils import add_cime_lib_to_path add_cime_lib_to_path() @@ -101,37 +102,48 @@ def get_extra_cmake_args(build_dir:str, mpilib:str) -> str: Returns: str: space-separated list of cmake arguments """ - # get the machine objects file - machobj = Machines() - - # get compiler - compiler = machobj.get_default_compiler() - - # get operating system - os_ = machobj.get_value("OS") - - # create the environment, and the Macros.cmake file - configure( - machobj, - build_dir, - ["CMake"], - compiler, - mpilib, - True, - "nuopc", - os_, - unit_testing=True, - ) - machspecific = EnvMachSpecific(build_dir, unit_testing=True) - - # make a fake case - fake_case = FakeCase(compiler, mpilib, True, "nuopc", threading=False) - machspecific.load_env(fake_case) + # Check if the test is being run in a FATES testing container + if (gethostname() == "fatestestcontainer"): + machinename = "fatestestcontainer" + compiler = "gnu" + mplilib = "mpi-serial" + # build_dir + else: + # If not in a testing container, assume we are running on a machine + # that has a supported environment + + # get the machine objects file + machobj = Machines() + + # get compiler + compiler = machobj.get_default_compiler() + + # get operating system + os_ = machobj.get_value("OS") + + # create the environment, and the Macros.cmake file + configure( + machobj, + build_dir, + ["CMake"], + compiler, + mpilib, + True, + "nuopc", + os_, + unit_testing=True, + ) + machspecific = EnvMachSpecific(build_dir, unit_testing=True) + + # make a fake case + fake_case = FakeCase(compiler, mpilib, True, "nuopc", threading=False) + machspecific.load_env(fake_case) + machinename = machobj.get_machine_name() # create cmake argument list with information from the fake case and machine object cmake_args_list = [ f"-DOS={os_}", - f"-DMACH={machobj.get_machine_name()}", + f"-DMACH={machinename}", f"-DCOMPILER={compiler}", f"-DDEBUG={stringify_bool(True)}", f"-DMPILIB={mpilib}", diff --git a/testing/path_utils.py b/testing/path_utils.py index 0343a69f1b..2a9f7ad99c 100644 --- a/testing/path_utils.py +++ b/testing/path_utils.py @@ -39,6 +39,9 @@ def path_to_cime() -> str: cime_path = os.path.join(path_to_fates_root(), "../../cime") if os.path.isdir(cime_path): return cime_path + elif os.path.isdir("/cime"): + return "/cime" + raise RuntimeError("Cannot find cime.")