Skip to content

Commit 370d724

Browse files
Add TEST_FILE_DIR option to CMake build, where test data files can be found instead of using FTP. (#732)
Add handling for the TEST_FILE_DIR option in CMake. This allows the programmer to specify a local directory to check first, before downloading test data files from the FTP site. Use this capability, and a cache, to cache the data for all CI runs as well. This prevents the CI system from downloading these test files hundreds of times per day. Part of #719. Fixes #728
1 parent aad9912 commit 370d724

7 files changed

+114
-16
lines changed

.github/workflows/debug-docs-test_coverage.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ jobs:
100100
path: ufs_utils
101101
submodules: recursive
102102

103+
- name: cache-data
104+
id: cache-data
105+
uses: actions/cache@v2
106+
with:
107+
path: ~/data
108+
key: data-1
109+
103110
- name: build
104111
run: |
105112
export ESMFMKFILE=~/esmf/lib/esmf.mk
@@ -109,7 +116,7 @@ jobs:
109116
export CXX=mpicxx
110117
export FC=mpifort
111118
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
112-
cmake .. -DCMAKE_PREFIX_PATH='~/jasper;~/nceplibs' -DCMAKE_BUILD_TYPE=Debug -DENABLE_DOCS=On -DCMAKE_Fortran_FLAGS="-g -fprofile-arcs -ftest-coverage -O0"
119+
cmake -DTEST_FILE_DIR=/home/runner/data -DCMAKE_PREFIX_PATH='~/jasper;~/nceplibs' -DCMAKE_BUILD_TYPE=Debug -DENABLE_DOCS=On ..
113120
make -j2
114121
115122
- name: test

.github/workflows/developer.yml

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# UFS_UTILS test workflow.
22
#
3-
# This workflow tests all developer options - address santizer,
4-
# warning check, documentation check, and test code coverage.
3+
# This workflow tests all developer options including
4+
# documentation check, and test code coverage.
55
#
66
# Ed Hartnett 12/11/22
77
name: developer
@@ -326,15 +326,21 @@ jobs:
326326
path: ufs_utils
327327
submodules: true
328328

329+
- name: cache-data
330+
id: cache-data
331+
uses: actions/cache@v2
332+
with:
333+
path: ~/data
334+
key: data-1
335+
329336
- name: build
330337
run: |
331-
set -x
332338
cd ufs_utils
333339
mkdir build
334340
doxygen --version
335341
export ESMFMKFILE=~/esmf/lib/esmf.mk
336342
cd build
337-
cmake .. -DFTP_TEST_FILES=ON -DTEST_FILE_DIR=/home/runner/data -DENABLE_DOCS=On -DJasper_ROOT=~/jasper -DCMAKE_PREFIX_PATH="~/g2c;~/bacio;~/g2;~/w3nco;~/sfcio;~/sigio;~/nemsio;~/sp;~/ip" -DCMAKE_Fortran_FLAGS="-g -fprofile-arcs -ftest-coverage -O0" -DCMAKE_C_FLAGS="-g -fprofile-arcs -ftest-coverage -O0" -DCMAKE_BUILD_TYPE=Debug
343+
cmake -DTEST_FILE_DIR=/home/runner/data -DENABLE_DOCS=On -DCMAKE_PREFIX_PATH="~/jasper;~/g2c;~/bacio;~/g2;~/w3nco;~/sfcio;~/sigio;~/nemsio;~/sp;~/ip" -DCMAKE_Fortran_FLAGS="-g -fprofile-arcs -ftest-coverage -O0" -DCMAKE_C_FLAGS="-g -fprofile-arcs -ftest-coverage -O0" -DCMAKE_BUILD_TYPE=Debug ..
338344
make -j2 VERBOSE=1
339345
340346
- name: test
@@ -343,6 +349,18 @@ jobs:
343349
ctest --verbose --rerun-failed --output-on-failure
344350
gcovr --root .. -v --html-details --exclude ../tests --exclude CMakeFiles --print-summary -o test-coverage.html &> /dev/null
345351
352+
- name: cache-data
353+
if: steps.cache-data.outputs.cache-hit != 'true'
354+
run: |
355+
mkdir ~/data
356+
cp ufs_utils/build/tests/chgres_cube/data/* ~/data
357+
cp ufs_utils/build/tests/sfc_climo_gen/data/* ~/data
358+
cp ufs_utils/build/tests/cpld_gridgen/data/* ~/data
359+
cp ufs_utils/tests/filter_topo/data/* ~/data
360+
cp ufs_utils/tests/emcsfc_snow2mdl/data/* ~/data
361+
cp ufs_utils/tests/chgres_cube/data/* ~/data
362+
ls -l ~/data
363+
346364
- name: upload-test-coverage
347365
uses: actions/upload-artifact@v2
348366
with:

.github/workflows/intel.yml

+22-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
- README.md
1313

1414
# Use custom shell with -l so .bash_profile is sourced which loads intel/oneapi/setvars.sh
15-
# without having to do it in manually every step
15+
# without having to do it in manually every step.
1616
defaults:
1717
run:
1818
shell: bash -leo pipefail {0}
@@ -166,16 +166,36 @@ jobs:
166166
path: ufs_utils
167167
submodules: recursive
168168

169+
- name: cache-data
170+
id: cache-data
171+
uses: actions/cache@v2
172+
with:
173+
path: ~/data
174+
key: data-1
175+
169176
- name: build
170177
run: |
171178
export ESMFMKFILE=~/esmf/lib/esmf.mk
172179
cd ufs_utils
173180
mkdir build && cd build
174181
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
175-
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH='~;~/jasper;~/nceplibs;~/netcdf'
182+
cmake -DTEST_FILE_DIR=/home/runner/data -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH='~;~/jasper;~/nceplibs;~/netcdf' ..
176183
make -j2
177184
178185
- name: test
179186
run: |
180187
cd ufs_utils/build
181188
ctest --rerun-failed --output-on-failure
189+
190+
- name: cache-data
191+
if: steps.cache-data.outputs.cache-hit != 'true'
192+
run: |
193+
mkdir ~/data
194+
cp ufs_utils/build/tests/chgres_cube/data/* ~/data
195+
cp ufs_utils/build/tests/sfc_climo_gen/data/* ~/data
196+
cp ufs_utils/build/tests/cpld_gridgen/data/* ~/data
197+
cp ufs_utils/tests/filter_topo/data/* ~/data
198+
cp ufs_utils/tests/emcsfc_snow2mdl/data/* ~/data
199+
cp ufs_utils/tests/chgres_cube/data/* ~/data
200+
ls -l ~/data
201+

.github/workflows/linux-mac-nceplibs-mpi.yml

+21-1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ jobs:
217217
path: ufs_utils
218218
submodules: recursive
219219

220+
- name: cache-data
221+
id: cache-data
222+
uses: actions/cache@v2
223+
with:
224+
path: ~/data
225+
key: data-2
226+
220227
- name: build
221228
run: |
222229
export ESMFMKFILE=~/esmf/lib/esmf.mk
@@ -227,7 +234,7 @@ jobs:
227234
export FC=mpifort
228235
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
229236
export DYLD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
230-
cmake .. -DCMAKE_PREFIX_PATH='~/jasper;~/nceplibs;~/netcdf'
237+
cmake -DTEST_FILE_DIR=/home/runner/data -DCMAKE_PREFIX_PATH='~/jasper;~/nceplibs;~/netcdf' ..
231238
make -j2
232239
233240
- name: test
@@ -236,3 +243,16 @@ jobs:
236243
# Oversubscribe for OpenMPI to run more processes than CPUs
237244
export OMPI_MCA_rmaps_base_oversubscribe=1
238245
ctest --rerun-failed --output-on-failure
246+
247+
- name: cache-data
248+
if: steps.cache-data.outputs.cache-hit != 'true'
249+
run: |
250+
mkdir ~/data
251+
cp ufs_utils/build/tests/chgres_cube/data/* ~/data
252+
cp ufs_utils/build/tests/sfc_climo_gen/data/* ~/data
253+
cp ufs_utils/build/tests/cpld_gridgen/data/* ~/data
254+
cp ufs_utils/tests/filter_topo/data/* ~/data
255+
cp ufs_utils/tests/emcsfc_snow2mdl/data/* ~/data
256+
cp ufs_utils/tests/chgres_cube/data/* ~/data
257+
ls -l ~/data
258+

.github/workflows/netcdf-versions.yml

+22-1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ jobs:
151151
path: ufs_utils
152152
submodules: recursive
153153

154+
- name: cache-data
155+
id: cache-data
156+
uses: actions/cache@v2
157+
with:
158+
path: ~/data
159+
key: data-1
160+
154161
- name: build
155162
run: |
156163
export ESMFMKFILE=~/esmf/lib/esmf.mk
@@ -160,11 +167,25 @@ jobs:
160167
export CXX=mpicxx
161168
export FC=mpifort
162169
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:~/jasper/lib;~/jasper/lib64"
163-
cmake .. -DCMAKE_PREFIX_PATH='~/jasper;~/nceplibs;~/netcdf' -DCMAKE_BUILD_TYPE=Debug
170+
cmake -DTEST_FILE_DIR=/home/runner/work/UFS_UTILS/UFS_UTILS/data -DCMAKE_PREFIX_PATH='~/jasper;~/nceplibs;~/netcdf' -DCMAKE_BUILD_TYPE=Debug ..
164171
make -j2
165172
166173
- name: test
167174
run: |
168175
cd ufs_utils/build
169176
# export LSAN_OPTIONS=suppressions=LSanSuppress.supp
170177
ctest --rerun-failed --output-on-failure
178+
179+
- name: cache-data
180+
if: steps.cache-data.outputs.cache-hit != 'true'
181+
run: |
182+
mkdir ~/data
183+
cp ufs_utils/build/tests/chgres_cube/data/* ~/data
184+
cp ufs_utils/build/tests/sfc_climo_gen/data/* ~/data
185+
cp ufs_utils/build/tests/cpld_gridgen/data/* ~/data
186+
cp ufs_utils/tests/filter_topo/data/* ~/data
187+
cp ufs_utils/tests/emcsfc_snow2mdl/data/* ~/data
188+
cp ufs_utils/tests/chgres_cube/data/* ~/data
189+
ls -l ~/data
190+
191+

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1515
# User options.
1616
option(OPENMP "use OpenMP threading" ON)
1717
option(ENABLE_DOCS "Enable generation of doxygen-based documentation." OFF)
18+
SET(TEST_FILE_DIR "." CACHE STRING "Check this directory for test files before using FTP.")
1819

20+
# Set the build type.
1921
if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$")
2022
message(STATUS "Setting build type to 'Release' as none was specified.")
2123
set(CMAKE_BUILD_TYPE

tests/CMakeLists.txt

+17-7
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@
33
#
44
# Ed Hartnett 2/11/21
55

6-
# This function is used to download unit test data.
7-
# It takes two arguments, the URL and the file to
8-
# be downloaded.
9-
6+
# Some test files are large and are kept on the NOAA EMC FTP
7+
# site. This function is used to download such test data. It takes two
8+
# arguments, the URL and the file to be downloaded.
109
function(PULL_DATA THE_URL THE_FILE)
10+
# If the TEST_FILE_DIR was specified, look for our test data files
11+
# there before FTPing them. Developers can keep all test files on
12+
# their machines, and save the time of downloading them every time.
13+
message(STATUS "TEST_FILE_DIR ${TEST_FILE_DIR} THE_FILE ${THE_FILE}")
14+
if(NOT ${TEST_FILE_DIR} STREQUAL ".")
15+
if (EXISTS ${TEST_FILE_DIR}/${THE_FILE})
16+
message(STATUS "Copying file ${TEST_FILE_DIR}/${THE_FILE} to test data directory.")
17+
FILE(COPY ${TEST_FILE_DIR}/${THE_FILE}
18+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
19+
endif()
20+
endif()
1121
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/data/${THE_FILE}")
22+
message(STATUS "Downloading file ${CMAKE_CURRENT_BINARY_DIR}/data/${THE_FILE}.")
1223
file(DOWNLOAD
1324
${THE_URL}/${THE_FILE}
1425
${CMAKE_CURRENT_BINARY_DIR}/data/${THE_FILE}
15-
SHOW_PROGRESS
1626
STATUS status
17-
INACTIVITY_TIMEOUT 120
18-
)
27+
INACTIVITY_TIMEOUT 30
28+
)
1929
list(GET status 0 status_num)
2030
if(NOT status_num EQUAL 0 OR NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/data/${THE_FILE}")
2131
message(FATAL_ERROR "Could not download ${THE_FILE}")

0 commit comments

Comments
 (0)