Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / lirasm / testlirc.sh
1 #!/bin/bash
2
3 set -eu
4
5 exitcode=0
6
7 LIRASM=$1
8
9 TESTS_DIR=`dirname "$0"`/tests
10
11 function runtest {
12     local infile=$1
13     local options=${2-}
14
15     # Catch a request for the random tests.
16     if [[ $infile == --random* ]] ; then
17         local outfile=$TESTS_DIR/random.out
18     else
19         local outfile=`echo $infile | sed 's/\.in/\.out/'`
20     fi
21
22     if [[ ! -e "$outfile" ]] ; then
23         echo "$0: error: no out file $outfile"
24         exit 1
25     fi
26
27     # sed used to strip extra leading zeros from exponential values 'e+00' (see bug 602786)
28     if $LIRASM $options --execute $infile | tr -d '\r' | sed -e 's/e+00*/e+0/g' > testoutput.txt && cmp -s testoutput.txt $outfile ; then
29         echo "TEST-PASS | lirasm | lirasm $options --execute $infile"
30     else
31         echo "TEST-UNEXPECTED-FAIL | lirasm | lirasm $options --execute $infile"
32         echo "expected output"
33         cat $outfile
34         echo "actual output"
35         cat testoutput.txt
36         exitcode=1
37     fi
38 }
39
40 function runtests {
41     local testdir=$1
42     local options=${2-}
43     for infile in "$TESTS_DIR"/"$testdir"/*.in ; do
44         runtest $infile "$options"
45     done
46 }
47
48 if [[ $($LIRASM --show-arch 2>/dev/null) == "i386" ]] ; then
49     # i386 with SSE2.
50     runtests "."
51     runtests "hardfloat"
52     runtests "32-bit"
53     runtests "littleendian"
54     runtest "--random 1000000"
55     runtest "--random 1000000 --optimize"
56
57     # i386 without SSE2.
58     runtests "."               "--nosse"
59     runtests "hardfloat"       "--nosse"
60     runtests "32-bit"          "--nosse"
61     runtests "littleendian"    "--nosse"
62     runtest "--random 1000000" "--nosse"
63
64 elif [[ $($LIRASM --show-arch 2>/dev/null) == "X64" ]] ; then
65     # X64.
66     runtests "."
67     runtests "hardfloat"
68     runtests "64-bit"
69     runtests "littleendian"
70     runtest "--random 1000000"
71     runtest "--random 1000000 --optimize"
72
73 elif [[ $($LIRASM --show-arch 2>/dev/null) == "arm" ]] ; then
74     # ARMv7 with VFP.  We could test without VFP but such a platform seems
75     # unlikely.  ARM is bi-endian but usually configured as little-endian.
76     runtests "."
77     runtests "hardfloat"
78     runtests "32-bit"
79     runtests "littleendian"
80     runtest "--random 1000000"
81     runtest "--random 1000000" "--optimize"
82
83     # ARMv6 with VFP.  ARMv6 without VFP doesn't seem worth testing.
84     # Random tests are reduced.
85     runtests "."              "--arch 6"
86     runtests "hardfloat"      "--arch 6"
87     runtests "32-bit"         "--arch 6"
88     runtests "littleendian"   "--arch 6"
89     runtest "--random 100000" "--arch 6"
90
91     # ARMv5 without VFP.  ARMv5 with VFP doesn't seem worth testing.
92     # Random tests are reduced.
93     runtests "."              "--arch 5 --novfp"
94     runtests "softfloat"      "--arch 5 --novfp"
95     runtests "32-bit"         "--arch 5 --novfp"
96     runtests "littleendian"   "--arch 5 --novfp"
97     runtest "--random 100000" "--arch 5 --novfp"
98
99 elif [[ $($LIRASM --show-arch 2>/dev/null) == "ppc" ]] ; then
100     # PPC is bi-endian but usually configured as big-endian.
101     runtests "."
102     runtests "hardfloat"
103     if [[ $($LIRASM --show-word-size) == "32" ]] ; then
104         runtests "32-bit"
105     else
106         runtests "64-bit"
107     fi
108     runtests "bigendian"
109     runtest "--random 1000000"
110     runtest "--random 1000000 --optimize"
111
112 elif [[ $($LIRASM --show-arch 2>/dev/null) == "sparc" ]] ; then
113     # Sparc is bi-endian but usually configured as big-endian.
114     runtests "."
115     runtests "hardfloat"
116     runtests "32-bit"
117     runtests "bigendian"
118     runtest "--random 1000000"
119     runtest "--random 1000000 --optimize"
120
121 elif [[ $($LIRASM --show-arch 2>/dev/null) == "mips" ]] ; then
122     # MIPS is bi-endian but usually configured as big-endian.
123     # XXX: should we run softfloat tests as well?  Seems to depend on
124     # the configuration...
125     runtests "."
126     runtests "hardfloat"
127     runtests "32-bit"
128     runtests "bigendian"
129     runtest "--random 1000000"
130     runtest "--random 1000000 --optimize"
131
132 elif [[ $($LIRASM --show-arch 2>/dev/null) == "sh4" ]] ; then
133     # SH4 is bi-endian but usually configured as big-endian.
134     runtests "."
135     runtests "hardfloat"
136     runtests "32-bit"
137     runtests "bigendian"
138     runtest "--random 1000000"
139     runtest "--random 1000000 --optimize"
140
141 else
142     echo "bad arch"
143     exit 1
144 fi
145
146 rm testoutput.txt
147
148 exit $exitcode