blob: c19c7bd94ca3d68ce9fa3c269e8452e6337ec131 [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
69work_dir=$(mktemp -d)
70mount_point="$work_dir/image"
71
Roland Levillain38a938e2018-09-21 10:55:51 +010072function check_binary {
73 [[ -x "$mount_point/bin/$1" ]] || die "Cannot find binary '$1' in mounted image"
74}
75
76function check_multilib_binary {
77 # TODO: Use $TARGET_ARCH (e.g. check whether it is "arm" or "arm64") to improve
78 # the precision of this test?
79 [[ -x "$mount_point/bin/${1}32" ]] || [[ -x "$mount_point/bin/${1}64" ]] \
80 || die "Cannot find binary '$1' in mounted image"
81}
82
83function check_binary_symlink {
84 [[ -h "$mount_point/bin/$1" ]] || die "Cannot find symbolic link '$1' in mounted image"
85}
86
87function check_library {
88 # TODO: Use $TARGET_ARCH (e.g. check whether it is "arm" or "arm64") to improve
89 # the precision of this test?
90 [[ -f "$mount_point/lib/$1" ]] || [[ -f "$mount_point/lib64/$1" ]] \
91 || die "Cannot find library '$1' in mounted image"
92}
93
Alex Lightda948ce2018-12-06 17:05:41 +000094function build_apex {
95 if $build_apex_p; then
96 say "Building package $1" && make "$1" || die "Cannot build $1"
97 fi
98}
Roland Levillain38a938e2018-09-21 10:55:51 +010099
Alex Lightda948ce2018-12-06 17:05:41 +0000100function check_contents {
101
102 # Check that the mounted image contains a manifest.
103 [[ -f "$mount_point/apex_manifest.json" ]] || die "no manifest"
104
105 # Check that the mounted image contains ART base binaries.
106 check_multilib_binary dalvikvm
107 # TODO: Does not work yet.
108 : check_binary_symlink dalvikvm
109 check_binary dex2oat
110 check_binary dexoptanalyzer
111 check_binary profman
112
113 # Check that the mounted image contains ART tools binaries.
114 check_binary dexdiag
115 check_binary dexdump
116 check_binary dexlist
117 # oatdump is only in device apex's due to build rules
118 # check_binary oatdump
119
120 # Check that the mounted image contains ART debug binaries.
121 check_binary dex2oatd
122 check_binary dexoptanalyzerd
123 check_binary profmand
124
125 # Check that the mounted image contains ART libraries.
126 check_library libart-compiler.so
127 check_library libart.so
128 check_library libopenjdkjvm.so
129 check_library libopenjdkjvmti.so
130 check_library libadbconnection.so
131 # TODO: Should we check for these libraries too, even if they are not explicitly
132 # listed as dependencies in the Android Runtime APEX module rule?
133 check_library libartbase.so
134 check_library libart-dexlayout.so
135 check_library libdexfile.so
136 check_library libprofile.so
137
138 # Check that the mounted image contains ART debug libraries.
139 check_library libartd-compiler.so
140 check_library libartd.so
141 check_library libopenjdkd.so
142 check_library libopenjdkjvmd.so
143 check_library libopenjdkjvmtid.so
144 check_library libadbconnectiond.so
145 # TODO: Should we check for these libraries too, even if they are not explicitly
146 # listed as dependencies in the Android Runtime APEX module rule?
147 check_library libdexfiled.so
148 check_library libartbased.so
149 check_library libartd-dexlayout.so
150 check_library libprofiled.so
151
152 # TODO: Should we check for other libraries, such as:
153 #
154 # libbacktrace.so
155 # libbase.so
156 # liblog.so
157 # libsigchain.so
158 # libtombstoned_client.so
159 # libunwindstack.so
160 # libvixl.so
161 # libvixld.so
162 # ...
163 #
164 # ?
165}
166
167
168# *****************************************
169# * Testing for com.android.runtime.debug *
170# *****************************************
171
172# Garbage collection.
173function finish_device_debug {
174 # Don't fail early during cleanup.
175 set +e
176 guestunmount "$mount_point"
177 rm -rf "$work_dir"
178}
179
180trap finish_device_debug EXIT
181
182# TODO: Also exercise the Release Runtime APEX (`com.android.runtime.release`).
183apex_module="com.android.runtime.debug"
184
185# Build the Android Runtime APEX package (optional).
186build_apex $apex_module
187
188system_apexdir="$ANDROID_PRODUCT_OUT/system/apex"
189apex_package="$system_apexdir/$apex_module.apex"
190
191say "Extracting and mounting image"
192
193# Extract the payload from the Android Runtime APEX.
194image_filename="apex_payload.img"
195unzip -q "$apex_package" "$image_filename" -d "$work_dir"
196mkdir "$mount_point"
197image_file="$work_dir/$image_filename"
198
199# Check filesystems in the image.
200image_filesystems="$work_dir/image_filesystems"
201virt-filesystems -a "$image_file" >"$image_filesystems"
202# We expect a single partition (/dev/sda) in the image.
203partition="/dev/sda"
204echo "$partition" | cmp "$image_filesystems" -
205
206# Mount the image from the Android Runtime APEX.
207guestmount -a "$image_file" -m "$partition" "$mount_point"
208
209# List the contents of the mounted image (optional).
210$list_image_files_p && say "Listing image files" && ls -ld "$mount_point" && tree -ap "$mount_point"
211
212say "Running tests"
213
214check_contents
215
216# Check for files pulled in from device-only oatdump.
Roland Levillain38a938e2018-09-21 10:55:51 +0100217check_binary oatdump
Roland Levillain38a938e2018-09-21 10:55:51 +0100218check_library libart-disassembler.so
Roland Levillain38a938e2018-09-21 10:55:51 +0100219
Alex Lightda948ce2018-12-06 17:05:41 +0000220# Cleanup
221trap - EXIT
222guestunmount "$mount_point"
223rm -rf "$work_dir"
Roland Levillain38a938e2018-09-21 10:55:51 +0100224
Alex Lightda948ce2018-12-06 17:05:41 +0000225say "$apex_module Tests passed"
226
227# ****************************************
228# * Testing for com.android.runtime.host *
229# ****************************************
230
231# Garbage collection.
232function finish_host {
233 # Don't fail early during cleanup.
234 set +e
235 rm -rf "$work_dir"
236}
237
238work_dir=$(mktemp -d)
239mount_point="$work_dir/zip"
240
241trap finish_host EXIT
242
243apex_module="com.android.runtime.host"
244
245# Build the Android Runtime APEX package (optional).
246build_apex $apex_module
247
248system_apexdir="$ANDROID_HOST_OUT/apex"
249apex_package="$system_apexdir/$apex_module.zipapex"
250
251say "Extracting payload"
252
253# Extract the payload from the Android Runtime APEX.
254image_filename="apex_payload.zip"
255unzip -q "$apex_package" "$image_filename" -d "$work_dir"
256mkdir "$mount_point"
257image_file="$work_dir/$image_filename"
258
259# Unzipping the payload
260unzip -q "$image_file" -d "$mount_point"
261
262say "Running tests"
263
264check_contents
265
266say "$apex_module Tests passed"
Roland Levillain38a938e2018-09-21 10:55:51 +0100267
268say "Tests passed"