Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2021-2022 BUGSENG srl. All rights reserved. |
| 4 | # Copyright (c) 2022 Arm Limited. All rights reserved. |
| 5 | # |
| 6 | # SPDX-License-Identifier: BSD-3-Clause |
| 7 | |
| 8 | # Stop immediately if any executed command has exit status different from 0. |
| 9 | set -ex |
| 10 | |
| 11 | usage() { |
| 12 | echo "Usage: analyze.sh CONF" 1>&2 |
| 13 | echo " where CONF is the build configuration id passed to build.sh" 1>&2 |
| 14 | } |
| 15 | |
| 16 | if [ $# -ne 1 ] |
| 17 | then |
| 18 | usage |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | # Absolute path of the ECLAIR bin directory. |
| 23 | ECLAIR_BIN_DIR="/opt/bugseng/eclair/bin" |
| 24 | |
| 25 | # Directory where this script resides: usually in a directory named "ECLAIR". |
| 26 | SCRIPT_DIR="$(cd "$(dirname "$0")" ; echo "${PWD}")" |
| 27 | |
| 28 | # Directory where to put all ECLAIR output and temporary files. |
| 29 | ECLAIR_OUTPUT_DIR="${WORKSPACE}/ECLAIR/out" |
| 30 | |
Paul Sokolovsky | b3f7399 | 2022-10-05 18:27:22 +0300 | [diff] [blame^] | 31 | TF_CONFIG="$1" |
Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 32 | |
Paul Sokolovsky | b3f7399 | 2022-10-05 18:27:22 +0300 | [diff] [blame^] | 33 | # Automatically export vars |
| 34 | set -a |
| 35 | source ${WORKSPACE}/tf-a-ci-scripts/tf_config/${TF_CONFIG} |
| 36 | set +a |
Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 37 | |
| 38 | export CC_ALIASES="${CROSS_COMPILE}gcc" |
| 39 | export CXX_ALIASES="${CROSS_COMPILE}g++" |
| 40 | export LD_ALIASES="${CROSS_COMPILE}ld" |
| 41 | export AR_ALIASES="${CROSS_COMPILE}ar" |
| 42 | export AS_ALIASES="${CROSS_COMPILE}as" |
| 43 | export FILEMANIP_ALIASES="cp mv ${CROSS_COMPILE}objcopy" |
| 44 | |
| 45 | which ${CROSS_COMPILE}gcc |
| 46 | ${CROSS_COMPILE}gcc -v |
| 47 | |
| 48 | # ECLAIR binary data directory and workspace. |
| 49 | export ECLAIR_DATA_DIR="${ECLAIR_OUTPUT_DIR}/.data" |
| 50 | # ECLAIR workspace. |
| 51 | export ECLAIR_WORKSPACE="${ECLAIR_DATA_DIR}/eclair_workspace" |
| 52 | # Destination file for the ECLAIR diagnostics. |
| 53 | export ECLAIR_DIAGNOSTICS_OUTPUT="${ECLAIR_OUTPUT_DIR}/DIAGNOSTICS.txt" |
| 54 | |
| 55 | # Identifies the particular build of the project. |
Paul Sokolovsky | b3f7399 | 2022-10-05 18:27:22 +0300 | [diff] [blame^] | 56 | export ECLAIR_PROJECT_NAME="TF_A_${TF_CONFIG}" |
Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 57 | # All paths mentioned in ECLAIR reports that are below this directory |
| 58 | # will be presented as relative to ECLAIR_PROJECT_ROOT. |
| 59 | export ECLAIR_PROJECT_ROOT="${WORKSPACE}/trusted-firmware-a" |
| 60 | |
| 61 | # Erase and recreate the output directory and the data directory. |
| 62 | rm -rf "${ECLAIR_OUTPUT_DIR}" |
| 63 | mkdir -p "${ECLAIR_DATA_DIR}" |
| 64 | |
| 65 | ( |
| 66 | # Perform the build (from scratch) in an ECLAIR environment. |
| 67 | "${ECLAIR_BIN_DIR}/eclair_env" \ |
| 68 | "-eval_file='${SCRIPT_DIR}/MISRA_C_2012_selection.ecl'" \ |
Paul Sokolovsky | b3f7399 | 2022-10-05 18:27:22 +0300 | [diff] [blame^] | 69 | -- "${SCRIPT_DIR}/build-tfa.sh" "${TF_CONFIG}" |
Paul Sokolovsky | 3486b4e | 2022-09-06 13:33:57 +0300 | [diff] [blame] | 70 | ) |
| 71 | |
| 72 | # Create the project database. |
| 73 | PROJECT_ECD="${ECLAIR_OUTPUT_DIR}/PROJECT.ecd" |
| 74 | find "${ECLAIR_DATA_DIR}" -maxdepth 1 -name "FRAME.*.ecb" \ |
| 75 | | sort | xargs cat \ |
| 76 | | "${ECLAIR_BIN_DIR}/eclair_report" \ |
| 77 | "-create_db='${PROJECT_ECD}'" \ |
| 78 | -load=/dev/stdin |
| 79 | |
| 80 | |
| 81 | function make_self_contained() { |
| 82 | dir=$1 |
| 83 | mkdir -p $dir/lib |
| 84 | |
| 85 | cp -r /opt/bugseng/eclair-3.12.0/lib/html $dir/lib |
| 86 | |
| 87 | ${SCRIPT_DIR}/relativize_urls.py $dir |
| 88 | } |
| 89 | |
| 90 | ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} \ |
| 91 | -summary_txt=${ECLAIR_OUTPUT_DIR}/../summary_txt \ |
| 92 | -full_txt=${ECLAIR_OUTPUT_DIR}/../full_txt \ |
| 93 | -full_html=${ECLAIR_OUTPUT_DIR}/../full_html |
| 94 | |
| 95 | # summary_txt contains just a single report file not present in full_txt, move it there and be done with it. |
| 96 | mv ${ECLAIR_OUTPUT_DIR}/../summary_txt/by_service.txt ${ECLAIR_OUTPUT_DIR}/../full_txt/ |
| 97 | rm -rf ${ECLAIR_OUTPUT_DIR}/../summary_txt |
| 98 | make_self_contained ${ECLAIR_OUTPUT_DIR}/../full_html |
| 99 | |
| 100 | # Create the Jenkins reports file. |
| 101 | JENKINS_XML="${ECLAIR_OUTPUT_DIR}/../jenkins.xml" |
| 102 | ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} -reports_jenkins=${JENKINS_XML} |
| 103 | |
| 104 | |
| 105 | # Compress database to take less disk space in Jenkins archive |
| 106 | xz ${PROJECT_ECD} |