Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 1 | #!/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 Gampe | a0242cf | 2019-01-29 13:01:23 -0800 | [diff] [blame] | 20 | SCRIPT_DIR=$(dirname $0) |
| 21 | |
Roland Levillain | 43c08d2 | 2019-01-18 18:58:47 +0000 | [diff] [blame] | 22 | # Status of whole test script. |
| 23 | exit_status=0 |
| 24 | # Status of current test suite. |
| 25 | test_status=0 |
| 26 | |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 27 | function say { |
| 28 | echo "$0: $*" |
| 29 | } |
| 30 | |
| 31 | function die { |
| 32 | echo "$0: $*" |
| 33 | exit 1 |
| 34 | } |
| 35 | |
Roland Levillain | dd20d00 | 2019-07-19 16:09:47 +0100 | [diff] [blame] | 36 | function setup_die { |
| 37 | die "You need to source and lunch before you can use this script." |
| 38 | } |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 39 | |
Roland Levillain | dd20d00 | 2019-07-19 16:09:47 +0100 | [diff] [blame] | 40 | [[ -n "$ANDROID_BUILD_TOP" ]] || setup_die |
| 41 | [[ -n "$ANDROID_PRODUCT_OUT" ]] || setup_die |
| 42 | [[ -n "$ANDROID_HOST_OUT" ]] || setup_die |
| 43 | |
| 44 | flattened_apex_p=$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash --dumpvar-mode TARGET_FLATTEN_APEX)\ |
| 45 | || setup_die |
Andreas Gampe | a0242cf | 2019-01-29 13:01:23 -0800 | [diff] [blame] | 46 | |
Martin Stjernholm | 3cb59a4 | 2019-08-07 17:18:29 +0100 | [diff] [blame] | 47 | have_debugfs_p=false |
Martin Stjernholm | 9d4fb71 | 2019-09-04 16:10:05 +0100 | [diff] [blame] | 48 | if $flattened_apex_p; then :; else |
Martin Stjernholm | 3cb59a4 | 2019-08-07 17:18:29 +0100 | [diff] [blame] | 49 | 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 Gampe | a0242cf | 2019-01-29 13:01:23 -0800 | [diff] [blame] | 54 | fi |
| 55 | |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 56 | # Fail early. |
| 57 | set -e |
| 58 | |
| 59 | build_apex_p=true |
| 60 | list_image_files_p=false |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame] | 61 | print_image_tree_p=false |
Roland Levillain | 88e5569 | 2019-07-25 15:57:06 +0100 | [diff] [blame] | 62 | print_file_sizes_p=false |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 63 | |
| 64 | function usage { |
| 65 | cat <<EOF |
| 66 | Usage: $0 [OPTION] |
| 67 | Build (optional) and run tests on Android Runtime APEX package (on host). |
| 68 | |
Roland Levillain | 88e5569 | 2019-07-25 15:57:06 +0100 | [diff] [blame] | 69 | -B, --skip-build skip the build step |
Roland Levillain | 336245d | 2019-03-21 16:11:52 +0000 | [diff] [blame] | 70 | -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 Levillain | e91d787 | 2019-07-25 18:56:06 +0100 | [diff] [blame] | 72 | -s, --print-sizes print the size in bytes of each file when listing contents |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 73 | -h, --help display this help and exit |
| 74 | |
| 75 | EOF |
| 76 | exit |
| 77 | } |
| 78 | |
| 79 | while [[ $# -gt 0 ]]; do |
| 80 | case "$1" in |
Roland Levillain | 88e5569 | 2019-07-25 15:57:06 +0100 | [diff] [blame] | 81 | (-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 Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 85 | (-h|--help) usage;; |
| 86 | (*) die "Unknown option: '$1' |
| 87 | Try '$0 --help' for more information.";; |
| 88 | esac |
| 89 | shift |
| 90 | done |
| 91 | |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 92 | # build_apex APEX_MODULES |
| 93 | # ----------------------- |
| 94 | # Build APEX packages APEX_MODULES. |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 95 | function build_apex { |
| 96 | if $build_apex_p; then |
Roland Levillain | 2b9c8c9 | 2019-07-31 18:54:40 +0100 | [diff] [blame] | 97 | say "Building $@" && build/soong/soong_ui.bash --make-mode "$@" || die "Cannot build $@" |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 98 | fi |
| 99 | } |
Roland Levillain | 38a938e | 2018-09-21 10:55:51 +0100 | [diff] [blame] | 100 | |
Andreas Gampe | a0242cf | 2019-01-29 13:01:23 -0800 | [diff] [blame] | 101 | # maybe_list_apex_contents_apex APEX TMPDIR [other] |
| 102 | function maybe_list_apex_contents_apex { |
Roland Levillain | e91d787 | 2019-07-25 18:56:06 +0100 | [diff] [blame] | 103 | local print_options=() |
| 104 | if $print_file_sizes_p; then |
| 105 | print_options+=(--size) |
| 106 | fi |
| 107 | |
Andreas Gampe | a0242cf | 2019-01-29 13:01:23 -0800 | [diff] [blame] | 108 | # List the contents of the apex in list form. |
| 109 | if $list_image_files_p; then |
| 110 | say "Listing image files" |
Roland Levillain | e91d787 | 2019-07-25 18:56:06 +0100 | [diff] [blame] | 111 | $SCRIPT_DIR/art_apex_test.py --list ${print_options[@]} $@ |
Andreas Gampe | a0242cf | 2019-01-29 13:01:23 -0800 | [diff] [blame] | 112 | 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 Levillain | e91d787 | 2019-07-25 18:56:06 +0100 | [diff] [blame] | 117 | $SCRIPT_DIR/art_apex_test.py --tree ${print_options[@]} $@ |
Andreas Gampe | a0242cf | 2019-01-29 13:01:23 -0800 | [diff] [blame] | 118 | fi |
| 119 | } |
| 120 | |
Roland Levillain | 43c08d2 | 2019-01-18 18:58:47 +0000 | [diff] [blame] | 121 | function fail_check { |
| 122 | echo "$0: FAILED: $*" |
| 123 | test_status=1 |
| 124 | exit_status=1 |
| 125 | } |
| 126 | |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 127 | # Test all modules |
| 128 | |
| 129 | apex_modules=( |
Martin Stjernholm | ad909af | 2019-07-16 17:02:44 +0100 | [diff] [blame] | 130 | "com.android.art.release" |
| 131 | "com.android.art.debug" |
| 132 | "com.android.art.testing" |
| 133 | "com.android.art.host" |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 134 | ) |
| 135 | |
| 136 | # Build the APEX packages (optional). |
| 137 | build_apex ${apex_modules[@]} |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 138 | |
| 139 | # Clean-up. |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 140 | function cleanup { |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 141 | rm -rf "$work_dir" |
| 142 | } |
| 143 | |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 144 | # Garbage collection. |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 145 | function finish { |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 146 | # Don't fail early during cleanup. |
| 147 | set +e |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 148 | cleanup |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 149 | } |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 150 | |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 151 | for 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 Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 156 | |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 157 | 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 Levillain | dd20d00 | 2019-07-19 16:09:47 +0100 | [diff] [blame] | 164 | 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 Stjernholm | 3cb59a4 | 2019-08-07 17:18:29 +0100 | [diff] [blame] | 170 | if $have_debugfs_p; then |
| 171 | art_apex_test_args="$art_apex_test_args --debugfs $ANDROID_HOST_OUT/bin/debugfs" |
| 172 | fi |
Roland Levillain | 61f0716 | 2019-06-26 12:44:04 +0100 | [diff] [blame] | 173 | case $apex_module in |
| 174 | (*.debug) test_only_args="--debug";; |
| 175 | (*.testing) test_only_args="--testing";; |
| 176 | esac |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 177 | fi |
Roland Levillain | dd20d00 | 2019-07-19 16:09:47 +0100 | [diff] [blame] | 178 | say "APEX package path: $apex_path" |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 179 | |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 180 | # List the contents of the APEX image (optional). |
| 181 | maybe_list_apex_contents_apex $art_apex_test_args $apex_path |
Roland Levillain | 04e83d1 | 2018-11-16 15:03:47 +0000 | [diff] [blame] | 182 | |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 183 | # 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 Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 186 | |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 187 | # Clean up. |
| 188 | trap - EXIT |
| 189 | cleanup |
Roland Levillain | 996f42f | 2018-12-11 15:26:51 +0000 | [diff] [blame] | 190 | |
Martin Stjernholm | 6c5ed85 | 2019-03-18 21:02:28 +0000 | [diff] [blame] | 191 | [[ "$test_status" = 0 ]] && say "$apex_module tests passed" |
| 192 | echo |
| 193 | done |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 194 | |
Roland Levillain | 43c08d2 | 2019-01-18 18:58:47 +0000 | [diff] [blame] | 195 | [[ "$exit_status" = 0 ]] && say "All Android Runtime APEX tests passed" |
Alex Light | da948ce | 2018-12-06 17:05:41 +0000 | [diff] [blame] | 196 | |
Roland Levillain | 43c08d2 | 2019-01-18 18:58:47 +0000 | [diff] [blame] | 197 | exit $exit_status |