blob: 86cd8cb758ef9abe7b4e23852fa11cd8ef2a5834 [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
72# Garbage collection.
73function finish {
74 # Don't fail early during cleanup.
75 set +e
76 guestunmount "$mount_point"
77 rm -rf "$work_dir"
78}
79
80trap finish EXIT
81
Roland Levillain53058802018-11-14 17:32:18 +000082# TODO: Also exercise the Release Runtime APEX (`com.android.runtime.release`).
83apex_module="com.android.runtime.debug"
Roland Levillain38a938e2018-09-21 10:55:51 +010084
85# Build the Android Runtime APEX package (optional).
86$build_apex_p && say "Building package" && make "$apex_module"
87
88system_apexdir="$ANDROID_PRODUCT_OUT/system/apex"
89apex_package="$system_apexdir/$apex_module.apex"
90
91say "Extracting and mounting image"
92
93# Extract the image from the Android Runtime APEX.
94image_filename="image.img"
95unzip -q "$apex_package" "$image_filename" -d "$work_dir"
96mkdir "$mount_point"
97image_file="$work_dir/$image_filename"
98
99# Check filesystems in the image.
100image_filesystems="$work_dir/image_filesystems"
101virt-filesystems -a "$image_file" >"$image_filesystems"
102# We expect a single partition (/dev/sda) in the image.
103partition="/dev/sda"
104echo "$partition" | cmp "$image_filesystems" -
105
106# Mount the image from the Android Runtime APEX.
107guestmount -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
112say "Running tests"
113
114# Check that the mounted image contains a manifest.
115[[ -f "$mount_point/manifest.json" ]]
116
117function check_binary {
118 [[ -x "$mount_point/bin/$1" ]] || die "Cannot find binary '$1' in mounted image"
119}
120
121function 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
128function check_binary_symlink {
129 [[ -h "$mount_point/bin/$1" ]] || die "Cannot find symbolic link '$1' in mounted image"
130}
131
132function 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.
140check_multilib_binary dalvikvm
141# TODO: Does not work yet.
142: check_binary_symlink dalvikvm
143check_binary dex2oat
144check_binary dexoptanalyzer
145check_binary profman
146
147# Check that the mounted image contains ART tools binaries.
148check_binary dexdiag
149check_binary dexdump
150check_binary dexlist
151check_binary oatdump
152
153# Check that the mounted image contains ART debug binaries.
154check_binary dex2oatd
155check_binary dexoptanalyzerd
156check_binary profmand
157
158# Check that the mounted image contains ART libraries.
159check_library libart-compiler.so
160check_library libart.so
161check_library libopenjdkjvm.so
162check_library libopenjdkjvmti.so
163check_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?
166check_library libartbase.so
167check_library libart-dexlayout.so
168check_library libart-disassembler.so
169check_library libdexfile.so
170check_library libprofile.so
171
172# Check that the mounted image contains ART debug libraries.
173check_library libartd-compiler.so
174check_library libartd.so
175check_library libdexfiled.so
176check_library libopenjdkd.so
177check_library libopenjdkjvmd.so
178check_library libopenjdkjvmtid.so
179check_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?
182check_library libartbased.so
183check_library libartd-dexlayout.so
184check_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 Levillain53058802018-11-14 17:32:18 +0000194# libvixl.so
195# libvixld.so
Roland Levillain38a938e2018-09-21 10:55:51 +0100196# ...
197#
198# ?
199
200say "Tests passed"