• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# Copyright (C) 2008 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Set up prog to be the path of this script, including following symlinks,
18# and set up progdir to be the fully-qualified pathname of its directory.
19
20prog="$0"
21while [ -h "${prog}" ]; do
22    newProg=`/bin/ls -ld "${prog}"`
23    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
24    if expr "x${newProg}" : 'x/' >/dev/null; then
25        prog="${newProg}"
26    else
27        progdir=`dirname "${prog}"`
28        prog="${progdir}/${newProg}"
29    fi
30done
31oldwd=`pwd`
32progdir=`dirname "${prog}"`
33cd "${progdir}"
34progdir=`pwd`
35prog="${progdir}"/`basename "${prog}"`
36cd "${oldwd}"
37
38libdir=`dirname $progdir`/framework
39
40javaOpts=""
41while expr "x$1" : 'x-J' >/dev/null; do
42    opt=`expr "$1" : '-J\(.*\)'`
43    javaOpts="${javaOpts} -${opt}"
44    shift
45done
46
47#exec java $javaOpts -jar $libdir/hat.jar "$@"
48
49#######################################################################
50# Original content of invocation script follows. Uses values cleverly
51# deduced by the above code.
52#######################################################################
53
54selection=$1
55interpreter="fast"
56if [ "$selection" = "--portable" ]; then
57    selection=$2;
58    interpreter="portable"
59fi
60
61datadir=/tmp/${USER}
62rm -rf --preserve-root $datadir/dalvik-cache
63mkdir -p $datadir
64mkdir -p $datadir/dalvik-cache
65
66base=$OUT
67framework=$base/system/framework
68export ANDROID_PRINTF_LOG=tag
69export ANDROID_LOG_TAGS='*:s' # was: jdwp:i dalvikvm:i dalvikvmi:i'
70export ANDROID_DATA=$datadir
71export ANDROID_ROOT=$base/system
72export LD_LIBRARY_PATH=$base/system/lib
73export DYLD_LIBRARY_PATH=$base/system/lib
74debug_opts="-Xcheck:jni"
75exe=$base/system/bin/dalvikvm
76bpath=$framework/core.jar
77BASEDIR=$progdir/../cts/dxconverter
78
79echo "--------------------------------------------------"
80echo "DX Converter Test Suite"
81echo "Version 1.0"
82echo "Copyright (c) 2008 The Android Open Source Project"
83echo ""
84
85if [ "$selection" = "--help" ]; then
86    echo "Usage: dx-tests [--help|--portable] [<mnemonic>]"
87    echo ""
88    echo "    --help      prints this help message"
89    echo "    --portable  uses the portable interpreter;"
90    echo "                default is the fast one"
91    echo ""
92    echo "    <mnemonic>  specifies the instruction to test;"
93    echo "                default is to run all tests"
94    echo ""
95    exit 1;
96fi
97
98# we need for launching: the dx tool, the dalvikvm executable, and the directory with all .class files
99# - prep dxcore.jar
100# - init reportfile
101# for each package as stated in data/scriptdata (like dxc/junit/opcode/aaload) do
102#   - clear tmpoutput
103#   - try to dx Test_opcode.class and all .class files in the ./jm directory into a classes.jar file
104#   - launch dalvikvm, let it write output &> to tmpoutput (surrounded by magic key for start/stop)
105#   - look at tmpoutput -> green or red test result
106#   - append the result to the report.html file (table form)
107#   - clear the tmpoutput, the classes.jar etc.
108# end for
109# - close the report file and cat its path to stdout
110
111# sanity checks:
112# dx around?
113curmode=""
114dx --version &> /dev/null
115if [ ! $? -eq 0 ]
116then
117    echo "error:could not start dx tool"
118    exit 1;
119fi
120
121if [ "$TARGET_SIMULATOR" = "true" ]; then
122    echo "Simulator mode, $interpreter interpreter";
123    curmode="simulator"
124    if [ -f $exe ]; then
125        version=`${exe} -version 2> /dev/null | grep -o "version.*$"`
126        echo "Using Dalvik VM ${version}"
127    else
128        echo "No Dalvik VM found at $exe";
129        exit 1;
130    fi
131else
132    echo "Emulator mode, $interpreter interpreter";
133    curmode="emulator"
134    version=`adb shell dalvikvm -version 2> /dev/null | grep -o "version.*$"`
135    if [ "${version}" != "" ]; then
136        echo "Using Dalvik VM ${version}"
137    else
138        echo "No emulator or device found";
139        exit 1;
140    fi
141fi
142
143echo ""
144
145latestpath=""
146curdate=`date`
147dxtmpdir=$BASEDIR/dxtmp
148dxruntmpdir=$BASEDIR/dxruntmp
149javac_out=$BASEDIR/classout
150report=$BASEDIR/report.html
151mkdir -p $dxtmpdir
152rm -f $report
153pre_report="<html><head><style>
154table tr.ok { background:#a0ffa0; }
155table tr.nok { background:#ffa0a0; }
156table tr.wok { background:#ffffa0; }
157table tr.lok { background:#aaaaff; }
158</style></head>
159<body>
160<h1>DX test suite results</h1>
161Generated $curdate (using the $curmode)
162<p>
163<table width='100%'>
164<tr><td>Status</td><td>Target</td><td>Category</td><td>Details</td></tr>"
165post_report="</body></html>"
166echo $pre_report > $report
167
168# ----------- generating dxcore.jar
169cd $javac_out
170# consists of dxc.junit.DxAbstractMain and dxc.junit.DxUtil
171dx --dex --positions=lines --output="$BASEDIR/dxcore.jar" dxc/junit/DxAbstractMain.class dxc/junit/DxUtil.class
172
173# ----------- generating jars for each opcode test ------------
174
175export jpassedcnt=0
176export jwarningcnt=0
177export jvfefailedcnt=0
178export jfailedcnt=0
179export jallcnt=0
180export jcolumns=0
181
182function classnameToPath()
183{
184    echo $1 | sed -e 's#\.#/#g;s#$#.class#'
185}
186
187function lecho()
188{
189    if [ ! -z $CTS_DX_DEBUG ]; then echo $@; fi
190}
191
192while read -u 3 myline;
193do
194    mainclass=`echo $myline | cut -d";" -f1` # e.g dxc.junit.verify.t482_9.Main_testVFE2
195    classfiles=`classnameToPath $mainclass`
196
197    testclasses=`echo $myline | cut -d";" -f2` # e.g dxc.junit.verity.t482_9.jm.T_t482_9_1
198
199    for testclass in $testclasses; do
200        classfiles="$classfiles "`classnameToPath $testclass`;
201    done
202
203    jtitle=`echo $myline | cut -d";" -f3`
204    jcomment=`echo $myline | cut -d";" -f4`
205    details=`echo $myline | cut -d";" -f5`
206
207    if [ "$selection" == "" ] || [ "$jtitle" == "$selection" ]; then
208
209        (( jallcnt += 1 ))
210
211
212        rm -rf --preserve-root $dxtmpdir/*
213        mkdir -p $dxtmpdir
214        cd $dxtmpdir
215
216        for testclass in $classfiles; do
217            lecho -n "dexing $testclass : "
218            mkdir -p `dirname ${dxtmpdir}/${testclass}`
219            cp ${javac_out}/${testclass} ${dxtmpdir}/${testclass}
220
221            dx --dex --positions=lines $testclass &>/dev/null
222
223            if [ $? -eq 0 ]; then
224                lecho " dexable";
225            else
226                lecho " not dexable->remove";
227                rm $testclass
228            fi
229        done
230
231        dx --dex --positions=lines --output="$BASEDIR/dxclasses.jar" .
232
233        # run the previously prepared jar files in the dalvik vm.
234        # the dalvik vm executable (dalvikvm) must be on the PATH.
235        #
236        ### echo -n ">>> launch dalvikvm for class: $mainclass"
237        cd $BASEDIR
238        rm -f $BASEDIR/dalvikout
239        # write dalvik output to file
240        echo -n "mk_b:" > $BASEDIR/dalvikout
241            #echo ">>> launch dex package -classpath $BASEDIR/dxcore.jar:$BASEDIR/dxclasses.jar $mainclass"
242
243        if [ "$TARGET_SIMULATOR" = "true" ]; then
244            ### echo " on simulator";
245            $valgrind $exe -Xint:$interpreter -Xmx512M -Xss32K -Xbootclasspath:$bpath -DacceptCNF=true -classpath $BASEDIR/dxcore.jar:$BASEDIR/dxclasses.jar $debug_opts $mainclass "$@" >> $BASEDIR/dalvikout 2>&1
246            RESULTCODE=$?
247            if [ ${RESULTCODE} -ne 0 ]; then
248                echo "execute dalvikvm failed with resultcode: ${RESULTCODE}" >> $BASEDIR/dalvikout 2>&1
249            fi
250        else
251            # adb shell dalvikvm -Xint:$interpreter -Djava.io.tmpdir=/data/local/tmp -classpath /data/dxcore.jar:/data/dxclasses.jar dxc.junit.opcodes.aload.Main_testN2
252            # either no output (ok) or
253            # java.lang.RuntimeException: test did not cause the expected verify error, but:java.lang.RuntimeException, msg:AssertionFailedError msg:expected a verification exception
254            #    at dxc.junit.DxUtil.checkVerifyException(DxUtil.java:65)
255            #    at dxc.junit.opcodes.aload.Test_aload.testVFE10(Test_aload.java:181)
256            #    at dxc.junit.opcodes.aload.Main_testVFE10.main(Main_testVFE10.java:5)
257            #    at dalvik.system.NativeStart.main(Native Method)
258
259            ### echo " on emulator/device with adb push"
260            adb push $BASEDIR/dxcore.jar /data/dxcore.jar &> /dev/null
261            adb push $BASEDIR/dxclasses.jar /data/dxclasses.jar &> /dev/null
262            adb shell "dalvikvm -Djava.io.tmpdir=/data/local/tmp -classpath /data/dxcore.jar:/data/dxclasses.jar $mainclass && echo -n dvmpassed:" >> $BASEDIR/dalvikout 2>&1
263        fi
264
265        echo -n "mk_s:" >> $BASEDIR/dalvikout
266        # verify tmpout only contains mkdxc_start;mkdxc_stop -> no system.out/err because of exception.
267            # if ok -> green report line else red report with info between mkdxc_start and stop
268        ### echo "vmresult: $vmresult"
269        vmresult=`cat $BASEDIR/dalvikout`
270        if [[ ("$vmresult" == "mk_b:mk_s:") || ("$vmresult" == "mk_b:dvmpassed:mk_s:") ]]; then
271            (( jpassedcnt += 1 ))
272            echo "<tr class=\"ok\"><td>Success</td><td>$jtitle</td><td>$jcomment</td><td>$details</td></tr>" >> $report
273            ### echo " -> PASSED (passed:$jpassedcnt, failed:$jfailedcnt, vfe failed:$jvfefailedcnt, warnings:$jwarningcnt)"
274            echo -n "."
275        elif [[ ("$vmresult" == "mk_b:dvmvfe:mk_s:") || ("$vmresult" == "mk_b:dvmvfe:dvmpassed:mk_s:") ]]; then
276            (( jwarningcnt += 1 ))
277            echo "<tr class=\"wok\"><td>Warning</td><td>$jtitle</td><td>$jcomment</td><td>Special behavior regarding VerifyError</td></tr>" >> $report
278            ### echo " -> WARNING (passed:$jpassedcnt, failed:$jfailedcnt, vfe failed:$jvfefailedcnt, warnings:$jwarningcnt)"
279            echo -n "W"
280        else
281           vmres=`cat $BASEDIR/dalvikout | sed -e 's/mk_b://;s/mk_s://'`
282           vmres="$details<br><pre>$vmres</pre>"
283            # red with additional info if a VFE failed, red if either a N,B, or E failed
284            jtype=`echo "$mainclass" | sed -e 's/.*_test\([^0-9]*\)[0-9].*/\1/' `
285            if [ "$jtype" == "VFE" ]; then
286                (( jvfefailedcnt += 1 ))
287                echo -n "<tr class=\"nok\"><td>Verifier failure</td><td>$jtitle</td><td>$jcomment</td><td>$vmres</td></tr>" >> $report
288                ### echo " -> VFE FAILED (passed:$jpassedcnt, failed:$jfailedcnt, vfe failed:$jvfefailedcnt, warnings:$jwarningcnt)"
289                echo -n "V"
290            else
291                (( jfailedcnt += 1 ))
292                echo -n "<tr class=\"nok\"><td>Functional failure</td><td>$jtitle</td><td>$jcomment</td><td>$vmres</td></tr>" >> $report
293                ### echo " -> FAILED (passed:$jpassedcnt, failed:$jfailedcnt, vfe failed:$jvfefailedcnt, warnings:$jwarningcnt)"
294                echo -n "F"
295            fi
296        fi
297
298        (( jcolumns += 1 ))
299        if [ ${jcolumns} -eq 40 ]; then
300            echo ""
301            (( jcolumns = 0 ))
302        fi
303
304    fi
305
306done 3<$BASEDIR/data/scriptdata #we use fd nr 3 to avoid subshelling via cat since this looses all variables (and thus also the counters we are interested in).
307
308echo "</table>" >> $report
309let jallcalccnt=$jpassedcnt+$jfailedcnt+$jvfefailedcnt+$jwarningcnt
310if [ $jallcalccnt -ne $jallcnt ]; then
311    echo "<br>error: green & red != total , $jallcalccnt -ne $jallcnt" >> $report
312    exit 1;
313fi
314
315echo "<br>Tests run: ${jallcnt}" >> $report
316echo "<br>Functional failures: ${jfailedcnt}" >> $report
317echo "<br>Verifier failures: ${jvfefailedcnt}" >> $report
318echo "<br>Warnings: ${jwarningcnt}" >> $report
319
320echo $post_report >> $report
321
322if [[ jcolumns -ne 0 ]]; then
323    echo ""
324fi
325
326echo ""
327
328if [[ jallcnt -eq jpassedcnt ]]; then
329    echo "OK (${jpassedcnt} tests)"
330else
331    echo "FAILURES!!!"
332    echo ""
333    echo "Tests run          : ${jallcnt}"
334    echo "Functional failures: ${jfailedcnt}"
335    echo "Verifier failures  : ${jvfefailedcnt}"
336    echo "Warnings           : ${jwarningcnt}"
337fi
338
339echo ""
340echo "Please see complete report in ${report}"
341echo "--------------------------------------------------"
342