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