OSDN Git Service

Extend pmacro language, add testsuite.
[pf3gnuchains/pf3gnuchains3x.git] / cgen / testsuite / test-utils.sh.in
1 # Define various parameters for use in test runs.
2 # Requires $test to be defined before sourcing.
3
4 if [ "${test}" == "" ]
5 then
6     echo "\$test not defined" >&2
7     exit 1
8 fi
9
10 if [ "${test}" != "driver" ]
11 then
12     echo "Running ${test} ..."
13 fi
14
15 srcdir=@srcdir@
16
17 cgendir=${srcdir}/..
18
19 GUILE=`if test -f ../../guile/libguile/guile ; then echo ../../guile/libguile/guile; else echo guile ; fi`
20 GUILEFLAGS="-l ${cgendir}/guile.scm -s"
21
22 CGENFLAGS=
23
24 cgen_output_file=${test}.cgen.out
25 test_output_file=${test}.test.out
26 rm -f ${cgen_output_file} ${test_output_file}
27
28 tmp_match=match-${test}.tmp
29 tmp_expr=expr-${test}.tmp
30 rm -f ${tmp_match} ${tmp_expr}
31
32 exit_code=0
33
34 run_cgen() {
35     [ $# == 1 ] || { echo "missing cpu_file" >&2 ; exit 1 ; }
36     cpu_file=$1
37
38     if ! ${GUILE} ${GUILEFLAGS} ${cgendir}/cgen-testsuite.scm \
39         -s ${cgendir} \
40         -b ${CGENFLAGS} \
41         -a ${cpu_file} \
42         -T ${cgen_output_file} >& ${test_output_file}
43     then
44         fail "${test} run of cgen"
45     fi
46 }
47
48 post_process() {
49     file=${test_output_file}
50
51     if grep -q FAIL $file
52     then
53         fail "FAIL found in test output:"
54         grep FAIL $file
55     fi
56
57     grep "^MATCH: " $file | sed -e 's/^MATCH://' > ${tmp_match}
58     grep "^EXPR: " $file | sed -e 's/^EXPR://' > ${tmp_expr}
59
60     if ! cmp -s ${tmp_match} ${tmp_expr}
61     then
62         fail "Differences from expected output:"
63         diff ${tmp_match} ${tmp_expr}
64     fi
65 }
66
67 fail() {
68     echo "FAIL: $*"
69     exit_code=1
70 }
71
72 finish() {
73     exit ${exit_code}
74 }