diff --git a/.github/workflows/esmf-8.0.1_jasper-2.0.22_nceplibs-1.3.0.yml b/.github/workflows/esmf-8.0.1_jasper-2.0.22_nceplibs-1.3.0.yml index efb87d9cd..6883a6cec 100644 --- a/.github/workflows/esmf-8.0.1_jasper-2.0.22_nceplibs-1.3.0.yml +++ b/.github/workflows/esmf-8.0.1_jasper-2.0.22_nceplibs-1.3.0.yml @@ -124,6 +124,7 @@ jobs: mkdir build && cd build cmake .. -DCMAKE_PREFIX_PATH='~;~/jasper;~/nceplibs' make -j2 + make test diff --git a/.github/workflows/esmf-8.0.1_jasper-2.0.22_nceplibs-develop.yml b/.github/workflows/esmf-8.0.1_jasper-2.0.22_nceplibs-develop.yml index 3ff50dc7d..cd2beb295 100644 --- a/.github/workflows/esmf-8.0.1_jasper-2.0.22_nceplibs-develop.yml +++ b/.github/workflows/esmf-8.0.1_jasper-2.0.22_nceplibs-develop.yml @@ -115,6 +115,7 @@ jobs: mkdir build && cd build cmake .. -DCMAKE_PREFIX_PATH='~;~/jasper' make -j2 + make test diff --git a/CMakeLists.txt b/CMakeLists.txt index 9677e6c2a..266ec8c27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,8 @@ if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$") CACHE STRING "Choose the type of build." FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + message(STATUS "Set BUILD_TESTING to YES and build unit testing package under tests") + set(BUILD_TESTING "YES") endif() # Set compiler flags. @@ -73,6 +75,12 @@ endif() add_subdirectory(sorc) +# Run unit tests. +include(CTest) +if(BUILD_TESTING) + add_subdirectory(tests) +endif() + # If doxygen documentation we enabled, build it. if(ENABLE_DOCS) find_package(Doxygen REQUIRED) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..e1478e2e5 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,8 @@ +# This is the CMake file for the tests directory of the UFS_UTILS +# project. +# +# Ed Hartnett 2/11/21 + +# Add the test subdirecotries. +add_subdirectory(chres_cube) + diff --git a/tests/chres_cube/CMakeLists.txt b/tests/chres_cube/CMakeLists.txt new file mode 100644 index 000000000..f7c3b64ae --- /dev/null +++ b/tests/chres_cube/CMakeLists.txt @@ -0,0 +1,42 @@ +# This is the cmake build file for the tests directory of the +# UFS_UTILS project. +# +# George Gayno, Lin Gan, Ed Hartnett + +set(fortran_src + "${CMAKE_SOURCE_DIR}/sorc/chgres_cube.fd/utils.f90" + ftst_utils.F90) + +if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -r8 -convert big_endian -assume byterecl") +elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$") + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-0 -fdefault-real-8 -fconvert=big-endian") +endif() + +include_directories( + ${PROJECT_SOURCE_DIR} +) + +set(exe_name ftst_utils) +add_executable(${exe_name} ${fortran_src}) +add_test(NAME ftst_utils COMMAND ftst_utils) +target_link_libraries( + ftst_utils + nemsio::nemsio + sfcio::sfcio + sigio::sigio + bacio::bacio_4 + sp::sp_d + w3nco::w3nco_d + esmf + wgrib2::wgrib2_lib + wgrib2::wgrib2_api + MPI::MPI_Fortran + NetCDF::NetCDF_Fortran) +if(OpenMP_Fortran_FOUND) + target_link_libraries(ftst_utils OpenMP::OpenMP_Fortran) +endif() + + + + diff --git a/tests/chres_cube/ftst_utils.F90 b/tests/chres_cube/ftst_utils.F90 new file mode 100644 index 000000000..696552dd1 --- /dev/null +++ b/tests/chres_cube/ftst_utils.F90 @@ -0,0 +1,48 @@ +! Unit test for to_upper() and to_lower() functions under UFS_UTILS +! package, chres_cube utility. +! +! Lin Gan NCEP/EMC + +program ftst_utils + + + implicit none + + logical :: match_result + + character(len=12) :: test_input_char_1, test_input_char_2, u_st_base, l_st_base + + u_st_base="STAGGERLOCCE" + l_st_base="staggerlocce" + test_input_char_1="sTAGGErLOCCE" + test_input_char_2="staGGErLOCCE" + + print*, "Starting Unit Testing to_upper_lower." + print*, "testing to_lower and to_upper..." + +!------------------------------------------------------------------------- +! Execute testing below by running target function with testing string +! When match_result set to be T - compare to base line is identical +! When match_result set to be F - compare to base line is NOT identical +!------------------------------------------------------------------------- + + call to_lower(test_input_char_1) + match_result = test_input_char_1 == l_st_base + if (.not.match_result) then + stop + endif + + call to_upper(test_input_char_2) + match_result = test_input_char_2 == u_st_base + if (.not.match_result) then + stop + endif + +!------------------------------------------------------------------------- +! Display final result +!------------------------------------------------------------------------- + + print*, "OK" + print*, "SUCCESS!" + +end program ftst_utils