1#!/bin/bash 2 3# Copyright (C) 2018 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# Run ART APEX tests. 19 20SCRIPT_DIR=$(dirname $0) 21 22# Status of whole test script. 23exit_status=0 24# Status of current test suite. 25test_status=0 26 27function say { 28 echo "$0: $*" 29} 30 31function die { 32 echo "$0: $*" 33 exit 1 34} 35 36function setup_die { 37 die "You need to source and lunch before you can use this script." 38} 39 40[[ -n "$ANDROID_BUILD_TOP" ]] || setup_die 41[[ -n "$ANDROID_PRODUCT_OUT" ]] || setup_die 42[[ -n "$ANDROID_HOST_OUT" ]] || setup_die 43 44flattened_apex_p=$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash --dumpvar-mode TARGET_FLATTEN_APEX)\ 45 || setup_die 46 47have_debugfs_p=false 48if $flattened_apex_p; then :; else 49 if [ ! -e "$ANDROID_HOST_OUT/bin/debugfs" ] ; then 50 say "Could not find debugfs, building now." 51 build/soong/soong_ui.bash --make-mode debugfs-host || die "Cannot build debugfs" 52 fi 53 have_debugfs_p=true 54fi 55 56# Fail early. 57set -e 58 59build_apex_p=true 60list_image_files_p=false 61print_image_tree_p=false 62print_file_sizes_p=false 63 64function usage { 65 cat <<EOF 66Usage: $0 [OPTION] 67Build (optional) and run tests on ART APEX package (on host). 68 69 -B, --skip-build skip the build step 70 -l, --list-files list the contents of the ext4 image (\`find\`-like style) 71 -t, --print-tree list the contents of the ext4 image (\`tree\`-like style) 72 -s, --print-sizes print the size in bytes of each file when listing contents 73 -h, --help display this help and exit 74 75EOF 76 exit 77} 78 79while [[ $# -gt 0 ]]; do 80 case "$1" in 81 (-B|--skip-build) build_apex_p=false;; 82 (-l|--list-files) list_image_files_p=true;; 83 (-t|--print-tree) print_image_tree_p=true;; 84 (-s|--print-sizes) print_file_sizes_p=true;; 85 (-h|--help) usage;; 86 (*) die "Unknown option: '$1' 87Try '$0 --help' for more information.";; 88 esac 89 shift 90done 91 92# build_apex APEX_MODULES 93# ----------------------- 94# Build APEX packages APEX_MODULES. 95function build_apex { 96 if $build_apex_p; then 97 say "Building $@" && build/soong/soong_ui.bash --make-mode "$@" || die "Cannot build $@" 98 fi 99} 100 101# maybe_list_apex_contents_apex APEX TMPDIR [other] 102function maybe_list_apex_contents_apex { 103 local print_options=() 104 if $print_file_sizes_p; then 105 print_options+=(--size) 106 fi 107 108 # List the contents of the apex in list form. 109 if $list_image_files_p; then 110 say "Listing image files" 111 $SCRIPT_DIR/art_apex_test.py --list ${print_options[@]} $@ 112 fi 113 114 # List the contents of the apex in tree form. 115 if $print_image_tree_p; then 116 say "Printing image tree" 117 $SCRIPT_DIR/art_apex_test.py --tree ${print_options[@]} $@ 118 fi 119} 120 121function fail_check { 122 echo "$0: FAILED: $*" 123 test_status=1 124 exit_status=1 125} 126 127# Test all modules, if possible. 128 129apex_modules=( 130 "com.android.art.release" 131 "com.android.art.debug" 132 "com.android.art.testing" 133) 134if [[ "$HOST_PREFER_32_BIT" = true ]]; then 135 say "Skipping com.android.art.host, as \`HOST_PREFER_32_BIT\` equals \`true\`" 136else 137 apex_modules+=("com.android.art.host") 138fi 139 140# Build the APEX packages (optional). 141build_apex ${apex_modules[@]} 142 143# Clean-up. 144function cleanup { 145 rm -rf "$work_dir" 146} 147 148# Garbage collection. 149function finish { 150 # Don't fail early during cleanup. 151 set +e 152 cleanup 153} 154 155for apex_module in ${apex_modules[@]}; do 156 test_status=0 157 say "Checking APEX package $apex_module" 158 work_dir=$(mktemp -d) 159 trap finish EXIT 160 161 art_apex_test_args="--tmpdir $work_dir" 162 test_only_args="" 163 if [[ $apex_module = *.host ]]; then 164 apex_path="$ANDROID_HOST_OUT/apex/${apex_module}.zipapex" 165 art_apex_test_args="$art_apex_test_args --host" 166 test_only_args="--flavor debug" 167 else 168 if $flattened_apex_p; then 169 apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}" 170 art_apex_test_args="$art_apex_test_args --flattened" 171 else 172 apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}.apex" 173 fi 174 if $have_debugfs_p; then 175 art_apex_test_args="$art_apex_test_args --debugfs $ANDROID_HOST_OUT/bin/debugfs" 176 fi 177 case $apex_module in 178 (*.release) test_only_args="--flavor release";; 179 (*.debug) test_only_args="--flavor debug";; 180 (*.testing) test_only_args="--flavor testing";; 181 esac 182 fi 183 say "APEX package path: $apex_path" 184 185 # List the contents of the APEX image (optional). 186 maybe_list_apex_contents_apex $art_apex_test_args $apex_path 187 188 # Run tests on APEX package. 189 $SCRIPT_DIR/art_apex_test.py $art_apex_test_args $test_only_args $apex_path \ 190 || fail_check "Checks failed on $apex_module" 191 192 # Clean up. 193 trap - EXIT 194 cleanup 195 196 [[ "$test_status" = 0 ]] && say "$apex_module tests passed" 197 echo 198done 199 200[[ "$exit_status" = 0 ]] && say "All ART APEX tests passed" 201 202exit $exit_status 203