1 #!/bin/bash 2 # 3 # Copyright (C) 2015 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 while [ -h "${prog}" ]; do 21 newProg=`/bin/ls -ld "${prog}"` 22 newProg=`expr "${newProg}" : ".* -> \(.*\)$"` 23 if expr "x${newProg}" : 'x/' >/dev/null; then 24 prog="${newProg}" 25 else 26 progdir=`dirname "${prog}"` 27 prog="${progdir}/${newProg}" 28 fi 29 done 30 oldwd=`pwd` 31 progdir=`dirname "${prog}"` 32 cd "${progdir}" 33 progdir=`pwd` 34 prog="${progdir}"/`basename "${prog}"` 35 36 # Set up a temp directory for output. 37 tmpdir=/tmp/test-$$ 38 mkdir ${tmpdir} 39 40 # Set up tools and commands to run 41 DEXDUMP="${ANDROID_HOST_OUT}/bin/dexdump2" 42 DEXLIST="${ANDROID_HOST_OUT}/bin/dexlist" 43 44 declare -A SUFFIX_COMMAND_MAP 45 SUFFIX_COMMAND_MAP[txt]="${DEXDUMP} -adfh" 46 SUFFIX_COMMAND_MAP[xml]="${DEXDUMP} -e -l xml" 47 SUFFIX_COMMAND_MAP[lst]="${DEXLIST}" 48 49 # Parse command-line options 50 UPDATE="no" 51 USAGE="no" 52 while [ $# -ne 0 ]; do 53 case "$1" in 54 --update) 55 UPDATE="yes" 56 ;; 57 *) 58 echo "Unknown option $1" 1>&2 59 USAGE="yes" 60 ;; 61 esac 62 shift 63 done 64 65 if [ "${USAGE}" = "yes" ]; then 66 cat 1>&2 <<USAGE_END 67 Usage: 68 ${prog##*/} [--update] 69 Options: 70 --update Update reference outputs 71 USAGE_END 72 exit 1 73 fi 74 75 if [ "${UPDATE}" = "yes" ]; then 76 for dex in *.dex; do 77 for suffix in ${!SUFFIX_COMMAND_MAP[@]}; do 78 new_output=${dex%%.*}.${suffix} 79 ${SUFFIX_COMMAND_MAP[${suffix}]} ${dex} > ${new_output} 80 if [ $? -ne 0 ]; then 81 echo "Failed running ${SUFFIX_COMMAND_MAP[${suffix}]} ${dex} > ${new_output}" 2>&1 82 exit 1 83 fi 84 done 85 done 86 exit 0 87 fi 88 89 # Run the tests. 90 passed=0 91 failed=0 92 for dex in *.dex; do 93 echo ${dex} 94 for suffix in ${!SUFFIX_COMMAND_MAP[@]}; do 95 expected_output=${dex%%.*}.${suffix} 96 actual_output=${tmpdir}/${expected_output} 97 cmd="${SUFFIX_COMMAND_MAP[${suffix}]} ${dex}" 98 ${cmd} > ${actual_output} 99 cmp ${expected_output} ${actual_output} 100 if [ "$?" = "0" ]; then 101 ((passed += 1)) 102 else 103 ((failed += 1)) 104 echo failed: ${cmd} 105 fi 106 done 107 done 108 109 # Report results. 110 echo 111 echo "passed: ${passed} test(s)" 112 echo "failed: ${failed} test(s)" 113 echo 114 115 # Clean up, cd back to original dir. 116 rm -rf ${tmpdir} 117 cd ${oldwd} 118 119 # Return status. 120 if [ "${failed}" != "0" ]; then 121 echo failed 122 exit 1 123 fi 124 exit 0 125 126