blob: fe2f7b0cff1ee901ea6875415408426ee3cb27f9 [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
Fathi Boudra422bf772019-12-02 11:10:16 +020020# Initialize log file
21
22export LOG_TEST_FILENAME=$(pwd)/static-checks.log
23
24echo
25echo "###### Static checks ######"
26echo
27
28echo "###### Static checks ######" > "$LOG_TEST_FILENAME"
29echo >> "$LOG_TEST_FILENAME"
30
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +030031echo "Patch series being checked:" >> "$LOG_TEST_FILENAME"
32git log --oneline $(get_merge_base)..HEAD >> "$LOG_TEST_FILENAME"
33echo >> "$LOG_TEST_FILENAME"
34echo "Base branch reference commit:" >> "$LOG_TEST_FILENAME"
35git log --oneline -1 $(get_merge_base) >> "$LOG_TEST_FILENAME"
36
37echo >> "$LOG_TEST_FILENAME"
38
Fathi Boudra422bf772019-12-02 11:10:16 +020039# Reset error counters
40
41ERROR_COUNT=0
42WARNING_COUNT=0
43
44# Ensure all the files contain a copyright
45
46echo 'Checking copyright in source files...'
47echo
48"$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh .
49if [ "$?" != 0 ]; then
50 echo "Copyright test: FAILURE"
51 ((ERROR_COUNT++))
52else
53 echo "Copyright test: PASS"
54fi
55echo
56
57# Check alphabetic order of headers included.
58
59if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
60 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh . patch
61else
62 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh .
63fi
64if [ "$?" != 0 ]; then
65 echo "Include order test: FAILURE"
66 ((WARNING_COUNT++))
67else
68 echo "Include order test: PASS"
69fi
70echo
71
Govindraj Raja4db3c002025-04-10 17:23:19 -050072# Check ascending order of CPU ERRATUM and CVE added.
73
74if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
75 "$CI_ROOT"/script/static-checks/static-checks-cpu-erratum-order.sh . patch
76else
77 "$CI_ROOT"/script/static-checks/static-checks-cpu-erratum-order.sh .
78fi
79if [ "$?" != 0 ]; then
80 echo "CPU Errata, CVE in-order test: FAILURE"
81 ((ERROR_COUNT++))
82else
83 echo "CPU Errata, CVE in-order test: PASS"
84fi
85echo
86
Fathi Boudra422bf772019-12-02 11:10:16 +020087# Check line endings
88
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050089if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
90 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
91else
92 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
93fi
94
Fathi Boudra422bf772019-12-02 11:10:16 +020095if [ "$?" != 0 ]; then
96 echo "Line ending test: FAILURE"
97 ((ERROR_COUNT++))
98else
99 echo "Line ending test: PASS"
100fi
101echo
102
103# Check coding style
104
105echo 'Checking coding style compliance...'
106echo
107if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
108 "$CI_ROOT"/script/static-checks/static-checks-coding-style.sh
109else
110 "$CI_ROOT"/script/static-checks/static-checks-coding-style-entire-src-tree.sh
111fi
112if [ "$?" != 0 ]; then
113 echo "Coding style test: FAILURE"
114 ((ERROR_COUNT++))
115else
116 echo "Coding style test: PASS"
117fi
118echo
119
Zelalem219df412020-05-17 19:21:20 -0500120# Check for any Banned API usage
121
122echo 'Checking Banned API usage...'
123echo
124if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
125 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh . patch
126else
127 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh
128fi
129if [ "$?" != 0 ]; then
130 echo "Banned API check: FAILURE"
131 ((ERROR_COUNT++))
132else
133 echo "Banned API check: PASS"
134fi
135echo
136
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100137# Check to ensure newly added source files are detected for Coverity Scan analysis
138
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100139# Check to be executed only on trusted-firmware repository.
Manish V Badarkhe8b846f42021-10-13 15:43:58 +0100140if [ "$REPO_UNDER_TEST" = "trusted-firmware" ] || [ "$REPO_UNDER_TEST" = "trusted-firmware-a" ]; then
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100141 echo 'Checking whether the newly added source files are detected for Coverity Scan analysis...'
142 echo
143 "$CI_ROOT"/script/static-checks/static-checks-detect-newly-added-files.sh
144 if [ "$?" != 0 ]; then
145 echo "Files Detection check: FAILURE"
146 ((ERROR_COUNT++))
147 else
148 echo "Files Detection check: PASS"
149 fi
150 echo
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100151fi
Zelalem219df412020-05-17 19:21:20 -0500152
Fathi Boudra422bf772019-12-02 11:10:16 +0200153# Check error count
154
155if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
156 echo "Some static checks have failed."
157fi
158
159if [ "$ERROR_COUNT" != 0 ]; then
160 exit 1
161fi
162
163exit 0