blob: 7e7f1fa04626b3024da3a6b31f20421147998071 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Paul Sokolovsky74cf0f12024-06-18 23:21:07 +03003# Copyright (c) 2019-2024 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 Kay10a38d52025-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 Kay10a38d52025-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 Mutaic05d1412025-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 Mutaic05d1412025-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
76# Check line endings
77
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050078if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
79 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
80else
81 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
82fi
83
Fathi Boudra422bf772019-12-02 11:10:16 +020084if [ "$?" != 0 ]; then
85 echo "Line ending test: FAILURE"
86 ((ERROR_COUNT++))
87else
88 echo "Line ending test: PASS"
89fi
90echo
91
92# Check coding style
93
94echo 'Checking coding style compliance...'
95echo
96if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
97 "$CI_ROOT"/script/static-checks/static-checks-coding-style.sh
98else
99 "$CI_ROOT"/script/static-checks/static-checks-coding-style-entire-src-tree.sh
100fi
101if [ "$?" != 0 ]; then
102 echo "Coding style test: FAILURE"
103 ((ERROR_COUNT++))
104else
105 echo "Coding style test: PASS"
106fi
107echo
108
Zelalem219df412020-05-17 19:21:20 -0500109# Check for any Banned API usage
110
111echo 'Checking Banned API usage...'
112echo
113if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
114 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh . patch
115else
116 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh
117fi
118if [ "$?" != 0 ]; then
119 echo "Banned API check: FAILURE"
120 ((ERROR_COUNT++))
121else
122 echo "Banned API check: PASS"
123fi
124echo
125
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100126# Check to ensure newly added source files are detected for Coverity Scan analysis
127
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100128# Check to be executed only on trusted-firmware repository.
Manish V Badarkhe8b846f42021-10-13 15:43:58 +0100129if [ "$REPO_UNDER_TEST" = "trusted-firmware" ] || [ "$REPO_UNDER_TEST" = "trusted-firmware-a" ]; then
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100130 echo 'Checking whether the newly added source files are detected for Coverity Scan analysis...'
131 echo
132 "$CI_ROOT"/script/static-checks/static-checks-detect-newly-added-files.sh
133 if [ "$?" != 0 ]; then
134 echo "Files Detection check: FAILURE"
135 ((ERROR_COUNT++))
136 else
137 echo "Files Detection check: PASS"
138 fi
139 echo
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100140fi
Zelalem219df412020-05-17 19:21:20 -0500141
Fathi Boudra422bf772019-12-02 11:10:16 +0200142# Check error count
143
144if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
145 echo "Some static checks have failed."
146fi
147
148if [ "$ERROR_COUNT" != 0 ]; then
149 exit 1
150fi
151
152exit 0