blob: 05747f4b135cf44b3fa3347912d4f44581a06a3e [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Govindraj Raja4db3c002025-04-10 17:23:19 -05003# Copyright (c) 2019-2025 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8echo '----------------------------------------------'
9echo '-- Running static checks on the source code --'
10echo '----------------------------------------------'
11
12# Find the absolute path of the scripts' top directory
13
14cd "$(dirname "$0")/../.."
15export CI_ROOT=$(pwd)
16cd -
17
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +030018. $CI_ROOT/script/static-checks/common.sh
19
Harrison Mutai789decf2025-07-16 08:26:58 +000020merge_base=$(get_merge_base)
21if [[ -z "$merge_base" ]]; then
22 echo "Failed to find merge base, fetching entire change history"
23
24 # Set GERRIT_REFSPEC if not already defined
25 if [[ -z "$GERRIT_REFSPEC" ]]; then
26 if [[ "$TF_GERRIT_PROJECT" == *tf-a-tests ]]; then
27 GERRIT_REFSPEC="$TFTF_GERRIT_REFSPEC"
28 else
29 GERRIT_REFSPEC="$TF_GERRIT_REFSPEC"
30 fi
31 fi
32
Chris Kaybf2b4df2025-07-28 11:50:16 +010033 git fetch --unshallow
34 git fetch origin "$GERRIT_REFSPEC"
Harrison Mutai789decf2025-07-16 08:26:58 +000035 git checkout FETCH_HEAD
36
37 merge_base=$(get_merge_base)
38
39 if [[ -z "$merge_base" ]]; then
40 echo "Failed to determine merge base after fetching. Exiting." >&2
41 exit 1
42 fi
43fi
44
45export merge_base
Fathi Boudra422bf772019-12-02 11:10:16 +020046
47export LOG_TEST_FILENAME=$(pwd)/static-checks.log
48
49echo
50echo "###### Static checks ######"
51echo
52
53echo "###### Static checks ######" > "$LOG_TEST_FILENAME"
54echo >> "$LOG_TEST_FILENAME"
55
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +030056echo "Patch series being checked:" >> "$LOG_TEST_FILENAME"
Harrison Mutai789decf2025-07-16 08:26:58 +000057git log --oneline ${merge_base}..HEAD >> "$LOG_TEST_FILENAME"
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +030058echo >> "$LOG_TEST_FILENAME"
59echo "Base branch reference commit:" >> "$LOG_TEST_FILENAME"
Harrison Mutai789decf2025-07-16 08:26:58 +000060git log --oneline -1 ${merge_base} >> "$LOG_TEST_FILENAME"
61
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +030062
63echo >> "$LOG_TEST_FILENAME"
64
Fathi Boudra422bf772019-12-02 11:10:16 +020065# Reset error counters
66
67ERROR_COUNT=0
68WARNING_COUNT=0
69
70# Ensure all the files contain a copyright
71
72echo 'Checking copyright in source files...'
73echo
74"$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh .
75if [ "$?" != 0 ]; then
76 echo "Copyright test: FAILURE"
77 ((ERROR_COUNT++))
78else
79 echo "Copyright test: PASS"
80fi
81echo
82
83# Check alphabetic order of headers included.
84
85if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
86 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh . patch
87else
88 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh .
89fi
90if [ "$?" != 0 ]; then
91 echo "Include order test: FAILURE"
92 ((WARNING_COUNT++))
93else
94 echo "Include order test: PASS"
95fi
96echo
97
Govindraj Raja4db3c002025-04-10 17:23:19 -050098# Check ascending order of CPU ERRATUM and CVE added.
99
100if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
101 "$CI_ROOT"/script/static-checks/static-checks-cpu-erratum-order.sh . patch
102else
103 "$CI_ROOT"/script/static-checks/static-checks-cpu-erratum-order.sh .
104fi
105if [ "$?" != 0 ]; then
106 echo "CPU Errata, CVE in-order test: FAILURE"
107 ((ERROR_COUNT++))
108else
109 echo "CPU Errata, CVE in-order test: PASS"
110fi
111echo
112
Fathi Boudra422bf772019-12-02 11:10:16 +0200113# Check line endings
114
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -0500115if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
116 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
117else
118 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
119fi
120
Fathi Boudra422bf772019-12-02 11:10:16 +0200121if [ "$?" != 0 ]; then
122 echo "Line ending test: FAILURE"
123 ((ERROR_COUNT++))
124else
125 echo "Line ending test: PASS"
126fi
127echo
128
129# Check coding style
130
131echo 'Checking coding style compliance...'
132echo
133if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
134 "$CI_ROOT"/script/static-checks/static-checks-coding-style.sh
135else
136 "$CI_ROOT"/script/static-checks/static-checks-coding-style-entire-src-tree.sh
137fi
138if [ "$?" != 0 ]; then
139 echo "Coding style test: FAILURE"
140 ((ERROR_COUNT++))
141else
142 echo "Coding style test: PASS"
143fi
144echo
145
Zelalem219df412020-05-17 19:21:20 -0500146# Check for any Banned API usage
147
148echo 'Checking Banned API usage...'
149echo
150if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
151 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh . patch
152else
153 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh
154fi
155if [ "$?" != 0 ]; then
156 echo "Banned API check: FAILURE"
157 ((ERROR_COUNT++))
158else
159 echo "Banned API check: PASS"
160fi
161echo
162
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100163# Check to ensure newly added source files are detected for Coverity Scan analysis
164
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100165# Check to be executed only on trusted-firmware repository.
Manish V Badarkhe8b846f42021-10-13 15:43:58 +0100166if [ "$REPO_UNDER_TEST" = "trusted-firmware" ] || [ "$REPO_UNDER_TEST" = "trusted-firmware-a" ]; then
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100167 echo 'Checking whether the newly added source files are detected for Coverity Scan analysis...'
168 echo
169 "$CI_ROOT"/script/static-checks/static-checks-detect-newly-added-files.sh
170 if [ "$?" != 0 ]; then
171 echo "Files Detection check: FAILURE"
172 ((ERROR_COUNT++))
173 else
174 echo "Files Detection check: PASS"
175 fi
176 echo
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100177fi
Zelalem219df412020-05-17 19:21:20 -0500178
Fathi Boudra422bf772019-12-02 11:10:16 +0200179# Check error count
180
181if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
182 echo "Some static checks have failed."
183fi
184
185if [ "$ERROR_COUNT" != 0 ]; then
186 exit 1
187fi
188
189exit 0