blob: b290326e2fbf3978d76369182900c1287debdd8f [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
laurenw-armafdc3bc2022-09-14 15:31:42 -05003# Copyright (c) 2019-2022, Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8set -e
9
10in_red() {
11 echo "$(tput setaf 1)${1:?}$(tput sgr0)"
12}
13export -f in_red
14
15in_green() {
16 echo "$(tput setaf 2)${1:?}$(tput sgr0)"
17}
18export -f in_green
19
20in_yellow() {
21 echo "$(tput setaf 3)${1:?}$(tput sgr0)"
22}
23export -f in_yellow
24
25print_success() {
26 in_green "$1: SUCCESS"
27}
28export -f print_success
29
30print_failure() {
31 in_red "$1: FAILURE"
32}
33export -f print_failure
34
35print_unstable() {
36 in_yellow "$1: UNSTABLE"
37}
38export -f print_unstable
39
40gen_makefile() {
41 local num="$(find -name "*.test" -type f | wc -l)"
42 local i=0
43
44 cat <<EOF >Makefile
45SHELL=/bin/bash
46
47all:
48
49EOF
50
51 # If we're using local checkouts for either TF or TFTF, we must
52 # serialise builds
53 while [ "$i" -lt "$num" ]; do
54 {
Sandrine Bailleux4694fd32022-04-15 14:04:35 +020055 printf "all: %04d_run %04d_build\n" "$i" "$i"
Fathi Boudra422bf772019-12-02 11:10:16 +020056 if upon "$serialize_builds" && [ "$i" -gt 0 ]; then
Sandrine Bailleux4694fd32022-04-15 14:04:35 +020057 printf "%04d_build: %04d_build\n" "$i" "$((i - 1))"
Fathi Boudra422bf772019-12-02 11:10:16 +020058 fi
59 echo
60 } >>Makefile
61 let "++i"
62 done
63
64 cat <<EOF >>Makefile
65
66%_run: %_build
67 @run_one_test "\$@"
68
69%_build:
70 @run_one_test "\$@"
71EOF
72}
73
74# This function is invoked from the Makefile. Descriptor 5 points to the active
75# terminal.
76run_one_test() {
77 id="${1%%_*}"
78 action="${1##*_}"
79 test_file="$(find -name "$id*.test" -printf "%f\n")"
80
81 mkdir -p "$id"
82
83 # Copy the test_file into the workspace directory with the name
84 # TEST_DESC, just like Jenkins would.
85 export TEST_DESC="$(basename "$test_file")"
86 cp "$test_file" "$id/TEST_DESC"
87
Zelalem219df412020-05-17 19:21:20 -050088 workspace="$id" test_desc="$test_file" cc_enable="$cc_enable" "$ci_root/script/parse_test.sh"
Fathi Boudra422bf772019-12-02 11:10:16 +020089
90 set -a
91 source "$id/env"
92 set +a
93
94 # Makefiles don't like commas and colons in file names. We therefore
95 # replace them with _
96 config_subst="$(echo "$TEST_CONFIG" | tr ',:' '_')"
97 config_string="$id: $TEST_GROUP/$TEST_CONFIG"
98 workspace="$workspace/$TEST_GROUP/$config_subst"
99 mkdir -p "$workspace"
100
101 log_file="$workspace/artefacts/build.log"
102 if [ "$parallel" -gt 1 ]; then
103 console_file="$workspace/console.log"
104 exec 6>>"$console_file"
105 else
106 exec 6>&5
107 fi
108
109 # Unset make flags for build script
110 MAKEFLAGS=
111
Zelalem219df412020-05-17 19:21:20 -0500112 if [ $import_cc -eq 1 ]; then
113 # Path to plugin if there is no local reference
114 cc_path_spec=$workspace/cc_plugin
115 fi
116
Fathi Boudra422bf772019-12-02 11:10:16 +0200117 case "$action" in
118 "build")
119 echo "building: $config_string" >&5
Zelalem219df412020-05-17 19:21:20 -0500120 if ! ccpathspec="$cc_path_spec" bash $minus_x "$ci_root/script/build_package.sh" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200121 >&6 2>&1; then
122 {
123 print_failure "$config_string (build)"
124 if [ "$console_file" ]; then
125 echo " see $console_file"
126 fi
127 } >&5
128 exit 1
129 fi
130 ;;
131
132 "run")
Harrison Mutaia197d5d2022-09-15 13:45:21 +0100133 # Local runs for FVP, QEMU, or arm_fpga unless asked not to
134 if echo "$RUN_CONFIG" | grep -q "^\(fvp\|qemu\)" && \
Fathi Boudra422bf772019-12-02 11:10:16 +0200135 not_upon "$skip_runs"; then
136 echo "running: $config_string" >&5
Zelalem219df412020-05-17 19:21:20 -0500137 if [ -n "$cc_enable" ]; then
138 # Enable of code coverage during run
139 if cc_enable="$cc_enable" trace_file_prefix=tr \
140 coverage_trace_plugin=$cc_path_spec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov/model-plugin/CoverageTrace.so \
141 bash $minus_x "$ci_root/script/run_package.sh" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200142 >&6 2>&1; then
Zelalem219df412020-05-17 19:21:20 -0500143 if grep -q -e "--BUILD UNSTABLE--" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200144 "$log_file"; then
Zelalem219df412020-05-17 19:21:20 -0500145 print_unstable "$config_string" >&5
146 else
147 print_success "$config_string" >&5
148 if [ -d "$workspace/artefacts/release" ] && \
laurenw-armafdc3bc2022-09-14 15:31:42 -0500149 [ -f "$workspace/artefacts/release/tr-FVP_Base_RevC_2xAEMvA.cluster0.cpu0.log" ]; then
Zelalem219df412020-05-17 19:21:20 -0500150 cp $workspace/artefacts/release/*.log $workspace/artefacts/debug
151 fi
152 # Setting environmental variables for run of code coverage
153 OBJDUMP=$TOOLCHAIN/bin/aarch64-none-elf-objdump \
154 READELF=$TOOLCHAIN/bin/aarch64-none-elf-readelf \
155 ELF_FOLDER=$workspace/artefacts/debug \
156 TRACE_FOLDER=$workspace/artefacts/debug \
157 workspace=$workspace \
158 TRACE_PREFIX=tr python \
159 $cc_path_spec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov/report/gen-coverage-report.py --config \
160 $cc_path_spec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov/report/config_atf.py
161 fi
162 exit 0
Fathi Boudra422bf772019-12-02 11:10:16 +0200163 else
Zelalem219df412020-05-17 19:21:20 -0500164 {
165 print_failure "$config_string (run)"
166 if [ "$console_file" ]; then
167 echo " see $console_file"
168 fi
169 } >&5
170 exit 1
Fathi Boudra422bf772019-12-02 11:10:16 +0200171 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200172 else
Zelalem219df412020-05-17 19:21:20 -0500173 if bash $minus_x "$ci_root/script/run_package.sh" \
174 >&6 2>&1; then
175 if grep -q -e "--BUILD UNSTABLE--" \
176 "$log_file"; then
177 print_unstable "$config_string" >&5
178 else
179 print_success "$config_string" >&5
180 fi
181 exit 0
182 else
183 {
184 print_failure "$config_string (run)"
185 if [ "$console_file" ]; then
186 echo " see $console_file"
187 fi
188 } >&5
189 exit 1
Fathi Boudra422bf772019-12-02 11:10:16 +0200190 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200191 fi
192 else
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100193 # Local runs for arm_fpga platform
194 if echo "$RUN_CONFIG" | grep -q "^arm_fpga" && \
195 not_upon "$skip_runs"; then
196 echo "running: $config_string" >&5
197 if bash $minus_x "$ci_root/script/test_fpga_payload.sh" \
198 >&6 2>&1; then
199 if grep -q -e "--BUILD UNSTABLE--" \
200 "$log_file"; then
201 print_unstable "$config_string" >&5
202 else
203 print_success "$config_string" >&5
204 fi
205 exit 0
206 else
207 {
208 print_failure "$config_string (run)"
209 if [ "$console_file" ]; then
210 echo " see $console_file"
211 fi
212 } >&5
213 exit 1
214 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200215 else
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100216 if grep -q -e "--BUILD UNSTABLE--" \
217 "$log_file"; then
218 print_unstable "$config_string (not run)" >&5
219 else
220 print_success "$config_string (not run)" >&5
221 fi
222 exit 0
Fathi Boudra422bf772019-12-02 11:10:16 +0200223 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200224 fi
225 ;;
226
227 *)
228 in_red "Invalid action: $action!" >&5
229 exit 1
230 ;;
231 esac
232}
233export -f run_one_test
234
235workspace="${workspace:?}"
Boyan Karatotev51800062025-05-01 16:55:44 +0100236if [[ "$retain_paths" -eq 0 ]]; then
Jayanth Dodderi Chidanand985bb2f2025-04-09 17:02:39 +0100237 gcc_space="${gcc_space:?Environment variable 'gcc_space' must be set}"
238fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200239ci_root="$(readlink -f "$(dirname "$0")/..")"
240
241# If this script was invoked with bash -x, have subsequent build/run invocations
242# to use -x as well.
243if echo "$-" | grep -q "x"; then
244 export minus_x="-x"
245fi
246
Leonardo Sandoval8f9cea62020-07-10 11:08:55 -0500247# if test_groups variable is not present, check if it can be formed at least from 'test_group' and 'tf_config'
248# environment variables
249if [ -z "${test_groups}" ]; then
250 if [ -n "${test_group}" -a -n "${tf_config}" ]; then
251
252 # default the rest to nil if not present
253 tftf_config="${tftf_config:-nil}"
254 scp_config="${scp_config:-nil}"
255 scp_tools="${scp_tools:-nil}"
Manish Pandeyb466cf22021-02-12 13:15:40 +0000256 spm_config="${spm_config:-nil}"
Leonardo Sandoval8f9cea62020-07-10 11:08:55 -0500257 run_config="${run_config:-nil}"
258
Manish Pandeyb466cf22021-02-12 13:15:40 +0000259 # construct the 'long form' so it takes into account all possible configurations
Leonardo Sandoval07733aa2021-02-23 13:57:08 -0600260 if echo ${test_group} | grep -q '^scp-'; then
Manish Pandeyb466cf22021-02-12 13:15:40 +0000261 tg=$(printf "%s/%s,%s,%s,%s:%s" "${test_group}" "${scp_config}" "${tf_config}" "${tftf_config}" "${scp_tools}" "${run_config}")
Leonardo Sandoval07733aa2021-02-23 13:57:08 -0600262 elif echo ${test_group} | grep -q '^spm-'; then
Manish Pandeyb466cf22021-02-12 13:15:40 +0000263 tg=$(printf "%s/%s,%s,%s,%s,%s:%s" "${test_group}" "${spm_config}" "${tf_config}" "${tftf_config}" "${scp_config}" "${scp_tools}" "${run_config}")
Manish V Badarkhe5248c7f2025-04-11 13:22:16 +0100264 elif echo ${test_group} | grep -q '^rmm-'; then
265 tg=$(printf "%s/%s,%s,%s,%s,%s,%s:%s" "${test_group}" "${rmm_config}" "${tf_config}" "${tftf_config}" "${spm_config}" "${scp_config}" "${scp_tools}" "${run_config}")
Manish Pandeyb466cf22021-02-12 13:15:40 +0000266 else
267 tg=$(printf "%s/%s,%s,%s,%s,%s:%s" "${test_group}" "${tf_config}" "${tftf_config}" "${scp_config}" "${scp_tools}" "${spm_config}" "${run_config}")
268 fi
Leonardo Sandoval8f9cea62020-07-10 11:08:55 -0500269
270 # trim any ',nil:' from it
Manish Pandeyb466cf22021-02-12 13:15:40 +0000271 tg="${tg/,nil:/:}" tg="${tg/,nil:/:}"; tg="${tg/,nil:/:}"; tg="${tg/,nil:/:}"
Leonardo Sandoval8f9cea62020-07-10 11:08:55 -0500272
273 # finally exported
274 export test_groups="${tg}"
275 fi
276fi
277
Fathi Boudra422bf772019-12-02 11:10:16 +0200278# For a local run, when some variables as specified as "?", launch zenity to
279# prompt for test config via. GUI. If it's "??", then choose a directory.
280if [ "$test_groups" = "?" -o "$test_groups" = "??" ]; then
281 zenity_opts=(
282 --file-selection
283 --filename="$ci_root/group/README"
284 --multiple
285 --title "Choose test config"
286 )
287
288 if [ "$test_groups" = "??" ]; then
289 zenity_opts+=("--directory")
290 fi
291
292 # In case of multiple selections, zenity returns absolute paths of files
293 # separated by '|'. We remove the pipe characters, and make the paths
294 # relative to the group directory.
295 selections="$(cd "$ci_root"; zenity ${zenity_opts[*]})"
296 test_groups="$(echo "$selections" | tr '|' ' ')"
297 test_groups="$(echo "$test_groups" | sed "s#$ci_root/group/##g")"
298fi
299
300test_groups="${test_groups:?}"
301local_count=0
302
303if [ -z "$tf_root" ]; then
304 in_red "NOTE: NOT using local work tree for TF"
305else
306 tf_root="$(readlink -f $tf_root)"
307 tf_refspec=
308 in_green "Using local work tree for TF"
309 let "++local_count"
310fi
311
312if [ -z "$tftf_root" ]; then
313 in_red "NOTE: NOT using local work tree for TFTF"
314 tforg_user="${tforg_user:?}"
315else
316 tftf_root="$(readlink -f $tftf_root)"
Zelalem219df412020-05-17 19:21:20 -0500317 tftf_refspec=
Fathi Boudra422bf772019-12-02 11:10:16 +0200318 in_green "Using local work tree for TFTF"
319 let "++local_count"
320fi
321
322if [ -z "$scp_root" ]; then
323 in_red "NOTE: NOT using local work tree for SCP"
324else
325 scp_root="$(readlink -f $scp_root)"
326 scp_refspec=
327 in_green "Using local work tree for SCP"
328 let "++local_count"
329fi
330
Zelalem219df412020-05-17 19:21:20 -0500331if [ -n "$cc_enable" ]; then
332 in_green "Code Coverage enabled"
333 if [ -z "$TOOLCHAIN" ]; then
334 in_red "TOOLCHAIN not set for code coverage: ex: export TOOLCHAIN=<path to toolchain>/gcc-arm-<gcc version>-x86_64-aarch64-none-elf"
335 exit 1
336 fi
337 if [ -n "$cc_path" ]; then
338 in_green "Code coverage plugin path specified"
339 cc_path_spec=$cc_path
340 import_cc=0
341 else
342 in_red "Code coverage plugin path not specified"
343 cc_path_spec="$workspace/cc_plugin"
344 import_cc=1
345 fi
Jimmy Brisson4347d8a2020-07-24 10:26:16 -0500346else
347 in_green "Code coverage disabled"
348 import_cc=1
Zelalem219df412020-05-17 19:21:20 -0500349fi
350
Olivier Deprezf1d1fcd2019-12-16 14:09:43 +0100351if [ -z "$spm_root" ]; then
352 in_red "NOTE: NOT using local work tree for SPM"
353else
354 spm_root="$(readlink -f $spm_root)"
355 spm_refspec=
356 in_green "Using local work tree for SPM"
357 let "++local_count"
358fi
359
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000360if [ -z "$rmm_root" ]; then
361 in_red "NOTE: NOT using local work tree for RMM"
362else
363 rmm_root="$(readlink -f $rmm_root)"
364 rmm_refspec=
365 in_green "Using local work tree for RMM"
366 let "++local_count"
367fi
368
369if [ -z "$tfm_tests_root" ]; then
370 in_red "NOTE: NOT using local work tree for TF-M-TESTS"
371else
372 tfm_tests_root="$(readlink -f $tfm_tests_root)"
373 tfm_tests_refspec=
374 in_green "Using local work tree for TF-M-TESTS"
375 let "++local_count"
376fi
377
378if [ -z "$tfm_extras_root" ]; then
379 in_red "NOTE: NOT using local work tree for TF-M-EXTRAS"
380else
381 tfm_extras_root="$(readlink -f $tfm_extras_root)"
382 tfm_extras_refspec=
383 in_green "Using local work tree for TF-M-EXTRAS"
384 let "++local_count"
385fi
386
Fathi Boudra422bf772019-12-02 11:10:16 +0200387# User preferences
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000388[ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && user_connect_debugger=1
389user_test_run="${user_connect_debugger:-$test_run}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200390user_dont_clean="$dont_clean"
391user_keep_going="$keep_going"
392user_primary_live="$primary_live"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000393user_connect_debugger="${user_connect_debugger:-0}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200394
395export ci_root
396export dont_clean=0
397export local_ci=1
398export parallel
399export test_run=0
400export primary_live=0
Zelalem219df412020-05-17 19:21:20 -0500401export cc_path_spec
402export import_cc
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000403export connect_debugger="$user_connect_debugger"
Fathi Boudra422bf772019-12-02 11:10:16 +0200404
405rm -rf "$workspace"
406mkdir -p "$workspace"
407
408source "$ci_root/utils.sh"
409
410# SCP is not cloned by default
411export clone_scp
412export scp_root
413if not_upon "$scp_root" && upon "$clone_scp"; then
414 clone_scp=1
415else
416 clone_scp=0
417fi
418
Zelalem219df412020-05-17 19:21:20 -0500419# Enable of code coverage and whether there is a local plugin
420if upon "$cc_enable" && not_upon "$cc_path"; then
421 no_cc_t=1
422else
423 no_cc_t=0
424fi
425
426# Use clone_repos.sh to clone and share repositories that aren't local.
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000427no_tf="$tf_root" no_tftf="$tftf_root" no_spm="$spm_root" no_rmm="$rmm_root" \
428no_ci="$ci_root" no_cc="$import_cc" no_tfm_tests="$tfm_tests_root" no_tfm_extras="$tfm_extras_root" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200429 bash $minus_x "$ci_root/script/clone_repos.sh"
430
431set -a
432source "$workspace/env"
433set +a
434
435if [ "$local_count" -gt 0 ]; then
436 # At least one repository is local
437 serialize_builds=1
438else
439 dont_clean=0
440fi
441
442export -f upon not_upon
443
444# Generate test descriptions
445"$ci_root/script/gen_test_desc.py"
446
447# Iterate through test files in workspace
448pushd "$workspace"
449
450if not_upon "$parallel" || echo "$parallel" | grep -vq "[0-9]"; then
451 parallel=1
452 test_run="$user_test_run"
453 dont_clean="$user_dont_clean"
454 primary_live="$user_primary_live"
455fi
456
457if [ "$parallel" -gt 1 ]; then
458 msg="Running at most $parallel jobs in parallel"
459 if upon "$serialize_builds"; then
460 msg+=" (builds serialized)"
461 fi
462 msg+="..."
463fi
464
465# Generate Makefile
466gen_makefile
467
468if upon "$msg"; then
469 echo "$msg"
470 echo
471fi
472
473keep_going="${user_keep_going:-1}"
474if not_upon "$keep_going"; then
475 keep_going=
476fi
477
478MAKEFLAGS= make -r -j "$parallel" ${keep_going+-k} 5>&1 &>"make.log"