blob: 95cc32fc4e380d64b6cb9e51e31c251f5c1fa7c1 [file] [log] [blame]
Saul Romerocacda172023-03-10 14:23:41 +00001#!/usr/bin/env bash
2#
3# Copyright (c) 2023, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# Include variables and functions to be used by these scripts
9source "$CI_ROOT/utils.sh"
10################################################################################
11# CI VARIABLES:
12# workspace, warehouse, artefacts
13# GLOBAL VARIABLES:
14# OUTDIR, PROJECT, FALLBACK_PLUGIN_URL, FALLBACK_FILES, PLUGIN_BINARY
15################################################################################
16# Defining constants
17GERRIT_URL=${GERRIT_URL:-https://gerrit.oss.arm.com}
18QA_REPO_USER=jenkins_auto
19QA_REPO_INTERNAL=${QA_REPO_INTERNAL:-https://${QA_REPO_USER}:${QA_REPO_TOKEN}@git.gitlab.arm.com/tooling/qa-tools-internal.git}
20QA_REPO_PUBLIC=${QA_REPO_PUBLIC:-https://git.gitlab.arm.com/tooling/qa-tools.git}
21QA_REPO_NAME=qa-tools
22# Internal globals
23CODE_COVERAGE_FOLDER="${OUTDIR:-$workspace}/qa-code-coverage"
24DEBUG_FOLDER=${artefacts}/debug
25RELEASE_FOLDER=${artefacts}/release
26TRACE_FILE_PREFIX=covtrace
27CONFIG_JSON=${CODE_COVERAGE_FOLDER}/configuration_file.json
28INTERMEDIATE_LAYER_FILE=${CODE_COVERAGE_FOLDER}/intermediate_layer.json
29INFO_FILE=${CODE_COVERAGE_FOLDER}/coverage.info
30REPORT_FOLDER=${CODE_COVERAGE_FOLDER}/lcov
31
Paul Sokolovskyd008f5d2023-03-24 16:10:47 +070032QA_REPO=${QA_TOOLS_REPO:-$QA_REPO_PUBLIC}
33QA_REFSPEC=${QA_TOOLS_BRANCH:-master}
Saul Romerocacda172023-03-10 14:23:41 +000034
35
36################################################################################
37# Deploy qa-tools into the current directory
38# GLOBALS:
39# QA_REPO, QA_REPO_NAME, QA_REFSPEC
40# ARGUMENTS:
41# None
42# OUTPUTS:
43# Clones the qa-tools repo from the global variables with the given
44# commit hash.
45# RETURN:
46# 0 if succeeds, non-zero on error.
47################################################################################
48deploy_qa_tools() {
49 git clone "${QA_REPO}" ${QA_REPO_NAME}
50 cd ${QA_REPO_NAME} && git checkout "${QA_REFSPEC}" && cd ..
51}
52
53
54################################################################################
55# Builds or downloads the QA Code Coverage Tool
56# GLOBALS:
57# CODE_COVERAGE_FOLDER, QA_REPO, QA_REPO_NAME, QA_REFSPEC, FALLBACK_PLUGIN_URL
58# ARGUMENTS:
59# None
60# OUTPUTS:
61# Creates coverage folder and builds/downloads there the plugin binaries.
62# It exports the binary plugin location to coverage_trace_plugin.
63# RETURN:
64# 0 if succeeds, non-zero on error.
65################################################################################
66build_tool() {
67 echo "Building QA Code coverage tool..."
68 PLUGIN_BINARY="${FALLBACK_FILES%%,*}" # The first in the list of the binary files
69 local PVLIB_HOME="warehouse/SysGen/PVModelLib/$model_version/$model_build/external"
70 local LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CODE_COVERAGE_FOLDER
71 mkdir -p ${CODE_COVERAGE_FOLDER}
72 pushd "${CODE_COVERAGE_FOLDER}"
73 deploy_qa_tools
74 local cc_source=$(find . -type f -name 'coverage_trace.cc')
75 local fallback="wget -q ${FALLBACK_PLUGIN_URL}/{$FALLBACK_FILES}"
76 echo "Warehouse=${warehouse}"
77 eval "$fallback"
78 ls -al
79 export coverage_trace_plugin="${CODE_COVERAGE_FOLDER}/${PLUGIN_BINARY}"
80 popd
81}
82
83 ################################################################################
84 # Creates configuration file for intermediate layer generation
85 # GLOBALS:
86 # PROJECT, CONFIG_JSON, INTERMEDIATE_LAYER_FILE, CODE_COVERAGE_FOLDER
87 # ARGUMENTS:
88 # $1 Folder where are the elf/axf files.
89 # $2 List of elf/axf file names.
90 # $3 Path for trace files.
91 # $4 Root folder name where all the repos are cloned.
92 # OUTPUTS:
93 # Creates coverage folder and builds/downloads there the plugin binaries.
94 # RETURN:
95 # 0 if succeeds, non-zero on error.
96 ################################################################################
97create_config_json() {
98 set +e
99 if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]
100 then
101 cat << END
102Missing argument at '${FUNCNAME[0]}'.
103USAGE:
104 create_config_json ' Glob binaries' 'Glob trace files' 'Repos root folder name'
105 Example:
106 create_config_json 'bl1.elf bl2.elf' 'tf'
107END
108 exit 1
109 fi
110 local ELF_FOLDER=$1
111 local dwarf_array=($2)
112 local TRACE_FOLDER=$3
113 local root_repos_foolder="${4:-$workspace}"
114 local scm_sources=""
115
116 # Obtaining binaries from array
117 bin_section=""
118 for index in "${!dwarf_array[@]}"
119 do
120 local elf_file="${ELF_FOLDER}/${dwarf_array[$index]}"
121 cp "$elf_file" ${CODE_COVERAGE_FOLDER}/.
122 read -r -d '' bin_section << EOM
123${bin_section}
124 {
125 "name": "$elf_file",
126 "traces": [
127 "${TRACE_FOLDER}/${TRACE_FILE_PREFIX:-covtrace}-*.log"
128 ]
129 }
130EOM
131 if [ $index -lt $((${#dwarf_array[@]} - 1)) ];then
132 bin_section="${bin_section},"
133 fi
134 done
135
136 if [ "$PROJECT" = "SCP" ]; then
137 read -r -d '' scm_sources << EOM
138 [
139 {
140 "type": "git",
141 "URL": "$CC_SCP_URL",
142 "COMMIT": "$CC_SCP_COMMIT",
143 "REFSPEC": "$CC_SCP_REFSPEC",
144 "LOCATION": "scp"
145 },
146 {
147 "type": "git",
148 "URL": "$CC_CMSIS_URL",
149 "COMMIT": "$CC_CMSIS_COMMIT",
150 "REFSPEC": "$CC_CMSIS_REFSPEC",
151 "LOCATION": "scp/contrib/cmsis/git"
152 }
153 ]
154EOM
155elif [ "$PROJECT" = "TF-A" ]; then
156 read -r -d '' scm_sources << EOM
157 [
158 {
159 "type": "git",
160 "URL": "$CC_TRUSTED_FIRMWARE_URL",
161 "COMMIT": "$CC_TRUSTED_FIRMWARE_COMMIT",
162 "REFSPEC": "$CC_TRUSTED_FIRMWARE_REFSPEC",
163 "LOCATION": "trusted_firmware"
164 },
165 {
166 "type": "http",
167 "URL": "$mbedtls_archive",
168 "COMPRESSION": "xz",
169 "EXTRA_PARAMS": "--strip-components=1",
170 "LOCATION": "mbedtls"
171 }
172 ]
173EOM
Saul Romero82bcfb02023-06-27 16:24:13 +0100174elif [ "$PROJECT" = "HAFNIUM" ]; then
175 read -r -d '' scm_sources << EOM
176 [
177 {
178 "type": "git",
179 "URL": "$CC_TRUSTED_FIRMWARE_URL",
180 "COMMIT": "$CC_TRUSTED_FIRMWARE_COMMIT",
181 "REFSPEC": "$CC_TRUSTED_FIRMWARE_REFSPEC",
182 "LOCATION": "trusted_firmware"
183 },
184 {
185 "type": "git",
186 "URL": "$CC_SPM_URL",
187 "COMMIT": "$CC_SPM_COMMIT",
188 "REFSPEC": "$CC_SPM_REFSPEC",
189 "LOCATION": "spm"
190 }
191 ]
192EOM
Saul Romerocacda172023-03-10 14:23:41 +0000193 else
194 echo "SCM sources not provided for project '${PROJECT}'"
195 exit 1
196 fi
197local metadata="\"BUILD_CONFIG\": \"${BUILD_CONFIG}\", \"RUN_CONFIG\": \"${RUN_CONFIG}\""
198cat <<EOF > "${CONFIG_JSON}"
199{
200 "configuration":
201 {
202 "remove_workspace": true,
203 "include_assembly": true
204 },
205 "parameters":
206 {
207 "objdump": "${OBJDUMP}",
208 "readelf": "${READELF}",
209 "sources": $scm_sources,
210 "workspace": "${root_repos_foolder}",
211 "output_file": "${INTERMEDIATE_LAYER_FILE}",
212 "metadata": {$metadata}
213 },
214 "elfs": [
215 ${bin_section}
216 ]
217}
218EOF
219
220}
221
222################################################################################
223# Creates intermediate layer json file with trace coverage data.
224#
225# Creates a configuration JSON file to be the input for the intermediate
226# layer file creation.
227# GLOBALS:
228# TRACE_FILE_PREFIX, CODE_COVERAGE_FOLDER
229# ARGUMENTS:
230# $1 Location of trace files.
231# $2 Location of elf/axf files.
232# $3 List of binaries to be checked the traces.
233# $4 Root folder name where all the repos are cloned.
234# OUTPUTS:
235# A configuration JSON file.
236# An intermediate layer JSON file.
237# RETURN:
238# 0 if succeeds, non-zero on error.
239################################################################################
240create_intermediate_layer() {
241 local TRACE_FOLDER="$1"
242 local ELF_FOLDER="$2"
243 local LIST_OF_BINARIES="$3"
244 local root_repos_foolder="$4"
245
246 # Copying trace files into the qa-tools executables folder
247 if [ $(ls -1 ${TRACE_FOLDER}/${TRACE_FILE_PREFIX}-* 2>/dev/null | wc -l) != 0 ]; then
248 cp ${TRACE_FOLDER}/${TRACE_FILE_PREFIX}-* ${CODE_COVERAGE_FOLDER}/.
249 else
250 echo "Trace files not present, aborting reports..."
251 ls -al ${TRACE_FOLDER}
252 exit -1
253 fi
254 create_config_json "${ELF_FOLDER}" "${LIST_OF_BINARIES}" "${TRACE_FOLDER}" "$root_repos_foolder"
255 python3 ${CODE_COVERAGE_FOLDER}/qa-tools/coverage-tool/coverage-reporting/intermediate_layer.py \
256 --config-json ${CONFIG_JSON}
257
258}
259
260
261################################################################################
262# Creates LCOV coverage report.
263# GLOBALS:
264# CODE_COVERAGE_FOLDER, workspace, INTERMEDIATE_LAYER_FILE, INFO_FILE,
265# REPORT_FOLDER
266# ARGUMENTS:
267# None
268# OUTPUTS:
269# A coverage info file.
270# LCOV HTML coverage report.
271# RETURN:
272# 0 if succeeds, non-zero on error.
273################################################################################
274create_coverage_report() {
275 python3 ${CODE_COVERAGE_FOLDER}/qa-tools/coverage-tool/coverage-reporting/generate_info_file.py \
276 --workspace ${workspace} --json ${INTERMEDIATE_LAYER_FILE} --info ${INFO_FILE}
277 genhtml --branch-coverage ${INFO_FILE} --output-directory ${REPORT_FOLDER}
278}