blob: 714b86e7c3d54d79672398b2c479a6aba749ee6e [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
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -060051 # If we're using local checkouts for either TF-A or TFTF, we must
52 # serialise builds
Fathi Boudra422bf772019-12-02 11:10:16 +020053 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() {
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -060077 source "$ci_root/utils.sh"
78
Fathi Boudra422bf772019-12-02 11:10:16 +020079 id="${1%%_*}"
80 action="${1##*_}"
81 test_file="$(find -name "$id*.test" -printf "%f\n")"
82
83 mkdir -p "$id"
84
85 # Copy the test_file into the workspace directory with the name
86 # TEST_DESC, just like Jenkins would.
87 export TEST_DESC="$(basename "$test_file")"
88 cp "$test_file" "$id/TEST_DESC"
89
Zelalem219df412020-05-17 19:21:20 -050090 workspace="$id" test_desc="$test_file" cc_enable="$cc_enable" "$ci_root/script/parse_test.sh"
Fathi Boudra422bf772019-12-02 11:10:16 +020091
92 set -a
93 source "$id/env"
94 set +a
95
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -060096 run_config_tfa="$(echo "$RUN_CONFIG" | awk -F, '{print $1}')"
97 run_config_tfut="$(echo "$RUN_CONFIG" | awk -F, '{print $2}')"
98
Fathi Boudra422bf772019-12-02 11:10:16 +020099 # Makefiles don't like commas and colons in file names. We therefore
100 # replace them with _
101 config_subst="$(echo "$TEST_CONFIG" | tr ',:' '_')"
102 config_string="$id: $TEST_GROUP/$TEST_CONFIG"
103 workspace="$workspace/$TEST_GROUP/$config_subst"
104 mkdir -p "$workspace"
105
106 log_file="$workspace/artefacts/build.log"
Boyan Karatotev49106802025-05-02 10:08:43 +0100107 # fd 5 is the terminal where run_local_ci.sh is running. *Only* status
108 # of the run is printed as this is shared for all jobs and this may
109 # happen in parallel.
110 # Each job has its own verbose output as well. This will be progress
111 # messages but also any debugging prints. This is the default and it
112 # gets redirected to a file per job for archiving and disambiguation
113 # when running in parallel.
Boyan Karatotevf2e145b2025-08-27 15:51:46 +0100114 console_file="$workspace/console.log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200115 if [ "$parallel" -gt 1 ]; then
Boyan Karatotev49106802025-05-02 10:08:43 +0100116 exec >> $console_file 2>&1
Fathi Boudra422bf772019-12-02 11:10:16 +0200117 else
Boyan Karatotev49106802025-05-02 10:08:43 +0100118 # when running in serial, no scrambling is possible so print to
119 # stdout
Boyan Karatotevf2e145b2025-08-27 15:51:46 +0100120 exec > >(tee $console_file >&5) 2>&1
Fathi Boudra422bf772019-12-02 11:10:16 +0200121 fi
122
123 # Unset make flags for build script
124 MAKEFLAGS=
125
Zelalem219df412020-05-17 19:21:20 -0500126 if [ $import_cc -eq 1 ]; then
127 # Path to plugin if there is no local reference
128 cc_path_spec=$workspace/cc_plugin
129 fi
130
Fathi Boudra422bf772019-12-02 11:10:16 +0200131 case "$action" in
132 "build")
133 echo "building: $config_string" >&5
Boyan Karatotev49106802025-05-02 10:08:43 +0100134 if ! ccpathspec="$cc_path_spec" bash $minus_x "$ci_root/script/build_package.sh"; then {
135 print_failure "$config_string (build)" >&5
Fathi Boudra422bf772019-12-02 11:10:16 +0200136 if [ "$console_file" ]; then
137 echo " see $console_file"
138 fi
139 } >&5
140 exit 1
141 fi
142 ;;
143
144 "run")
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -0600145 #Run unit tests (TFUT)
Boyan Karatotev56d72ea2025-08-27 15:11:16 +0100146 if config_valid "$run_config_tfut"; then
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -0600147 echo "running TFUT: $config_string" >&5
Boyan Karatotev56d72ea2025-08-27 15:11:16 +0100148
149 if upon "$skip_tfut_runs"; then
150 #No run config for TFUT
151 if grep -q -e "--BUILD UNSTABLE--" "$log_file"; then
152 print_unstable "$config_string (tfut) (not run)" >&5
153 else
154 print_success "$config_string (tfut) (not run)" >&5
155 fi
156 exit 0
157 fi
158
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -0600159 if bash $minus_x "$ci_root/script/run_unit_tests.sh"; then
160 if grep -q -e "--BUILD UNSTABLE--" \
161 "$log_file"; then
162 print_unstable "$config_string (tfut)" >&5
163 else
164 print_success "$config_string (tfut)" >&5
165 fi
Boyan Karatotev56d72ea2025-08-27 15:11:16 +0100166 exit 0
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -0600167 else
168 {
169 print_failure "$config_string (tfut) (run)" >&5
170 if [ "$console_file" ]; then
171 echo " see $console_file"
172 fi
173 } >&5
174 exit 1
175 fi
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -0600176 fi
177
178 #Run TF-A
179 if echo "$run_config_tfa" | grep -q "^\(fvp\|qemu\)" && \
Fathi Boudra422bf772019-12-02 11:10:16 +0200180 not_upon "$skip_runs"; then
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -0600181 # Local runs for FVP, QEMU, or arm_fpga unless asked not to
182 echo "running TF-A: $config_string" >&5
Zelalem219df412020-05-17 19:21:20 -0500183 if [ -n "$cc_enable" ]; then
184 # Enable of code coverage during run
185 if cc_enable="$cc_enable" trace_file_prefix=tr \
186 coverage_trace_plugin=$cc_path_spec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov/model-plugin/CoverageTrace.so \
Boyan Karatotev49106802025-05-02 10:08:43 +0100187 bash $minus_x "$ci_root/script/run_package.sh"; then
Zelalem219df412020-05-17 19:21:20 -0500188 if grep -q -e "--BUILD UNSTABLE--" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200189 "$log_file"; then
Zelalem219df412020-05-17 19:21:20 -0500190 print_unstable "$config_string" >&5
191 else
192 print_success "$config_string" >&5
193 if [ -d "$workspace/artefacts/release" ] && \
laurenw-armafdc3bc2022-09-14 15:31:42 -0500194 [ -f "$workspace/artefacts/release/tr-FVP_Base_RevC_2xAEMvA.cluster0.cpu0.log" ]; then
Zelalem219df412020-05-17 19:21:20 -0500195 cp $workspace/artefacts/release/*.log $workspace/artefacts/debug
196 fi
197 # Setting environmental variables for run of code coverage
198 OBJDUMP=$TOOLCHAIN/bin/aarch64-none-elf-objdump \
199 READELF=$TOOLCHAIN/bin/aarch64-none-elf-readelf \
200 ELF_FOLDER=$workspace/artefacts/debug \
201 TRACE_FOLDER=$workspace/artefacts/debug \
202 workspace=$workspace \
203 TRACE_PREFIX=tr python \
204 $cc_path_spec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov/report/gen-coverage-report.py --config \
205 $cc_path_spec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov/report/config_atf.py
206 fi
207 exit 0
Fathi Boudra422bf772019-12-02 11:10:16 +0200208 else
Zelalem219df412020-05-17 19:21:20 -0500209 {
Boyan Karatotev49106802025-05-02 10:08:43 +0100210 print_failure "$config_string (run)" >&5
Zelalem219df412020-05-17 19:21:20 -0500211 if [ "$console_file" ]; then
212 echo " see $console_file"
213 fi
214 } >&5
215 exit 1
Fathi Boudra422bf772019-12-02 11:10:16 +0200216 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200217 else
Boyan Karatotev49106802025-05-02 10:08:43 +0100218 if bash $minus_x "$ci_root/script/run_package.sh"; then
Zelalem219df412020-05-17 19:21:20 -0500219 if grep -q -e "--BUILD UNSTABLE--" \
220 "$log_file"; then
221 print_unstable "$config_string" >&5
222 else
223 print_success "$config_string" >&5
224 fi
225 exit 0
226 else
227 {
Boyan Karatotev49106802025-05-02 10:08:43 +0100228 print_failure "$config_string (run)" >&5
Zelalem219df412020-05-17 19:21:20 -0500229 if [ "$console_file" ]; then
230 echo " see $console_file"
231 fi
232 } >&5
233 exit 1
Fathi Boudra422bf772019-12-02 11:10:16 +0200234 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200235 fi
236 else
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100237 # Local runs for arm_fpga platform
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -0600238 if echo "$run_config_tfa" | grep -q "^arm_fpga" && \
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100239 not_upon "$skip_runs"; then
240 echo "running: $config_string" >&5
Boyan Karatotev49106802025-05-02 10:08:43 +0100241 if bash $minus_x "$ci_root/script/test_fpga_payload.sh"; then
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100242 if grep -q -e "--BUILD UNSTABLE--" \
243 "$log_file"; then
244 print_unstable "$config_string" >&5
245 else
246 print_success "$config_string" >&5
247 fi
248 exit 0
249 else
250 {
Boyan Karatotev49106802025-05-02 10:08:43 +0100251 print_failure "$config_string (run)" >&5
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100252 if [ "$console_file" ]; then
253 echo " see $console_file"
254 fi
255 } >&5
256 exit 1
257 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200258 else
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100259 if grep -q -e "--BUILD UNSTABLE--" \
260 "$log_file"; then
261 print_unstable "$config_string (not run)" >&5
262 else
263 print_success "$config_string (not run)" >&5
264 fi
265 exit 0
Fathi Boudra422bf772019-12-02 11:10:16 +0200266 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200267 fi
268 ;;
269
270 *)
271 in_red "Invalid action: $action!" >&5
272 exit 1
273 ;;
274 esac
275}
276export -f run_one_test
277
278workspace="${workspace:?}"
Boyan Karatotev51800062025-05-01 16:55:44 +0100279if [[ "$retain_paths" -eq 0 ]]; then
Jayanth Dodderi Chidanand985bb2f2025-04-09 17:02:39 +0100280 gcc_space="${gcc_space:?Environment variable 'gcc_space' must be set}"
281fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200282ci_root="$(readlink -f "$(dirname "$0")/..")"
283
284# If this script was invoked with bash -x, have subsequent build/run invocations
285# to use -x as well.
286if echo "$-" | grep -q "x"; then
287 export minus_x="-x"
288fi
289
Leonardo Sandoval8f9cea62020-07-10 11:08:55 -0500290# if test_groups variable is not present, check if it can be formed at least from 'test_group' and 'tf_config'
291# environment variables
292if [ -z "${test_groups}" ]; then
293 if [ -n "${test_group}" -a -n "${tf_config}" ]; then
294
295 # default the rest to nil if not present
296 tftf_config="${tftf_config:-nil}"
Manish Pandeyb466cf22021-02-12 13:15:40 +0000297 spm_config="${spm_config:-nil}"
Leonardo Sandoval8f9cea62020-07-10 11:08:55 -0500298 run_config="${run_config:-nil}"
299
Manish Pandeyb466cf22021-02-12 13:15:40 +0000300 # construct the 'long form' so it takes into account all possible configurations
Chris Kay4f7846a2025-08-04 19:56:35 +0100301 if echo ${test_group} | grep -q '^spm-'; then
302 tg=$(printf "%s/%s,%s,%s:%s" "${test_group}" "${spm_config}" "${tf_config}" "${tftf_config}" "${run_config}")
Manish V Badarkhe5248c7f2025-04-11 13:22:16 +0100303 elif echo ${test_group} | grep -q '^rmm-'; then
Chris Kay4f7846a2025-08-04 19:56:35 +0100304 tg=$(printf "%s/%s,%s,%s,%s:%s" "${test_group}" "${rmm_config}" "${tf_config}" "${tftf_config}" "${spm_config}" "${run_config}")
Manish Pandeyb466cf22021-02-12 13:15:40 +0000305 else
Chris Kay4f7846a2025-08-04 19:56:35 +0100306 tg=$(printf "%s/%s,%s,%s:%s" "${test_group}" "${tf_config}" "${tftf_config}" "${spm_config}" "${run_config}")
Manish Pandeyb466cf22021-02-12 13:15:40 +0000307 fi
Leonardo Sandoval8f9cea62020-07-10 11:08:55 -0500308
309 # trim any ',nil:' from it
Manish Pandeyb466cf22021-02-12 13:15:40 +0000310 tg="${tg/,nil:/:}" tg="${tg/,nil:/:}"; tg="${tg/,nil:/:}"; tg="${tg/,nil:/:}"
Leonardo Sandoval8f9cea62020-07-10 11:08:55 -0500311
312 # finally exported
313 export test_groups="${tg}"
314 fi
315fi
316
Fathi Boudra422bf772019-12-02 11:10:16 +0200317# For a local run, when some variables as specified as "?", launch zenity to
318# prompt for test config via. GUI. If it's "??", then choose a directory.
319if [ "$test_groups" = "?" -o "$test_groups" = "??" ]; then
320 zenity_opts=(
321 --file-selection
322 --filename="$ci_root/group/README"
323 --multiple
324 --title "Choose test config"
325 )
326
327 if [ "$test_groups" = "??" ]; then
328 zenity_opts+=("--directory")
329 fi
330
331 # In case of multiple selections, zenity returns absolute paths of files
332 # separated by '|'. We remove the pipe characters, and make the paths
333 # relative to the group directory.
334 selections="$(cd "$ci_root"; zenity ${zenity_opts[*]})"
335 test_groups="$(echo "$selections" | tr '|' ' ')"
336 test_groups="$(echo "$test_groups" | sed "s#$ci_root/group/##g")"
337fi
338
339test_groups="${test_groups:?}"
340local_count=0
341
342if [ -z "$tf_root" ]; then
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -0600343 in_red "NOTE: NOT using local work tree for TF-A"
Fathi Boudra422bf772019-12-02 11:10:16 +0200344else
345 tf_root="$(readlink -f $tf_root)"
346 tf_refspec=
Juan Pablo Conde6eb0d1e2023-12-08 13:52:21 -0600347 in_green "Using local work tree for TF-A"
Fathi Boudra422bf772019-12-02 11:10:16 +0200348 let "++local_count"
349fi
350
351if [ -z "$tftf_root" ]; then
352 in_red "NOTE: NOT using local work tree for TFTF"
353 tforg_user="${tforg_user:?}"
354else
355 tftf_root="$(readlink -f $tftf_root)"
Zelalem219df412020-05-17 19:21:20 -0500356 tftf_refspec=
Fathi Boudra422bf772019-12-02 11:10:16 +0200357 in_green "Using local work tree for TFTF"
358 let "++local_count"
359fi
360
Zelalem219df412020-05-17 19:21:20 -0500361if [ -n "$cc_enable" ]; then
362 in_green "Code Coverage enabled"
363 if [ -z "$TOOLCHAIN" ]; then
364 in_red "TOOLCHAIN not set for code coverage: ex: export TOOLCHAIN=<path to toolchain>/gcc-arm-<gcc version>-x86_64-aarch64-none-elf"
365 exit 1
366 fi
367 if [ -n "$cc_path" ]; then
368 in_green "Code coverage plugin path specified"
369 cc_path_spec=$cc_path
370 import_cc=0
371 else
372 in_red "Code coverage plugin path not specified"
373 cc_path_spec="$workspace/cc_plugin"
374 import_cc=1
375 fi
Jimmy Brisson4347d8a2020-07-24 10:26:16 -0500376else
377 in_green "Code coverage disabled"
378 import_cc=1
Zelalem219df412020-05-17 19:21:20 -0500379fi
380
Olivier Deprezf1d1fcd2019-12-16 14:09:43 +0100381if [ -z "$spm_root" ]; then
382 in_red "NOTE: NOT using local work tree for SPM"
383else
384 spm_root="$(readlink -f $spm_root)"
385 spm_refspec=
386 in_green "Using local work tree for SPM"
387 let "++local_count"
388fi
389
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000390if [ -z "$rmm_root" ]; then
391 in_red "NOTE: NOT using local work tree for RMM"
392else
393 rmm_root="$(readlink -f $rmm_root)"
394 rmm_refspec=
395 in_green "Using local work tree for RMM"
396 let "++local_count"
397fi
398
399if [ -z "$tfm_tests_root" ]; then
400 in_red "NOTE: NOT using local work tree for TF-M-TESTS"
401else
402 tfm_tests_root="$(readlink -f $tfm_tests_root)"
403 tfm_tests_refspec=
404 in_green "Using local work tree for TF-M-TESTS"
405 let "++local_count"
406fi
407
408if [ -z "$tfm_extras_root" ]; then
409 in_red "NOTE: NOT using local work tree for TF-M-EXTRAS"
410else
411 tfm_extras_root="$(readlink -f $tfm_extras_root)"
412 tfm_extras_refspec=
413 in_green "Using local work tree for TF-M-EXTRAS"
414 let "++local_count"
415fi
416
Fathi Boudra422bf772019-12-02 11:10:16 +0200417# User preferences
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000418[ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && user_connect_debugger=1
419user_test_run="${user_connect_debugger:-$test_run}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200420user_dont_clean="$dont_clean"
421user_keep_going="$keep_going"
422user_primary_live="$primary_live"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000423user_connect_debugger="${user_connect_debugger:-0}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200424
425export ci_root
426export dont_clean=0
427export local_ci=1
428export parallel
429export test_run=0
430export primary_live=0
Zelalem219df412020-05-17 19:21:20 -0500431export cc_path_spec
432export import_cc
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000433export connect_debugger="$user_connect_debugger"
Fathi Boudra422bf772019-12-02 11:10:16 +0200434
435rm -rf "$workspace"
436mkdir -p "$workspace"
437
438source "$ci_root/utils.sh"
439
Zelalem219df412020-05-17 19:21:20 -0500440# Enable of code coverage and whether there is a local plugin
441if upon "$cc_enable" && not_upon "$cc_path"; then
442 no_cc_t=1
443else
444 no_cc_t=0
445fi
446
447# Use clone_repos.sh to clone and share repositories that aren't local.
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000448no_tf="$tf_root" no_tftf="$tftf_root" no_spm="$spm_root" no_rmm="$rmm_root" \
449no_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 +0200450 bash $minus_x "$ci_root/script/clone_repos.sh"
451
452set -a
453source "$workspace/env"
454set +a
455
Fathi Boudra422bf772019-12-02 11:10:16 +0200456export -f upon not_upon
457
458# Generate test descriptions
459"$ci_root/script/gen_test_desc.py"
460
461# Iterate through test files in workspace
462pushd "$workspace"
463
464if not_upon "$parallel" || echo "$parallel" | grep -vq "[0-9]"; then
465 parallel=1
466 test_run="$user_test_run"
467 dont_clean="$user_dont_clean"
468 primary_live="$user_primary_live"
469fi
470
471if [ "$parallel" -gt 1 ]; then
472 msg="Running at most $parallel jobs in parallel"
473 if upon "$serialize_builds"; then
474 msg+=" (builds serialized)"
475 fi
476 msg+="..."
477fi
478
479# Generate Makefile
480gen_makefile
481
482if upon "$msg"; then
483 echo "$msg"
484 echo
485fi
486
487keep_going="${user_keep_going:-1}"
488if not_upon "$keep_going"; then
489 keep_going=
490fi
491
Boyan Karatotev49106802025-05-02 10:08:43 +0100492MAKEFLAGS= make -r -j "$parallel" ${keep_going+-k} 5>&1 |& tee "make.log"