blob: b6c91464a93278fcc1e69fe1f65fc0389a924ce0 [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
20FEEDBACK=feedback.log
21COVTRACE=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
39grep ^${COVPREFIX} ${FEEDBACK} > ${COVTRACE}
40
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
78 grep ^${trace_file} ${COVTRACE} > ${trace_file}
79 sed -i "s;${trace_file} ;;g" ${trace_file}
80done
81
82# List the elf files
83find ${ELF_ARTIFACTS_DIR} -name '*.elf' > elfs.txt
84elfs=($(cat elfs.txt))
85
86# Populate elfs config elements
87for elf in ${elfs[@]::${#elfs[@]}-1}; do
88 # fill the 'elfs' elements
89 cat >> ${CONFIG_JSON} <<EOF
90 {
91 "name": "${elf}",
92 "traces": [ "${TRACES_DIR}/${COVPREFIX}*" ]
93 },
94EOF
95done
96
97# print last elf and close main json body
98cat >> ${CONFIG_JSON} <<EOF
99 {
100 "name": "${elfs[-1]}",
101 "traces": [ "${TRACES_DIR}/${COVPREFIX}*" ]
102 }
103 ]
104}
105EOF