blob: 2d94b35e7ee0a8dc565864ac28176e8b73f6027c [file] [log] [blame]
Roland Levillain38a938e2018-09-21 10:55:51 +01001#!/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
20function say {
21 echo "$0: $*"
22}
23
24function die {
25 echo "$0: $*"
26 exit 1
27}
28
29which guestmount >/dev/null && which guestunmount >/dev/null && which virt-filesystems >/dev/null \
30 || die "This script requires 'guestmount', 'guestunmount',
31and 'virt-filesystems' from libguestfs. On Debian-based systems, these tools
32can 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.
40set -e
41
42build_apex_p=true
43list_image_files_p=false
44
45function usage {
46 cat <<EOF
47Usage: $0 [OPTION]
48Build (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
54EOF
55 exit
56}
57
58while [[ $# -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'
64Try '$0 --help' for more information.";;
65 esac
66 shift
67done
68
Roland Levillain996f42f2018-12-11 15:26:51 +000069
70# build_apex APEX_MODULE
71# ----------------------
72# Build APEX package APEX_MODULE.
73function 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 Levillain38a938e2018-09-21 10:55:51 +010079
Roland Levillain38a938e2018-09-21 10:55:51 +010080function check_binary {
81 [[ -x "$mount_point/bin/$1" ]] || die "Cannot find binary '$1' in mounted image"
82}
83
84function 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
91function check_binary_symlink {
92 [[ -h "$mount_point/bin/$1" ]] || die "Cannot find symbolic link '$1' in mounted image"
93}
94
95function 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 Levillain996f42f2018-12-11 15:26:51 +0000102# Check contents of APEX payload located in `$mount_point`.
103function check_release_contents {
Alex Lightda948ce2018-12-06 17:05:41 +0000104 # 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 Levillain996f42f2018-12-11 15:26:51 +0000109 # TODO: Does not work yet (b/119942078).
Alex Lightda948ce2018-12-06 17:05:41 +0000110 : check_binary_symlink dalvikvm
111 check_binary dex2oat
112 check_binary dexoptanalyzer
113 check_binary profman
114
Alex Lightda948ce2018-12-06 17:05:41 +0000115 # oatdump is only in device apex's due to build rules
Roland Levillain996f42f2018-12-11 15:26:51 +0000116 # TODO: Check for it when it is also built for host.
117 : check_binary oatdump
Alex Lightda948ce2018-12-06 17:05:41 +0000118
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 Lightda948ce2018-12-06 17:05:41 +0000132 # 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 Levillain996f42f2018-12-11 15:26:51 +0000147# Check debug contents of APEX payload located in `$mount_point`.
148function 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 Lightda948ce2018-12-06 17:05:41 +0000153
Roland Levillain996f42f2018-12-11 15:26:51 +0000154 # Check that the mounted image contains ART debug binaries.
155 check_binary dex2oatd
156 check_binary dexoptanalyzerd
157 check_binary profmand
Alex Lightda948ce2018-12-06 17:05:41 +0000158
Roland Levillain996f42f2018-12-11 15:26:51 +0000159 # 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.
178function cleanup_target {
Alex Lightda948ce2018-12-06 17:05:41 +0000179 guestunmount "$mount_point"
180 rm -rf "$work_dir"
181}
182
Roland Levillain996f42f2018-12-11 15:26:51 +0000183# Garbage collection.
184function finish_target {
185 # Don't fail early during cleanup.
186 set +e
187 cleanup_target
188}
Alex Lightda948ce2018-12-06 17:05:41 +0000189
Roland Levillain996f42f2018-12-11 15:26:51 +0000190# setup_target_apex APEX_MODULE MOUNT_POINT
191# -----------------------------------------
192# Extract image from target APEX_MODULE and mount it in MOUNT_POINT.
193function 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
225apex_module="com.android.runtime.release"
226
227work_dir=$(mktemp -d)
228mount_point="$work_dir/image"
229
230trap finish_target EXIT
231
232# Build the APEX package (optional).
233build_apex "$apex_module"
234
235# Set up APEX package.
236setup_target_apex "$apex_module" "$mount_point"
237
238# Run tests on APEX package.
239say "Checking APEX package $apex_module"
240check_release_contents
241
242# Clean up.
243trap - EXIT
244cleanup_target
245
246say "$apex_module tests passed"
247
248# Testing debug APEX package (com.android.runtime.debug).
249# -------------------------------------------------------
250
Alex Lightda948ce2018-12-06 17:05:41 +0000251apex_module="com.android.runtime.debug"
252
Roland Levillain996f42f2018-12-11 15:26:51 +0000253work_dir=$(mktemp -d)
254mount_point="$work_dir/image"
Alex Lightda948ce2018-12-06 17:05:41 +0000255
Roland Levillain996f42f2018-12-11 15:26:51 +0000256trap finish_target EXIT
Alex Lightda948ce2018-12-06 17:05:41 +0000257
Roland Levillain996f42f2018-12-11 15:26:51 +0000258# Build the APEX package (optional).
259build_apex "$apex_module"
Alex Lightda948ce2018-12-06 17:05:41 +0000260
Roland Levillain996f42f2018-12-11 15:26:51 +0000261# Set up APEX package.
262setup_target_apex "$apex_module" "$mount_point"
Alex Lightda948ce2018-12-06 17:05:41 +0000263
Roland Levillain996f42f2018-12-11 15:26:51 +0000264# Run tests on APEX package.
265say "Checking APEX package $apex_module"
266check_release_contents
267check_debug_contents
268# Check for files pulled in from debug target-only oatdump.
Roland Levillain38a938e2018-09-21 10:55:51 +0100269check_binary oatdump
Roland Levillain38a938e2018-09-21 10:55:51 +0100270check_library libart-disassembler.so
Roland Levillain38a938e2018-09-21 10:55:51 +0100271
Roland Levillain996f42f2018-12-11 15:26:51 +0000272# Clean up.
Alex Lightda948ce2018-12-06 17:05:41 +0000273trap - EXIT
Roland Levillain996f42f2018-12-11 15:26:51 +0000274cleanup_target
Roland Levillain38a938e2018-09-21 10:55:51 +0100275
Roland Levillain996f42f2018-12-11 15:26:51 +0000276say "$apex_module tests passed"
Alex Lightda948ce2018-12-06 17:05:41 +0000277
Roland Levillain996f42f2018-12-11 15:26:51 +0000278
279# Testing host APEX package (com.android.runtime.host).
280# =====================================================
281
282# Clean-up.
283function cleanup_host {
284 rm -rf "$work_dir"
285}
Alex Lightda948ce2018-12-06 17:05:41 +0000286
287# Garbage collection.
288function finish_host {
289 # Don't fail early during cleanup.
290 set +e
Roland Levillain996f42f2018-12-11 15:26:51 +0000291 cleanup_host
Alex Lightda948ce2018-12-06 17:05:41 +0000292}
293
Roland Levillain996f42f2018-12-11 15:26:51 +0000294# setup_host_apex APEX_MODULE MOUNT_POINT
295# ---------------------------------------
296# Extract Zip file from host APEX_MODULE and extract it in MOUNT_POINT.
297function 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
315apex_module="com.android.runtime.host"
316
Alex Lightda948ce2018-12-06 17:05:41 +0000317work_dir=$(mktemp -d)
318mount_point="$work_dir/zip"
319
320trap finish_host EXIT
321
Roland Levillain996f42f2018-12-11 15:26:51 +0000322# Build the APEX package (optional).
323build_apex "$apex_module"
Alex Lightda948ce2018-12-06 17:05:41 +0000324
Roland Levillain996f42f2018-12-11 15:26:51 +0000325# Set up APEX package.
326setup_host_apex "$apex_module" "$mount_point"
Alex Lightda948ce2018-12-06 17:05:41 +0000327
Roland Levillain996f42f2018-12-11 15:26:51 +0000328# Run tests on APEX package.
329say "Checking APEX package $apex_module"
330check_release_contents
331check_debug_contents
Alex Lightda948ce2018-12-06 17:05:41 +0000332
Roland Levillain996f42f2018-12-11 15:26:51 +0000333# Clean up.
334trap - EXIT
335cleanup_host
Alex Lightda948ce2018-12-06 17:05:41 +0000336
Roland Levillain996f42f2018-12-11 15:26:51 +0000337say "$apex_module tests passed"
Alex Lightda948ce2018-12-06 17:05:41 +0000338
Alex Lightda948ce2018-12-06 17:05:41 +0000339
Roland Levillain996f42f2018-12-11 15:26:51 +0000340say "All Android Runtime APEX tests passed"