Skip to content

Commit 230fd17

Browse files
authored
Merge pull request #1245 from adrifoster/testing_refator
Refactor to testing scripts.
2 parents 4ffab32 + d10f218 commit 230fd17

15 files changed

+1291
-692
lines changed

testing/README.testing.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# FATES Testing
2+
3+
These scripts set up, build, and run FATES functional tests and unit tests.
4+
5+
By "functional" test, we mean a standalone Fortran program that runs pieces of the FATES
6+
production code, potentially outputs results (i.e. to a netcdf file), and potentially
7+
plots or runs some other test on the output in python. These tests do not necessarily
8+
have a pass/fail status, but are meant to be more hands-on for the user.
9+
10+
Unit tests do have a pass/fail outcome, and are written as such. We accommodate both Ctest
11+
and pfunit tests.
12+
13+
## How to run
14+
15+
To run the testing scripts, `run_functional_tests.py` or `run_unit_tests.py`, you will
16+
need a few python packages. You can create a conda environment with these packages
17+
using the `testing.yml` file: `conda env create --file=testing.yml`
18+
19+
Though these tests do not need host land model code, you will need the `cime` and `shr`
20+
repositories, as well as a machine configuration file. If you are already set up to run
21+
FATES on a machine (e.g. derecho at NCAR), you should be able to run these scripts out
22+
of the box on that machine.
23+
24+
Additionally, these tests require netcdf and netcdff, as well as a fortran compiler (e.g. gnu),
25+
esmf, and pfunit. See `cime_setup.md` for tips on how to do this.
26+
27+
Once you are set up, you should be able to just run the scripts. For the functional test
28+
script, you can point to your own parameter file (cdl or nc; `./run_functional_tests -f my_param_file.nc`).
29+
If none is supplied the script will use the default cdl file in `parameter_files`.
30+
31+
You can run an individual set of tests by passing the script a comma-separated list of
32+
test names. See the `functional_tests.cfg` or `unit_tests.cfg` for the test names. If you
33+
do not supply a list, the script will run all tests.
34+
35+
## How to create new tests
36+
37+
First, determine if you are going to create a functional or unit test. Remember,
38+
unit tests must have a pass/fail outcome. These are best for testing edgecases, error
39+
handling, or where we know exactly what the result should be from a method.
40+
41+
First, add your test to either the `functional_tests.cfg` or `unit_tests.cfg` config file,
42+
depending on the test you want to create.
43+
44+
### Config file information
45+
46+
The `test_dir` is where cmake will place relevant libraries created from your test.
47+
The convention is to call this directory `fates_{testname}_ftest` for functional tests
48+
and `fates_{testname}_utest` for unit tests.
49+
50+
The `test_exe` (only applicable for functional tests) is the executable the script will
51+
create based on your test program. The convention is to call it `FATES_{testname}_exe`.
52+
53+
The `out_file` (only applicable for functional tests) is the output file name that your test
54+
may or may not create. Set the value to `None` if your test does not create one.
55+
56+
Set `use_param_file` to `True` if your test uses the FATES parameter file, and `False`
57+
otherwise. This is only applicable for functional tests.
58+
59+
Add any other arguments your test needs in the `other_args` list.
60+
This is only applicable for functional tests.
61+
62+
### Cmake setup
63+
64+
Under the `testing/functional_testing` or `testing/unit_testing` directory, depending
65+
on your test type, create a new directory for your test, e.g. "my_new_test".
66+
67+
In the file `testing/CMakeLists.txt` add your test directory to the list of tests, e.g.:
68+
69+
`add_subdirectory(functional_testing/my_new_test fates_new_test_ftest)`
70+
71+
The first argument must match your directory name, and the second must match the
72+
`test_dir` value you set up in the config file above.
73+
74+
Inside your new testing directory create a new `CMakeLists.txt` file to tell cmake
75+
how to build and compile your program. It may be easiest to copy an existing one
76+
from another similar test and then update the relevant information.
77+
78+
Importantly, the sources must be set to tell the program which file(s) contain your
79+
test program. Additionally, for functional tests, the executable name must match what
80+
you set up in the config file above.
81+
82+
### Fortran program
83+
84+
Write your Fortran tests. For functional tests, this should be an actual Fortran `program`.
85+
For unit tests this will be either a ctest or a pfunit test. See existing tests for examples.
86+
87+
For functional tests, if you output an output file, the name must match what you set up
88+
in the config file above.
89+
90+
### Python setup - functional tests
91+
92+
For functional tests, you will need to add your test as a new concrete class based on
93+
the abstract FunctionalTest class. See examples in the `functional_testing` directory.
94+
Most of the work involves creating a plotting function for your test.
95+
96+
You will then need to add this class as an import statment at the top of the
97+
`run_functional_tests.py` script.

0 commit comments

Comments
 (0)