1 #!/bin/bash 2 # 3 # Copyright (C) 2017 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 prog="$0" 20 args="$@" 21 while [ -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 30 done 31 oldwd=`pwd` 32 progdir=`dirname "${prog}"` 33 cd "${progdir}" 34 progdir=`pwd` 35 prog="${progdir}"/`basename "${prog}"` 36 test_dir="test-$$" 37 if [ -z "$TMPDIR" ]; then 38 tmp_dir="/tmp/$USER/${test_dir}" 39 else 40 tmp_dir="${TMPDIR}/${test_dir}" 41 fi 42 43 if [ "x$ANDROID_BUILD_TOP" = "x" ]; then 44 echo Build environment is not set-up. 45 exit -1 46 fi 47 48 # This only works internally for now (sorry folks!) 49 jack_annotations_lib=/google/data/rw/teams/android-runtime/jack/jack-test-annotations-lib.jack 50 if [ ! -f $jack_annotations_lib ]; then 51 echo Try 'prodaccess' to access android-runtime directory. 52 exit -1 53 fi 54 55 # Compile test into a base64 string that can be instantiated via 56 # reflection on hosts without the jack-test-annotations-lib.jack file. 57 mkdir $tmp_dir 58 for input_file in $progdir/*.java; do 59 i=${input_file##*/Test} 60 i=${i%%.java} 61 src_file=$progdir/Test$i.java 62 jack_file=./src.jack 63 dex_file=./classes.dex 64 base_64_file=$tmp_dir/TestData$i.base64 65 output_file=$progdir/../src/TestData$i.java 66 # Compile source file to jack file. 67 jack -g -cp $ANDROID_BUILD_TOP/out/host/linux-x86/../common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack:$ANDROID_BUILD_TOP/out/host/linux-x86/../common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/classes.jack:$jack_annotations_lib -D sched.runner=multi-threaded -D sched.runner.thread.kind=fixed -D sched.runner.thread.fixed.count=4 -D jack.java.source.version=1.7 -D jack.android.min-api-level=o-b2 --output-jack $jack_file $src_file 68 # Compile jack file to classes.dex. 69 jack -g -cp $ANDROID_BUILD_TOP/out/host/linux-x86/../common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes.jack:$ANDROID_BUILD_TOP/out/host/linux-x86/../common/obj/JAVA_LIBRARIES/core-oj-hostdex_intermediates/classes.jack -D sched.runner=multi-threaded -D sched.runner.thread.kind=fixed -D sched.runner.thread.fixed.count=4 -D jack.java.source.version=1.7 -D jack.android.min-api-level=o-b2 --import $jack_file --output-dex . 70 # Pack the classes.dex file into a base64 string. 71 base64 -w 72 $dex_file > $base_64_file 72 # Emit a managed source file containing the base64 string. The test can be 73 # run by loading this string as a dex file and invoking it via reflection. 74 cat > $output_file <<HEADER 75 /* Generated by ${prog##*/} from ${src_file##*/} */ 76 public class TestData$i { 77 public static final String BASE64_DEX_FILE = 78 HEADER 79 sed -e 's/^\(.*\)$/ "\1" +/' -e '$s/ +/;/' $base_64_file >> $output_file 80 cat >> $output_file <<FOOTER 81 } 82 FOOTER 83 rm $dex_file $jack_file 84 done 85 86 rm -rf $tmp_dir 87