diff --git a/CMakeLists.txt b/CMakeLists.txt index 063e5ce4f6..9760a39c1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,3 @@ -<<<<<<< HEAD cmake_minimum_required(VERSION 3.4) list(APPEND CMAKE_MODULE_PATH ${CIME_CMAKE_MODULE_DIRECTORY}) @@ -89,81 +88,3 @@ link_directories(${CMAKE_CURRENT_BINARY_DIR}) # Add the main test directory add_subdirectory(${HLM_ROOT}/src/fates/testing) -||||||| e2621983 -======= -# This file helps to build unit test programs to test FATES, but is not used in -# production runs - -cmake_minimum_required(VERSION 3.4) - -list(APPEND CMAKE_MODULE_PATH ${CIME_CMAKE_MODULE_DIRECTORY}) -include(CIME_initial_setup) - -project(FATES_tests Fortran C) - -include(CIME_utils) - -set(HLM_ROOT "../../") - -# Add source directories from other share code (csm_share, etc.) -add_subdirectory(${HLM_ROOT}/share/src csm_share) -add_subdirectory(${HLM_ROOT}/share/unit_test_stubs/util csm_share_stubs) - -# Add FATES source directories -add_subdirectory(${HLM_ROOT}/src/fates/main fates_main) -add_subdirectory(${HLM_ROOT}/src/fates/biogeochem fates_biogeochem) -add_subdirectory(${HLM_ROOT}/src/fates/fire fates_fire) -add_subdirectory(${HLM_ROOT}/src/fates/radiation fates_radiation) - -# Remove shr_mpi_mod from share_sources. -# This is needed because we want to use the mock shr_mpi_mod in place of the real one -# -# TODO: this should be moved into a general-purpose function in Sourcelist_utils. -# Then this block of code could be replaced with a single call, like: -# remove_source_file(${share_sources} "shr_mpi_mod.F90") -foreach (sourcefile ${share_sources}) - string(REGEX MATCH "shr_mpi_mod.F90" match_found ${sourcefile}) - if(match_found) - list(REMOVE_ITEM share_sources ${sourcefile}) - endif() -endforeach() - -# Remove shr_cal_mod from share_sources. -# -# shr_cal_mod depends on ESMF (or the lightweight esmf wrf timemgr, at -# least). Since CTSM doesn't currently use shr_cal_mod, we're avoiding -# the extra overhead of including esmf_wrf_timemgr sources in this -# build. -# -# TODO: like above, this should be moved into a general-purpose function -# in Sourcelist_utils. Then this block of code could be replaced with a -# single call, like: remove_source_file(${share_sources} -# "shr_cal_mod.F90") -foreach (sourcefile ${share_sources}) - string(REGEX MATCH "shr_cal_mod.F90" match_found ${sourcefile}) - if(match_found) - list(REMOVE_ITEM share_sources ${sourcefile}) - endif() -endforeach() - -# Build libraries containing stuff needed for the unit tests. -# Eventually, these add_library calls should probably be distributed into the correct location, rather than being in this top-level CMakeLists.txt file. -add_library(csm_share ${share_sources}) -declare_generated_dependencies(csm_share "${share_genf90_sources}") -add_library(fates ${fates_sources}) -add_dependencies(fates csm_share) - -# We need to look for header files here, in order to pick up shr_assert.h -include_directories(${HLM_ROOT}/share/include) - -# Tell cmake to look for libraries & mod files here, because this is where we built libraries -include_directories(${CMAKE_CURRENT_BINARY_DIR}) -link_directories(${CMAKE_CURRENT_BINARY_DIR}) - -# Add the test directories -# Note: it's possible that these could be added by each source directory that -# has tests in it. However, it appears that the order needs to be done -# carefully: for example, include_directories and link_directories needs to be -# done before adding the tests themselves. -add_subdirectory(${HLM_ROOT}/src/fates/fire/test fates_fire_test) ->>>>>>> main diff --git a/fire/test/CMakeLists.txt b/fire/test/CMakeLists.txt deleted file mode 100644 index 4dcfa244d4..0000000000 --- a/fire/test/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(fire_weather_test) \ No newline at end of file diff --git a/radiation/CMakeLists.txt b/radiation/CMakeLists.txt index abd2b99a94..74d625b12d 100644 --- a/radiation/CMakeLists.txt +++ b/radiation/CMakeLists.txt @@ -1,6 +1,7 @@ # This file is required for unit testing, but is not used for production runs list(APPEND fates_sources TwoStreamMLPEMod.F90 + FatesRadiationMemMod.F90 ) sourcelist_to_parent(fates_sources) diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index ac3ac02d18..d59509c73d 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -1,3 +1,8 @@ # This is where you add specific test directories -add_subdirectory(functional_testing/allometry fates_allom_test) -add_subdirectory(functional_testing/math_utils fates_math_test) \ No newline at end of file + +## Functional tests +add_subdirectory(functional_testing/allometry fates_allom_ftest) +add_subdirectory(functional_testing/math_utils fates_math_ftest) + +## Unit tests +add_subdirectory(unit_testing/fire_weather_test fates_fire_weather_utest) \ No newline at end of file diff --git a/testing/run_fates_tests.py b/testing/run_fates_tests.py index 7a6b8cc296..6816e034ad 100755 --- a/testing/run_fates_tests.py +++ b/testing/run_fates_tests.py @@ -53,7 +53,7 @@ # command-line argument list _ALL_TESTS_DICT = { "allometry": { - "test_dir": "fates_allom_test", + "test_dir": "fates_allom_ftest", "test_exe": "FATES_allom_exe", "out_file": "allometry_out.nc", "has_unit_test": False, @@ -62,13 +62,22 @@ "plotting_function": plot_allometry_dat, }, "quadratic": { - "test_dir": "fates_math_test", + "test_dir": "fates_math_ftest", "test_exe": "FATES_math_exe", "out_file": "quad_out.nc", "has_unit_test": False, "use_param_file": False, "other_args": [], "plotting_function": plot_quadratic_dat, + }, + "fire_weather":{ + "test_dir": "fates_fire_weather_utest", + "test_exe": None, + "out_file": None, + "has_unit_test": True, + "use_param_file": False, + "other_args": [], + "plotting_function": None, } } @@ -197,6 +206,17 @@ def run_tests(clean, verbose_make, build_tests, run_executables, build_dir, run_ # run run_fortran_exectuables(build_dir_path, attributes['test_dir'], attributes['test_exe'], run_dir_path, args) + + # run unit tests + for test, attributes in dict(filter(lambda pair: pair[1]['has_unit_test'], + test_dict.items())).items(): + print(f"Running unit tests for {test}.") + + test_dir = os.path.join(build_dir_path, _TEST_SUB_DIR, attributes['test_dir']) + ctest_command = ["ctest", "--output-on-failure"] + output = run_cmd_no_fail(" ".join(ctest_command), from_dir=test_dir, + combine_output=True) + print(output) # plot output for relevant tests for test, attributes in dict(filter(lambda pair: pair[1]['plotting_function'] is not None, @@ -204,6 +224,7 @@ def run_tests(clean, verbose_make, build_tests, run_executables, build_dir, run_ attributes['plotting_function'](run_dir_path, attributes['out_file'], save_figs, os.path.join(run_dir_path, 'plots', test)) + # show plots plt.show() def out_file_exists(run_dir, out_file): diff --git a/testing/unit_testing/README_unit_testing b/testing/unit_testing/README_unit_testing deleted file mode 100644 index 1df3d0220a..0000000000 --- a/testing/unit_testing/README_unit_testing +++ /dev/null @@ -1 +0,0 @@ -Nothing here yet - but we will put some tests here eventually. \ No newline at end of file diff --git a/fire/test/fire_weather_test/CMakeLists.txt b/testing/unit_testing/fire_weather_test/CMakeLists.txt similarity index 100% rename from fire/test/fire_weather_test/CMakeLists.txt rename to testing/unit_testing/fire_weather_test/CMakeLists.txt diff --git a/fire/test/fire_weather_test/test_FireWeather.pf b/testing/unit_testing/fire_weather_test/test_FireWeather.pf similarity index 100% rename from fire/test/fire_weather_test/test_FireWeather.pf rename to testing/unit_testing/fire_weather_test/test_FireWeather.pf