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
24	./kokoro/test.sh ${TEST_ARGS[@]}
25}
26
27source "$(dirname ${BASH_SOURCE[0]})/../build/bash/common.inc"
28
29# Initialize global variables, prepare repo for building.
30init_build
31
32# Assign default values to variables.
33if is_kokoro_build
34then
35	# Default config for Kokoro builds.
36	default_value HAFNIUM_HERMETIC_BUILD true
37	default_value HAFNIUM_SKIP_LONG_RUNNING_TESTS false
38	default_value USE_TFA true
39	default_value HAFNIUM_RUN_ASSERT_DISABLED_BUILD true
40elif is_jenkins_build
41then
42	# Default config for Jenkins builds.
43	default_value HAFNIUM_HERMETIC_BUILD false
44	default_value HAFNIUM_SKIP_LONG_RUNNING_TESTS false
45	default_value USE_TFA true
46	default_value HAFNIUM_RUN_ASSERT_DISABLED_BUILD false
47else
48	# Default config for local builds.
49	default_value HAFNIUM_HERMETIC_BUILD false
50	default_value HAFNIUM_SKIP_LONG_RUNNING_TESTS true
51	default_value USE_TFA false
52	default_value HAFNIUM_RUN_ASSERT_DISABLED_BUILD false
53fi
54
55# If HAFNIUM_HERMETIC_BUILD is "true", relaunch this script inside a container.
56# The 'run_in_container.sh' script will set the variable value to 'inside' to
57# avoid recursion.
58if [ "${HAFNIUM_HERMETIC_BUILD}" == "true" ]
59then
60	exec "${ROOT_DIR}/build/run_in_container.sh" "$(get_script_path)" $@
61fi
62
63USE_FVP=false
64
65while test $# -gt 0
66do
67	case "$1" in
68	--fvp)
69		USE_FVP=true
70		;;
71	--skip-long-running-tests)
72		HAFNIUM_SKIP_LONG_RUNNING_TESTS=true
73		;;
74	--run-assert-disabled-build)
75		HAFNIUM_RUN_ASSERT_DISABLED_BUILD=true
76		;;
77	*)
78		echo "Unexpected argument $1"
79		exit 1
80		;;
81	esac
82	shift
83done
84
85#
86# Build and run tests with asserts disabled if required.
87#
88if [ "$HAFNIUM_RUN_ASSERT_DISABLED_BUILD" == "true" ]
89then
90	#
91	# Call 'make clean' and remove args.gn file to ensure the value of
92	# enable_assertions is updated from the default.
93	#
94	if [ -d "out/reference" ]; then
95		make clean
96		rm -f out/reference/build.ninja out/reference/args.gn
97	fi
98
99	make PROJECT=reference ENABLE_ASSERTIONS=0
100
101	run_tests
102
103	#
104	# Call 'make clean' and remove args.gn file so future runs of make
105	# include assertions.
106	#
107	make clean
108	rm out/reference/build.ninja out/reference/args.gn
109fi
110
111#
112# Build and run with asserts enabled.
113#
114
115make PROJECT=reference ENABLE_ASSERTIONS=1
116run_tests
117