blob: 7acdacaf44928061fab01faceb052e5a7d7c49e2 [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
Andreas Gampea0242cf2019-01-29 13:01:23 -080020SCRIPT_DIR=$(dirname $0)
21
Roland Levillain43c08d22019-01-18 18:58:47 +000022# Status of whole test script.
23exit_status=0
24# Status of current test suite.
25test_status=0
26
Roland Levillain38a938e2018-09-21 10:55:51 +010027function say {
28 echo "$0: $*"
29}
30
31function die {
32 echo "$0: $*"
33 exit 1
34}
35
Roland Levillaindd20d002019-07-19 16:09:47 +010036function setup_die {
37 die "You need to source and lunch before you can use this script."
38}
Roland Levillain38a938e2018-09-21 10:55:51 +010039
Roland Levillaindd20d002019-07-19 16:09:47 +010040[[ -n "$ANDROID_BUILD_TOP" ]] || setup_die
41[[ -n "$ANDROID_PRODUCT_OUT" ]] || setup_die
42[[ -n "$ANDROID_HOST_OUT" ]] || setup_die
43
44flattened_apex_p=$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash --dumpvar-mode TARGET_FLATTEN_APEX)\
45 || setup_die
Andreas Gampea0242cf2019-01-29 13:01:23 -080046
Martin Stjernholm3cb59a42019-08-07 17:18:29 +010047have_debugfs_p=false
Martin Stjernholm9d4fb712019-09-04 16:10:05 +010048if $flattened_apex_p; then :; else
Martin Stjernholm3cb59a42019-08-07 17:18:29 +010049 if [ ! -e "$ANDROID_HOST_OUT/bin/debugfs" ] ; then
50 say "Could not find debugfs, building now."
51 build/soong/soong_ui.bash --make-mode debugfs-host || die "Cannot build debugfs"
52 fi
53 have_debugfs_p=true
Andreas Gampea0242cf2019-01-29 13:01:23 -080054fi
55
Roland Levillain38a938e2018-09-21 10:55:51 +010056# Fail early.
57set -e
58
59build_apex_p=true
60list_image_files_p=false
Roland Levillain04e83d12018-11-16 15:03:47 +000061print_image_tree_p=false
Roland Levillain88e55692019-07-25 15:57:06 +010062print_file_sizes_p=false
Roland Levillain38a938e2018-09-21 10:55:51 +010063
64function usage {
65 cat <<EOF
66Usage: $0 [OPTION]
67Build (optional) and run tests on Android Runtime APEX package (on host).
68
Roland Levillain88e55692019-07-25 15:57:06 +010069 -B, --skip-build skip the build step
Roland Levillain336245d2019-03-21 16:11:52 +000070 -l, --list-files list the contents of the ext4 image (\`find\`-like style)
71 -t, --print-tree list the contents of the ext4 image (\`tree\`-like style)
Roland Levillaine91d7872019-07-25 18:56:06 +010072 -s, --print-sizes print the size in bytes of each file when listing contents
Roland Levillain38a938e2018-09-21 10:55:51 +010073 -h, --help display this help and exit
74
75EOF
76 exit
77}
78
79while [[ $# -gt 0 ]]; do
80 case "$1" in
Roland Levillain88e55692019-07-25 15:57:06 +010081 (-B|--skip-build) build_apex_p=false;;
82 (-l|--list-files) list_image_files_p=true;;
83 (-t|--print-tree) print_image_tree_p=true;;
84 (-s|--print-sizes) print_file_sizes_p=true;;
Roland Levillain38a938e2018-09-21 10:55:51 +010085 (-h|--help) usage;;
86 (*) die "Unknown option: '$1'
87Try '$0 --help' for more information.";;
88 esac
89 shift
90done
91
Martin Stjernholm6c5ed852019-03-18 21:02:28 +000092# build_apex APEX_MODULES
93# -----------------------
94# Build APEX packages APEX_MODULES.
Roland Levillain996f42f2018-12-11 15:26:51 +000095function build_apex {
96 if $build_apex_p; then
Roland Levillain2b9c8c92019-07-31 18:54:40 +010097 say "Building $@" && build/soong/soong_ui.bash --make-mode "$@" || die "Cannot build $@"
Roland Levillain996f42f2018-12-11 15:26:51 +000098 fi
99}
Roland Levillain38a938e2018-09-21 10:55:51 +0100100
Andreas Gampea0242cf2019-01-29 13:01:23 -0800101# maybe_list_apex_contents_apex APEX TMPDIR [other]
102function maybe_list_apex_contents_apex {
Roland Levillaine91d7872019-07-25 18:56:06 +0100103 local print_options=()
104 if $print_file_sizes_p; then
105 print_options+=(--size)
106 fi
107
Andreas Gampea0242cf2019-01-29 13:01:23 -0800108 # List the contents of the apex in list form.
109 if $list_image_files_p; then
110 say "Listing image files"
Roland Levillaine91d7872019-07-25 18:56:06 +0100111 $SCRIPT_DIR/art_apex_test.py --list ${print_options[@]} $@
Andreas Gampea0242cf2019-01-29 13:01:23 -0800112 fi
113
114 # List the contents of the apex in tree form.
115 if $print_image_tree_p; then
116 say "Printing image tree"
Roland Levillaine91d7872019-07-25 18:56:06 +0100117 $SCRIPT_DIR/art_apex_test.py --tree ${print_options[@]} $@
Andreas Gampea0242cf2019-01-29 13:01:23 -0800118 fi
119}
120
Roland Levillain43c08d22019-01-18 18:58:47 +0000121function fail_check {
122 echo "$0: FAILED: $*"
123 test_status=1
124 exit_status=1
125}
126
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000127# Test all modules
128
129apex_modules=(
Martin Stjernholmad909af2019-07-16 17:02:44 +0100130 "com.android.art.release"
131 "com.android.art.debug"
132 "com.android.art.testing"
133 "com.android.art.host"
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000134)
135
136# Build the APEX packages (optional).
137build_apex ${apex_modules[@]}
Roland Levillain996f42f2018-12-11 15:26:51 +0000138
139# Clean-up.
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000140function cleanup {
Alex Lightda948ce2018-12-06 17:05:41 +0000141 rm -rf "$work_dir"
142}
143
Roland Levillain996f42f2018-12-11 15:26:51 +0000144# Garbage collection.
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000145function finish {
Roland Levillain996f42f2018-12-11 15:26:51 +0000146 # Don't fail early during cleanup.
147 set +e
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000148 cleanup
Roland Levillain996f42f2018-12-11 15:26:51 +0000149}
Alex Lightda948ce2018-12-06 17:05:41 +0000150
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000151for apex_module in ${apex_modules[@]}; do
152 test_status=0
153 say "Checking APEX package $apex_module"
154 work_dir=$(mktemp -d)
155 trap finish EXIT
Roland Levillain996f42f2018-12-11 15:26:51 +0000156
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000157 art_apex_test_args="--tmpdir $work_dir"
158 test_only_args=""
159 if [[ $apex_module = *.host ]]; then
160 apex_path="$ANDROID_HOST_OUT/apex/${apex_module}.zipapex"
161 art_apex_test_args="$art_apex_test_args --host"
162 test_only_args="--debug"
163 else
Roland Levillaindd20d002019-07-19 16:09:47 +0100164 if $flattened_apex_p; then
165 apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}"
166 art_apex_test_args="$art_apex_test_args --flattened"
167 else
168 apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}.apex"
169 fi
Martin Stjernholm3cb59a42019-08-07 17:18:29 +0100170 if $have_debugfs_p; then
171 art_apex_test_args="$art_apex_test_args --debugfs $ANDROID_HOST_OUT/bin/debugfs"
172 fi
Roland Levillain61f07162019-06-26 12:44:04 +0100173 case $apex_module in
174 (*.debug) test_only_args="--debug";;
175 (*.testing) test_only_args="--testing";;
176 esac
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000177 fi
Roland Levillaindd20d002019-07-19 16:09:47 +0100178 say "APEX package path: $apex_path"
Roland Levillain996f42f2018-12-11 15:26:51 +0000179
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000180 # List the contents of the APEX image (optional).
181 maybe_list_apex_contents_apex $art_apex_test_args $apex_path
Roland Levillain04e83d12018-11-16 15:03:47 +0000182
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000183 # Run tests on APEX package.
184 $SCRIPT_DIR/art_apex_test.py $art_apex_test_args $test_only_args $apex_path \
185 || fail_check "Checks failed on $apex_module"
Roland Levillain996f42f2018-12-11 15:26:51 +0000186
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000187 # Clean up.
188 trap - EXIT
189 cleanup
Roland Levillain996f42f2018-12-11 15:26:51 +0000190
Martin Stjernholm6c5ed852019-03-18 21:02:28 +0000191 [[ "$test_status" = 0 ]] && say "$apex_module tests passed"
192 echo
193done
Alex Lightda948ce2018-12-06 17:05:41 +0000194
Roland Levillain43c08d22019-01-18 18:58:47 +0000195[[ "$exit_status" = 0 ]] && say "All Android Runtime APEX tests passed"
Alex Lightda948ce2018-12-06 17:05:41 +0000196
Roland Levillain43c08d22019-01-18 18:58:47 +0000197exit $exit_status