Jaewan Kim | 3ad58c3 | 2024-06-13 08:59:29 +0000 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2024 Google Inc. All rights reserved. |
| 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 | ## Precondition checks for running ferrochrome |
| 19 | ## Used by CI for skipping tests. |
| 20 | |
| 21 | REQUIRED_DISK_SPACE=7340032 # Requires 7G, while image is 6.5G |
| 22 | |
| 23 | # `adb root` always returns exit code 0 |
| 24 | if [[ "$(adb root)" == *"cannot"* ]]; then |
| 25 | >&2 echo "Failed to run adb root" |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | # `pm resolve-activity` always returns exit code 0 |
| 30 | resolved_activity=$(adb shell pm resolve-activity -a android.virtualization.VM_LAUNCHER) |
| 31 | if [[ "${resolved_activity}" == "No activity found" ]]; then |
| 32 | >&2 echo "Failed to find vmlauncher" |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
| 36 | free_space=$(adb shell df /data/local | tail -1 | awk '{print $4}') |
| 37 | if [[ ${free_space} -lt ${REQUIRED_DISK_SPACE} ]]; then |
| 38 | >&2 echo "Insufficient space on DUT. Need ${REQUIRED_DISK_SPACE}, but was ${free_space}" |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | free_space=$(df /tmp | tail -1 | awk '{print $4}') |
| 43 | if [[ ${free_space} -lt ${REQUIRED_DISK_SPACE} ]]; then |
| 44 | >&2 echo "Insufficient space on host. Need ${REQUIRED_DISK_SPACE}, but was ${free_space}" |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | cpu_abi=$(adb shell getprop ro.product.cpu.abi) |
| 49 | if [[ "${cpu_abi}" != "arm64"* ]]; then |
| 50 | >&2 echo "Unsupported architecture. Requires arm64, but was ${cpu_abi}" |
| 51 | exit 1 |
| 52 | fi |
| 53 | |
| 54 | device=$(adb shell getprop ro.product.vendor.device) |
| 55 | if [[ "${device}" == "vsock_"* ]]; then |
| 56 | >&2 echo "Unsupported device. Cuttlefish isn't supported" |
| 57 | exit 1 |
| 58 | fi |