blob: 7a0959cb0cc4e6726de2b7951c03a7fd67fd75c4 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Zelalemc9531f82020-08-04 15:37:08 -05003# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
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
Zelalemc9531f82020-08-04 15:37:08 -050023# around time. To mitigate this, all Coverity commands, are called from a
24# Makefile, and run in parallel.
Fathi Boudra422bf772019-12-02 11:10:16 +020025
26coverity_wrapper() {
27 local cov_dir="$workspace/coverity"
Fathi Boudra422bf772019-12-02 11:10:16 +020028 local cov_compiler="${cov_compiler:-${CROSS_COMPILE}gcc}"
29
Zelalemaec58152020-08-11 12:49:29 -050030 local auth_file="$cov_auth_file"
Zelalemc9531f82020-08-04 15:37:08 -050031 local makefile="$ci_root/script/coverity-Makefile"
32 local defects_summary="$workspace/defects-summary.txt"
Fathi Boudra422bf772019-12-02 11:10:16 +020033
Fathi Boudra422bf772019-12-02 11:10:16 +020034 local description
35 local need_compare
36
Zelalemaec58152020-08-11 12:49:29 -050037 # If auth file is not provided and if on Arm infrastructure copy it
Gary Morrison999a9d72022-03-14 18:29:06 -050038 if [ -z "$auth_file" ] && echo "$JENKINS_URL" | grep -q "oss.arm.com"; then
Zelalemaec58152020-08-11 12:49:29 -050039 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 Boudra422bf772019-12-02 11:10:16 +020048 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}"
Zelalemc9531f82020-08-04 15:37:08 -050055 local defects_file="$workspace/diff-defects.txt"
56 else
57 local defects_file="$workspace/full-defects.txt"
Fathi Boudra422bf772019-12-02 11:10:16 +020058 fi
59
60 if upon "$local_ci"; then
61 description="$USER-local ${cov_checker:?}"
Fathi Boudra422bf772019-12-02 11:10:16 +020062 else
63 description="$JOB_NAME#$BUILD_NUMBER ${cov_checker:?}"
Fathi Boudra422bf772019-12-02 11:10:16 +020064 fi
65
66 # Create a stream and assign to Trusted Firmware project
67 chmod 400 "$auth_file"
68
Fathi Boudra422bf772019-12-02 11:10:16 +020069 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:?}"
Zelalemc9531f82020-08-04 15:37:08 -050076 # 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 Boudra422bf772019-12-02 11:10:16 +020089
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
Zelalemc9531f82020-08-04 15:37:08 -0500104 cat $defects_summary >&3
Fathi Boudra422bf772019-12-02 11:10:16 +0200105 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}