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 | |
| 69 | work_dir=$(mktemp -d) |
| 70 | mount_point="$work_dir/image" |
| 71 | |
| 72 | # Garbage collection. |
| 73 | function finish { |
| 74 | # Don't fail early during cleanup. |
| 75 | set +e |
| 76 | guestunmount "$mount_point" |
| 77 | rm -rf "$work_dir" |
| 78 | } |
| 79 | |
| 80 | trap finish EXIT |
| 81 | |
Roland Levillain | 5305880 | 2018-11-14 17:32:18 +0000 | [diff] [blame^] | 82 | # TODO: Also exercise the Release Runtime APEX (`com.android.runtime.release`). |
| 83 | apex_module="com.android.runtime.debug" |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 84 | |
| 85 | # Build the Android Runtime APEX package (optional). |
| 86 | $build_apex_p && say "Building package" && make "$apex_module" |
| 87 | |
| 88 | system_apexdir="$ANDROID_PRODUCT_OUT/system/apex" |
| 89 | apex_package="$system_apexdir/$apex_module.apex" |
| 90 | |
| 91 | say "Extracting and mounting image" |
| 92 | |
| 93 | # Extract the image from the Android Runtime APEX. |
| 94 | image_filename="image.img" |
| 95 | unzip -q "$apex_package" "$image_filename" -d "$work_dir" |
| 96 | mkdir "$mount_point" |
| 97 | image_file="$work_dir/$image_filename" |
| 98 | |
| 99 | # Check filesystems in the image. |
| 100 | image_filesystems="$work_dir/image_filesystems" |
| 101 | virt-filesystems -a "$image_file" >"$image_filesystems" |
| 102 | # We expect a single partition (/dev/sda) in the image. |
| 103 | partition="/dev/sda" |
| 104 | echo "$partition" | cmp "$image_filesystems" - |
| 105 | |
| 106 | # Mount the image from the Android Runtime APEX. |
| 107 | guestmount -a "$image_file" -m "$partition" "$mount_point" |
| 108 | |
| 109 | # List the contents of the mounted image (optional). |
| 110 | $list_image_files_p && say "Listing image files" && ls -ld "$mount_point" && tree -ap "$mount_point" |
| 111 | |
| 112 | say "Running tests" |
| 113 | |
| 114 | # Check that the mounted image contains a manifest. |
| 115 | [[ -f "$mount_point/manifest.json" ]] |
| 116 | |
| 117 | function check_binary { |
| 118 | [[ -x "$mount_point/bin/$1" ]] || die "Cannot find binary '$1' in mounted image" |
| 119 | } |
| 120 | |
| 121 | function check_multilib_binary { |
| 122 | # TODO: Use $TARGET_ARCH (e.g. check whether it is "arm" or "arm64") to improve |
| 123 | # the precision of this test? |
| 124 | [[ -x "$mount_point/bin/${1}32" ]] || [[ -x "$mount_point/bin/${1}64" ]] \ |
| 125 | || die "Cannot find binary '$1' in mounted image" |
| 126 | } |
| 127 | |
| 128 | function check_binary_symlink { |
| 129 | [[ -h "$mount_point/bin/$1" ]] || die "Cannot find symbolic link '$1' in mounted image" |
| 130 | } |
| 131 | |
| 132 | function check_library { |
| 133 | # TODO: Use $TARGET_ARCH (e.g. check whether it is "arm" or "arm64") to improve |
| 134 | # the precision of this test? |
| 135 | [[ -f "$mount_point/lib/$1" ]] || [[ -f "$mount_point/lib64/$1" ]] \ |
| 136 | || die "Cannot find library '$1' in mounted image" |
| 137 | } |
| 138 | |
| 139 | # Check that the mounted image contains ART base binaries. |
| 140 | check_multilib_binary dalvikvm |
| 141 | # TODO: Does not work yet. |
| 142 | : check_binary_symlink dalvikvm |
| 143 | check_binary dex2oat |
| 144 | check_binary dexoptanalyzer |
| 145 | check_binary profman |
| 146 | |
| 147 | # Check that the mounted image contains ART tools binaries. |
| 148 | check_binary dexdiag |
| 149 | check_binary dexdump |
| 150 | check_binary dexlist |
| 151 | check_binary oatdump |
| 152 | |
| 153 | # Check that the mounted image contains ART debug binaries. |
| 154 | check_binary dex2oatd |
| 155 | check_binary dexoptanalyzerd |
| 156 | check_binary profmand |
| 157 | |
| 158 | # Check that the mounted image contains ART libraries. |
| 159 | check_library libart-compiler.so |
| 160 | check_library libart.so |
| 161 | check_library libopenjdkjvm.so |
| 162 | check_library libopenjdkjvmti.so |
| 163 | check_library libadbconnection.so |
| 164 | # TODO: Should we check for these libraries too, even if they are not explicitly |
| 165 | # listed as dependencies in the Android Runtime APEX module rule? |
| 166 | check_library libartbase.so |
| 167 | check_library libart-dexlayout.so |
| 168 | check_library libart-disassembler.so |
| 169 | check_library libdexfile.so |
| 170 | check_library libprofile.so |
| 171 | |
| 172 | # Check that the mounted image contains ART debug libraries. |
| 173 | check_library libartd-compiler.so |
| 174 | check_library libartd.so |
| 175 | check_library libdexfiled.so |
| 176 | check_library libopenjdkd.so |
| 177 | check_library libopenjdkjvmd.so |
| 178 | check_library libopenjdkjvmtid.so |
| 179 | check_library libadbconnectiond.so |
| 180 | # TODO: Should we check for these libraries too, even if they are not explicitly |
| 181 | # listed as dependencies in the Android Runtime APEX module rule? |
| 182 | check_library libartbased.so |
| 183 | check_library libartd-dexlayout.so |
| 184 | check_library libprofiled.so |
| 185 | |
| 186 | # TODO: Should we check for other libraries, such as: |
| 187 | # |
| 188 | # libbacktrace.so |
| 189 | # libbase.so |
| 190 | # liblog.so |
| 191 | # libsigchain.so |
| 192 | # libtombstoned_client.so |
| 193 | # libunwindstack.so |
Roland Levillain | 5305880 | 2018-11-14 17:32:18 +0000 | [diff] [blame^] | 194 | # libvixl.so |
| 195 | # libvixld.so |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 196 | # ... |
| 197 | # |
| 198 | # ? |
| 199 | |
| 200 | say "Tests passed" |