Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 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 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 30 | local auth_file="${cov_auth_file:-$ci_root/coverity/tfcibot@$coverity_host}" |
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 | |
| 37 | echo_w |
| 38 | mkdir -p "$cov_dir" |
| 39 | |
| 40 | if echo "${cov_run_type:?}" | grep -iq "branch-report-compare"; then |
| 41 | need_compare=1 |
| 42 | local golden_url="${cov_golden_url:-$tf_src_repo_url}" |
| 43 | local golden_ref="${cov_golden_ref:-master}" |
Zelalem | c9531f8 | 2020-08-04 15:37:08 -0500 | [diff] [blame^] | 44 | local defects_file="$workspace/diff-defects.txt" |
| 45 | else |
| 46 | local defects_file="$workspace/full-defects.txt" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 47 | fi |
| 48 | |
| 49 | if upon "$local_ci"; then |
| 50 | description="$USER-local ${cov_checker:?}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 51 | else |
| 52 | description="$JOB_NAME#$BUILD_NUMBER ${cov_checker:?}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 53 | fi |
| 54 | |
| 55 | # Create a stream and assign to Trusted Firmware project |
| 56 | chmod 400 "$auth_file" |
| 57 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 58 | local minus_j="-j" |
| 59 | if upon "$cov_serial_build"; then |
| 60 | minus_j= |
| 61 | fi |
| 62 | |
| 63 | # Call Coverity targets |
| 64 | echo "Coverity run type: ${cov_run_type:?}" |
Zelalem | c9531f8 | 2020-08-04 15:37:08 -0500 | [diff] [blame^] | 65 | # Remove the `make` from the front of the command line as we need to |
| 66 | # insert -C <directory> inside the makefile |
| 67 | shift |
| 68 | MAKEFLAGS= SUBMAKE="$@" make -r $minus_j -f "$makefile" -C "$workspace" \ |
| 69 | auth_file=$auth_file\ |
| 70 | golden_url=$golden_url\ |
| 71 | golden_ref=$golden_ref\ |
| 72 | tf_src_repo_url=$tf_src_repo_url\ |
| 73 | cov_compiler=$cov_compiler\ |
| 74 | minus_j=$minus_j\ |
| 75 | description="$description"\ |
| 76 | ci_root="$ci_root"\ |
| 77 | $cov_run_type 2>&3 || exit 1 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 78 | |
| 79 | # If there were defects, print them out to the console. For local CI, |
| 80 | # print them in yellow--the same color we'd use for UNSTABLE builds. |
| 81 | if [ -s "$defects_file" ]; then |
| 82 | echo_w |
| 83 | echo_w "Coverity defects found:" |
| 84 | echo_w |
| 85 | if upon "$local_ci"; then |
| 86 | echo_w "$(tput setaf 3)" |
| 87 | fi |
| 88 | cat "$defects_file" >&3 |
| 89 | if upon "$local_ci"; then |
| 90 | echo_w "$(tput sgr0)" |
| 91 | fi |
| 92 | echo_w |
Zelalem | c9531f8 | 2020-08-04 15:37:08 -0500 | [diff] [blame^] | 93 | cat $defects_summary >&3 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 94 | echo_w |
| 95 | build_unstable >&3 |
| 96 | echo_w |
| 97 | else |
| 98 | echo_w |
| 99 | echo_w "No coverity defects found." |
| 100 | echo_w |
| 101 | fi |
| 102 | } |