blob: 92702eeedc34bd4086ec8e20e810f2a42b908c3b [file] [log] [blame]
Jaewan Kimb5fb9692024-06-10 14:18:12 +09001#!/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## Booting tests for ferrochrome
18## Keep this file synced with docs/custom_vm.md
19
20set -e
21
22FECR_GS_URL="https://storage.googleapis.com/chromiumos-image-archive/ferrochrome-public"
23FECR_DEFAULT_VERSION="R127-15916.0.0"
24FECR_DEVICE_DIR="/data/local/tmp/ferrochrome"
25FECR_CONFIG_PATH="/data/local/tmp/vm_config.json" # hardcoded at VmLauncherApp
26FECR_CONSOLE_LOG_PATH="/data/data/\${pkg_name}/files/console.log"
27FECR_BOOT_COMPLETED_LOG="Have fun and send patches!"
28FECR_BOOT_TIMEOUT="300" # 5 minutes (300 seconds)
29AOSP_PKG_NAME="com.android.virtualization.vmlauncher"
30SIGNED_PKG_NAME="com.google.android.virtualization.vmlauncher"
31
32fecr_clean_up() {
33 trap - INT
34
35 if [[ -d ${fecr_dir} && -z ${fecr_keep} ]]; then
36 rm -rf ${fecr_dir}
37 fi
38}
39
40print_usage() {
41 echo "ferochrome.sh: Launches ferrochrome image"
42 echo ""
43 echo "By default, this downloads ferrochrome image with version ${FECR_DEFAULT_VERSION},"
44 echo "launches, and waits for boot completed."
45 echo "When done, removes downloaded image."
46 echo ""
47 echo "Usage: ferrochrome.sh [options]"
48 echo ""
49 echo "Options"
50 echo " --help or -h: This message"
51 echo " --dir \${dir}: Use ferrochrome images at the dir instead of downloading"
52 echo " --skip: Skipping downloading and/or pushing images"
53 echo " --version \${version}: ferrochrome version to be downloaded"
54 echo " --keep: Keep downloaded ferrochrome image"
55}
56
57
58fecr_version=""
59fecr_dir=""
60fecr_keep=""
61fecr_skip=""
62fecr_script_path=$(dirname ${0})
63
64# Parse parameters
65while (( "${#}" )); do
66 case "${1}" in
67 --version)
68 shift
69 fecr_version="${1}"
70 ;;
71 --dir)
72 shift
73 fecr_dir="${1}"
74 fecr_keep="true"
75 ;;
76 --keep)
77 fecr_keep="true"
78 ;;
79 --skip)
80 fecr_skip="true"
81 ;;
82 -h|--help)
83 print_usage
84 exit 0
85 ;;
86 *)
87 print_usage
88 exit 1
89 ;;
90 esac
91 shift
92done
93
94trap fecr_clean_up INT
95trap fecr_clean_up EXIT
96
97if [[ -z "${fecr_skip}" ]]; then
98 if [[ -z "${fecr_dir}" ]]; then
99 # Download fecr image archive, and extract necessary files
100 # DISCLAIMER: Image is too large (1.5G+ for compressed, 6.5G+ for uncompressed), so can't submit.
101 fecr_dir=$(mktemp -d)
102
Jaewan Kim94455ba2024-06-18 14:22:44 +0900103 echo "Downloading & extracting ferrochrome image to ${fecr_dir}"
Jaewan Kimb5fb9692024-06-10 14:18:12 +0900104 fecr_version=${fecr_version:-${FECR_DEFAULT_VERSION}}
Jaewan Kim94455ba2024-06-18 14:22:44 +0900105 curl ${FECR_GS_URL}/${fecr_version}/chromiumos_test_image.tar.xz | tar xfJ - -C ${fecr_dir}
Jaewan Kimb5fb9692024-06-10 14:18:12 +0900106 fi
107
108 echo "Pushing ferrochrome image to ${FECR_DEVICE_DIR}"
109 adb shell mkdir -p ${FECR_DEVICE_DIR} > /dev/null || true
110 adb push ${fecr_dir}/chromiumos_test_image.bin ${FECR_DEVICE_DIR}
Jaewan Kimb5fb9692024-06-10 14:18:12 +0900111 adb push ${fecr_script_path}/assets/vm_config.json ${FECR_CONFIG_PATH}
112fi
113
114adb root > /dev/null
115adb shell pm list packages | grep ${AOSP_PKG_NAME} > /dev/null
116if [[ "${?}" == "0" ]]; then
117 pkg_name=${AOSP_PKG_NAME}
118else
119 pkg_name=${SIGNED_PKG_NAME}
120fi
121
122adb shell pm enable ${pkg_name}/${AOSP_PKG_NAME}.MainActivity > /dev/null
123adb shell pm grant ${pkg_name} android.permission.USE_CUSTOM_VIRTUAL_MACHINE > /dev/null
124adb shell pm clear ${pkg_name} > /dev/null
125
126echo "Starting ferrochrome"
127adb shell am start-activity ${pkg_name}/${AOSP_PKG_NAME}.MainActivity > /dev/null
128
129log_path="/data/data/${pkg_name}/files/console.log"
130fecr_start_time=${EPOCHSECONDS}
131
132while [[ $((EPOCHSECONDS - fecr_start_time)) -lt ${FECR_BOOT_TIMEOUT} ]]; do
133 adb shell grep -sF \""${FECR_BOOT_COMPLETED_LOG}"\" "${log_path}" && exit 0
134 sleep 10
135done
136
137echo "Ferrochrome failed to boot"
138exit 1