Added test utility shell funcs

This commit is contained in:
Shahram Najm 2015-04-30 10:14:58 +01:00
parent ec335f5aea
commit 453f2a4a3a
7 changed files with 89 additions and 13 deletions

View File

@ -32,6 +32,7 @@ EXTRA_DIST = README AUTHORS NOTICE LICENSE ChangeLog version.sh html \
src/dummy.am \
definitions/dummy.am \
definitions/make_makefile_am.pl \
data/grib_data_files.txt \
data/ls.log \
data/multi.ok \
data/in_copy.grib \
@ -111,6 +112,7 @@ EXTRA_DIST = README AUTHORS NOTICE LICENSE ChangeLog version.sh html \
data/step_grib1.log \
data/julian.out.good \
data/test_uuid.grib2 \
data/tigge/tigge_data_files.txt \
data/tigge/tigge_ammc_pl_gh.grib \
data/tigge/tigge_ammc_pl_q.grib \
data/tigge/tigge_ammc_pl_t.grib \

View File

@ -79,6 +79,7 @@ list( APPEND tests2
read_any
padding
debug
neg_fctime
)
# These tests do not require any data downloads
@ -86,7 +87,7 @@ foreach( test ${tests1} )
ecbuild_add_test( TARGET t_${test}
TYPE SCRIPT
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${test}.sh
RESOURCES include.sh number_compare.pl
RESOURCES include.sh utils.sh number_compare.pl
)
endforeach()
@ -97,7 +98,7 @@ foreach( test ${tests2} )
ecbuild_add_test( TARGET t_${test}
TYPE SCRIPT
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/${test}.sh
RESOURCES include.sh number_compare.pl
RESOURCES include.sh utils.sh number_compare.pl
TEST_DEPENDS get_gribs get_tigge_gribs get_bufrs get_metars get_gts
)
endforeach()

View File

@ -14,7 +14,7 @@ TESTS = definitions.sh calendar.sh \
multi_from_message.sh change_scanning.sh \
julian.sh statistics.sh tigge.sh tigge_conversions.sh \
read_any.sh padding.sh lamb_az_eq_area.sh grib_to_netcdf.sh debug.sh \
jpeg.sh ccsds.sh
jpeg.sh ccsds.sh neg_fctime.sh
# First download all the necessary data for testing
# Note: if download fails, no tests will be done

View File

@ -16,16 +16,6 @@ temp1=temp1.calendar.$$
temp2=temp2.calendar.$$
sample=$ECCODES_SAMPLES_PATH/GRIB2.tmpl
########### Utility function ##############
check_key_equals()
{
file=$1
key=$2
val=$3
result=`${tools_dir}grib_get -p $key $file`
[ "$result" = "$val" ]
}
###########################################
${tools_dir}grib_set -s tablesVersion=13,setCalendarId=1,typeOfCalendar=0 $sample $temp1
check_key_equals $temp1 calendarIdPresent 1

View File

@ -8,6 +8,8 @@
#
set -ea
. ./utils.sh
CMAKE_INCLUDE_FILE=include.ctest.sh
if [ -f "$CMAKE_INCLUDE_FILE" ]; then
# This is the config file for Cmake tests

55
tests/neg_fctime.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/sh
# Copyright 2005-2015 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
. ./include.sh
REDIRECT=/dev/null
temp=neg_fctime.temp.grib
input=${data_dir}/sample.grib2
# check input time and date
check_key_equals $input 'dataDate,dataTime' '20080206 1200'
# Negative step in same day
# --------------------------
${tools_dir}grib_set -s forecastTime=-2 $input $temp
check_key_equals $temp 'validityDate,validityTime' '20080206 1000'
${tools_dir}grib_set -s forecastTime=-11 $input $temp
check_key_equals $temp 'validityDate,validityTime' '20080206 100'
${tools_dir}grib_set -s forecastTime=-12 $input $temp
check_key_equals $temp 'validityDate,validityTime' '20080206 0'
# Negative step previous day
# --------------------------
${tools_dir}grib_set -s forecastTime=-13 $input $temp
check_key_equals $temp 'validityDate,validityTime' '20080205 2300'
${tools_dir}grib_set -s forecastTime=-24 $input $temp
check_key_equals $temp 'validityDate,validityTime' '20080205 1200'
${tools_dir}grib_set -s forecastTime=-33 $input $temp
check_key_equals $temp 'validityDate,validityTime' '20080205 300'
# Negative step further back
# --------------------------
${tools_dir}grib_set -s forecastTime=-38 $input $temp
check_key_equals $temp 'validityDate,validityTime' '20080204 2200'
${tools_dir}grib_set -s forecastTime=-185 $input $temp
check_key_equals $temp 'validityDate,validityTime' '20080129 1900'
# Clean up
rm -f $temp

26
tests/utils.sh Normal file
View File

@ -0,0 +1,26 @@
# Copyright 2005-2015 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#
set -ea
#
# Utility functions for testing
#
# Check the key(s) in the given grib file have the expected value(s)
# Assumes the file has only ONE message otherwise output goes on to
# several lines
check_key_equals()
{
file=$1
key=$2
val=$3
result=`${tools_dir}grib_get -p $key $file`
[ "$result" = "$val" ]
}