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 18function _log() 19{ 20 echo -e "$*" >&2 21} 22 23function _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 45errors=0 46script="$(readlink -f "$BASH_SOURCE")" 47prefix="$(dirname "$script")" 48target_path="${prefix}/tests/data/target/target.apk" 49overlay_path="${prefix}/tests/data/overlay/overlay.apk" 50idmap_path="/tmp/a.idmap" 51valgrind="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" 59exit $errors 60