| MÃ¥rten Kongstad | dd63e5d2 | 2019-09-27 10:00:18 +0200 | [diff] [blame] | 1 | #!/bin/bash | 
 | 2 | # | 
 | 3 | # Copyright (C) 2019 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 |  | 
 | 18 | function _log() | 
 | 19 | { | 
 | 20 |     echo -e "$*" >&2 | 
 | 21 | } | 
 | 22 |  | 
 | 23 | function _eval() | 
 | 24 | { | 
 | 25 |     local label="$1" | 
 | 26 |     local cmd="$2" | 
 | 27 |     local red="\e[31m" | 
 | 28 |     local green="\e[32m" | 
 | 29 |     local reset="\e[0m" | 
 | 30 |     local output | 
 | 31 |  | 
 | 32 |     _log "${green}[ RUN      ]${reset} ${label}" | 
 | 33 |     output="$(eval "$cmd" 2>&1)" | 
 | 34 |     if [[ $? -eq 0 ]]; then | 
 | 35 |         _log "${green}[       OK ]${reset} ${label}" | 
 | 36 |         return 0 | 
 | 37 |     else | 
 | 38 |         echo "${output}" | 
 | 39 |         _log "${red}[  FAILED  ]${reset} ${label}" | 
 | 40 |         errors=$((errors + 1)) | 
 | 41 |         return 1 | 
 | 42 |     fi | 
 | 43 | } | 
 | 44 |  | 
 | 45 | errors=0 | 
 | 46 | script="$(readlink -f "$BASH_SOURCE")" | 
 | 47 | prefix="$(dirname "$script")" | 
 | 48 | target_path="${prefix}/tests/data/target/target.apk" | 
 | 49 | overlay_path="${prefix}/tests/data/overlay/overlay.apk" | 
 | 50 | idmap_path="/tmp/a.idmap" | 
 | 51 | valgrind="valgrind --error-exitcode=1 -q --track-origins=yes --leak-check=full" | 
 | 52 |  | 
 | 53 | _eval "idmap2 create" "$valgrind idmap2 create --policy public --target-apk-path $target_path --overlay-apk-path $overlay_path --idmap-path $idmap_path" | 
 | 54 | _eval "idmap2 dump" "$valgrind idmap2 dump --idmap-path $idmap_path" | 
 | 55 | _eval "idmap2 lookup" "$valgrind idmap2 lookup --idmap-path $idmap_path --config '' --resid test.target:string/str1" | 
 | 56 | _eval "idmap2 scan" "$valgrind idmap2 scan --input-directory ${prefix}/tests/data/overlay --recursive --target-package-name test.target --target-apk-path $target_path --output-directory /tmp --override-policy public" | 
 | 57 | _eval "idmap2 verify" "$valgrind idmap2 verify --idmap-path $idmap_path" | 
 | 58 | _eval "idmap2_tests" "$valgrind $ANDROID_HOST_OUT/nativetest64/idmap2_tests/idmap2_tests" | 
 | 59 | exit $errors |