blob: fd022a34e9a9266f642380ecfe8a501af5781e17 [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
Chris Kayba047fe2025-07-31 16:13:20 +010018git fetch --unshallow --update-shallow origin
19git fetch --unshallow --update-shallow origin ${GERRIT_BRANCH} ${GERRIT_REFSPEC}
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +030020
Chris Kayba047fe2025-07-31 16:13:20 +010021export merge_base=$(git merge-base \
22 $(head -n1 .git/FETCH_HEAD | cut -f1) \
23 $(tail -n1 .git/FETCH_HEAD | cut -f1))
Fathi Boudra422bf772019-12-02 11:10:16 +020024
25export LOG_TEST_FILENAME=$(pwd)/static-checks.log
26
27echo
28echo "###### Static checks ######"
29echo
30
31echo "###### Static checks ######" > "$LOG_TEST_FILENAME"
32echo >> "$LOG_TEST_FILENAME"
33
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +030034echo "Patch series being checked:" >> "$LOG_TEST_FILENAME"
Harrison Mutai789decf2025-07-16 08:26:58 +000035git log --oneline ${merge_base}..HEAD >> "$LOG_TEST_FILENAME"
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +030036echo >> "$LOG_TEST_FILENAME"
37echo "Base branch reference commit:" >> "$LOG_TEST_FILENAME"
Harrison Mutai789decf2025-07-16 08:26:58 +000038git log --oneline -1 ${merge_base} >> "$LOG_TEST_FILENAME"
39
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +030040
41echo >> "$LOG_TEST_FILENAME"
42
Fathi Boudra422bf772019-12-02 11:10:16 +020043# Reset error counters
44
45ERROR_COUNT=0
46WARNING_COUNT=0
47
48# Ensure all the files contain a copyright
49
50echo 'Checking copyright in source files...'
51echo
52"$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh .
53if [ "$?" != 0 ]; then
54 echo "Copyright test: FAILURE"
55 ((ERROR_COUNT++))
56else
57 echo "Copyright test: PASS"
58fi
59echo
60
61# Check alphabetic order of headers included.
62
63if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
64 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh . patch
65else
66 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh .
67fi
68if [ "$?" != 0 ]; then
69 echo "Include order test: FAILURE"
70 ((WARNING_COUNT++))
71else
72 echo "Include order test: PASS"
73fi
74echo
75
Govindraj Raja4db3c002025-04-10 17:23:19 -050076# Check ascending order of CPU ERRATUM and CVE added.
77
78if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
79 "$CI_ROOT"/script/static-checks/static-checks-cpu-erratum-order.sh . patch
80else
81 "$CI_ROOT"/script/static-checks/static-checks-cpu-erratum-order.sh .
82fi
83if [ "$?" != 0 ]; then
84 echo "CPU Errata, CVE in-order test: FAILURE"
85 ((ERROR_COUNT++))
86else
87 echo "CPU Errata, CVE in-order test: PASS"
88fi
89echo
90
Fathi Boudra422bf772019-12-02 11:10:16 +020091# Check line endings
92
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050093if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
94 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
95else
96 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
97fi
98
Fathi Boudra422bf772019-12-02 11:10:16 +020099if [ "$?" != 0 ]; then
100 echo "Line ending test: FAILURE"
101 ((ERROR_COUNT++))
102else
103 echo "Line ending test: PASS"
104fi
105echo
106
107# Check coding style
108
109echo 'Checking coding style compliance...'
110echo
111if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
112 "$CI_ROOT"/script/static-checks/static-checks-coding-style.sh
113else
114 "$CI_ROOT"/script/static-checks/static-checks-coding-style-entire-src-tree.sh
115fi
116if [ "$?" != 0 ]; then
117 echo "Coding style test: FAILURE"
118 ((ERROR_COUNT++))
119else
120 echo "Coding style test: PASS"
121fi
122echo
123
Zelalem219df412020-05-17 19:21:20 -0500124# Check for any Banned API usage
125
126echo 'Checking Banned API usage...'
127echo
128if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
129 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh . patch
130else
131 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh
132fi
133if [ "$?" != 0 ]; then
134 echo "Banned API check: FAILURE"
135 ((ERROR_COUNT++))
136else
137 echo "Banned API check: PASS"
138fi
139echo
140
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100141# Check to ensure newly added source files are detected for Coverity Scan analysis
142
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100143# Check to be executed only on trusted-firmware repository.
Manish V Badarkhe8b846f42021-10-13 15:43:58 +0100144if [ "$REPO_UNDER_TEST" = "trusted-firmware" ] || [ "$REPO_UNDER_TEST" = "trusted-firmware-a" ]; then
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100145 echo 'Checking whether the newly added source files are detected for Coverity Scan analysis...'
146 echo
147 "$CI_ROOT"/script/static-checks/static-checks-detect-newly-added-files.sh
148 if [ "$?" != 0 ]; then
149 echo "Files Detection check: FAILURE"
150 ((ERROR_COUNT++))
151 else
152 echo "Files Detection check: PASS"
153 fi
154 echo
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100155fi
Zelalem219df412020-05-17 19:21:20 -0500156
Fathi Boudra422bf772019-12-02 11:10:16 +0200157# Check error count
158
159if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
160 echo "Some static checks have failed."
161fi
162
163if [ "$ERROR_COUNT" != 0 ]; then
164 exit 1
165fi
166
167exit 0