blob: 7ccecabdac8abfcccd1de72abecbe78e9c61c248 [file] [log] [blame]
Paul Sokolovsky3486b4e2022-09-06 13:33:57 +03001#!/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.
9set -ex
10
11usage() {
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
16if [ $# -ne 1 ]
17then
18 usage
19 exit 1
20fi
21
22# Absolute path of the ECLAIR bin directory.
23ECLAIR_BIN_DIR="/opt/bugseng/eclair/bin"
24
25# Directory where this script resides: usually in a directory named "ECLAIR".
26SCRIPT_DIR="$(cd "$(dirname "$0")" ; echo "${PWD}")"
27
28export CROSS_COMPILE="/opt/gcc-arm-11.2-2022.02-x86_64-aarch64-none-elf/bin/aarch64-none-elf-"
29
30PLAT="$1"
31
32export CC_ALIASES="${CROSS_COMPILE}gcc"
33export CXX_ALIASES="${CROSS_COMPILE}g++"
34export LD_ALIASES="${CROSS_COMPILE}ld"
35export AR_ALIASES="${CROSS_COMPILE}ar"
36export AS_ALIASES="${CROSS_COMPILE}as"
37export FILEMANIP_ALIASES="cp mv ${CROSS_COMPILE}objcopy"
38
39# Identifies the particular build of the project.
40export ECLAIR_PROJECT_NAME="TF_A_${PLAT}"
41# All paths mentioned in ECLAIR reports that are below this directory
42# will be presented as relative to ECLAIR_PROJECT_ROOT.
43export ECLAIR_PROJECT_ROOT="${WORKSPACE}/trusted-firmware-a"
44
45
46function do_analyze() {
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 # Erase and recreate the output directory and the data directory.
56 rm -rf "${ECLAIR_OUTPUT_DIR}"
57 mkdir -p "${ECLAIR_DATA_DIR}"
58
59 (
60 # Perform the build (from scratch) in an ECLAIR environment.
61 "${ECLAIR_BIN_DIR}/eclair_env" \
62 "-eval_file='${SCRIPT_DIR}/MISRA_C_2012_selection.ecl'" \
63 -- "${SCRIPT_DIR}/build-tfa.sh" "${PLAT}"
64 )
65
66 # Create the project database.
67 PROJECT_ECD="${ECLAIR_OUTPUT_DIR}/PROJECT.ecd"
68 find "${ECLAIR_DATA_DIR}" -maxdepth 1 -name "FRAME.*.ecb" \
69 | sort | xargs cat \
70 | "${ECLAIR_BIN_DIR}/eclair_report" \
71 "-create_db='${PROJECT_ECD}'" \
72 -load=/dev/stdin
73
74
75 function make_self_contained() {
76 dir=$1
77 mkdir -p $dir/lib
78
79 cp -r /opt/bugseng/eclair-3.12.0/lib/html $dir/lib
80
81 ${SCRIPT_DIR}/relativize_urls.py $dir
82 }
83
84 ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} \
85 -summary_txt=${ECLAIR_OUTPUT_DIR}/../summary_txt \
86 -full_txt=${ECLAIR_OUTPUT_DIR}/../full_txt \
87 -full_html=${ECLAIR_OUTPUT_DIR}/../full_html
88
89 # summary_txt contains just a single report file not present in full_txt, move it there and be done with it.
90 mv ${ECLAIR_OUTPUT_DIR}/../summary_txt/by_service.txt ${ECLAIR_OUTPUT_DIR}/../full_txt/
91 rm -rf ${ECLAIR_OUTPUT_DIR}/../summary_txt
92 make_self_contained ${ECLAIR_OUTPUT_DIR}/../full_html
93
94 # Create the Jenkins reports file.
95 JENKINS_XML="${ECLAIR_OUTPUT_DIR}/../jenkins.xml"
96 ${ECLAIR_BIN_DIR}/eclair_report -db=${PROJECT_ECD} -reports_jenkins=${JENKINS_XML}
97
98}
99
100# Directory where to put all ECLAIR output and temporary files.
101ECLAIR_OUTPUT_DIR="${WORKSPACE}/ECLAIR/out"
102
103do_analyze
104
105ECLAIR_OUTPUT_DIR="${WORKSPACE}/ECLAIR_BASE/out"
106
107(
108 cd ${ECLAIR_PROJECT_ROOT}
109 git checkout HEAD^
110 git log --oneline -n5
111)
112
113do_analyze
114
115diff -I '^Timestamp:' -x frames.txt -x files.txt -x explain.txt \
116 -ur ${WORKSPACE}/ECLAIR_BASE/summary_txt/ ${WORKSPACE}/ECLAIR/summary_txt/ > ${WORKSPACE}/ECLAIR/summary_txt.diff || true
117
118
119(
120${ECLAIR_BIN_DIR}/eclair_report -diff_criteria=fingerprint -diff_full_txt=ECLAIR_BASE/out/PROJECT.ecd,ECLAIR/out/PROJECT.ecd
121ls -l diff_output
122
123eclair_report -db=ECLAIR_BASE/out/PROJECT.ecd -sel_tag_glob=new,diff,missing -full_html=resolved_issues_html
124make_self_contained resolved_issues_html
125
126eclair_report -db=ECLAIR/out/PROJECT.ecd -sel_tag_glob=new,diff,missing -full_html=new_issues_html
127make_self_contained new_issues_html
128
129xz ECLAIR_BASE/out/PROJECT.ecd ECLAIR/out/PROJECT.ecd
130)
131
132${SCRIPT_DIR}/eclair_diff_report.py diff_output > misra_delta.txt
133
134
135cat <<EOF >index.html
136<html>
137<body>
138<h1>MISRA Delta reports for the patch</h1>
Paul Sokolovskya1be51a2022-09-29 18:37:15 +0300139
140<p>
141Patch: <a href="${GERRIT_CHANGE_URL}/${GERRIT_PATCHSET_NUMBER}">${GERRIT_CHANGE_URL}/${GERRIT_PATCHSET_NUMBER}</a><br />
142CI Build: <a href="${BUILD_URL}">${BUILD_URL}</a>
143</p>
144
Paul Sokolovsky3486b4e2022-09-06 13:33:57 +0300145<li><a href="misra_delta.txt">Cumulative TXT report</a>
146<li><a href="diff_output/">Per MISRA rule TXT reports</a>
147<li><a href="new_issues_html/by_service.html#first_file/service&kind">New issues, groupped per file changed (HTML).</a>
148<li><a href="resolved_issues_html/by_service.html#first_file/service&kind">Resolved issues, groupped per file changed (HTML).</a>
149</body>
150</html>
151EOF