| #!/usr/bin/env bash |
| |
| # Copyright 2021 The Android KVM Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| set -eufo pipefail |
| |
| PASS() { echo -e "\e[32mPASS\e[0m"; } |
| FAIL() { echo -e "\e[31mFAIL\e[0m"; } |
| |
| CLIENT_SH=/dev/vdc |
| KERNEL_IMAGE=/dev/vdd |
| ROOT_FS=/dev/vde |
| CROSVM_FS=/dev/vdf |
| |
| KERNEL_BIN=/tmp/kernel |
| GUEST_LOG=/tmp/guest.log |
| |
| CROSVM_MOUNT=/mnt |
| CROSVM=${CROSVM_MOUNT}/bin/crosvm |
| |
| mount ${CROSVM_FS} ${CROSVM_MOUNT} |
| |
| # Try to extract first (assuming this is Image.gz), otherwise |
| # assume it is a raw binary. |
| (zcat ${KERNEL_IMAGE} > ${KERNEL_BIN}) || \ |
| cp ${KERNEL_IMAGE} ${KERNEL_BIN} |
| |
| ${CROSVM} run --disable-sandbox \ |
| -r ${ROOT_FS} -d ${CLIENT_SH} \ |
| --serial=type=stdout,hardware=virtio-console \ |
| ${KERNEL_BIN} | tee ${GUEST_LOG} |
| EXIT_STATUS=$? |
| |
| if [ ${EXIT_STATUS} -eq 0 ]; then |
| if grep 'Hello World!' ${GUEST_LOG} >/dev/null; then |
| PASS |
| else |
| FAIL |
| EXIT_STATUS=1 |
| fi |
| else |
| FAIL |
| fi |
| exit ${EXIT_STATUS} |