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