| 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/dexdump" |
| 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 |
ALL_DEX_FILES_JAR=all-dex-files.jar |
| 50 |
|
| 51 |
# Parse command-line options |
| 52 |
UPDATE="no" |
| 53 |
USAGE="no" |
| 54 |
while [ $# -ne 0 ]; do |
| 55 |
case "$1" in |
| 56 |
--update) |
| 57 |
UPDATE="yes" |
| 58 |
;; |
| 59 |
*) |
| 60 |
echo "Unknown option $1" 1>&2 |
| 61 |
USAGE="yes" |
| 62 |
;; |
| 63 |
esac |
| 64 |
shift |
| 65 |
done |
| 66 |
|
| 67 |
if [ "${USAGE}" = "yes" ]; then |
| 68 |
cat 1>&2 <<USAGE_END |
| 69 |
Usage: |
| 70 |
${prog##*/} [--update] |
| 71 |
Options: |
| 72 |
--update Update reference outputs |
| 73 |
USAGE_END |
| 74 |
exit 1 |
| 75 |
fi |
| 76 |
|
| 77 |
if [ "${UPDATE}" = "yes" ]; then |
| 78 |
for dex in *.dex; do |
| 79 |
for suffix in ${!SUFFIX_COMMAND_MAP[@]}; do |
| 80 |
new_output=${dex%%.*}.${suffix} |
| 81 |
${SUFFIX_COMMAND_MAP[${suffix}]} ${dex} > ${new_output} |
| 82 |
if [ $? -ne 0 ]; then |
| 83 |
echo "Failed running ${SUFFIX_COMMAND_MAP[${suffix}]} ${dex} > ${new_output}" 2>&1 |
| 84 |
exit 1 |
| 85 |
fi |
| 86 |
done |
| 87 |
done |
| 88 |
|
| 89 |
# Create a .jar file containing all dex files, renamed as expected by the runtime. |
| 90 |
count=0 |
| 91 |
for i in *.dex; do |
| 92 |
if [ ${count} = 0 ] ; then |
| 93 |
dex_file=classes.dex |
| 94 |
flags="-cf" |
| 95 |
else |
| 96 |
dex_file=classes${count}.dex |
| 97 |
flags="-uf" |
| 98 |
fi |
| 99 |
cp $i ${tmpdir}/${dex_file} |
| 100 |
jar ${flags} ${ALL_DEX_FILES_JAR} -C ${tmpdir} ${dex_file} |
| 101 |
((count += 1)) |
| 102 |
rm ${tmpdir}/${dex_file} |
| 103 |
done |
| 104 |
|
| 105 |
prefix=$(basename ${ALL_DEX_FILES_JAR} .jar) |
| 106 |
for suffix in ${!SUFFIX_COMMAND_MAP[@]}; do |
| 107 |
new_output=${prefix}.${suffix} |
| 108 |
${SUFFIX_COMMAND_MAP[${suffix}]} ${ALL_DEX_FILES_JAR} > ${new_output} |
| 109 |
done |
| 110 |
|
| 111 |
exit 0 |
| 112 |
fi |
| 113 |
|
| 114 |
# Run the tests. |
| 115 |
passed=0 |
| 116 |
failed=0 |
| 117 |
for input in *.dex *.jar; do |
| 118 |
echo ${input} |
| 119 |
for suffix in ${!SUFFIX_COMMAND_MAP[@]}; do |
| 120 |
expected_output=${input%%.*}.${suffix} |
| 121 |
actual_output=${tmpdir}/${expected_output} |
| 122 |
cmd="${SUFFIX_COMMAND_MAP[${suffix}]} ${input}" |
| 123 |
${cmd} > ${actual_output} |
| 124 |
cmp ${expected_output} ${actual_output} |
| 125 |
if [ "$?" = "0" ]; then |
| 126 |
((passed += 1)) |
| 127 |
else |
| 128 |
((failed += 1)) |
| 129 |
echo failed: ${cmd} |
| 130 |
fi |
| 131 |
done |
| 132 |
done |
| 133 |
|
| 134 |
# Report results. |
| 135 |
echo |
| 136 |
echo "passed: ${passed} test(s)" |
| 137 |
echo "failed: ${failed} test(s)" |
| 138 |
echo |
| 139 |
|
| 140 |
# Clean up, cd back to original dir. |
| 141 |
rm -rf ${tmpdir} |
| 142 |
cd ${oldwd} |
| 143 |
|
| 144 |
# Return status. |
| 145 |
if [ "${failed}" != "0" ]; then |
| 146 |
echo failed |
| 147 |
exit 1 |
| 148 |
fi |
| 149 |
exit 0 |
| 150 |
|