Leonardo Sandoval | 9dfdd1b | 2020-08-06 17:08:11 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 2 | # |
Jayanth Dodderi Chidanand | bf7369d | 2022-04-06 10:59:14 +0100 | [diff] [blame] | 3 | # Copyright (c) 2019-2022, Arm Limited. All rights reserved. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # This file is meant to be SOURCED only after setting $ci_root. $ci_root must be |
| 9 | # the absolute path to the root of the CI repository |
| 10 | # |
| 11 | # A convenient way to set ci_root from the calling script like this: |
| 12 | # ci_root="$(readlink -f "$(dirname "$0")/..")" |
| 13 | # |
| 14 | |
| 15 | # Accept root of CI location from $CI_ROOT or $ci_root, in that order |
| 16 | ci_root="${ci_root:-$CI_ROOT}" |
| 17 | ci_root="${ci_root:?}" |
| 18 | |
Sandrine Bailleux | aaaffe0 | 2020-08-07 11:15:55 +0200 | [diff] [blame] | 19 | # Optionally source a file containing environmental settings. |
| 20 | if [ -n "$host_env" ]; then |
| 21 | source "$host_env" |
| 22 | else |
| 23 | # Are we running on Arm infrastructure? |
Gary Morrison | 999a9d7 | 2022-03-14 18:29:06 -0500 | [diff] [blame] | 24 | if echo "$JENKINS_URL" | grep -q "oss.arm.com"; then |
Sandrine Bailleux | aaaffe0 | 2020-08-07 11:15:55 +0200 | [diff] [blame] | 25 | source "$ci_root/arm-env.sh" |
Chris Kay | 3a0b71d | 2022-11-18 11:42:59 +0000 | [diff] [blame] | 26 | elif echo "$JENKINS_URL" | grep -q "ci.trustedfirmware.org"; then |
| 27 | source "$ci_root/openci-env.sh" |
Sandrine Bailleux | aaaffe0 | 2020-08-07 11:15:55 +0200 | [diff] [blame] | 28 | fi |
| 29 | fi |
| 30 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 31 | # Storage area to host toolchains, rootfs, tools, models, binaries, etc... |
| 32 | nfs_volume="${nfs_volume:-$NFS_VOLUME}" |
| 33 | nfs_volume="${nfs_volume:?}" |
| 34 | |
| 35 | # Override workspace for local runs |
| 36 | workspace="${workspace:-$WORKSPACE}" |
| 37 | workspace="${workspace:?}" |
| 38 | workspace="$(readlink -f "$workspace")" |
| 39 | artefacts="$workspace/artefacts" |
| 40 | |
| 41 | # pushd and popd outputs the directory stack every time, which could be |
| 42 | # confusing when shown on the log. Suppress its output. |
| 43 | pushd() { |
| 44 | builtin pushd "$1" &>/dev/null |
| 45 | } |
| 46 | popd() { |
| 47 | builtin popd &>/dev/null |
| 48 | } |
| 49 | |
| 50 | # Copy a file to the $archive directory |
| 51 | archive_file() { |
| 52 | local f out target md5 |
| 53 | f="${1:?}" |
| 54 | |
| 55 | out="${archive:?}" |
| 56 | [ ! -d "$out" ] && die "$out is not a directory" |
| 57 | |
| 58 | target="$out/$(basename $f)" |
| 59 | if [ -f "$target" ]; then |
| 60 | # Prevent same file error |
| 61 | if [ "$(stat --format=%i "$target")" = \ |
| 62 | "$(stat --format=%i "$f")" ]; then |
| 63 | return |
| 64 | fi |
| 65 | fi |
| 66 | |
| 67 | md5="$(md5sum "$f" | awk '{print $1}')" |
| 68 | cp -t "$out" "$f" |
| 69 | echo "Archived: $f (md5: $md5)" |
| 70 | } |
| 71 | |
| 72 | die() { |
| 73 | [ "$1" ] && echo "$1" >&2 |
| 74 | exit 1 |
| 75 | } |
| 76 | |
| 77 | # Emit environment variables for the purpose of sourcing from shells and as |
| 78 | # Jenkins property files. Whether the RHS is quoted depends on "$quote". |
| 79 | emit_env() { |
| 80 | local env_file="${env_file:?}" |
| 81 | local var="${1:?}" |
| 82 | |
| 83 | # Value parameter is mandatory, but allow for it to be empty |
| 84 | local val="${2?}" |
| 85 | |
| 86 | if upon "$quote"; then |
| 87 | val="\"$val\"" |
| 88 | else |
| 89 | # If RHS is not required to be quoted, any white space in it |
| 90 | # won't go well with a shell sourcing this file. |
| 91 | if echo "$var" | grep -q '\s'; then |
| 92 | die "$var: value '$val' has white space" |
| 93 | fi |
| 94 | fi |
| 95 | |
| 96 | echo "$var=$val" >> "$env_file" |
| 97 | } |
| 98 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 99 | fetch_directory() { |
| 100 | local base="$(basename "${url:?}")" |
| 101 | local sa |
| 102 | |
Fathi Boudra | dd31e7b | 2020-01-29 15:44:42 +0200 | [diff] [blame] | 103 | case "${url}" in |
| 104 | http*://*) |
| 105 | # Have exactly one trailing / |
| 106 | local modified_url="$(echo "${url}" | sed 's#/*$##')/" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 107 | |
Fathi Boudra | dd31e7b | 2020-01-29 15:44:42 +0200 | [diff] [blame] | 108 | # Figure out the number of components between hostname and the |
| 109 | # final one |
| 110 | local cut_dirs="$(echo "$modified_url" | awk -F/ '{print NF - 5}')" |
| 111 | sa="${saveas:-$base}" |
| 112 | echo "Fetch: $modified_url -> $sa" |
laurenw-arm | 2d62c71 | 2022-09-13 14:27:15 -0500 | [diff] [blame] | 113 | wget -rq -nH --cut-dirs="$cut_dirs" --no-parent -e robots=off \ |
Fathi Boudra | dd31e7b | 2020-01-29 15:44:42 +0200 | [diff] [blame] | 114 | --reject="index.html*" "$modified_url" |
| 115 | if [ "$sa" != "$base" ]; then |
| 116 | mv "$base" "$sa" |
| 117 | fi |
| 118 | ;; |
| 119 | file://*) |
| 120 | sa="${saveas:-.}" |
| 121 | echo "Fetch: ${url} -> $sa" |
| 122 | cp -r "${url#file://}" "$sa" |
| 123 | ;; |
| 124 | *) |
| 125 | sa="${saveas:-.}" |
| 126 | echo "Fetch: ${url} -> $sa" |
| 127 | cp -r "${url}" "$sa" |
| 128 | ;; |
| 129 | esac |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | fetch_file() { |
| 133 | local url="${url:?}" |
| 134 | local sa |
| 135 | local saveas |
| 136 | |
| 137 | if is_url "$url"; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 138 | saveas="${saveas-"$(basename "$url")"}" |
Sandrine Bailleux | 3da4bd1 | 2020-08-06 16:18:36 +0200 | [diff] [blame] | 139 | sa="${saveas+-o $saveas}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 140 | echo "Fetch: $url -> $saveas" |
| 141 | # Use curl to support file protocol |
Sandrine Bailleux | 2a05b9c | 2021-02-25 13:52:21 +0100 | [diff] [blame] | 142 | curl --fail -sLS $sa "$url" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 143 | else |
| 144 | sa="${saveas-.}" |
| 145 | echo "Fetch: $url -> $sa" |
| 146 | cp "$url" "$sa" |
| 147 | fi |
| 148 | } |
| 149 | |
Harrison Mutai | a197d5d | 2022-09-15 13:45:21 +0100 | [diff] [blame] | 150 | fetch_and_archive() { |
| 151 | url=${url:?} |
| 152 | filename=${filename:-basename $url} |
| 153 | |
| 154 | url="$url" saveas="$filename" fetch_file |
| 155 | archive_file "$filename" |
| 156 | } |
| 157 | |
| 158 | filter_artefacts(){ |
| 159 | local model_param_file="${model_param_file-$archive/model_params}" |
| 160 | |
| 161 | # Bash doesn't have array values, we have to create references to the |
| 162 | # array of artefacts and the artefact filters. |
| 163 | declare -ga "$1" |
| 164 | declare -n artefacts="$1" |
| 165 | declare -n filters="$2" |
| 166 | |
| 167 | for artefact in "${!filters[@]}"; do |
| 168 | if grep -E -q "${filters[${artefact}]}" "$model_param_file"; then |
| 169 | artefacts+=("${artefact}") |
| 170 | fi |
| 171 | done |
| 172 | } |
| 173 | |
| 174 | gen_lava_job_def() { |
| 175 | local yaml_template_file="${yaml_template_file:?}" |
| 176 | local yaml_file="${yaml_file:?}" |
| 177 | local yaml_job_file="${yaml_job_file}" |
| 178 | |
| 179 | # Bash doesn't have array values, we have to create references to the |
| 180 | # array of artefacts and their urls. |
| 181 | declare -n artefacts="$1" |
| 182 | declare -n artefact_urls="$2" |
| 183 | |
| 184 | readarray -t boot_arguments < "${lava_model_params}" |
| 185 | |
| 186 | # Generate the LAVA job definition, minus the test expectations |
| 187 | expand_template "${yaml_template_file}" > "${yaml_file}" |
| 188 | |
| 189 | if [[ ! $model =~ "qemu" ]]; then |
| 190 | # Append expect commands into the job definition through |
| 191 | # test-interactive commands |
| 192 | gen_fvp_yaml_expect >> "$yaml_file" |
| 193 | fi |
| 194 | |
| 195 | # create job.yaml |
| 196 | cp "$yaml_file" "$yaml_job_file" |
| 197 | |
| 198 | # archive both yamls |
| 199 | archive_file "$yaml_file" |
| 200 | archive_file "$yaml_job_file" |
| 201 | } |
| 202 | |
| 203 | gen_lava_model_params() { |
| 204 | local lava_model_params="${lava_model_params:?}" |
| 205 | declare -n macros="$1" |
| 206 | |
| 207 | #Â Derive LAVA model parameters from the non-LAVA ones |
| 208 | cp "${archive}/model_params" "${lava_model_params}" |
| 209 | |
| 210 | if [[ $model =~ "qemu" ]]; then |
| 211 | #Â Strip the model parameters of parameters already specified in the deploy |
| 212 | #Â overlay and job context. |
| 213 | sed -i '/-M/d;/kernel/d;/initrd/d;/bios/d;/cpu/d;/^[[:space:]]*$/d' \ |
| 214 | $lava_model_params |
| 215 | elif [[ ! $model =~ "qemu" ]]; then |
| 216 | # FIXME find a way to properly match FVP configurations. |
| 217 | #Â Ensure braces in the FVP model parameters are not accidentally |
| 218 | #Â interpreted as LAVA macros. |
| 219 | sed -i -e 's/{/{{/g' "${lava_model_params}" |
| 220 | sed -i -e 's/}/}}/g' "${lava_model_params}" |
| 221 | else |
| 222 | echo "Unsupported emulated platform $model." |
| 223 | fi |
| 224 | |
| 225 | # LAVA expects binary paths as macros, i.e. `{X}` instead of `x.bin`, so |
| 226 | #Â replace the file paths in our pre-generated model parameters. |
| 227 | for regex in "${!macros[@]}"; do |
| 228 | sed -i -e "s!${regex}!${macros[${regex}]}!" "${lava_model_params}" |
| 229 | done |
| 230 | } |
| 231 | |
| 232 | gen_yaml_template() { |
| 233 | local target="${target-fvp}" |
| 234 | local yaml_template_file="${yaml_template_file-$workspace/${target}_template.yaml}" |
| 235 | |
| 236 | local payload_type="${payload_type:?}" |
| 237 | |
| 238 | cp "${ci_root}/script/lava-templates/${target}-${payload_type:?}.yaml" \ |
| 239 | "${yaml_template_file}" |
| 240 | |
| 241 | archive_file "$yaml_template_file" |
| 242 | } |
| 243 | |
| 244 | # Generate link to an archived binary. |
| 245 | gen_bin_url() { |
| 246 | local bin_mode="${bin_mode:?}" |
| 247 | local bin="${1:?}" |
| 248 | |
| 249 | if upon "$jenkins_run"; then |
| 250 | echo "$jenkins_url/job/$JOB_NAME/$BUILD_NUMBER/artifact/artefacts/$bin_mode/$bin" |
| 251 | else |
| 252 | echo "file://$workspace/artefacts/$bin_mode/$bin" |
| 253 | fi |
| 254 | } |
| 255 | |
| 256 | get_kernel() { |
| 257 | local kernel_type="${kernel_type:?}" |
| 258 | local url="${plat_kernel_list[$kernel_type]}" |
| 259 | |
| 260 | url="${url:?}" filename="kernel.bin" fetch_and_archive |
| 261 | } |
| 262 | |
Chris Kay | a75c0a6 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 263 | # Get the path to the run environment variables file. |
| 264 | # |
| 265 | # Run environment variables are the test-specific environment variables |
| 266 | #Â configured by the CI's test configuration. |
| 267 | # |
| 268 | # Usage: get_run_env_path <archive> |
| 269 | get_run_env_path() { |
| 270 | echo "${1:?}/run/env" |
| 271 | } |
| 272 | |
| 273 | # Get a run environment variable. |
| 274 | # |
| 275 | # Run environment variables are the test-specific environment variables |
| 276 | #Â configured by the CI's test configuration. |
| 277 | # |
| 278 | # Usage: get_run_env <archive> <variable> [default] |
| 279 | get_run_env() { |
| 280 | if [ -f "$(get_run_env_path "${1:?}")" ] && [ ! -v "${2:?}" ]; then |
| 281 | . "$(get_run_env_path "${1:?}")" |
| 282 | fi |
| 283 | |
| 284 | echo "${!2:-${3}}" |
| 285 | } |
| 286 | |
| 287 | # Get the number of UARTs configured by the current test configuration. This |
| 288 | # defaults to `4`. |
| 289 | # |
| 290 | # Usage: get_num_uarts <archive> [default] |
| 291 | get_num_uarts() { |
| 292 | local default=4 |
| 293 | |
| 294 | get_run_env "${1:?}" num_uarts "${2-${default}}" |
| 295 | } |
| 296 | |
| 297 | #Â Get the ports script configured by the current test configuration. This |
| 298 | # defaults to `script/default-ports-script.awk`. |
| 299 | # |
| 300 | # Usage: get_ports_script <archive> [default] |
| 301 | get_ports_script() { |
| 302 | local default="${ci_root}/script/default-ports-script.awk" |
| 303 | |
| 304 | get_run_env "${1:?}" ports_script "${2-${default}}" |
| 305 | } |
| 306 | |
| 307 | #Â Get the primary UART configured by the current test configuration. This |
| 308 | #Â defaults to `0`. |
| 309 | # |
| 310 | # Usage: get_primary_uart <archive> [default] |
| 311 | get_primary_uart() { |
| 312 | local default=0 |
| 313 | |
| 314 | get_run_env "${1:?}" primary_uart "${2-${default}}" |
| 315 | } |
| 316 | |
| 317 | #Â Get the payload UART configured by the current test configuration. This |
| 318 | #Â defaults to the primary UART. |
| 319 | # |
| 320 | # Usage: get_payload_uart <archive> [default] |
| 321 | get_payload_uart() { |
| 322 | local default="$(get_primary_uart "${1:?}")" |
| 323 | |
| 324 | get_run_env "${1:?}" payload_uart "${2-${default}}" |
| 325 | } |
| 326 | |
| 327 | # Get the path to a UART's environment variable directory. |
| 328 | # |
| 329 | # UART environment variables are the UART-specific environment variables |
| 330 | #Â configured by the CI's test configuration. |
| 331 | # |
| 332 | # Usage: get_uart_env_path <archive> <uart> |
| 333 | get_uart_env_path() { |
| 334 | echo "${1:?}/run/uart${2:?}" |
| 335 | } |
| 336 | |
| 337 | # Get a UART environment variable. |
| 338 | # |
| 339 | # UART environment variables are the UART-specific environment variables |
| 340 | #Â configured by the CI's test configuration. |
| 341 | # |
| 342 | # Usage: get_uart_env <archive> <uart> <variable> [default] |
| 343 | get_uart_env() { |
| 344 | if [ ! -v "${3:?}" ] && [ -f "$(get_uart_env_path "${1:?}" "${2:?}")/${3:?}" ]; then |
| 345 | cat "$(get_uart_env_path "${1:?}" "${2:?}")/${3:?}" |
| 346 | else |
Chris Kay | 3a96886 | 2022-11-17 19:18:32 +0000 | [diff] [blame] | 347 | echo "${!3-${4}}" |
Chris Kay | a75c0a6 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 348 | fi |
| 349 | } |
| 350 | |
| 351 | # Get the path to the Expect script for a given UART. This defaults to nothing. |
| 352 | # |
| 353 | # Usage: get_uart_expect_script <archive> <uart> [default] |
| 354 | get_uart_expect_script() { |
| 355 | local default= |
| 356 | |
| 357 | get_uart_env "${1:?}" "${2:?}" expect "${3-${default}}" |
| 358 | } |
| 359 | |
| 360 | # Get the FVP port for a given UART. This defaults to `5000 + ${uart}`. |
| 361 | # |
| 362 | # Usage: get_uart_port <archive> <uart> [default] |
| 363 | get_uart_port() { |
| 364 | local default="$(( 5000 + "${2:?}" ))" |
| 365 | |
| 366 | get_uart_env "${1:?}" "${2:?}" port "${3-${default}}" |
| 367 | } |
| 368 | |
Chris Kay | 4943746 | 2022-11-23 12:53:30 +0000 | [diff] [blame^] | 369 | # Set a UART environment variable. |
| 370 | # |
| 371 | # UART environment variables are the UART-specific environment variables |
| 372 | #Â configured by the CI's test configuration. |
| 373 | # |
| 374 | # Usage: set_uart_env <archive> <uart> <variable> <value> |
| 375 | set_uart_env() { |
| 376 | local path="$(get_uart_env_path "${1:?}" "${2:?}")" |
| 377 | |
| 378 | mkdir -p "${path}" && \ |
| 379 | echo "${4:?}" > "${path}/${3:?}" |
| 380 | } |
| 381 | |
| 382 | # Set the FVP port for a given UART. |
| 383 | # |
| 384 | # Usage: set_uart_port <archive> <uart> <port> |
| 385 | set_uart_port() { |
| 386 | set_uart_env "${1:?}" "${2:?}" port "${3:?}" |
| 387 | } |
| 388 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 389 | # Make a temporary directory/file insdie workspace, so that it doesn't need to |
| 390 | # be cleaned up. Jenkins is setup to clean up workspace before a job runs. |
| 391 | mktempdir() { |
| 392 | local ws="${workspace:?}" |
| 393 | |
| 394 | mktemp -d --tmpdir="$ws" |
| 395 | } |
| 396 | mktempfile() { |
| 397 | local ws="${workspace:?}" |
| 398 | |
| 399 | mktemp --tmpdir="$ws" |
| 400 | } |
| 401 | |
| 402 | not_upon() { |
| 403 | ! upon "$1" |
| 404 | } |
| 405 | |
| 406 | # Use "$1" as a boolean |
| 407 | upon() { |
| 408 | case "$1" in |
| 409 | "" | "0" | "false") return 1;; |
| 410 | *) return 0;; |
| 411 | esac |
| 412 | } |
| 413 | |
| 414 | # Check if the argument is a URL |
| 415 | is_url() { |
| 416 | echo "$1" | grep -q "://" |
| 417 | } |
| 418 | |
| 419 | # Check if a path is absolute |
| 420 | is_abs() { |
| 421 | [ "${1:0:1}" = "/" ] |
| 422 | } |
| 423 | |
| 424 | # Unset a variable based on its boolean value |
| 425 | # If foo=, foo will be unset |
| 426 | # If foo=blah, then leave it as is |
| 427 | reset_var() { |
| 428 | local var="$1" |
| 429 | local val="${!var}" |
| 430 | |
| 431 | if [ -z "$val" ]; then |
| 432 | unset "$var" |
| 433 | else |
| 434 | var="$val" |
| 435 | fi |
| 436 | } |
| 437 | |
| 438 | default_var() { |
| 439 | local var="$1" |
| 440 | local val="${!var}" |
| 441 | local default="$2" |
| 442 | |
| 443 | if [ -z "$val" ]; then |
| 444 | eval "$var=$default" |
| 445 | fi |
| 446 | } |
| 447 | |
| 448 | # String various items joined by ":" to form a path. Items are prepended by |
| 449 | # default; or 'op' can be set to 'append' to have them appended. |
| 450 | # For example, to set: PATH=foo:bar:baz:$PATH |
| 451 | extend_path() { |
| 452 | local path_var="$1" |
| 453 | local array_var="$2" |
Leonardo Sandoval | 2af9320 | 2020-07-16 17:29:18 -0500 | [diff] [blame] | 454 | local path_val="${!path_var}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 455 | local op="${op:-prepend}" |
Leonardo Sandoval | 2af9320 | 2020-07-16 17:29:18 -0500 | [diff] [blame] | 456 | local sep=':' |
| 457 | local array_val |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 458 | |
Leonardo Sandoval | 2af9320 | 2020-07-16 17:29:18 -0500 | [diff] [blame] | 459 | eval "array_val=\"\${$array_var[@]}\"" |
| 460 | array_val="$(echo ${array_val// /:})" |
| 461 | |
| 462 | [ -z "$path_val" ] && sep='' |
| 463 | |
| 464 | if [ "$op" = "prepend" ]; then |
| 465 | array_val="${array_val}${sep}${path_val}" |
| 466 | elif [ "$op" = "append" ]; then |
| 467 | array_val="${path_val}${sep}${array_val}" |
| 468 | fi |
| 469 | |
| 470 | eval "$path_var=\"$array_val\"" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 471 | } |
| 472 | |
Chris Kay | 3d80788 | 2022-08-31 16:00:02 +0100 | [diff] [blame] | 473 | #Â Expand and evaluate Bash variables and expressions in a file, whose path is |
| 474 | #Â given by the first parameter. |
| 475 | # |
| 476 | # For example, to expand a file containing the following: |
| 477 | # |
| 478 | # My name is ${name}! |
| 479 | # |
| 480 | # You might use: |
| 481 | # |
| 482 | # name="Chris" expand_template "path-to-my-file.txt" |
| 483 | # |
| 484 | # This would yield: |
| 485 | # |
| 486 | # My name is Chris! |
| 487 | # |
| 488 | # If you need to run multiple expansions on a file (e.g. to fill out information |
| 489 | # incrementally), then you can escape expansion of a variable with a backslash, |
| 490 | # e.g. `\${name}`. |
| 491 | # |
| 492 | #Â The expanded output is printed to the standard output stream. |
| 493 | expand_template() { |
| 494 | local path="$1" |
| 495 | |
| 496 | eval "cat <<-EOF |
| 497 | $(<${path}) |
| 498 | EOF" |
| 499 | } |
| 500 | |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 501 | # Fetch and extract the latest supported version of the LLVM toolchain from |
| 502 | # a compressed archive file to a target directory, if it is required. |
| 503 | setup_llvm_toolchain() { |
| 504 | link="${1:-$llvm_archive}" |
| 505 | archive="${2:-"$workspace/llvm.tar.xz"}" |
| 506 | target_dir="${3:-$llvm_dir}" |
| 507 | |
| 508 | if is_arm_jenkins_env || upon "$local_ci"; then |
| 509 | url="$link" saveas="$archive" fetch_file |
| 510 | mkdir -p $target_dir |
| 511 | extract_tarball $archive $target_dir --strip-components=1 -k |
| 512 | fi |
| 513 | } |
| 514 | |
| 515 | # Extract files from compressed archive to target directory. Supports .zip, |
| 516 | # .tar.gz, and tar.xf format |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 517 | extract_tarball() { |
| 518 | local archive="$1" |
| 519 | local target_dir="$2" |
Leonardo Sandoval | ec9e16c | 2020-09-09 14:32:40 -0500 | [diff] [blame] | 520 | local extra_params="${3:-}" |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 521 | |
| 522 | pushd "$target_dir" |
| 523 | case $(file --mime-type -b "$archive") in |
| 524 | application/gzip) |
Leonardo Sandoval | ec9e16c | 2020-09-09 14:32:40 -0500 | [diff] [blame] | 525 | tar -xz $extra_params -f $archive |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 526 | ;; |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 527 | application/zip) |
Leonardo Sandoval | ec9e16c | 2020-09-09 14:32:40 -0500 | [diff] [blame] | 528 | unzip -q $extra_params $archive |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 529 | ;; |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 530 | application/x-xz) |
| 531 | tar -x $extra_params -f $archive |
| 532 | ;; |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 533 | esac |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 534 | popd "$target_dir" |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 535 | } |
| 536 | |
Gary Morrison | 999a9d7 | 2022-03-14 18:29:06 -0500 | [diff] [blame] | 537 | # See if execution is done by Jenkins. If called with a parameter, |
| 538 | # representing a 'domain', e.g. arm.com, it will also check if |
Leonardo Sandoval | 795b621 | 2020-08-14 16:20:00 -0500 | [diff] [blame] | 539 | # JENKINS_URL contains the latter. |
| 540 | is_jenkins_env () { |
| 541 | local domain="${1-}" |
| 542 | |
| 543 | # check if running under Jenkins, if not, return non-zero |
| 544 | # the checks assumes Jenkins executing if JENKINS_HOME is set |
| 545 | [ -z "$JENKINS_HOME" ] && return 1 |
| 546 | |
| 547 | # if no parameter passed, no more checks, quit |
| 548 | [ -z "$domain" ] && return 0 |
| 549 | |
| 550 | if echo "$JENKINS_URL" | grep -q "$domain"; then |
| 551 | return 0 |
| 552 | fi |
| 553 | |
| 554 | return 1 |
| 555 | } |
| 556 | |
| 557 | |
| 558 | # Check if execution is under ARM's jenkins |
| 559 | is_arm_jenkins_env() { |
| 560 | local arm_domain="arm.com" |
| 561 | return $(is_jenkins_env "$arm_domain") |
| 562 | } |
| 563 | |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 564 | |
| 565 | # Provide correct linaro cross toolchain based on environment |
| 566 | set_cross_compile_gcc_linaro_toolchain() { |
| 567 | local cross_compile_path="/home/buildslave/tools" |
| 568 | |
| 569 | # if under arm enviroment, overide cross-compilation path |
Madhukar Pappireddy | 21a5e67 | 2021-03-08 17:49:45 -0600 | [diff] [blame] | 570 | is_arm_jenkins_env || upon "$local_ci" && cross_compile_path="/arm/pdsw/tools" |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 571 | |
| 572 | echo "${cross_compile_path}/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-" |
| 573 | } |
| 574 | |
Leonardo Sandoval | 795b621 | 2020-08-14 16:20:00 -0500 | [diff] [blame] | 575 | if is_jenkins_env; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 576 | jenkins_run=1 |
| 577 | umask 0002 |
| 578 | else |
| 579 | unset jenkins_run |
| 580 | fi |
| 581 | |
| 582 | # Project scratch location for Trusted Firmware CI |
| 583 | project_filer="${nfs_volume}/projectscratch/ssg/trusted-fw" |
| 584 | project_scratch="${PROJECT_SCRATCH:-$project_filer/ci-workspace}" |
| 585 | warehouse="${nfs_volume}/warehouse" |
| 586 | jenkins_url="${JENKINS_URL%/*}" |
| 587 | jenkins_url="${jenkins_url:-https://ci.trustedfirmware.org/}" |
| 588 | |
laurenw-arm | 35faeaa | 2021-05-03 14:28:17 -0500 | [diff] [blame] | 589 | # 11.12 Model revisions |
| 590 | model_version_11_12="11.12" |
| 591 | model_build_11_12="38" |
| 592 | model_flavour_11_12="Linux64_GCC-6.4" |
| 593 | |
laurenw-arm | afdc3bc | 2022-09-14 15:31:42 -0500 | [diff] [blame] | 594 | # 11.16 Model revisions |
| 595 | model_version_11_16="11.16" |
| 596 | model_build_11_16="16" |
| 597 | model_flavour_11_16="Linux64_GCC-6.4" |
| 598 | |
| 599 | # 11.17 Model revisions |
| 600 | model_version_11_17="11.17" |
| 601 | model_build_11_17="21" |
| 602 | model_flavour_11_17="Linux64_GCC-9.3" |
| 603 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 604 | # Model revisions |
laurenw-arm | afdc3bc | 2022-09-14 15:31:42 -0500 | [diff] [blame] | 605 | model_version="${model_version:-11.19}" |
| 606 | model_build="${model_build:-14}" |
Maksims Svecovs | 5c54251 | 2022-03-29 10:13:05 +0100 | [diff] [blame] | 607 | model_flavour="${model_flavour:-Linux64_GCC-9.3}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 608 | |
| 609 | # Model snapshots from filer are not normally not accessible from developer |
| 610 | # systems. Ignore failures from picking real path for local runs. |
| 611 | pinned_cortex="$(readlink -f ${pinned_cortex:-$project_filer/models/cortex})" || true |
| 612 | pinned_css="$(readlink -f ${pinned_css:-$project_filer/models/css})" || true |
| 613 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 614 | tforg_gerrit_url="review.trustedfirmware.org" |
| 615 | |
| 616 | # Repository URLs. We're using anonymous HTTP as they appear to be faster rather |
| 617 | # than any scheme with authentication. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 618 | tf_src_repo_url="${tf_src_repo_url:-$TF_SRC_REPO_URL}" |
| 619 | tf_src_repo_url="${tf_src_repo_url:-https://$tforg_gerrit_url/TF-A/trusted-firmware-a}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 620 | tftf_src_repo_url="${tftf_src_repo_url:-$TFTF_SRC_REPO_URL}" |
| 621 | tftf_src_repo_url="${tftf_src_repo_url:-https://$tforg_gerrit_url/TF-A/tf-a-tests}" |
Jimmy Brisson | 29ca0a0 | 2020-09-22 16:15:35 -0500 | [diff] [blame] | 622 | ci_src_repo_url="${ci_src_repo_url:-$CI_SRC_REPO_URL}" |
| 623 | ci_src_repo_url="${ci_src_repo_url:-https://$tforg_gerrit_url/ci/tf-a-ci-scripts}" |
Zelalem | dd65527 | 2020-10-06 16:29:05 -0500 | [diff] [blame] | 624 | tf_ci_repo_url="$ci_src_repo_url" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 625 | scp_src_repo_url="${scp_src_repo_url:-$SCP_SRC_REPO_URL}" |
Girish Pathak | 97f7ad4 | 2020-08-27 11:38:15 +0100 | [diff] [blame] | 626 | scp_src_repo_url="${scp_src_repo_url:-$scp_src_repo_default}" |
Olivier Deprez | 965a779 | 2019-12-16 14:09:03 +0100 | [diff] [blame] | 627 | spm_src_repo_url="${spm_src_repo_url:-$SPM_SRC_REPO_URL}" |
| 628 | spm_src_repo_url="${spm_src_repo_url:-https://$tforg_gerrit_url/hafnium/hafnium}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 629 | |
Leonardo Sandoval | d98f833 | 2021-04-13 16:46:38 -0500 | [diff] [blame] | 630 | tf_downloads="${tf_downloads:-file:///downloads/}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 631 | tfa_downloads="${tfa_downloads:-file:///downloads/tf-a}" |
| 632 | css_downloads="${css_downloads:-$tfa_downloads/css}" |
| 633 | |
Jayanth Dodderi Chidanand | bf7369d | 2022-04-06 10:59:14 +0100 | [diff] [blame] | 634 | # SCP/MCP v2.10.0 release binaries. |
Manish V Badarkhe | 83e4b8d | 2022-10-26 12:02:41 +0100 | [diff] [blame] | 635 | scp_mcp_downloads="${scp_mcp_downloads:-$tfa_downloads/css_scp_2.11.0}" |
Alexei Fedorov | 9e4473d | 2020-11-04 10:13:07 +0000 | [diff] [blame] | 636 | |
Leonardo Sandoval | 1567606 | 2020-11-19 11:58:09 -0600 | [diff] [blame] | 637 | linaro_2001_release="${linaro_2001_release:-$tfa_downloads/linaro/20.01}" |
Alexei Fedorov | e405cc3 | 2020-09-30 18:13:55 +0100 | [diff] [blame] | 638 | linaro_release="${linaro_release:-$linaro_2001_release}" |
Daniel Boulby | b63dd8c | 2022-09-23 11:55:20 +0100 | [diff] [blame] | 639 | mbedtls_version="${mbedtls_version:-2.28.1}" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 640 | |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 641 | # mbedTLS archive public hosting available at github.com |
Sandrine Bailleux | df82389 | 2022-04-22 13:27:45 +0200 | [diff] [blame] | 642 | mbedtls_archive="${mbedtls_archive:-https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v${mbedtls_version}.tar.gz}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 643 | |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 644 | # FIXME: workaround to allow all on-prem host machines to access the latest LLVM |
| 645 | # LLVM archive public hosting available at github.com |
| 646 | llvm_version="${llvm_version:-14.0.0}" |
| 647 | llvm_dir="$workspace/llvm-$llvm_version" |
| 648 | llvm_archive="${llvm_archive:-https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version/clang+llvm-$llvm_version-x86_64-linux-gnu-ubuntu-18.04.tar.xz}" |
| 649 | |
Mark Dykes | 30138ad | 2021-11-09 16:48:17 -0600 | [diff] [blame] | 650 | coverity_path="${coverity_path:-${nfs_volume}/tools/coverity/static-analysis/2020.12}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 651 | coverity_default_checkers=( |
| 652 | "--all" |
| 653 | "--checker-option DEADCODE:no_dead_default:true" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 654 | "--enable AUDIT.SPECULATIVE_EXECUTION_DATA_LEAK" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 655 | "--enable ENUM_AS_BOOLEAN" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 656 | "--enable-constraint-fpp" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 657 | "--ticker-mode none" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 658 | "--hfa" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 659 | ) |
| 660 | |
Leonardo Sandoval | d76d1e2 | 2020-10-06 16:02:52 -0500 | [diff] [blame] | 661 | docker_registry="${docker_registry:-}" |
| 662 | |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 663 | # Define toolchain version and toolchain binary paths |
Jayanth Dodderi Chidanand | cc4d234 | 2022-09-12 14:44:21 +0100 | [diff] [blame] | 664 | toolchain_version="11.3.rel1" |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 665 | |
Jayanth Dodderi Chidanand | cc4d234 | 2022-09-12 14:44:21 +0100 | [diff] [blame] | 666 | aarch64_none_elf_dir="${nfs_volume}/pdsw/tools/arm-gnu-toolchain-${toolchain_version}-x86_64-aarch64-none-elf" |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 667 | aarch64_none_elf_prefix="aarch64-none-elf-" |
| 668 | |
Jayanth Dodderi Chidanand | cc4d234 | 2022-09-12 14:44:21 +0100 | [diff] [blame] | 669 | arm_none_eabi_dir="${nfs_volume}/pdsw/tools/arm-gnu-toolchain-${toolchain_version}-x86_64-arm-none-eabi" |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 670 | arm_none_eabi_prefix="arm-none-eabi-" |
| 671 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 672 | path_list=( |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 673 | "${aarch64_none_elf_dir}/bin" |
| 674 | "${arm_none_eabi_dir}/bin" |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 675 | "${llvm_dir}/bin" |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 676 | "${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin" |
| 677 | "$coverity_path/bin" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 678 | ) |
| 679 | |
| 680 | ld_library_path_list=( |
| 681 | ) |
| 682 | |
Sandrine Bailleux | a6a1d6e | 2020-08-07 10:24:17 +0200 | [diff] [blame] | 683 | license_path_list=${license_path_list-( |
| 684 | )} |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 685 | |
| 686 | # Setup various paths |
| 687 | if upon "$retain_paths"; then |
| 688 | # If explicitly requested, retain local paths; apppend CI paths to the |
| 689 | # existing ones. |
| 690 | op="append" extend_path "PATH" "path_list" |
| 691 | op="append" extend_path "LD_LIBRARY_PATH" "ld_library_path_list" |
| 692 | op="append" extend_path "LM_LICENSE_FILE" "license_path_list" |
| 693 | else |
| 694 | # Otherwise, prepend CI paths so that they take effect before local ones |
| 695 | extend_path "PATH" "path_list" |
| 696 | extend_path "LD_LIBRARY_PATH" "ld_library_path_list" |
| 697 | extend_path "LM_LICENSE_FILE" "license_path_list" |
| 698 | fi |
| 699 | |
| 700 | export LD_LIBRARY_PATH |
| 701 | export LM_LICENSE_FILE |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 702 | export ARM_TOOL_VARIANT=ult |
| 703 | |
| 704 | # vim: set tw=80 sw=8 noet: |