Skip to content

Commit

Permalink
reorganizing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AlysonStahl-NOAA committed Jun 4, 2024
1 parent 8a08a00 commit f97b32d
Show file tree
Hide file tree
Showing 91 changed files with 224 additions and 114 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1 --errors-f
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
if (BUILD_UTILS)
if (BUILD_WITH_W3EMC)
add_subdirectory(test_utils)
endif()
endif()
endif()

# Determine whether or not to generate documentation.
Expand Down
113 changes: 113 additions & 0 deletions test_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# This is the CMake file for the test_utils directory in the NCEPLIBS-g2
# project.
#
# Ed Hartnett

# This fortran test is for the internals of degrib2.
add_executable(test_degrib2_int test_degrib2_int.F90 ${CMAKE_SOURCE_DIR}/src/degrib2/prlevel.F90
${CMAKE_SOURCE_DIR}/src/degrib2/prvtime.F90)
target_link_libraries(test_degrib2_int PRIVATE g2::g2_4)
add_test(NAME test_degrib2_int COMMAND test_degrib2_int)

# Run each shell test.
function(gu_test name)
# Copy the test scripts.
file(COPY "${CMAKE_SOURCE_DIR}/test_utils/${name}.sh"
DESTINATION ${CMAKE_BINARY_DIR}/test_utils
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
# Add the shell script as a test.
add_test(NAME ${name}.sh COMMAND bash ${name}.sh)
endfunction()

# Copy each necessary test data file to the binary build directory.
function(gu_copy_test_data name)
file(COPY "${CMAKE_SOURCE_DIR}/test_utils/data/${name}"
DESTINATION ${CMAKE_BINARY_DIR}/test_utils/data
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endfunction()


# Copy necessary test data files.
gu_copy_test_data(ref_copygb2_test_gdaswave_2.ip.grib2.degrib2)
gu_copy_test_data(ref_copygb2_test_gdaswave.degrib2.txt)
gu_copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib2)
gu_copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.ip.grib2)
gu_copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib1)
gu_copy_test_data(ref_gdaswave_2.idx)
gu_copy_test_data(ref_gdaswave.degrib2.txt)
gu_copy_test_data(ref_gdaswave_grib1_inventory.txt)
gu_copy_test_data(ref_gdaswave.grb2index.idx)
gu_copy_test_data(ref_gdaswave.grb2index.idx2)
gu_copy_test_data(ref_gdaswave.grbindex.grib1.idx)
gu_copy_test_data(ref_gdaswave_2.grib1.idx)
gu_copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib2.idx)
gu_copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000_2.grib2.idx)
gu_copy_test_data(ref_gfs.landmask.grib1)
gu_copy_test_data(ref_grid_172.landmask.grib1)
gu_copy_test_data(ref_grid_220.landmask.grib1)
gu_copy_test_data(tocgrib2.nml)
gu_copy_test_data(tocgrib2_bad.nml)

if(FTP_TEST_FILES)
message(STATUS "Getting FTP test files...")
gu_copy_test_data(ref_blend.t19z.core.f001.co.grib2.degrib2)
gu_copy_test_data(ref_cmc_geavg.t12z.pgrb2a.0p50.f000.degrib2)
gu_copy_test_data(ref_WW3_Regional_US_West_Coast_20220718_0000.grib2.degrib2)
gu_copy_test_data(ref_WW3_Regional_US_East_Coast_20220717_0600.grib2.degrib2)
gu_copy_test_data(ref_gdas.t12z.pgrb2.1p00.anl.grib2.degrib2)
gu_copy_test_data(ref_flxf2022111712.01.2022111712.grb2.degrib2)
gu_copy_test_data(ref_GLOBAL.grib2.2022103000.0000.degrib2)
gu_copy_test_data(ref_hiresw.t00z.arw_5km.f00.hi.grib2.degrib2)
gu_copy_test_data(ref_naefs_ge10pt.t12z.pgrb2a.0p50_bcf003.degrib2)
gu_copy_test_data(ref_rap.t00z.awp130pgrbf00.grib2.degrib2)
gu_copy_test_data(ref_seaice.t00z.grb.grib2.degrib2)
gu_copy_test_data(ref_sgx_nwps_CG3_20221117_1200.grib2.degrib2)
gu_copy_test_data(ref_aqm.t12z.max_8hr_o3.227.grib2.degrib2)
if(FTP_LARGE_TEST_FILES)
message(STATUS "Getting FTP large test file...")
gu_copy_test_data(ref_fv3lam.t00z.prslev.f000.grib2.degrib2)
endif()
if(FTP_EXTRA_TEST_FILES)
message(STATUS "Getting extra FTP large test files...")
# gu_copy_test_data(ref_rrfs.t12z.prslevfaa.f010.na3km.grib2.degrib2)
gu_copy_test_data(ref_GFSPRS.GrbF06.degrib2)
gu_copy_test_data(ref_rrfs.t18z.prslev.f000.grib2.degrib2)
# gu_copy_test_data(ref_grib2.awips.rrfs.010)
endif()
endif()

# Run these shell tests.
gu_test(run_cnvgrib_tests)
gu_test(run_copygb_tests)
gu_test(run_copygb2_tests2)
gu_test(run_degrib2_tests)
gu_test(run_grbindex_tests)
gu_test(run_grb2index_tests)
gu_test(run_tocgrib2_tests)
gu_test(run_tocgrib2super_tests)

if(G2C_COMPARE)
find_program(G2C_COMPARE g2c_compare)
gu_test(run_copygb2_tests)
else()
message(STATUS "g2c_compare not found.")
endif()

if(FTP_TEST_FILES)
# Copy this inventory from the test directory. It's the expected
# inventory for one of the FTP files, after conversion to GRIB1.
gu_copy_test_data(ref_test_WW3_West.grib1.inventory.txt)
gu_copy_test_data(ref_test_WW3_West.grib2.idx)

# Run these shell tests which use the FTP files.
gu_test(run_ftp_tests)
gu_test(run_degrib2_ftp_tests)
if(FTP_LARGE_TEST_FILES)
gu_test(run_degrib2_large_file_tests)
endif()
if(FTP_EXTRA_TEST_FILES)
gu_test(run_degrib2_extra_file_tests)
gu_test(run_tocgrib2_extra_file_tests)
gu_test(run_tocgrib2super_extra_file_tests)
endif()
endif()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ echo "*** Running cnvgrib test"
../utils/cnvgrib -g12 test_gdaswave.t00z.wcoast.0p16.f000.grib1 test_gdaswave.t00z.wcoast.0p16.f000.grib2

# Create an index of a GRIB2 file.
../utils/grb2index 1 test_gdaswave.t00z.wcoast.0p16.f000.grib2 test_gdaswave.t00z.wcoast.0p16.f000.grib2.idx
../src/grb2index/grb2index 1 test_gdaswave.t00z.wcoast.0p16.f000.grib2 test_gdaswave.t00z.wcoast.0p16.f000.grib2.idx

# Check against expected output. First 120 bytes contain differences,
# so ignore them.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for f in $ftp_files
do
echo "Testing degrib2 with large file $f"
ls -l data/$f
../utils/degrib2 data/$f > ${f}.degrib2
../utils/degrib2 ../tests/data/$f > ${f}.degrib2
diff -w ${f}.degrib2 data/ref_${f}.degrib2
done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ for f in $ftp_files
do
echo "Testing degrib2 with file $f"
# ls -l data/$f
../utils/degrib2 data/$f > ${f}.degrib2
../utils/degrib2 ../tests/data/$f > ${f}.degrib2
diff -w ${f}.degrib2 data/ref_${f}.degrib2
done

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ for f in $ftp_files
do
echo "Testing degrib2 with large file $f"
ls -l data/$f
../utils/degrib2 data/$f > ${f}.degrib2
../utils/degrib2 ../tests/data/$f > ${f}.degrib2
diff -w ${f}.degrib2 data/ref_${f}.degrib2
done

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ echo ""
echo "*** Running FTP file tests"

# Convert test file to GRIB1.
../utils/cnvgrib -g21 data/WW3_Regional_US_West_Coast_20220718_0000.grib2 test_WW3_West.grib1
../utils/cnvgrib -g21 ../tests/data/WW3_Regional_US_West_Coast_20220718_0000.grib2 test_WW3_West.grib1

# Generate an inventory of the GRIB1 file.
#../src/wgrib/wgrib test_WW3_West.grib1 &> test_WW3_West.grib1.inventory.txt
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@

set -e
echo ""
echo "*** Running tocgrib2 tests"

# echo "*** Running tocgrib2 without input/output defined. Should return STOP 10"
# unset FORT11
# unset FORT51
# ../src/tocgrib2/tocgrib2 && exit 1
echo "*** Running tocgrib2 extra file tests"

echo "*** Running tocgrib2 with input/output defined, but one missing field. It will fail."
export FORT11="data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
export FORT11="../tests/data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
export FORT51=out.grib2
../utils/tocgrib2 < data/tocgrib2_bad.nml && exit 1

echo "*** Running tocgrib2 with input/output defined. It will succeed."
export FORT11="data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
export FORT11="../tests/data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
export FORT51=out.grib2
../utils/tocgrib2 < data/tocgrib2.nml

Expand Down
27 changes: 27 additions & 0 deletions test_utils/run_tocgrib2_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
# This is a test script for the NCEPLIBS-grib_util project. This tests
# the tocgrib2 utility.
#
# Ed Hartnett, 4/20/24

set -e
echo ""
echo "*** Running tocgrib2 tests"

echo "*** Running tocgrib2 without input/output defined. Should return STOP 10"
unset FORT11
unset FORT51
../utils/tocgrib2 && exit 1

#echo "*** Running tocgrib2 with input/output defined, but one missing field. It will fail."
# export FORT11="data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
# export FORT51=out.grib2
# ../src/tocgrib2/tocgrib2 < data/tocgrib2_bad.nml && exit 1

# echo "*** Running tocgrib2 with input/output defined. It will succeed."
# export FORT11="data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
# export FORT51=out.grib2
# ../src/tocgrib2/tocgrib2 < data/tocgrib2.nml

echo "*** SUCCESS!"
exit 0
22 changes: 22 additions & 0 deletions test_utils/run_tocgrib2super_extra_files_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# This is a test script for the NCEPLIBS-grib_util project. This tests
# the tocgrib2super utility with extra files downloaded from FTP.
#
# Ed Hartnett, 5/28/24

set -e
echo ""
echo "*** Running tocgrib2super extra tests"

echo "*** Running tocgrib2super with input/output defined, but one missing field. It will fail."
export FORT11="../tests/data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
export FORT51=out.grib2
../utils/tocgrib2super < data/tocgrib2_bad.nml && exit 1

echo "*** Running tocgrib2 with input/output defined. It will succeed."
export FORT11="../tests/data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
export FORT51=out.grib2
../utils/tocgrib2super < data/tocgrib2.nml

echo "*** SUCCESS!"
exit 0
27 changes: 27 additions & 0 deletions test_utils/run_tocgrib2super_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
# This is a test script for the NCEPLIBS-grib_util project. This tests
# the tocgrib2super utility.
#
# Ed Hartnett, 5/28/24

set -e
echo ""
echo "*** Running tocgrib2super tests"

echo "*** Running tocgrib2 without input/output defined. Should return STOP 10"
unset FORT11
unset FORT51
../utils/tocgrib2super && exit 1

# echo "*** Running tocgrib2super with input/output defined, but one missing field. It will fail."
# export FORT11="data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
# export FORT51=out.grib2
# ../src/tocgrib2super/tocgrib2super < data/tocgrib2_bad.nml && exit 1

# echo "*** Running tocgrib2 with input/output defined. It will succeed."
# export FORT11="data/rrfs.t12z.prslevfaa.f010.na3km.grib2"
# export FORT51=out.grib2
# ../src/tocgrib2super/tocgrib2super < data/tocgrib2.nml

echo "*** SUCCESS!"
exit 0
File renamed without changes.
85 changes: 3 additions & 82 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ endfunction()
# function copies such a data file to the build directory.
function(copy_test_data name)
message(STATUS "Copying test file ${name}")
file(COPY "${CMAKE_SOURCE_DIR}/tests/data/${name}"
DESTINATION ${CMAKE_BINARY_DIR}/tests/data
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/${name}"
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endfunction()

Expand Down Expand Up @@ -102,6 +102,7 @@ if(FTP_TEST_FILES)
sgx_nwps_CG3_20221117_1200.grib2
)


# User may also ask for large test file.
if(FTP_LARGE_TEST_FILES)
set(FTP_FILES ${FTP_FILES} fv3lam.t00z.prslev.f000.grib2)
Expand Down Expand Up @@ -221,83 +222,3 @@ foreach(kind ${kinds})
endif()
endforeach()

# Tests that use grib utilities
if (BUILD_UTILS)
if (BUILD_WITH_W3EMC)
# This fortran test is for the internals of degrib2.
add_executable(test_degrib2_int test_degrib2_int.F90 ${CMAKE_SOURCE_DIR}/utils/prlevel.F90
${CMAKE_SOURCE_DIR}/utils/prvtime.F90)
target_link_libraries(test_degrib2_int PUBLIC ${PROJECT_NAME}_4)
add_test(NAME test_degrib2_int COMMAND test_degrib2_int)

gu_test(run_cnvgrib_tests)
gu_test(run_copygb_tests)
gu_test(run_copygb2_tests2)
gu_test(run_degrib2_tests)
gu_test(run_grbindex_tests)
gu_test(run_grb2index_tests)

copy_test_data(ref_copygb2_test_gdaswave_2.ip.grib2.degrib2)
copy_test_data(ref_copygb2_test_gdaswave.degrib2.txt)
copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib2)
copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.ip.grib2)
copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib1)
copy_test_data(ref_gdaswave_2.idx)
copy_test_data(ref_gdaswave.degrib2.txt)
copy_test_data(ref_gdaswave_grib1_inventory.txt)
copy_test_data(ref_gdaswave.grb2index.idx)
copy_test_data(ref_gdaswave.grb2index.idx2)
copy_test_data(ref_gdaswave.grbindex.grib1.idx)
copy_test_data(ref_gdaswave_2.grib1.idx)
copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000.grib2.idx)
copy_test_data(ref_gdaswave.t00z.wcoast.0p16.f000_2.grib2.idx)
copy_test_data(ref_gfs.landmask.grib1)
copy_test_data(ref_grid_172.landmask.grib1)
copy_test_data(ref_grid_220.landmask.grib1)
copy_test_data(tocgrib2.nml)
copy_test_data(tocgrib2_bad.nml)

if(G2C_COMPARE)
find_program(G2C_COMPARE g2c_compare)
gu_test(run_copygb2_tests)
else()
message(STATUS "g2c_compare not found.")
endif()

if (FTP_TEST_FILES)
# Copy this inventory from the test directory. It's the expected
# inventory for one of the FTP files, after conversion to GRIB1.
copy_test_data(ref_blend.t19z.core.f001.co.grib2.degrib2)
copy_test_data(ref_cmc_geavg.t12z.pgrb2a.0p50.f000.degrib2)
copy_test_data(ref_WW3_Regional_US_West_Coast_20220718_0000.grib2.degrib2)
copy_test_data(ref_WW3_Regional_US_East_Coast_20220717_0600.grib2.degrib2)
copy_test_data(ref_gdas.t12z.pgrb2.1p00.anl.grib2.degrib2)
copy_test_data(ref_flxf2022111712.01.2022111712.grb2.degrib2)
copy_test_data(ref_GLOBAL.grib2.2022103000.0000.degrib2)
copy_test_data(ref_hiresw.t00z.arw_5km.f00.hi.grib2.degrib2)
copy_test_data(ref_naefs_ge10pt.t12z.pgrb2a.0p50_bcf003.degrib2)
copy_test_data(ref_rap.t00z.awp130pgrbf00.grib2.degrib2)
copy_test_data(ref_seaice.t00z.grb.grib2.degrib2)
copy_test_data(ref_sgx_nwps_CG3_20221117_1200.grib2.degrib2)
copy_test_data(ref_aqm.t12z.max_8hr_o3.227.grib2.degrib2)
copy_test_data(ref_test_WW3_West.grib1.inventory.txt)
copy_test_data(ref_test_WW3_West.grib2.idx)

gu_test(run_util_ftp_tests)
gu_test(run_degrib2_ftp_tests)
if(FTP_LARGE_TEST_FILES)
copy_test_data(ref_fv3lam.t00z.prslev.f000.grib2.degrib2)

gu_test(run_degrib2_large_file_tests)
endif()
if(FTP_EXTRA_TEST_FILES)
copy_test_data(ref_GFSPRS.GrbF06.degrib2)
copy_test_data(ref_rrfs.t18z.prslev.f000.grib2.degrib2)
copy_test_data(ref_grib2.awips.rrfs.010)

gu_test(run_degrib2_extra_file_tests)
gu_test(run_tocgrib2_tests)
endif()
endif()
endif()
endif()
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/run_jasper_warning_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ls -l
cat test_jpcpack_4_output.txt

# Check against expected output.
diff -w test_jpcpack_4_output.txt data/ref_test_jpcpack_4_output.txt
diff -w test_jpcpack_4_output.txt ref_test_jpcpack_4_output.txt

set -x
echo "*** SUCCESS!"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_create_index.F90
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ end subroutine g2_create_index
print *, 'testing g2_create_index version ', idxver

! Open GRIB2 file for reading.
call baopenr(lugb, 'data/' // TEST_FILE_GDAS, ios)
call baopenr(lugb, TEST_FILE_GDAS, ios)
if (ios .ne. 0) stop 2

! Open output file where index will be written.
Expand Down
Loading

0 comments on commit f97b32d

Please sign in to comment.