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 | # |
Zelalem | c9531f8 | 2020-08-04 15:37:08 -0500 | [diff] [blame] | 3 | # Copyright (c) 2019-2020, 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 sourced from the build_package.sh script to use |
| 9 | # coverity_wrapper() function as a build wrapper. |
| 10 | # |
| 11 | # This wrapper supports two work flows: |
| 12 | # |
| 13 | # - Compare the branch under test with that of master, and print defects. If |
| 14 | # there are defects, we arrange the build to be marked as unstable. Set |
| 15 | # $cov_run_type to 'branch-report-compare' to use this. |
| 16 | # |
| 17 | # - Commit and create snapshot for the entire branch. Set $cov_run_type to |
| 18 | # 'branch-report-full' to use this. |
| 19 | # |
| 20 | # Coverity analysis involves contacting the server, which have shown to be very |
| 21 | # slow. Depending on the type of analysis performed, we might have to do |
| 22 | # analysis more than once, and doing that in series would only increase the turn |
Zelalem | c9531f8 | 2020-08-04 15:37:08 -0500 | [diff] [blame] | 23 | # around time. To mitigate this, all Coverity commands, are called from a |
| 24 | # Makefile, and run in parallel. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 25 | |
| 26 | coverity_wrapper() { |
| 27 | local cov_dir="$workspace/coverity" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 28 | local cov_compiler="${cov_compiler:-${CROSS_COMPILE}gcc}" |
| 29 | |
Zelalem | aec5815 | 2020-08-11 12:49:29 -0500 | [diff] [blame] | 30 | local auth_file="$cov_auth_file" |
Zelalem | c9531f8 | 2020-08-04 15:37:08 -0500 | [diff] [blame] | 31 | local makefile="$ci_root/script/coverity-Makefile" |
| 32 | local defects_summary="$workspace/defects-summary.txt" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 33 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 34 | local description |
| 35 | local need_compare |
| 36 | |
Zelalem | aec5815 | 2020-08-11 12:49:29 -0500 | [diff] [blame] | 37 | # If auth file is not provided and if on Arm infrastructure copy it |
Arthur She | 4c61059 | 2025-02-03 21:39:57 -0800 | [diff] [blame^] | 38 | if [ -z "$auth_file" ] && echo "$JENKINS_PUBLIC_URL" | grep -q "oss.arm.com"; then |
Zelalem | aec5815 | 2020-08-11 12:49:29 -0500 | [diff] [blame] | 39 | local auth_url="$project_filer/ci-files/coverity/tfcibot@$coverity_host" |
| 40 | url="$auth_url" saveas="$workspace/tfcibot@$coverity_host" fetch_file |
| 41 | auth_file="$workspace/tfcibot@$coverity_host" |
| 42 | fi |
| 43 | |
| 44 | if [ -z "$auth_file" ]; then |
| 45 | die "Coverity authentication token not provided" |
| 46 | fi |
| 47 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 48 | echo_w |
| 49 | mkdir -p "$cov_dir" |
| 50 | |
| 51 | if echo "${cov_run_type:?}" | grep -iq "branch-report-compare"; then |
| 52 | need_compare=1 |
| 53 | local golden_url="${cov_golden_url:-$tf_src_repo_url}" |
| 54 | local golden_ref="${cov_golden_ref:-master}" |
Zelalem | c9531f8 | 2020-08-04 15:37:08 -0500 | [diff] [blame] | 55 | local defects_file="$workspace/diff-defects.txt" |
| 56 | else |
| 57 | local defects_file="$workspace/full-defects.txt" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 58 | fi |
| 59 | |
| 60 | if upon "$local_ci"; then |
| 61 | description="$USER-local ${cov_checker:?}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 62 | else |
| 63 | description="$JOB_NAME#$BUILD_NUMBER ${cov_checker:?}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 64 | fi |
| 65 | |
| 66 | # Create a stream and assign to Trusted Firmware project |
| 67 | chmod 400 "$auth_file" |
| 68 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 69 | local minus_j="-j" |
| 70 | if upon "$cov_serial_build"; then |
| 71 | minus_j= |
| 72 | fi |
| 73 | |
| 74 | # Call Coverity targets |
| 75 | echo "Coverity run type: ${cov_run_type:?}" |
Zelalem | c9531f8 | 2020-08-04 15:37:08 -0500 | [diff] [blame] | 76 | # Remove the `make` from the front of the command line as we need to |
| 77 | # insert -C <directory> inside the makefile |
| 78 | shift |
| 79 | MAKEFLAGS= SUBMAKE="$@" make -r $minus_j -f "$makefile" -C "$workspace" \ |
| 80 | auth_file=$auth_file\ |
| 81 | golden_url=$golden_url\ |
| 82 | golden_ref=$golden_ref\ |
| 83 | tf_src_repo_url=$tf_src_repo_url\ |
| 84 | cov_compiler=$cov_compiler\ |
| 85 | minus_j=$minus_j\ |
| 86 | description="$description"\ |
| 87 | ci_root="$ci_root"\ |
| 88 | $cov_run_type 2>&3 || exit 1 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 89 | |
| 90 | # If there were defects, print them out to the console. For local CI, |
| 91 | # print them in yellow--the same color we'd use for UNSTABLE builds. |
| 92 | if [ -s "$defects_file" ]; then |
| 93 | echo_w |
| 94 | echo_w "Coverity defects found:" |
| 95 | echo_w |
| 96 | if upon "$local_ci"; then |
| 97 | echo_w "$(tput setaf 3)" |
| 98 | fi |
| 99 | cat "$defects_file" >&3 |
| 100 | if upon "$local_ci"; then |
| 101 | echo_w "$(tput sgr0)" |
| 102 | fi |
| 103 | echo_w |
Zelalem | c9531f8 | 2020-08-04 15:37:08 -0500 | [diff] [blame] | 104 | cat $defects_summary >&3 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 105 | echo_w |
| 106 | build_unstable >&3 |
| 107 | echo_w |
| 108 | else |
| 109 | echo_w |
| 110 | echo_w "No coverity defects found." |
| 111 | echo_w |
| 112 | fi |
| 113 | } |