Raef Coles | 8cbeed5 | 2024-03-11 16:24:57 +0000 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright (c) 2024, Arm Limited. All rights reserved. |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | |
| 6 | error() |
| 7 | { |
| 8 | printf "\e[31m[ERR] $1\e[0m\n" 1>&2 |
| 9 | if test -n "$2" |
| 10 | then |
| 11 | exit $2 |
| 12 | else |
| 13 | exit 1 |
| 14 | fi |
| 15 | } |
| 16 | |
| 17 | usage() { |
| 18 | echo "$0 --source_dir <source_dir> --build_dir <build_dir> --output_dir <output_dir> data_file [data_file ...]" |
| 19 | } |
| 20 | |
| 21 | set -ex |
| 22 | |
| 23 | SCRIPT_DIR="$( dirname "${BASH_SOURCE[0]}")" |
| 24 | |
| 25 | # Parse arguments |
| 26 | while test $# -gt 0; do |
| 27 | case $1 in |
| 28 | -s|--source_dir) |
| 29 | SOURCE_DIR="$2" |
| 30 | shift |
| 31 | shift |
| 32 | ;; |
| 33 | -b|--build_dir) |
| 34 | BUILD_DIR="$2" |
| 35 | shift |
| 36 | shift |
| 37 | ;; |
| 38 | -b|--output_dir) |
| 39 | OUTPUT_DIR="$2" |
| 40 | shift |
| 41 | shift |
| 42 | ;; |
| 43 | -h|--help) |
| 44 | usage |
| 45 | exit 0 |
| 46 | ;; |
| 47 | *) |
| 48 | break |
| 49 | ;; |
| 50 | esac |
| 51 | done |
| 52 | |
| 53 | if test -z "$SOURCE_DIR" |
| 54 | then |
| 55 | usage |
| 56 | error "No source dir specified" |
| 57 | fi |
| 58 | |
| 59 | if test -z "$BUILD_DIR" |
| 60 | then |
| 61 | usage |
| 62 | error "No build dir specified" |
| 63 | fi |
| 64 | |
| 65 | if test -z "$OUTPUT_DIR" |
| 66 | then |
| 67 | usage |
| 68 | error "No output dir specified" |
| 69 | fi |
| 70 | |
| 71 | if ! test $# -gt 0 |
| 72 | then |
| 73 | usage |
| 74 | error "At least one data file must be input" |
| 75 | fi |
| 76 | |
| 77 | info_dir=$(mktemp -d) |
| 78 | |
| 79 | for x in "$@" |
| 80 | do |
| 81 | tmpdir=$(mktemp -d) |
| 82 | |
| 83 | if ${SCRIPT_DIR}/ingest_tarmac.py \ |
| 84 | --input_file "$x" \ |
| 85 | --output_file "${tmpdir}/$(basename "$x").data" |
| 86 | then |
| 87 | input_file="${tmpdir}/$(basename "$x").data" |
| 88 | else |
| 89 | input_file="$x" |
| 90 | fi |
| 91 | |
| 92 | |
| 93 | ${SCRIPT_DIR}/generate_report_config_json.py \ |
| 94 | --source_dir "${SOURCE_DIR}" \ |
| 95 | --build_dir "${BUILD_DIR}" \ |
| 96 | --output_config_file "${tmpdir}/$(basename "$x")_config.json" \ |
| 97 | --output_intermediate_file "${tmpdir}/$(basename "$x")_intermediate.json" \ |
| 98 | "$input_file" |
| 99 | |
| 100 | python3 ${SCRIPT_DIR}/qa-tools/coverage-tool/coverage-reporting/intermediate_layer.py \ |
| 101 | --config-json "${tmpdir}/$(basename "$x")_config.json" |
| 102 | |
| 103 | python3 ${SCRIPT_DIR}/qa-tools/coverage-tool/coverage-reporting/generate_info_file.py \ |
| 104 | --workspace ${SOURCE_DIR} \ |
| 105 | --json "${tmpdir}/$(basename "$x")_intermediate.json" \ |
| 106 | --info ${info_dir}/${RANDOM}${RANDOM}.info |
| 107 | done |
| 108 | |
| 109 | info_file="$(mktemp).info" |
| 110 | |
| 111 | if test $(find "$info_dir" -type f | wc -l) -gt 1 |
| 112 | then |
| 113 | arguments=$(find "$info_dir" -type f | xargs -I{} echo "-a {}") |
| 114 | |
| 115 | python3 ${SCRIPT_DIR}/qa-tools/coverage-tool/coverage-reporting/merge.py \ |
| 116 | $arguments \ |
| 117 | -o ${info_file} |
| 118 | else |
| 119 | info_file=$(find "$info_dir" -type f) |
| 120 | fi |
| 121 | |
| 122 | genhtml --branch-coverage "${info_file}" --output-directory "$OUTPUT_DIR" |