Imported Upstream version 0.4.8
[platform/upstream/libsmi.git] / test / smidump-yang.test.in
1 #!/bin/sh
2 #
3 # smidump-FORMAT.test --
4 #
5 #       smidump test for various output formats and conversions.
6 #
7 # FORMAT=xxx : 
8 #   Check `smidump -f xxx' output for all TESTMIBS read from the libsmi MIB
9 #   repository against nominal dumps/xxx/ files.
10 #
11 # FORMAT=xxx-yyy :
12 #   Check `smidump -f yyy' output for all TESTMIBS read from dumps/xxx/
13 #   against nominal dumps/yyy-xxx/ files.
14 #
15 # FORMAT=orig-yyy : 
16 #   Check `smidump -f yyy' output for all TESTMIBS read from the libsmi MIB
17 #   repository against the original files from the repository. This is done
18 #   by extracting unified characteristics of both files of each check
19 #   (see the filter shell function) and comparing the diff with the nominal
20 #   diff in dumps/orig-yyy/.
21 #
22
23 FORMAT=`echo $0 | sed -e 's/^.*smidump-\(.*\).test/\1/'`
24 ACTUALDIR=smidump-${FORMAT}.out
25 NOMINALDIR=dumps/${FORMAT}
26 INFORMAT=`echo -$FORMAT | sed -e 's/-[^-]*$//' -e 's/-//'`
27 OUTFORMAT=`echo $FORMAT | sed -e 's/[a-z0-9]*-//'`
28
29
30
31 filter() {
32     # 1. strip off comments
33     # 2. condens white space
34     # 3. remove ambigious white space
35     # 4. strip off texts enclosed in double qoutes
36     # 5. convert blanks back to nl, and finally
37     # 6. sort
38     sed -e 's/\"[a-z]*\"//g' | \
39     sed -e 's/--[^\"-]*--//g' -e 's/--[^\"]*$//' | \
40     tr '\t\n' '  ' | \
41     sed -e 's/  */ /g' | \
42     sed -e 's/SIZE (/SIZE(/g' -e 's/ }/}/g' | \
43     sed -e 's/\"[^\"]*\"/\"\"/g' | \
44     tr ' ' '\n' | \
45     sort
46 }
47
48
49
50 rm -rf ${ACTUALDIR}
51 mkdir ${ACTUALDIR}
52
53 RC=0
54 FAILED=""
55 for mib in ${TESTMIBS} ; do
56     if [ "$INFORMAT" -a "$INFORMAT" != "orig" ] ; then
57         input=../dumps/${INFORMAT}/$mib
58     else
59         input=$mib
60     fi
61     echo "comparing \`smidump -f ${OUTFORMAT} $input' output with ${NOMINALDIR}/*."
62     cd ${ACTUALDIR}
63     ../../tools/smidump -c/dev/null -f ${OUTFORMAT} $input > $mib 2>/dev/null
64     if [ ! -s $mib ] ; then
65         rm $mib
66         FILES=""
67     else
68         FILES="$mib"
69     fi
70     FILES="$FILES "`ls -1 | grep -v '\.diff' | grep '\.'`
71     cd ..
72     for file in $FILES ; do
73         if [ "$INFORMAT" != "orig" ] ; then
74             @DIFF@ ${ACTUALDIR}/$file ${NOMINALDIR}/$file >> ${ACTUALDIR}/$file.diff
75         else
76             filter < ../mibs/ietf/$mib > ${ACTUALDIR}/$file.orig
77             filter < ${ACTUALDIR}/$mib > ${ACTUALDIR}/$file.out
78             @DIFF@ ${ACTUALDIR}/$file.orig ${ACTUALDIR}/$file.out > ${ACTUALDIR}/$file
79             @DIFF@ ${ACTUALDIR}/$file ${NOMINALDIR}/$file > ${ACTUALDIR}/$file.diff
80         fi
81         if [ ! -s ${ACTUALDIR}/$file.diff ] ; then
82             rm ${ACTUALDIR}/$file.diff
83         else
84             FAILED=1
85         fi
86
87         echo "cmp -s ${ACTUALDIR}/$file ${NOMINALDIR}/$file || \$CMDPREFIX cp -v ${ACTUALDIR}/$file ${NOMINALDIR}/$file" >> sync-dumps
88     done
89     rm -f ${ACTUALDIR}/*.orig ${ACTUALDIR}/*.out
90 done
91
92 if [ "$FAILED" ] ; then
93     echo "*** smidump output differs, see ${ACTUALDIR}/*.diff"
94     RC=1
95 fi
96
97 exit ${RC}