Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 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 Android Runtime APEX tests. |
| 19 | |
| 20 | function say { |
| 21 | echo "$0: $*" |
| 22 | } |
| 23 | |
| 24 | function die { |
| 25 | echo "$0: $*" |
| 26 | exit 1 |
| 27 | } |
| 28 | |
| 29 | which guestmount >/dev/null && which guestunmount >/dev/null && which virt-filesystems >/dev/null \ |
| 30 | || die "This script requires 'guestmount', 'guestunmount', |
| 31 | and 'virt-filesystems' from libguestfs. On Debian-based systems, these tools |
| 32 | can be installed with: |
| 33 | |
| 34 | sudo apt-get install libguestfs-tools |
| 35 | " |
Pete Bentley | f34e743 | 2018-12-11 18:12:25 +0000 | [diff] [blame] | 36 | |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 37 | [[ -n "$ANDROID_PRODUCT_OUT" ]] \ |
| 38 | || die "You need to source and lunch before you can use this script." |
| 39 | |
| 40 | # Fail early. |
| 41 | set -e |
| 42 | |
| 43 | build_apex_p=true |
| 44 | list_image_files_p=false |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 45 | print_image_tree_p=false |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 46 | |
| 47 | function usage { |
| 48 | cat <<EOF |
| 49 | Usage: $0 [OPTION] |
| 50 | Build (optional) and run tests on Android Runtime APEX package (on host). |
| 51 | |
| 52 | -s, --skip-build skip the build step |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 53 | -l, --list-files list the contents of the ext4 image using `find` |
| 54 | -t, --print-tree list the contents of the ext4 image using `tree` |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 55 | -h, --help display this help and exit |
| 56 | |
| 57 | EOF |
| 58 | exit |
| 59 | } |
| 60 | |
| 61 | while [[ $# -gt 0 ]]; do |
| 62 | case "$1" in |
| 63 | (-s|--skip-build) build_apex_p=false;; |
| 64 | (-l|--list-files) list_image_files_p=true;; |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 65 | (-t|--print-tree) print_image_tree_p=true;; |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 66 | (-h|--help) usage;; |
| 67 | (*) die "Unknown option: '$1' |
| 68 | Try '$0 --help' for more information.";; |
| 69 | esac |
| 70 | shift |
| 71 | done |
| 72 | |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 73 | if $print_image_tree_p; then |
| 74 | which tree >/dev/null || die "This script requires the 'tree' tool. |
| 75 | On Debian-based systems, this can be installed with: |
| 76 | |
| 77 | sudo apt-get install tree |
| 78 | " |
| 79 | fi |
| 80 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 81 | |
| 82 | # build_apex APEX_MODULE |
| 83 | # ---------------------- |
| 84 | # Build APEX package APEX_MODULE. |
| 85 | function build_apex { |
| 86 | if $build_apex_p; then |
| 87 | local apex_module=$1 |
| 88 | say "Building package $apex_module" && make "$apex_module" || die "Cannot build $apex_module" |
| 89 | fi |
| 90 | } |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 91 | |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 92 | # maybe_list_apex_contents MOUNT_POINT |
| 93 | # ------------------------------------ |
| 94 | # If any listing/printing option was used, honor them and display the contents |
| 95 | # of the APEX payload at MOUNT_POINT. |
| 96 | function maybe_list_apex_contents { |
| 97 | local mount_point=$1 |
| 98 | |
| 99 | # List the contents of the mounted image using `find` (optional). |
| 100 | if $list_image_files_p; then |
| 101 | say "Listing image files" && find "$mount_point" |
| 102 | fi |
| 103 | |
| 104 | # List the contents of the mounted image using `tree` (optional). |
| 105 | if $print_image_tree_p; then |
| 106 | say "Printing image tree" && ls -ld "$mount_point" && tree -aph --du "$mount_point" |
| 107 | fi |
| 108 | } |
| 109 | |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 110 | function check_binary { |
| 111 | [[ -x "$mount_point/bin/$1" ]] || die "Cannot find binary '$1' in mounted image" |
| 112 | } |
| 113 | |
| 114 | function check_multilib_binary { |
| 115 | # TODO: Use $TARGET_ARCH (e.g. check whether it is "arm" or "arm64") to improve |
| 116 | # the precision of this test? |
| 117 | [[ -x "$mount_point/bin/${1}32" ]] || [[ -x "$mount_point/bin/${1}64" ]] \ |
| 118 | || die "Cannot find binary '$1' in mounted image" |
| 119 | } |
| 120 | |
| 121 | function check_binary_symlink { |
| 122 | [[ -h "$mount_point/bin/$1" ]] || die "Cannot find symbolic link '$1' in mounted image" |
| 123 | } |
| 124 | |
| 125 | function check_library { |
| 126 | # TODO: Use $TARGET_ARCH (e.g. check whether it is "arm" or "arm64") to improve |
| 127 | # the precision of this test? |
| 128 | [[ -f "$mount_point/lib/$1" ]] || [[ -f "$mount_point/lib64/$1" ]] \ |
| 129 | || die "Cannot find library '$1' in mounted image" |
| 130 | } |
| 131 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 132 | # Check contents of APEX payload located in `$mount_point`. |
| 133 | function check_release_contents { |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 134 | # Check that the mounted image contains a manifest. |
| 135 | [[ -f "$mount_point/apex_manifest.json" ]] || die "no manifest" |
| 136 | |
| 137 | # Check that the mounted image contains ART base binaries. |
| 138 | check_multilib_binary dalvikvm |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 139 | # TODO: Does not work yet (b/119942078). |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 140 | : check_binary_symlink dalvikvm |
| 141 | check_binary dex2oat |
| 142 | check_binary dexoptanalyzer |
| 143 | check_binary profman |
| 144 | |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 145 | # oatdump is only in device apex's due to build rules |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 146 | # TODO: Check for it when it is also built for host. |
| 147 | : check_binary oatdump |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 148 | |
| 149 | # Check that the mounted image contains ART libraries. |
| 150 | check_library libart-compiler.so |
| 151 | check_library libart.so |
| 152 | check_library libopenjdkjvm.so |
| 153 | check_library libopenjdkjvmti.so |
| 154 | check_library libadbconnection.so |
| 155 | # TODO: Should we check for these libraries too, even if they are not explicitly |
| 156 | # listed as dependencies in the Android Runtime APEX module rule? |
| 157 | check_library libartbase.so |
| 158 | check_library libart-dexlayout.so |
| 159 | check_library libdexfile.so |
| 160 | check_library libprofile.so |
| 161 | |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 162 | # TODO: Should we check for other libraries, such as: |
| 163 | # |
| 164 | # libbacktrace.so |
| 165 | # libbase.so |
| 166 | # liblog.so |
| 167 | # libsigchain.so |
| 168 | # libtombstoned_client.so |
| 169 | # libunwindstack.so |
| 170 | # libvixl.so |
| 171 | # libvixld.so |
| 172 | # ... |
| 173 | # |
| 174 | # ? |
| 175 | } |
| 176 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 177 | # Check debug contents of APEX payload located in `$mount_point`. |
| 178 | function check_debug_contents { |
| 179 | # Check that the mounted image contains ART tools binaries. |
| 180 | check_binary dexdiag |
| 181 | check_binary dexdump |
| 182 | check_binary dexlist |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 183 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 184 | # Check that the mounted image contains ART debug binaries. |
| 185 | check_binary dex2oatd |
| 186 | check_binary dexoptanalyzerd |
| 187 | check_binary profmand |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 188 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 189 | # Check that the mounted image contains ART debug libraries. |
| 190 | check_library libartd-compiler.so |
| 191 | check_library libartd.so |
| 192 | check_library libopenjdkd.so |
| 193 | check_library libopenjdkjvmd.so |
| 194 | check_library libopenjdkjvmtid.so |
| 195 | check_library libadbconnectiond.so |
| 196 | # TODO: Should we check for these libraries too, even if they are not explicitly |
| 197 | # listed as dependencies in the Android Runtime APEX module rule? |
| 198 | check_library libdexfiled.so |
| 199 | check_library libartbased.so |
| 200 | check_library libartd-dexlayout.so |
| 201 | check_library libprofiled.so |
| 202 | } |
| 203 | |
| 204 | # Testing target (device) APEX packages. |
| 205 | # ====================================== |
| 206 | |
| 207 | # Clean-up. |
| 208 | function cleanup_target { |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 209 | guestunmount "$mount_point" |
| 210 | rm -rf "$work_dir" |
| 211 | } |
| 212 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 213 | # Garbage collection. |
| 214 | function finish_target { |
| 215 | # Don't fail early during cleanup. |
| 216 | set +e |
| 217 | cleanup_target |
| 218 | } |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 219 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 220 | # setup_target_apex APEX_MODULE MOUNT_POINT |
| 221 | # ----------------------------------------- |
| 222 | # Extract image from target APEX_MODULE and mount it in MOUNT_POINT. |
| 223 | function setup_target_apex { |
| 224 | local apex_module=$1 |
| 225 | local mount_point=$2 |
| 226 | local system_apexdir="$ANDROID_PRODUCT_OUT/system/apex" |
| 227 | local apex_package="$system_apexdir/$apex_module.apex" |
| 228 | |
| 229 | say "Extracting and mounting image" |
| 230 | |
| 231 | # Extract the payload from the Android Runtime APEX. |
| 232 | local image_filename="apex_payload.img" |
| 233 | unzip -q "$apex_package" "$image_filename" -d "$work_dir" |
| 234 | mkdir "$mount_point" |
| 235 | local image_file="$work_dir/$image_filename" |
| 236 | |
| 237 | # Check filesystems in the image. |
| 238 | local image_filesystems="$work_dir/image_filesystems" |
| 239 | virt-filesystems -a "$image_file" >"$image_filesystems" |
| 240 | # We expect a single partition (/dev/sda) in the image. |
| 241 | local partition="/dev/sda" |
| 242 | echo "$partition" | cmp "$image_filesystems" - |
| 243 | |
| 244 | # Mount the image from the Android Runtime APEX. |
| 245 | guestmount -a "$image_file" -m "$partition" "$mount_point" |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | # Testing release APEX package (com.android.runtime.release). |
| 249 | # ----------------------------------------------------------- |
| 250 | |
| 251 | apex_module="com.android.runtime.release" |
| 252 | |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 253 | say "Processing APEX package $apex_module" |
| 254 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 255 | work_dir=$(mktemp -d) |
| 256 | mount_point="$work_dir/image" |
| 257 | |
| 258 | trap finish_target EXIT |
| 259 | |
| 260 | # Build the APEX package (optional). |
| 261 | build_apex "$apex_module" |
| 262 | |
| 263 | # Set up APEX package. |
| 264 | setup_target_apex "$apex_module" "$mount_point" |
| 265 | |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 266 | # List the contents of the APEX image (optional). |
| 267 | maybe_list_apex_contents "$mount_point" |
| 268 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 269 | # Run tests on APEX package. |
| 270 | say "Checking APEX package $apex_module" |
| 271 | check_release_contents |
| 272 | |
| 273 | # Clean up. |
| 274 | trap - EXIT |
| 275 | cleanup_target |
| 276 | |
| 277 | say "$apex_module tests passed" |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 278 | echo |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 279 | |
| 280 | # Testing debug APEX package (com.android.runtime.debug). |
| 281 | # ------------------------------------------------------- |
| 282 | |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 283 | apex_module="com.android.runtime.debug" |
| 284 | |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 285 | say "Processing APEX package $apex_module" |
| 286 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 287 | work_dir=$(mktemp -d) |
| 288 | mount_point="$work_dir/image" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 289 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 290 | trap finish_target EXIT |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 291 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 292 | # Build the APEX package (optional). |
| 293 | build_apex "$apex_module" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 294 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 295 | # Set up APEX package. |
| 296 | setup_target_apex "$apex_module" "$mount_point" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 297 | |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 298 | # List the contents of the APEX image (optional). |
| 299 | maybe_list_apex_contents "$mount_point" |
| 300 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 301 | # Run tests on APEX package. |
| 302 | say "Checking APEX package $apex_module" |
| 303 | check_release_contents |
| 304 | check_debug_contents |
| 305 | # Check for files pulled in from debug target-only oatdump. |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 306 | check_binary oatdump |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 307 | check_library libart-disassembler.so |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 308 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 309 | # Clean up. |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 310 | trap - EXIT |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 311 | cleanup_target |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 312 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 313 | say "$apex_module tests passed" |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 314 | echo |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 315 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 316 | |
| 317 | # Testing host APEX package (com.android.runtime.host). |
| 318 | # ===================================================== |
| 319 | |
| 320 | # Clean-up. |
| 321 | function cleanup_host { |
| 322 | rm -rf "$work_dir" |
| 323 | } |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 324 | |
| 325 | # Garbage collection. |
| 326 | function finish_host { |
| 327 | # Don't fail early during cleanup. |
| 328 | set +e |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 329 | cleanup_host |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 332 | # setup_host_apex APEX_MODULE MOUNT_POINT |
| 333 | # --------------------------------------- |
| 334 | # Extract Zip file from host APEX_MODULE and extract it in MOUNT_POINT. |
| 335 | function setup_host_apex { |
| 336 | local apex_module=$1 |
| 337 | local mount_point=$2 |
| 338 | local system_apexdir="$ANDROID_HOST_OUT/apex" |
| 339 | local apex_package="$system_apexdir/$apex_module.zipapex" |
| 340 | |
| 341 | say "Extracting payload" |
| 342 | |
| 343 | # Extract the payload from the Android Runtime APEX. |
| 344 | local image_filename="apex_payload.zip" |
| 345 | unzip -q "$apex_package" "$image_filename" -d "$work_dir" |
| 346 | mkdir "$mount_point" |
| 347 | local image_file="$work_dir/$image_filename" |
| 348 | |
| 349 | # Unzipping the payload |
| 350 | unzip -q "$image_file" -d "$mount_point" |
| 351 | } |
| 352 | |
| 353 | apex_module="com.android.runtime.host" |
| 354 | |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 355 | say "Processing APEX package $apex_module" |
| 356 | |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 357 | work_dir=$(mktemp -d) |
| 358 | mount_point="$work_dir/zip" |
| 359 | |
| 360 | trap finish_host EXIT |
| 361 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 362 | # Build the APEX package (optional). |
| 363 | build_apex "$apex_module" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 364 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 365 | # Set up APEX package. |
| 366 | setup_host_apex "$apex_module" "$mount_point" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 367 | |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame^] | 368 | # List the contents of the APEX image (optional). |
| 369 | maybe_list_apex_contents "$mount_point" |
| 370 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 371 | # Run tests on APEX package. |
| 372 | say "Checking APEX package $apex_module" |
| 373 | check_release_contents |
| 374 | check_debug_contents |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 375 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 376 | # Clean up. |
| 377 | trap - EXIT |
| 378 | cleanup_host |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 379 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 380 | say "$apex_module tests passed" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 381 | |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 382 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 383 | say "All Android Runtime APEX tests passed" |