| 1 | #!/bin/bashscip-shell filesystem . . `/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 | set -e |
| 19 | |
| 20 | # Run ART APEX tests. |
| 21 | |
| 22 | SCRIPT_DIR=$(dirnamescip-shell system . . dirname. $0) |
| 23 | |
| 24 | # Status of whole test script. |
| 25 | exit_status=0 |
| 26 | # Status of current test suite. |
| 27 | test_status=0 |
| 28 | |
| 29 | function sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). { |
| 30 | echoscip-shell system . . echo. "$0: $*" |
| 31 | } |
| 32 | |
| 33 | function diescip-shell shell android-platform-art 14.0.0+r15-6 die(). { |
| 34 | echoscip-shell system . . echo. "$0: $*" |
| 35 | exit 1 |
| 36 | } |
| 37 | |
| 38 | if [[ -z "$ANDROID_BUILD_TOP" ]]; then |
| 39 | export ANDROID_BUILD_TOP=$(pwdscip-shell system . . pwd.) |
| 40 | if [[ ! -x "$ANDROID_BUILD_TOP/build/soong/soong_ui.bash" ]]; then |
| 41 | diescip-shell shell android-platform-art 14.0.0+r15-6 die(). "Run from the root of the Android tree, or run lunch/banchan/tapas first." |
| 42 | fi |
| 43 | fi |
| 44 | |
| 45 | query_build_vars=( |
| 46 | HOST_OUT |
| 47 | PRODUCT_COMPRESSED_APEX |
| 48 | PRODUCT_OUT |
| 49 | TARGET_FLATTEN_APEX |
| 50 | ) |
| 51 | vars="$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash \ |
| 52 | --dumpvars-mode --vars="${query_build_vars[*]}")" |
| 53 | # Assign to a variable and eval that, since bash ignores any error status from |
| 54 | # the command substitution if it's directly on the eval line. |
| 55 | eval $vars |
| 56 | |
| 57 | # Switch the build system to unbundled mode in the reduced manifest branch. |
| 58 | if [scip-shell system . . `[`. ! -d $ANDROID_BUILD_TOP/frameworks/base ]; then |
| 59 | export TARGET_BUILD_UNBUNDLED=true |
| 60 | fi |
| 61 | |
| 62 | deapex_binaries=( |
| 63 | blkid_static |
| 64 | deapexer |
| 65 | debugfs_static |
| 66 | fsck.erofs |
| 67 | ) |
| 68 | |
| 69 | have_deapex_binaries=false |
| 70 | if [[ "$TARGET_FLATTEN_APEX" != true ]]; then |
| 71 | have_deapex_binaries=true |
| 72 | for f in ${deapex_binaries[@]}; do |
| 73 | if [scip-shell system . . `[`. ! -e "$HOST_OUT/bin/$f" ]; then |
| 74 | have_deapex_binaries=false |
| 75 | fi |
| 76 | done |
| 77 | if $have_deapex_binaries; then :; else |
| 78 | deapex_targets=( ${deapex_binaries[@]/%/-host} ) |
| 79 | sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). "Building host binaries for deapexer: ${deapex_targets[*]}" |
| 80 | build/soong/soong_ui.bash --make-mode ${deapex_targets[@]} || \ |
| 81 | die "Failed to build: ${deapex_targets[*]}" |
| 82 | fi |
| 83 | fi |
| 84 | |
| 85 | # Fail early. |
| 86 | set -e |
| 87 | |
| 88 | build_apex_p=true |
| 89 | list_image_files_p=false |
| 90 | print_image_tree_p=false |
| 91 | print_file_sizes_p=false |
| 92 | |
| 93 | function usagescip-shell shell android-platform-art 14.0.0+r15-6 usage(). { |
| 94 | catscip-shell system . . cat. <<EOF |
| 95 | Usage: $0 [OPTION] [apexes...] |
| 96 | Build (optional) and run tests on ART APEX package (on host). Defaults to all |
| 97 | applicable APEXes if none is given on the command line. |
| 98 | |
| 99 | -B, --skip-build skip the build step |
| 100 | -l, --list-files list the contents of the ext4 image (\`find\`-like style) |
| 101 | -t, --print-tree list the contents of the ext4 image (\`tree\`-like style) |
| 102 | -s, --print-sizes print the size in bytes of each file when listing contents |
| 103 | --bitness=32|64|multilib|auto passed on to art_apex_test.py for non-host APEXes |
| 104 | -h, --help display this help and exit |
| 105 | |
| 106 | EOF |
| 107 | exit |
| 108 | } |
| 109 | |
| 110 | device_bitness_arg="" |
| 111 | apex_modules=() |
| 112 | |
| 113 | while [[ $# -gt 0 ]]; do |
| 114 | case "$1" in |
| 115 | (-B|--skip-build) build_apex_p=false;; |
| 116 | (-l|--list-files) list_image_files_p=true;; |
| 117 | (-t|--print-tree) print_image_tree_p=true;; |
| 118 | (-s|--print-sizes) print_file_sizes_p=true;; |
| 119 | (--bitness=*) device_bitness_arg=$1;; |
| 120 | (-h|--help) usagescip-shell shell android-platform-art 14.0.0+r15-6 usage().;; |
| 121 | (-*) diescip-shell shell android-platform-art 14.0.0+r15-6 die(). "Unknown option: '$1' |
| 122 | Try '$0 --help' for more information.";; |
| 123 | (*) apex_modules+=($1);; |
| 124 | esac |
| 125 | shift |
| 126 | done |
| 127 | |
| 128 | # build_apex APEX_MODULES |
| 129 | # ----------------------- |
| 130 | # Build APEX packages APEX_MODULES. |
| 131 | function build_apexscip-shell shell android-platform-art 14.0.0+r15-6 build_apex(). { |
| 132 | if $build_apex_p; then |
| 133 | sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). "Building $@" && build/soong/soong_ui.bash --make-mode "$@" || diescip-shell shell android-platform-art 14.0.0+r15-6 die(). "Cannot build $@" |
| 134 | fi |
| 135 | } |
| 136 | |
| 137 | # maybe_list_apex_contents_apex APEX TMPDIR [other] |
| 138 | function maybe_list_apex_contents_apexscip-shell shell android-platform-art 14.0.0+r15-6 maybe_list_apex_contents_apex(). { |
| 139 | local print_options=() |
| 140 | if $print_file_sizes_p; then |
| 141 | print_options+=(--size) |
| 142 | fi |
| 143 | |
| 144 | # List the contents of the apex in list form. |
| 145 | if $list_image_files_p; then |
| 146 | sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). "Listing image files" |
| 147 | $SCRIPT_DIR/art_apex_test.py --list ${print_options[@]} $@ |
| 148 | fi |
| 149 | |
| 150 | # List the contents of the apex in tree form. |
| 151 | if $print_image_tree_p; then |
| 152 | sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). "Printing image tree" |
| 153 | $SCRIPT_DIR/art_apex_test.py --tree ${print_options[@]} $@ |
| 154 | fi |
| 155 | } |
| 156 | |
| 157 | function fail_checkscip-shell shell android-platform-art 14.0.0+r15-6 fail_check(). { |
| 158 | echoscip-shell system . . echo. "$0: FAILED: $*" |
| 159 | test_status=1 |
| 160 | exit_status=1 |
| 161 | } |
| 162 | |
| 163 | if [scip-shell system . . `[`. ${#apex_modules[@]} -eq 0 ]; then |
| 164 | # Test as many modules as possible. |
| 165 | apex_modules=( |
| 166 | "com.android.art" |
| 167 | "com.android.art.debug" |
| 168 | "com.android.art.testing" |
| 169 | ) |
| 170 | if [[ "$HOST_PREFER_32_BIT" = true ]]; then |
| 171 | sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). "Skipping com.android.art.host, as \`HOST_PREFER_32_BIT\` equals \`true\`" |
| 172 | else |
| 173 | apex_modules+=("com.android.art.host") |
| 174 | fi |
| 175 | fi |
| 176 | |
| 177 | # Build the APEX packages (optional). |
| 178 | build_apexscip-shell shell android-platform-art 14.0.0+r15-6 build_apex(). ${apex_modules[@]} |
| 179 | |
| 180 | # Clean-up. |
| 181 | function cleanupscip-shell shell android-platform-art 14.0.0+r15-6 cleanup(). { |
| 182 | rmscip-shell system . . rm. -rf "$work_dir" |
| 183 | } |
| 184 | |
| 185 | # Garbage collection. |
| 186 | function finishscip-shell shell android-platform-art 14.0.0+r15-6 finish(). { |
| 187 | # Don't fail early during cleanup. |
| 188 | set +e |
| 189 | cleanupscip-shell shell android-platform-art 14.0.0+r15-6 cleanup(). |
| 190 | } |
| 191 | |
| 192 | for apex_module in ${apex_modules[@]}; do |
| 193 | test_status=0 |
| 194 | sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). "Checking APEX package $apex_module" |
| 195 | work_dir=$(mktempscip-shell system . . mktemp. -d) |
| 196 | trap finish EXIT |
| 197 | |
| 198 | art_apex_test_args="--tmpdir $work_dir" |
| 199 | test_only_args="" |
| 200 | if [[ $apex_module = *.host ]]; then |
| 201 | apex_path="$HOST_OUT/apex/${apex_module}.zipapex" |
| 202 | art_apex_test_args="$art_apex_test_args --host" |
| 203 | test_only_args="--flavor debug" |
| 204 | # The host APEX is always built multilib. |
| 205 | art_apex_test_args="$art_apex_test_args --bitness=multilib" |
| 206 | else |
| 207 | art_apex_test_args="$art_apex_test_args $device_bitness_arg" |
| 208 | if [[ "$TARGET_FLATTEN_APEX" = true ]]; then |
| 209 | apex_path="$PRODUCT_OUT/system/apex/${apex_module}" |
| 210 | art_apex_test_args="$art_apex_test_args --flattened" |
| 211 | else |
| 212 | # Note: The Testing ART APEX is never built as a Compressed APEX. |
| 213 | if [[ "$PRODUCT_COMPRESSED_APEX" = true && $apex_module != *.testing ]]; then |
| 214 | apex_path="$PRODUCT_OUT/system/apex/${apex_module}.capex" |
| 215 | else |
| 216 | apex_path="$PRODUCT_OUT/system/apex/${apex_module}.apex" |
| 217 | fi |
| 218 | fi |
| 219 | if $have_deapex_binaries; then |
| 220 | art_apex_test_args="$art_apex_test_args --deapexer $HOST_OUT/bin/deapexer" |
| 221 | art_apex_test_args="$art_apex_test_args --debugfs $HOST_OUT/bin/debugfs_static" |
| 222 | art_apex_test_args="$art_apex_test_args --fsckerofs $HOST_OUT/bin/fsck.erofs" |
| 223 | art_apex_test_args="$art_apex_test_args --blkid $HOST_OUT/bin/blkid_static" |
| 224 | fi |
| 225 | case $apex_module in |
| 226 | (*.debug) test_only_args="--flavor debug";; |
| 227 | (*.testing) test_only_args="--flavor testing";; |
| 228 | (*) test_only_args="--flavor release";; |
| 229 | esac |
| 230 | fi |
| 231 | sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). "APEX package path: $apex_path" |
| 232 | |
| 233 | # List the contents of the APEX image (optional). |
| 234 | maybe_list_apex_contents_apexscip-shell shell android-platform-art 14.0.0+r15-6 maybe_list_apex_contents_apex(). $art_apex_test_args $apex_path |
| 235 | |
| 236 | # Run tests on APEX package. |
| 237 | $SCRIPT_DIR/art_apex_test.py $art_apex_test_args $test_only_args $apex_path \ |
| 238 | || fail_checkscip-shell shell android-platform-art 14.0.0+r15-6 fail_check(). "Checks failed on $apex_module" |
| 239 | |
| 240 | # Clean up. |
| 241 | trap - EXIT |
| 242 | cleanupscip-shell shell android-platform-art 14.0.0+r15-6 cleanup(). |
| 243 | |
| 244 | [[ "$test_status" = 0 ]] && sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). "$apex_module tests passed" |
| 245 | echoscip-shell system . . echo. |
| 246 | done |
| 247 | |
| 248 | [[ "$exit_status" = 0 ]] && sayscip-shell shell android-platform-art 14.0.0+r15-6 say(). "All ART APEX tests passed" |
| 249 | |
| 250 | exit $exit_status |