• 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
48#######################################################################
49# Original content of invocation script follows. Uses values cleverly
50# deduced by the above code.
51#######################################################################
52
53selection=$1
54interpreter="fast"
55if [ "$selection" = "--portable" ]; then
56    selection=$2;
57    interpreter="portable"
58fi
59
60dalviktest=$progdir/../cts_dalviktests
61dalviktestdir=$dalviktest/tests
62dexcore=$dalviktest/tests/dot/junit/dexcore.jar
63scriptdata=$dalviktest/data/scriptdata
64report=$dalviktest/report.html
65curdate=`date`
66curmode=""
67datadir=/tmp/${USER}
68base=$OUT
69framework=$base/system/framework
70export ANDROID_PRINTF_LOG=tag
71export ANDROID_LOG_TAGS='*:s' # was: jdwp:i dalvikvm:i dalvikvmi:i'
72export ANDROID_DATA=$datadir
73export ANDROID_ROOT=$base/system
74export LD_LIBRARY_PATH=$base/system/lib
75export DYLD_LIBRARY_PATH=$base/system/lib
76debug_opts="-Xcheck:jni -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
77exe=$base/system/bin/dalvikvm
78bpath=$framework/core.jar
79
80echo "--------------------------------------------------"
81echo "Dalvik VM Test Suite"
82echo "Version 1.0"
83echo "Copyright (c) 2008 The Android Open Source Project"
84echo ""
85
86if [ "$selection" = "--help" ]; then
87    echo "Usage: vm-tests [--help|--portable] [<mnemonic>]"
88    echo ""
89    echo "    --help      prints this help message"
90    echo "    --portable  uses the portable interpreter;"
91    echo "                default is the fast one"
92    echo ""
93    echo "    <mnemonic>  specifies the instruction to test;"
94    echo "                default is to run all tests"
95    echo ""
96    exit 1;
97fi
98
99rm -rf --preserve-root $datadir/dalvik-cache
100mkdir -p $datadir
101mkdir -p $datadir/dalvik-cache
102
103if [ "$TARGET_SIMULATOR" = "true" ]; then
104    echo "Simulator mode, $interpreter interpreter";
105    curmode="simulator"
106    if [ -f $exe ]; then
107        version=`${exe} -version 2> /dev/null | grep -o "version.*$"`
108        echo "Using Dalvik VM ${version}"
109    else
110        echo "No Dalvik VM found at $exe";
111        exit 1;
112    fi
113else
114    echo "Emulator mode, $interpreter interpreter";
115    curmode="emulator"
116    version=`adb shell dalvikvm -version 2> /dev/null | grep -o "version.*$"`
117    if [ "${version}" != "" ]; then
118        echo "Using Dalvik VM ${version}"
119    else
120        echo "No emulator or device found";
121        exit 1;
122    fi
123fi
124
125echo ""
126
127pre_report="<html><head><style>
128table tr.ok { background:#a0ffa0; }
129table tr.nok { background:#ffa0a0; }
130table tr.wok { background:#ffffa0; }
131table tr.lok { background:#aaaaff; }
132</style></head>
133<body>
134<h1>Dalvik VM test suite results</h1>
135Generated $curdate (using the $curmode)
136<p>
137<table width='100%'>
138<tr><td>Status</td><td>Target</td><td>Category</td><td>Details</td></tr>"
139post_report="</body></html>"
140
141rm -f $report
142echo $pre_report > $report
143
144# ----------- running each opcode test ------------
145
146export jpassedcnt=0
147export jfailedcnt=0
148export jvfefailedcnt=0
149export jwarningcnt=0
150export jallcnt=0
151export jcolumns=0
152
153# TODO unhack
154if [ "$TARGET_SIMULATOR" = "true" ]; then
155    echo -n ""
156else
157    adb push $dexcore /data/dexcore.jar >> /dev/null 2>&1
158fi
159
160function classnameToJar()
161{
162    echo $1 | sed -e 's#\.#/#g;s#$#.jar#'
163}
164
165while read -u 3 myline;
166do
167    # dot.junit.opcodes.add_double.Main_testB1;dot.junit.opcodes.add_double.d.T_add_double_1 ;opcode add_double;test B #1 (border edge case)
168    # ->
169    # mainclass: dot.junit.opcodes.add_double.Main_testB1
170    # testcasedir: opcodes/add_double
171    # testname: testB1 ->
172    # dir dot/junit/opcodes/add_double/testB1
173
174    # e.g dot.junit.opcodes.add_double.Main_testB1
175    mainclass=`echo $myline | cut -d";" -f1`
176    # e.g dot.junit.opcodes.add_double.d.T_add_double_1, space sep. >=1 entries
177    deps=`echo $myline | cut -d";" -f2`
178
179    jtitle=`echo $myline | cut -d";" -f3`
180    jcomment=`echo $myline | cut -d";" -f4`
181    details=`echo $myline | cut -d";" -f5`
182
183    if [ "$selection" == "" ] || [ "$jtitle" == "$selection" ]; then
184
185        (( jallcnt += 1 ))
186
187        cd $dalviktestdir
188        rm -f $datadir/dalvikout
189        # write dalvik output to file
190        echo -n "mk_b:" > $datadir/dalvikout
191
192        if [ "$TARGET_SIMULATOR" = "true" ]; then
193            classpath=`classnameToJar ${mainclass}`
194            for dep in ${deps}; do
195                depJar=`classnameToJar ${dep}`
196                classpath=${classpath}:${depJar}
197            done
198            $valgrind $exe -Xint:$interpreter -Xmx512M -Xss32K -Xbootclasspath:$bpath $debug_opts \
199                -classpath $dexcore:$classpath $mainclass >> $datadir/dalvikout 2>&1
200
201            RESULTCODE=$?
202            if [ ${RESULTCODE} -ne 0 ]; then
203                echo "Dalvik VM failed, result=${RESULTCODE}" >> $datadir/dalvikout 2>&1
204            fi
205        else
206            classpath="/data/dexcore.jar"
207            deps=${deps}" "${mainclass}
208            pushedjars=""
209            for dep in ${deps}; do
210                depJar=`classnameToJar ${dep}`
211                depFileName=`basename ${depJar}`
212                deviceFileName=/data/${depFileName}
213                adb push ${depJar} ${deviceFileName} &> /dev/null
214                classpath=${classpath}:${deviceFileName}
215                pushedjars=${pushedjars}" "${deviceFileName}
216            done
217
218            adb shell dalvikvm -Xint:$interpreter -Xmx512M -Xss32K -Djava.io.tmpdir=/data/local/tmp \
219                -classpath $classpath $mainclass >> $datadir/dalvikout 2>&1 && \
220                echo -n dvmpassed: >> $datadir/dalvikout 2>&1
221
222            for jar in ${pushedjars}; do
223                adb shell rm ${jar} &> /dev/null
224            done
225        fi
226
227        echo -n "mk_s:" >> $datadir/dalvikout
228        # Verify tmpout only contains mkdxc_start;mkdxc_stop -> no system.out/err
229        # because of exception. If ok -> green report line else red report with info
230        # between mkdxc_start and stop
231        vmresult=`cat $datadir/dalvikout`
232
233        if [[ ("$vmresult" == "mk_b:mk_s:") || ("$vmresult" == "mk_b:dvmpassed:mk_s:") ]]; then
234            (( jpassedcnt += 1 ))
235            echo -n "<tr class=\"ok\"><td>Success</td><td>$jtitle</td>" >> $report
236            echo "<td>$jcomment</td><td>$details</td></tr>" >> $report
237            echo -n "."
238        else
239            vmres=`cat $datadir/dalvikout | sed -e 's/mk_b://;s/mk_s://'`
240            vmres="$details<br><pre>$vmres</pre>"
241
242            stacktraces=`echo $vmresult | grep "java\.lang\." | grep -c "at dot\.junit\."`
243            if [[ $stacktraces > 0 ]]; then
244                jtype=`echo "$mainclass" | sed -e 's/.*_test\([^0-9]*\)[0-9].*/\1/' `
245                if [ "$jtype" == "VFE" ]; then
246                    (( jvfefailedcnt += 1 ))
247                    echo -n "V"
248                else
249                    (( jfailedcnt += 1 ))
250                    echo -n "F"
251                fi
252
253                echo "<tr class=\"nok\"><td>Failure</td><td>$jtitle</td><td>" >> $report
254                echo "$jcomment</td><td>$vmres</td></tr>" >> $report
255            else
256                (( jwarningcnt += 1 ))
257                echo "<tr class=\"wok\"><td>Failure</td><td>$jtitle</td><td>" >> $report
258                echo "$jcomment</td><td>(No stacktrace, but errors on console)" >> $report
259                echo "<br>$vmres</td></tr>" >> $report
260                echo -n "C"
261            fi
262        fi
263
264        (( jcolumns += 1 ))
265        if [ ${jcolumns} -eq 40 ]; then
266            echo ""
267            (( jcolumns = 0 ))
268        fi
269
270    fi
271# Use fd nr 3 to avoid subshelling via cat since this looses all
272# variables(and thus also the counters we are interested in).
273done 3<$scriptdata
274
275echo "</table>" >> $report
276let jallcalccnt=$jpassedcnt+$jfailedcnt+$jvfefailedcnt+$jwarningcnt
277if [ $jallcalccnt -ne $jallcnt ]; then
278    echo "<br>error: green & red != total , $jallcalccnt -ne $jallcnt" >> $report
279    exit 1;
280fi
281
282echo $post_report >> $report
283
284echo "<br>Tests run: ${jallcnt}" >> $report
285echo "<br>Functional failures: ${jfailedcnt}" >> $report
286echo "<br>Verifier failures: ${jvfefailedcnt}" >> $report
287echo "<br>Console errors: ${jwarningcnt}" >> $report
288
289echo $post_report >> $report
290
291if [[ jcolumns -ne 0 ]]; then
292    echo ""
293fi
294
295echo ""
296
297if [[ jallcnt -eq jpassedcnt ]]; then
298    echo "OK (${jpassedcnt} tests)"
299else
300    echo "FAILURES!!!"
301    echo ""
302    echo "Tests run          : ${jallcnt}"
303    echo "Functional failures: ${jfailedcnt}"
304    echo "Verifier failures  : ${jvfefailedcnt}"
305    echo "Console errors     : ${jwarningcnt}"
306fi
307
308echo ""
309echo "Please see complete report in ${report}"
310echo "--------------------------------------------------"
311