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 9run_tests () 10{ 11 local TEST_ARGS=() 12 if [ $USE_FVP == true ] 13 then 14 TEST_ARGS+=(--fvp) 15 elif [ $USE_TFA == true ] 16 then 17 TEST_ARGS+=(--tfa) 18 fi 19 if [ $HAFNIUM_SKIP_LONG_RUNNING_TESTS == true ] 20 then 21 TEST_ARGS+=(--skip-long-running-tests) 22 fi 23 if [ $HAFNIUM_RUN_ALL_QEMU_CPUS == true ] 24 then 25 TEST_ARGS+=(--run-all-qemu-cpus) 26 fi 27 28 ./kokoro/test.sh ${TEST_ARGS[@]} 29 30 # Run again the test suite with VHE option. 31 TEST_ARGS+=(--vhe) 32 TEST_ARGS+=(--skip-unit-tests) 33 ./kokoro/test.sh ${TEST_ARGS[@]} 34} 35 36source "$(dirname ${BASH_SOURCE[0]})/../build/bash/common.inc" 37 38# Initialize global variables, prepare repo for building. 39init_build 40 41export PATH=$(dirname $CLANG):$PWD/prebuilts/linux-x64/dtc:$PATH 42 43# Assign default values to variables. 44if is_kokoro_build 45then 46 # Default config for Kokoro builds. 47 default_value HAFNIUM_HERMETIC_BUILD true 48 default_value HAFNIUM_SKIP_LONG_RUNNING_TESTS false 49 default_value HAFNIUM_RUN_ALL_QEMU_CPUS true 50 default_value USE_TFA true 51 default_value HAFNIUM_RUN_ASSERT_DISABLED_BUILD true 52elif is_jenkins_build 53then 54 # Default config for Jenkins builds. 55 default_value HAFNIUM_HERMETIC_BUILD false 56 default_value HAFNIUM_SKIP_LONG_RUNNING_TESTS false 57 default_value HAFNIUM_RUN_ALL_QEMU_CPUS true 58 default_value USE_TFA true 59 default_value HAFNIUM_RUN_ASSERT_DISABLED_BUILD true 60else 61 # Default config for local builds. 62 default_value HAFNIUM_HERMETIC_BUILD false 63 default_value HAFNIUM_SKIP_LONG_RUNNING_TESTS true 64 default_value HAFNIUM_RUN_ALL_QEMU_CPUS false 65 default_value USE_TFA false 66 default_value HAFNIUM_RUN_ASSERT_DISABLED_BUILD false 67fi 68 69# If HAFNIUM_HERMETIC_BUILD is "true", relaunch this script inside a container. 70# The 'run_in_container.sh' script will set the variable value to 'inside' to 71# avoid recursion. 72if [ "${HAFNIUM_HERMETIC_BUILD}" == "true" ] 73then 74 exec "${ROOT_DIR}/build/run_in_container.sh" "$(get_script_path)" $@ 75fi 76 77USE_FVP=false 78 79while test $# -gt 0 80do 81 case "$1" in 82 --fvp) 83 USE_FVP=true 84 ;; 85 --skip-long-running-tests) 86 HAFNIUM_SKIP_LONG_RUNNING_TESTS=true 87 ;; 88 --run-all-qemu-cpus) 89 HAFNIUM_RUN_ALL_QEMU_CPUS=true 90 ;; 91 --run-assert-disabled-build) 92 HAFNIUM_RUN_ASSERT_DISABLED_BUILD=true 93 ;; 94 *) 95 echo "Unexpected argument $1" 96 exit 1 97 ;; 98 esac 99 shift 100done 101 102# 103# Build and run tests with asserts disabled if required. 104# 105if [ "$HAFNIUM_RUN_ASSERT_DISABLED_BUILD" == "true" ] 106then 107 # 108 # Call 'make clean' and remove args.gn file to ensure the value of 109 # enable_assertions is updated from the default. 110 # 111 if [ -d "out/reference" ]; then 112 make clean 113 rm -f out/reference/build.ninja out/reference/args.gn 114 fi 115 116 make PROJECT=reference ENABLE_ASSERTIONS=0 117 118 run_tests 119 120 # 121 # Call 'make clean' and remove args.gn file so future runs of make 122 # include assertions. 123 # 124 make clean 125 rm out/reference/build.ninja out/reference/args.gn 126fi 127 128# 129# Build and run with asserts enabled. 130# 131 132make PROJECT=reference ENABLE_ASSERTIONS=1 133run_tests 134 135# 136# Static analysis. 137# 138 139make check 140if is_repo_dirty 141then 142 echo "Run \`make check\' locally to fix this." 143 exit 1 144fi 145 146# 147# Make sure the code looks good. 148# 149 150make format 151if is_repo_dirty 152then 153 echo "Run \`make format\' locally to fix this." 154 exit 1 155fi 156 157make checkpatch 158 159# 160# Make sure there's not lint. 161# 162 163make tidy 164if is_repo_dirty 165then 166 echo "Run \`make tidy\' locally to fix this." 167 exit 1 168fi 169 170# 171# Make sure all the files have a license. 172# 173 174make license 175if is_repo_dirty 176then 177 echo "Run \`make license\' locally to fix this." 178 exit 1 179fi 180 181# Make sure the Linux driver maintains style. It's already built as 182# part of the tests. 183( 184unset CHECKPATCH && 185export ARCH=arm64 && 186export CROSS_COMPILE=aarch64-linux-gnu- && 187cd driver/linux && 188make HAFNIUM_PATH="${ROOT_DIR}" checkpatch 189) 190