1 # $Id: func.sh 3626 2018-09-29 19:26:57Z jkoshy $
2 # `init' initializes test engine global data.
6 TOPDIR=${THISDIR}/../..
8 RANLIB=${TOPDIR}/ar/ranlib
10 # keep a record of total tests and number of tests passed.
11 TOTALCT=/tmp/bsdar-test-total
12 PASSEDCT=/tmp/bsdar-test-passed
17 # `inittest' initializes individual test process. (set up temp dirs,
18 # make copies of files used in the test if necessary, etc.)
22 echo "usage: inittest tcname tcdir"
28 TESTDIR=/tmp/bsdar-${TC}
29 OUTDIR=/tmp/bsdar-${TC}-out
30 RLTDIR=/tmp/bsdar-${TC}-rlt
34 mkdir -p ${TESTDIR} || exit 1
35 mkdir -p ${OUTDIR} || exit 1
36 mkdir -p ${RLTDIR} || exit 1
38 if [ -d "${TCDIR}/in" ]; then
39 cp -R ${TCDIR}/in/* ${TESTDIR} || exit 1
42 if [ -d "${TCDIR}/out" ]; then
43 cp -R ${TCDIR}/out/* ${RLTDIR} || exit 1
47 # `extshar' extracts shar file in the specific dir,
48 # then uudecode the resulting file(s).
52 echo "usage: extshar dir"
58 sh $f > /dev/null 2>&1 || exit 1
65 # `udecode' calls uudecode to decode files encoded by
66 # uuencode in the specific dir.
70 echo "usage: uudecode dir"
75 find . -type f -a -name '*.uu' -execdir uudecode {} \;
76 find . -type f -name '*.uu' -delete
79 # `runcmd' runs `cmd' on the work/result dir.
81 # cmd: command to execute
83 # rec: true (keep a record of the stdout and stderr)
84 # false (do not record)
88 echo "usage: runcmd cmd loc rec"
92 # prefix executable with abolute pathname.
93 executable=`echo $1 | cut -f 1 -d ' '`
94 relapath=`dirname ${executable}`
96 absolpath=`cd ${relapath} && /bin/pwd`
97 newcmd=${absolpath}/`basename ${executable}`" "`echo $1 | cut -f 2- -d ' '`
98 redirin=`echo $newcmd | cut -f 2- -d '<'`
99 if [ "$redirin" != "$newcmd" ]; then
100 newcmd=`echo $newcmd | cut -f 1 -d '<'`
101 redirin=`echo ${redirin} | sed 's/^ *\(.*\) *$/\1/'`
104 if [ "$2" = work ]; then
105 cd ${TESTDIR} || exit 1
106 elif [ "$2" = result ]; then
107 cd ${RLTDIR} || exit 1
109 echo "loc must be work or result."
113 if [ "$3" = true ]; then
114 if [ "$redirin" != "$newcmd" ]; then
115 ${newcmd} < ${redirin} > ${OUTDIR}/${TC}.out 2> ${OUTDIR}/${TC}.err
117 ${newcmd} > ${OUTDIR}/${TC}.out 2> ${OUTDIR}/${TC}.err
119 echo $? > ${OUTDIR}/${TC}.eval
120 elif [ "$3" = false ]; then
121 if [ "$redirin" != "$newcmd" ]; then
122 ${newcmd} < ${redirin}
127 echo "rec must be true of false."
134 # `rundiff' performs standard diff to compare exit value,
135 # stdout output, stderr output and resulting files with
136 # "standard answers".
139 # $1 indicates whether we should compare resulting files.
140 if [ $# -ne 1 ]; then
141 echo "usage: rundiff [true|false]"
144 cd ${THISDIR} || exit 1
145 if [ -f ${TCDIR}/${TC}.eval ]; then
147 diff -urN ${TCDIR}/${TC}.eval ${OUTDIR}/${TC}.eval
148 if [ $? -eq 0 ]; then
149 echo "${TC} exit value - ok"
152 echo "${TC} exit value - not ok"
156 if [ -f ${TCDIR}/${TC}.out ]; then
158 diff -urN ${TCDIR}/${TC}.out ${OUTDIR}/${TC}.out
159 if [ $? -eq 0 ]; then
160 echo "${TC} stdout - ok"
163 echo "${TC} stdout - not ok"
167 if [ -f ${TCDIR}/${TC}.err ]; then
169 diff -urN ${TCDIR}/${TC}.err ${OUTDIR}/${TC}.err
170 if [ $? -eq 0 ]; then
171 echo "${TC} stderr - ok"
174 echo "${TC} stderr - not ok"
178 if [ "$1" = true ]; then
180 diff -urN ${RLTDIR} ${TESTDIR}
181 if [ $? -eq 0 ]; then
182 echo "${TC} resulting files - ok"
185 echo "${TC} resulting files - not ok"
190 # `innct' increase specified counter by 1.
192 if [ $# -ne 1 ]; then
193 echo "usage: incct counterfile"
200 newval=`expr ${val} + 1`
208 # `statistic' shows number of test passed.
218 echo "${pval} out of ${tval} passed."