Testing: tools error conditions

This commit is contained in:
Shahram Najm 2023-12-27 18:31:59 +00:00
parent 4d079fb3ef
commit 547ea60f6f
3 changed files with 42 additions and 26 deletions

View File

@ -10,8 +10,6 @@
. ./include.ctest.sh . ./include.ctest.sh
#set -x
# Enter data dir # Enter data dir
cd ${data_dir}/bufr cd ${data_dir}/bufr
@ -26,10 +24,9 @@ touch $fLog
# Define tmp bufr file # Define tmp bufr file
fBufrTmp=${label}".bufr.tmp" fBufrTmp=${label}".bufr.tmp"
#---------------------------------------------------- #-----------------------------------------------
# Test: setting header for single message file # Test: setting header for single message file
#---------------------------------------------------- #-----------------------------------------------
rm -f $fBufrTmp rm -f $fBufrTmp
f="syno_1.bufr" f="syno_1.bufr"
@ -43,7 +40,6 @@ centre=`${tools_dir}/bufr_get -p bufrHeaderCentre $fBufrTmp`
#---------------------------------------------------- #----------------------------------------------------
# Test: setting header for multi-message file # Test: setting header for multi-message file
#---------------------------------------------------- #----------------------------------------------------
rm -f $fBufrTmp rm -f $fBufrTmp
f="syno_multi.bufr" f="syno_multi.bufr"
@ -60,7 +56,6 @@ done
#----------------------------------------------------- #-----------------------------------------------------
# Test: setting data values for single message file # Test: setting data values for single message file
#----------------------------------------------------- #-----------------------------------------------------
# TODO: when ECC-37 is fixed we need to enable it. # TODO: when ECC-37 is fixed we need to enable it.
rm -f $fBufrTmp rm -f $fBufrTmp
@ -77,7 +72,6 @@ echo "file: $f" >> $fLog
#---------------------------------------------------- #----------------------------------------------------
# Test: setting header for multi-message file # Test: setting header for multi-message file
#---------------------------------------------------- #----------------------------------------------------
# TODO: when ECC-37 is fixed we need to enable it. # TODO: when ECC-37 is fixed we need to enable it.
rm -f $fBufrTmp rm -f $fBufrTmp
@ -93,13 +87,22 @@ echo "file: $f" >> $fLog
#done #done
#----------------------------------------------------------- #-----------------------------------------------------------
# Test: with nonexistent keys. # Test: No keys set
#-----------------------------------------------------------
set +e
${tools_dir}/bufr_set $f $fBufrTmp > $fLog 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "provide some keys to set" $fLog
#-----------------------------------------------------------
# Test: with nonexistent keys
#----------------------------------------------------------- #-----------------------------------------------------------
# Key "center" does not exist!! # Key "center" does not exist!!
# Invoke without -f i.e. should fail if error encountered # Invoke without -f i.e. should fail if error encountered
set +e set +e
f="syno_1.bufr" f="syno_1.bufr"
echo "Test: nonexistent keys" >> $fLog echo "Test: nonexistent keys" >> $fLog
echo "file: $f" >> $fLog echo "file: $f" >> $fLog
@ -117,12 +120,10 @@ ${tools_dir}/bufr_set -f -s center=98 $f $fBufrTmp 2>>$fLog 1>>$fLog
#----------------------------------------------------------- #-----------------------------------------------------------
# Test: with not allowed key values # Test: with not allowed key values
#----------------------------------------------------------- #-----------------------------------------------------------
# Here 1024 is out of range for centre (it is 8-bit only for edition=3 files) # Here 1024 is out of range for centre (it is 8-bit only for edition=3 files)
# Invoke without -f i.e. should fail if error encountered # Invoke without -f i.e. should fail if error encountered
set +e set +e
f="syno_1.bufr" f="syno_1.bufr"
echo "Test: nonexistent keys" >> $fLog echo "Test: nonexistent keys" >> $fLog
echo "file: $f" >> $fLog echo "file: $f" >> $fLog
@ -184,7 +185,6 @@ ${tools_dir}/bufr_set -s messageLength:s=333 $sample $fBufrTmp
result=`${tools_dir}/bufr_get -p messageLength $fBufrTmp` result=`${tools_dir}/bufr_get -p messageLength $fBufrTmp`
[ "$result" = "333" ] [ "$result" = "333" ]
#----------------------------------------------------------- #-----------------------------------------------------------
# Invalid masterTablesVersionNumber # Invalid masterTablesVersionNumber
#----------------------------------------------------------- #-----------------------------------------------------------
@ -210,6 +210,15 @@ set -e
grep -q "ECCODES ERROR.*unable to get hash value for sequences" $fLog grep -q "ECCODES ERROR.*unable to get hash value for sequences" $fLog
# Unreadable message
#-----------------------------------------------------------
echo BUFR > $fBufrTmp
set +e
${tools_dir}/bufr_set -s masterTablesVersionNumber=10 $fBufrTmp /dev/null > $fLog 2>&1
status=$?
set -e
grep -q "unreadable message" $fLog
# Clean up # Clean up
rm -f $fLog rm -f $fLog

View File

@ -108,5 +108,25 @@ ${tools_dir}/grib_dump -w count=4 $file > $temp 2>&1
ECCODES_DEBUG=1 ${tools_dir}/grib_dump $data_dir/sample.grib2 ECCODES_DEBUG=1 ${tools_dir}/grib_dump $data_dir/sample.grib2
# Unreadable message
#-----------------------------------------------------------
tempOut=temp.$label.out
echo GRIB > $temp
set +e
${tools_dir}/grib_dump $temp > $tempOut 2>&1
status=$?
set -e
grep -q "unreadable message" $tempOut
set +e
${tools_dir}/grib_dump -j $temp > $tempOut 2>&1
status=$?
set -e
grep -q "unreadable message" $tempOut
rm -f $tempOut
# Clean up # Clean up
rm -f $temp rm -f $temp

View File

@ -13,9 +13,6 @@
grib_option grib_options[] = { grib_option grib_options[] = {
/* {id, args, help}, on, command_line, value*/ /* {id, args, help}, on, command_line, value*/
{ "s:", 0, 0, 1, 1, 0 }, { "s:", 0, 0, 1, 1, 0 },
/* {"r",0,0,0,1,0}, */
/* {"d:",0,0,0,1,0},*/
/* {"n:","noise percentage","\n\t\tAdd noise to the data values. The noise added is the given percentage of the data value.\n",0,1,0},*/
{ "p:", 0, 0, 1, 1, 0 }, { "p:", 0, 0, 1, 1, 0 },
{ "P:", 0, 0, 0, 1, 0 }, { "P:", 0, 0, 0, 1, 0 },
{ "w:", "key[:{s|d|i}]=value,key[:{s|d|i}]=value,...", { "w:", "key[:{s|d|i}]=value,key[:{s|d|i}]=value,...",
@ -32,7 +29,6 @@ grib_option grib_options[] = {
{ "U", 0, 0, 1, 0, 0 }, { "U", 0, 0, 1, 0, 0 },
{ "V", 0, 0, 0, 1, 0 }, { "V", 0, 0, 0, 1, 0 },
{ "g", 0, 0, 0, 1, 0 }, { "g", 0, 0, 0, 1, 0 },
/* {"G",0,0,0,1,0}, */
{ "T:", 0, 0, 1, 0, "B" }, { "T:", 0, 0, 1, 0, "B" },
{ "f", 0, 0, 0, 1, 0 }, { "f", 0, 0, 0, 1, 0 },
{ "v", 0, 0, 0, 1, 0 }, { "v", 0, 0, 0, 1, 0 },
@ -67,15 +63,6 @@ int grib_tool_init(grib_runtime_options* options)
} }
if (options->verbose) if (options->verbose)
options->print_header = 1; options->print_header = 1;
/*if (grib_options_on("n:")) {
noise=atof(grib_options_get_option("n:"));
options->repack=1;
}*/
if (grib_options_on("n:") && grib_options_on("d:")) {
fprintf(stderr, "ERROR: -n and -d options are incompatible. Choose one of the two please.\n");
exit(1);
}
// if (options->outfile && options->outfile->name) { // if (options->outfile && options->outfile->name) {
// options->outfile->file = fopen(options->outfile->name,"w"); // options->outfile->file = fopen(options->outfile->name,"w");