File: grib_filter_fail.sh

package info (click to toggle)
eccodes 2.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 154,404 kB
  • sloc: cpp: 162,953; ansic: 26,308; sh: 21,742; f90: 6,854; perl: 6,361; python: 5,172; java: 2,226; javascript: 1,427; yacc: 854; fortran: 543; lex: 359; makefile: 283; xml: 183; awk: 66
file content (154 lines) | stat: -rwxr-xr-x 3,643 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/sh
# (C) Copyright 2005- 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.ctest.sh

REDIRECT=/dev/null

label="grib_filter_fail_test"
tempFilt="temp.$label.filt"
tempGrib="temp.$label.grib"
tempOut="temp.$label.txt"
tempRef="temp.$label.ref"

sample_grib2=$ECCODES_SAMPLES_PATH/GRIB2.tmpl


echo "Test with nonexistent keys. Note spelling of centre!"
# ---------------------------------------------------------
cat >${data_dir}/nonexkey.rules <<EOF
 set center="john";
EOF
# Invoke without -f i.e. should fail if error encountered
set +e
${tools_dir}/grib_filter ${data_dir}/nonexkey.rules ${data_dir}/tigge_pf_ecmwf.grib2 2> $REDIRECT > $REDIRECT
if [ $? -eq 0 ]; then
   echo "ERROR: grib_filter should have failed if key not found" >&2
   exit 1
fi
set -e

# Now repeat with -f option (do not exit on error)
${tools_dir}/grib_filter -f ${data_dir}/nonexkey.rules ${data_dir}/tigge_pf_ecmwf.grib2 2> $REDIRECT > $REDIRECT

rm -f ${data_dir}/nonexkey.rules

echo "Test IEEE float overflow"
# -----------------------------------------
input="${samp_dir}/GRIB2.tmpl"
cat >$tempFilt <<EOF
  set values={ 5.4e100 };
  write;
EOF
set +e
${tools_dir}/grib_filter $tempFilt $input 2> $tempOut
status=$?
set -e
[ $status -ne 0 ]
grep -q "ECCODES ERROR.*Number is too large" $tempOut

# Assert statement
# -----------------
cat >$tempFilt <<EOF
  assert(edition == 0);
EOF
set +e
${tools_dir}/grib_filter $tempFilt $sample_grib2 2> $tempOut
status=$?
set -e
[ $status -ne 0 ]
grep "Assertion failure" $tempOut


# Bad write
# ---------
set +e
echo 'write(-10);' | ${tools_dir}/grib_filter -o $tempGrib - $sample_grib2 > $tempOut 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Invalid argument" $tempOut

# Bad write
# ----------
set +e
echo 'write "/";' | ${tools_dir}/grib_filter - $input > $tempOut 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Unable to open file" $tempOut


# Bad print
# ----------
set +e
echo 'print ("/") "should fail";' | ${tools_dir}/grib_filter - $input > $tempOut 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "IO ERROR" $tempOut


# Signed bits
# -----------
cat >$tempFilt <<EOF
  meta _sb signed_bits(widthOfWidths, numberOfGroups);
  print "[_sb]";
EOF
set +e
${tools_dir}/grib_filter $tempFilt $data_dir/boustrophedonic.grib1 > $tempOut 2>&1
status=$?
set -e
[ $status -ne 0 ]


# Non existent filter
# --------------------
set +e
${tools_dir}/grib_filter a_non_existent_filter_file $sample_grib2 > $tempOut 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Cannot include file" $tempOut

# Functor not implemented
# -------------------------
cat >$tempFilt <<EOF
  if (unicorn(pl) == 1) { print "Say what?"; }
EOF
set +e
${tools_dir}/grib_filter $tempFilt $sample_grib2 > $tempOut 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "ECCODES ERROR.*failed for 'unicorn'" $tempOut
grep -q "Function not yet implemented" $tempOut

# Direction Increment
# --------------------
input="${samp_dir}/GRIB1.tmpl"
cat >$tempFilt <<EOF
  set ijDirectionIncrementGiven = 0;
  set Ni = 1;
  set Nj = 1;
  set values = { 0 };
  print "[jDirectionIncrementInDegrees]";
EOF
set +e
${tools_dir}/grib_filter $tempFilt $input 2> $tempOut
status=$?
set -e
[ $status -ne 0 ]
grep -q "Cannot compute lat/lon increments. Not enough points" $tempOut



# Clean up
rm -f $tempGrib $tempFilt $tempOut $tempRef