Skip to content

Commit

Permalink
move pfunit test to new testing dir
Browse files Browse the repository at this point in the history
  • Loading branch information
adrifoster committed May 7, 2024
1 parent b05fe49 commit 5ee5750
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 85 deletions.
79 changes: 0 additions & 79 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< HEAD
cmake_minimum_required(VERSION 3.4)

list(APPEND CMAKE_MODULE_PATH ${CIME_CMAKE_MODULE_DIRECTORY})
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion fire/test/CMakeLists.txt

This file was deleted.

1 change: 1 addition & 0 deletions radiation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 7 additions & 2 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

## 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)
25 changes: 23 additions & 2 deletions testing/run_fates_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -197,13 +206,25 @@ 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,
test_dict.items())).items():
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):
Expand Down
1 change: 0 additions & 1 deletion testing/unit_testing/README_unit_testing

This file was deleted.

File renamed without changes.

0 comments on commit 5ee5750

Please sign in to comment.