| #!/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. |
| |
| # Variables to represent VHE and nVHE emulation parameter |
| VHE=1 |
| NVHE=0 |
| |
| function get_qemu_binary() |
| { |
| local qemucmd |
| local qemu |
| |
| qemucmd=${QEMU:-qemu-system-aarch64} |
| if $qemucmd --help 2>/dev/null | grep -q 'QEMU'; then |
| qemu="$qemucmd" |
| fi |
| |
| if [ -z "${qemu}" ]; then |
| return |
| fi |
| |
| command -v "${qemu}" |
| } |
| |
| function get_outcome() |
| { |
| grep -E -h --color=never "[^ ](PASS|FAIL|SKIP)[^:]" |
| } |
| |
| function usage() |
| { |
| cat <<EOF |
| |
| Usage: $0 [-h] [-t TEST-FILES] [-j NUM-TASKS] [-l KERNEL] [-e QEMU] [-r ROOT] |
| |
| -h Output this help text |
| -t kvm-unit-tests standalone directory |
| -x tests to exclude (regex), can be specified more than once |
| -j Execute tests in parallel |
| -l Linux kernel image to use |
| -e QEMU emulator binary |
| -r Root file system image to use |
| |
| EOF |
| } |
| |
| function usage_abort() |
| { |
| usage |
| exit 1 |
| } |
| |
| function run_job() |
| { |
| local job="$1" |
| if [ -z "$job" ]; then |
| return |
| fi |
| |
| while (( $(jobs | wc -l) == $j )); do |
| # Wait for background jobs |
| wait -n 2>/dev/null |
| done |
| |
| if [ $j = 1 ]; then |
| bash -c "$@" |
| else |
| bash -c "$@" & |
| fi |
| } |
| |
| script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| test_dir="" |
| exclude_regex="" |
| j=1 |
| linux="" |
| rootfs="" |
| verbose=${VERBOSE:-0} |
| qemu=$(get_qemu_binary) |
| |
| while getopts ":t:x:j:l:r:e:hv" opt; do |
| case "${opt}" in |
| t) |
| test_dir=${OPTARG} |
| ;; |
| x) |
| # OR with the previous regex if specified |
| if [ ! -z $exclude_regex ]; then |
| exclude_regex+="|" |
| fi |
| exclude_regex+="(^${OPTARG}$)" |
| ;; |
| j) |
| j=${OPTARG} |
| ;; |
| l) |
| linux=${OPTARG} |
| ;; |
| r) |
| rootfs=${OPTARG} |
| ;; |
| e) |
| qemu=${OPTARG} |
| ;; |
| h) |
| usage |
| exit 0 |
| ;; |
| v) |
| verbose=1 |
| ;; |
| *) |
| usage_abort |
| ;; |
| esac |
| done |
| if ((OPTIND == 1)); then |
| usage_abort |
| fi |
| shift $((OPTIND-1)) |
| |
| if [[ ! -d ${test_dir} ]]; then |
| echo "No test directory specified." |
| usage_abort |
| fi |
| |
| if [[ ! -f ${linux} ]]; then |
| echo "Linux kernel image file not found." |
| usage_abort |
| fi |
| |
| if [[ ! -f ${rootfs} ]]; then |
| echo "Root filesystem image file not found." |
| usage_abort |
| fi |
| |
| if [[ ! -x ${qemu} ]]; then |
| echo "QEMU executable not found." |
| usage_abort |
| fi |
| |
| rm -rf logs.old |
| if [ -d logs ]; then |
| mv logs logs.old |
| fi |
| mkdir -p logs/vhe || exit 2 |
| mkdir -p logs/nvhe || exit 2 |
| |
| for test in ${test_dir}/*; do |
| test_name="$(basename ${test})" |
| |
| if [[ ! -z $exclude_regex && "${test_name}" =~ ${exclude_regex} ]]; then |
| if [ "$verbose" != "0" ]; then |
| echo "Excluding ${test_name}" |
| fi |
| continue |
| fi |
| |
| if [ "$verbose" != "0" ]; then |
| echo "Running ${test_name}" |
| fi |
| |
| # Redirect output instead of pipe to preserve exit status. |
| run_job "${script_dir}/run_emu.sh ${test} ${linux} ${rootfs} ${qemu} ${VHE} &> >(tee logs/vhe/${test_name}.log | grep -E -h --color=never \"[^ ](PASS|FAIL|SKIP)[^:]\")" |
| run_job "${script_dir}/run_emu.sh ${test} ${linux} ${rootfs} ${qemu} ${NVHE} &> >(tee logs/nvhe/${test_name}.log | grep -E -h --color=never \"[^ ](PASS|FAIL|SKIP)[^:]\")" |
| done |
| wait |