blob: 058c74127b3a1e9f25346ee3d90fae17ad4eb90d [file] [log] [blame]
Leonardo Sandovaladfb6ad2021-07-16 12:09:03 -05001#!/usr/bin/env bash
2#
3# Copyright (c) 2021 Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7# Takes as input the feedback.log, produced previously `log-splitter.py` script and creates
8# several files, including a configuration file (config_file.json) and one more traces files, i.e.
9# covtrace-FVP_Base_RevC_2xAEMvA.cluster0.cpu0.log, covtrace-FVP_Base_RevC_2xAEMvA.cluster0.cpu1.log,
10# etc. The output files are used by reporting tools (https://gitlab.arm.com/tooling/qa-tools/-/tree/master/coverage-tool) to produce coverage html reports
11#
12# Parameters:
13# 1. Full path folder name where the project resides, i.e. path to trusted-firmware-a
14# 2. Full path folder where the traces reside
15# 3. Full path folder where ELFs reside
16# 4. The corresponding git-refspec for the commit being traced
17
18set -x
19
Manish V Badarkhe9a32add2022-11-25 13:56:11 +000020FEEDBACK=lava-common.log
Leonardo Sandovaladfb6ad2021-07-16 12:09:03 -050021COVTRACE=covtrace.log
22COVPREFIX=covtrace-
23CONFIG_JSON=config_file.json
24OUTPUT_JSON=output_file.json
25
26# Variables aware of environment variables
27PROJECT_ROOT="${1:-${PWD}}"
28TRACES_DIR="${2:-${PWD}}"
29ELF_ARTIFACTS_DIR="${3:-${PWD}}"
30TF_GERRIT_REFSPEC="${4:-}"
31
32# check if LAVA feedback.log exists, if not, just quit
33if [ ! -f ${FEEDBACK} ]; then
34 echo ${FEEDBACK} file not found
35 exit 0
36fi
37
38# From the feedback log, take only the trace data
Paul Sokolovsky14e67af2023-02-15 15:43:36 +070039grep -a ^${COVPREFIX} ${FEEDBACK} > ${COVTRACE}
Leonardo Sandovaladfb6ad2021-07-16 12:09:03 -050040
41# Check if there are traces
42if [ -n "$(find ${COVTRACE} -empty)" ]; then
43 echo no code coverage traces found
44 exit 0
45fi
46
47# Generate config json file required for coverage reporting tools
48cat > ${CONFIG_JSON} <<EOF
49{
50 "configuration":
51 {
52 "remove_workspace": false,
53 "include_assembly": true
54 },
55 "parameters":
56 {
57 "objdump": "aarch64-none-elf-objdump",
58 "readelf": "aarch64-none-elf-readelf",
59 "sources": [
60 {
61 "type": "git",
62 "URL": "https://review.trustedfirmware.org/TF-A/trusted-firmware-a",
63 "COMMIT": "",
64 "REFSPEC": "${TF_GERRIT_REFSPEC}",
65 "LOCATION": "trusted-firmware-a"
Saul Romero9b64c962023-11-20 14:42:36 +000066 },
67 {
68 "type": "git",
69 "URL": "https://review.trustedfirmware.org/hafnium/hafnium",
70 "COMMIT": "",
71 "REFSPEC": "${SPM_REFSPEC}",
Saul Romerodfadeb62024-08-15 13:50:35 +010072 "LOCATION": "spm"
Saul Romero9b64c962023-11-20 14:42:36 +000073 },
74 {
75 "type": "http",
76 "URL": "$MBEDTLS_URL",
77 "COMPRESSION": "xz",
78 "EXTRA_PARAMS": "--strip-components=1",
Saul Romerodfadeb62024-08-15 13:50:35 +010079 "LOCATION": "mbedtls"
Saul Romero9b64c962023-11-20 14:42:36 +000080 }
Leonardo Sandovaladfb6ad2021-07-16 12:09:03 -050081 ],
82 "workspace": "${PROJECT_ROOT}",
83 "output_file": "${OUTPUT_JSON}"
84 },
85 "elfs": [
86EOF
87
88# Split COVTRACE into different files
89for trace_file in $(awk '{print $1}' ${COVTRACE} | uniq); do
90
91 # split & remove trace filename in log
Paul Sokolovsky14e67af2023-02-15 15:43:36 +070092 grep -a ^${trace_file} ${COVTRACE} > ${trace_file}
Leonardo Sandovaladfb6ad2021-07-16 12:09:03 -050093 sed -i "s;${trace_file} ;;g" ${trace_file}
94done
95
96# List the elf files
97find ${ELF_ARTIFACTS_DIR} -name '*.elf' > elfs.txt
J-Alves943b1312024-07-15 18:35:06 +010098grep -w "bl1\|bl2\|bl31\|secure_hafnium" elfs.txt > tf-a-elfs.txt
Manish V Badarkhe70017fd2023-01-19 13:55:43 +000099elfs=($(cat tf-a-elfs.txt))
Leonardo Sandovaladfb6ad2021-07-16 12:09:03 -0500100
101# Populate elfs config elements
102for elf in ${elfs[@]::${#elfs[@]}-1}; do
103 # fill the 'elfs' elements
104 cat >> ${CONFIG_JSON} <<EOF
105 {
106 "name": "${elf}",
107 "traces": [ "${TRACES_DIR}/${COVPREFIX}*" ]
108 },
109EOF
110done
111
112# print last elf and close main json body
113cat >> ${CONFIG_JSON} <<EOF
114 {
115 "name": "${elfs[-1]}",
116 "traces": [ "${TRACES_DIR}/${COVPREFIX}*" ]
117 }
118 ]
119}
120EOF