blob: 1658e287575cedef1bd01c1774af7d42c49e61e5 [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"
66 }
67 ],
68 "workspace": "${PROJECT_ROOT}",
69 "output_file": "${OUTPUT_JSON}"
70 },
71 "elfs": [
72EOF
73
74# Split COVTRACE into different files
75for trace_file in $(awk '{print $1}' ${COVTRACE} | uniq); do
76
77 # split & remove trace filename in log
Paul Sokolovsky14e67af2023-02-15 15:43:36 +070078 grep -a ^${trace_file} ${COVTRACE} > ${trace_file}
Leonardo Sandovaladfb6ad2021-07-16 12:09:03 -050079 sed -i "s;${trace_file} ;;g" ${trace_file}
80done
81
82# List the elf files
83find ${ELF_ARTIFACTS_DIR} -name '*.elf' > elfs.txt
Manish V Badarkhe70017fd2023-01-19 13:55:43 +000084grep -w "bl1\|bl2\|bl31" elfs.txt > tf-a-elfs.txt
85elfs=($(cat tf-a-elfs.txt))
Leonardo Sandovaladfb6ad2021-07-16 12:09:03 -050086
87# Populate elfs config elements
88for elf in ${elfs[@]::${#elfs[@]}-1}; do
89 # fill the 'elfs' elements
90 cat >> ${CONFIG_JSON} <<EOF
91 {
92 "name": "${elf}",
93 "traces": [ "${TRACES_DIR}/${COVPREFIX}*" ]
94 },
95EOF
96done
97
98# print last elf and close main json body
99cat >> ${CONFIG_JSON} <<EOF
100 {
101 "name": "${elfs[-1]}",
102 "traces": [ "${TRACES_DIR}/${COVPREFIX}*" ]
103 }
104 ]
105}
106EOF