Leonardo Sandoval | adfb6ad | 2021-07-16 12:09:03 -0500 | [diff] [blame] | 1 | #!/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 | |
| 18 | set -x |
| 19 | |
| 20 | FEEDBACK=feedback.log |
| 21 | COVTRACE=covtrace.log |
| 22 | COVPREFIX=covtrace- |
| 23 | CONFIG_JSON=config_file.json |
| 24 | OUTPUT_JSON=output_file.json |
| 25 | |
| 26 | # Variables aware of environment variables |
| 27 | PROJECT_ROOT="${1:-${PWD}}" |
| 28 | TRACES_DIR="${2:-${PWD}}" |
| 29 | ELF_ARTIFACTS_DIR="${3:-${PWD}}" |
| 30 | TF_GERRIT_REFSPEC="${4:-}" |
| 31 | |
| 32 | # check if LAVA feedback.log exists, if not, just quit |
| 33 | if [ ! -f ${FEEDBACK} ]; then |
| 34 | echo ${FEEDBACK} file not found |
| 35 | exit 0 |
| 36 | fi |
| 37 | |
| 38 | # From the feedback log, take only the trace data |
| 39 | grep ^${COVPREFIX} ${FEEDBACK} > ${COVTRACE} |
| 40 | |
| 41 | # Check if there are traces |
| 42 | if [ -n "$(find ${COVTRACE} -empty)" ]; then |
| 43 | echo no code coverage traces found |
| 44 | exit 0 |
| 45 | fi |
| 46 | |
| 47 | # Generate config json file required for coverage reporting tools |
| 48 | cat > ${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": [ |
| 72 | EOF |
| 73 | |
| 74 | # Split COVTRACE into different files |
| 75 | for 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} |
| 80 | done |
| 81 | |
| 82 | # List the elf files |
| 83 | find ${ELF_ARTIFACTS_DIR} -name '*.elf' > elfs.txt |
| 84 | elfs=($(cat elfs.txt)) |
| 85 | |
| 86 | # Populate elfs config elements |
| 87 | for 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 | }, |
| 94 | EOF |
| 95 | done |
| 96 | |
| 97 | # print last elf and close main json body |
| 98 | cat >> ${CONFIG_JSON} <<EOF |
| 99 | { |
| 100 | "name": "${elfs[-1]}", |
| 101 | "traces": [ "${TRACES_DIR}/${COVPREFIX}*" ] |
| 102 | } |
| 103 | ] |
| 104 | } |
| 105 | EOF |