1#!/bin/bash
2#
3# Copyright 2018 The Hafnium Authors.
4#
5# Use of this source code is governed by a BSD-style
6# license that can be found in the LICENSE file or at
7# https://opensource.org/licenses/BSD-3-Clause.
8
9# Note: this assumes that the images have all been built and the current working
10# directory is the root of the repo.
11
12USE_FVP=false
13USE_TFA=false
14USE_VHE=false
15EL0_TEST_ONLY=false
16SKIP_LONG_RUNNING_TESTS=false
17SKIP_UNIT_TESTS=false
18RUN_ALL_QEMU_CPUS=false
19ASSERT_DISABLED_BUILD=false
20DEFAULT_HFTEST_TIMEOUT="600s"
21
22while test $# -gt 0
23do
24  case "$1" in
25    --fvp) USE_FVP=true
26      ;;
27    --tfa) USE_TFA=true
28      ;;
29    --vhe) USE_VHE=true
30      ;;
31    --el0) EL0_TEST_ONLY=true
32      ;;
33    --skip-unit-tests) SKIP_UNIT_TESTS=true
34      ;;
35    --skip-long-running-tests) SKIP_LONG_RUNNING_TESTS=true
36      ;;
37    --run-all-qemu-cpus) RUN_ALL_QEMU_CPUS=true
38      ;;
39    --assert-disabled-build) ASSERT_DISABLED_BUILD=true
40      ;;
41    *) echo "Unexpected argument $1"
42      exit 1
43      ;;
44  esac
45  shift
46done
47
48# TIMEOUT, PROJECT, OUT, LOG_DIR_BASE set in:
49KOKORO_DIR="$(dirname "$0")"
50source $KOKORO_DIR/test_common.sh
51
52# Run the tests with a timeout so they can't loop forever.
53HFTEST=(${TIMEOUT[@]} $DEFAULT_HFTEST_TIMEOUT ./test/hftest/hftest.py)
54HYPERVISOR_PATH="$OUT/"
55if [ $USE_FVP == true ]
56then
57if [ $USE_VHE == true ]
58then
59  HYPERVISOR_PATH+="aem_v8a_fvp_vhe_clang"
60  HFTEST+=(--out_initrd "$OUT/aem_v8a_fvp_vhe_vm_clang")
61  HFTEST+=(--out_partitions "$OUT/aem_v8a_fvp_vhe_vm_clang")
62  HFTEST+=(--driver=fvp)
63else
64  HYPERVISOR_PATH+="aem_v8a_fvp_clang"
65  HFTEST+=(--out_initrd "$OUT/aem_v8a_fvp_vm_clang")
66  HFTEST+=(--out_partitions "$OUT/aem_v8a_fvp_vm_clang")
67  HFTEST+=(--driver=fvp)
68fi
69else
70if [ $USE_VHE == true ]
71then
72  HYPERVISOR_PATH+="qemu_aarch64_vhe_clang"
73  HFTEST+=(--out_initrd "$OUT/qemu_aarch64_vhe_vm_clang")
74else
75  HYPERVISOR_PATH+="qemu_aarch64_clang"
76  HFTEST+=(--out_initrd "$OUT/qemu_aarch64_vm_clang")
77fi
78fi
79if [ $USE_TFA == true ]
80then
81  HFTEST+=(--tfa)
82fi
83if [ $SKIP_LONG_RUNNING_TESTS == true ]
84then
85  HFTEST+=(--skip-long-running-tests)
86fi
87
88if [ $SKIP_UNIT_TESTS == false ]
89then
90# Run the host unit tests.
91mkdir -p "${LOG_DIR_BASE}/unit_tests"
92  ${TIMEOUT[@]} 30s "$OUT/host_fake_clang/unit_tests" \
93    --gtest_output="xml:${LOG_DIR_BASE}/unit_tests/sponge_log.xml" \
94    | tee "${LOG_DIR_BASE}/unit_tests/sponge_log.log"
95fi
96
97CPUS=("")
98
99if [ $RUN_ALL_QEMU_CPUS == true ]
100then
101  CPUS=("cortex-a53" "max")
102fi
103
104for CPU in "${CPUS[@]}"
105do
106  HFTEST_CPU=("${HFTEST[@]}")
107  if [ -n "$CPU" ]
108  then
109    # Per-CPU log directory to avoid filename conflicts.
110    HFTEST_CPU+=(--cpu "$CPU" --log "$LOG_DIR_BASE/$CPU")
111  else
112    HFTEST_CPU+=(--log "$LOG_DIR_BASE")
113  fi
114
115  if [ $EL0_TEST_ONLY == false ]
116  then
117    "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/arch_test.bin"
118    if [ $USE_TFA == true -o $USE_FVP == true ]
119    then
120      "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/aarch64_test.bin"
121    fi
122
123    "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/hafnium.bin" \
124                       --initrd test/vmapi/arch/aarch64/aarch64_test
125
126    "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/hafnium.bin" \
127                       --initrd test/vmapi/arch/aarch64/gicv3/gicv3_test
128
129    "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/hafnium.bin" \
130                       --initrd test/vmapi/primary_only/primary_only_test
131
132    "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/hafnium.bin" \
133                       --initrd test/vmapi/primary_with_secondaries/primary_with_secondaries_test
134
135    "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/hafnium.bin" \
136                       --initrd test/vmapi/primary_with_secondaries/primary_with_secondaries_no_fdt
137
138    "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/hafnium.bin" \
139                       --initrd test/linux/linux_test \
140                       --force-long-running --vm_args "rdinit=/test_binary --"
141  fi
142
143  # For VHE EL0 test cases, omit cortex-a53 as it doesn't support ARMv8.1.
144  if [ $USE_VHE == true ] && [ "$CPU" != "cortex-a53" ]
145  then
146    "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/hafnium.bin" \
147                       --initrd test/vmapi/el0_partitions/el0_partitions_test
148  fi
149
150  # TODO: Get Trusty tests working on FVP too.
151  if [ $USE_TFA == true ]
152  then
153    "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/hafnium.bin" \
154                       --initrd test/vmapi/arch/aarch64/trusty/trusty_test
155  fi
156
157  if [ $USE_TFA == true ] && [ $USE_FVP == true ]
158  then
159     "${HFTEST_CPU[@]}" --hypervisor "$HYPERVISOR_PATH/hafnium.bin" \
160                        --partitions_json test/vmapi/primary_only_ffa/primary_only_ffa_test.json
161  fi
162done
163