| #!/usr/bin/env bash |
| |
| # Copyright 2020 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. |
| |
| source "$(dirname "${BASH_SOURCE[0]}")/../common.inc" |
| |
| default_var TIMEOUT 180s |
| default_var VHE 0 |
| default_var VERBOSE 0 |
| default_var QUIET 0 |
| default_var GDB 0 |
| default_var KERNEL "" |
| default_var TEST_PATH "" |
| default_var DISPLAY_NAME "" |
| default_var OUTPUT "" |
| |
| # QEMU CPUs to use for VHE and nVHE runs |
| CPU_VHE="max" |
| CPU_NVHE="cortex-a53" |
| |
| function usage() { |
| cat <<EOF |
| |
| Usage: $0 [-h] [-v] [-q] [-G] [-V] |
| [-k KERNEL] [-d DISPLAY_NAME] [-o OUTPUT] |
| PATH [-- RUN_QEMU_ARGS] |
| |
| PATH Path to test binary. Basenames are resolved in the default output folder. |
| -h Output this help text |
| -v Print invoked command |
| -q Print only the result of the test |
| -k Kernel image |
| -d Override test name displayed in result |
| -o Redirect stdout/stderr output to given file (implies -q) |
| -V Enable VHE configuration |
| -G Enable debugging of emulated system with GDB |
| EOF |
| } |
| |
| while getopts ":k:d:o:vVGqh" OPT; do |
| case "${OPT}" in |
| k) KERNEL="${OPTARG}" ;; |
| d) DISPLAY_NAME="${OPTARG}" ;; |
| v) VERBOSE=1 ;; |
| V) VHE=1 ;; |
| q) QUIET=1 ;; |
| G) GDB=1 ;; |
| o) |
| OUTPUT="${OPTARG}" |
| QUIET=1 |
| ;; |
| h) |
| usage |
| exit 0 |
| ;; |
| \?) |
| echo "Invalid option: ${!OPTIND}" 1>&2 |
| usage 1>&2 |
| exit 1 |
| ;; |
| :) |
| echo "Invalid option: -${OPTARG} requires an argument" 1>&2 |
| usage 1>&2 |
| exit 1 |
| ;; |
| esac |
| done |
| shift $((OPTIND -1)) |
| |
| # Parse test name from a positional argument. |
| if [ $# -eq 0 ]; then |
| usage 1>&2 |
| exit 1 |
| fi |
| TEST_PATH="$1" |
| shift 1 |
| |
| # If there are arguments after "--", pass them to the underlying run_qemu.sh. |
| RUN_QEMU_ARGS=() |
| if [ $# -gt 0 ]; then |
| if [ $1 = "--" ]; then |
| shift 1 |
| RUN_QEMU_ARGS=("$@") |
| else |
| echo "Unrecognized options: $@" 1>&2 |
| usage 1>&2 |
| exit 1 |
| fi |
| fi |
| |
| # Default display name is the basename from TEST_PATH. |
| if [ -z "${DISPLAY_NAME}" ]; then |
| DISPLAY_NAME="$(basename "${TEST_PATH}")" |
| fi |
| |
| # If TEST_PATH is just a basename, search for the test in |
| # the kvm-unit-tests' default output folder. |
| if [ "$(basename "${TEST_PATH}")" = "${TEST_PATH}" ]; then |
| TEST_PATH="${KUT_TEST_DIR}/${TEST_PATH}" |
| fi |
| |
| CMD=("${SCRIPT_RUN_QEMU}" -R "${TEST_PATH}" -t "${TIMEOUT}") |
| |
| if [ "${VHE}" -eq 1 ]; then |
| CMD+=(-c "${CPU_VHE}") |
| else |
| CMD+=(-c "${CPU_NVHE}") |
| fi |
| |
| if [ -n "${KERNEL}" ]; then |
| CMD+=(-k "${KERNEL}") |
| fi |
| |
| if [ "${GDB}" -eq 1 ]; then |
| CMD+=(-G) |
| fi |
| |
| # Extra arguments passed directly to the underlying script. |
| CMD+=("${RUN_QEMU_ARGS[@]}") |
| |
| # Disable exiting on failure. |
| set +eo pipefail |
| |
| if [ "${VERBOSE}" -eq 1 ]; then |
| echo "+ ${CMD[@]}" 1>&2 |
| fi |
| |
| if [ "${QUIET}" -eq 0 ]; then |
| exec "${CMD[@]}" |
| else |
| if [ -z "${OUTPUT}" ]; then |
| OUTPUT="$(mktemp)" |
| fi |
| |
| "${CMD[@]}" &> "${OUTPUT}" |
| EXIT_STATUS=$? |
| |
| RESULT=$(grep -E -h --color=never "[^ ](PASS|FAIL|SKIP)[^:]" "${OUTPUT}") |
| if [ -z "${RESULT}" ]; then |
| RESULT="\e[31;1mTIMEOUT/CRASH\e[0m" |
| EXIT_STATUS=1 |
| fi |
| |
| echo -e "${DISPLAY_NAME}: ${RESULT}" |
| exit ${EXIT_STATUS} |
| fi |