blob: ffd58f2b53bd79c02bc1e0d2949c5bf0140277c1 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Paul Sokolovsky422020c2024-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
Paul Sokolovsky422020c2024-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 Sokolovsky422020c2024-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
72# Check line endings
73
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050074if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
75 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
76else
77 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
78fi
79
Fathi Boudra422bf772019-12-02 11:10:16 +020080if [ "$?" != 0 ]; then
81 echo "Line ending test: FAILURE"
82 ((ERROR_COUNT++))
83else
84 echo "Line ending test: PASS"
85fi
86echo
87
88# Check coding style
89
90echo 'Checking coding style compliance...'
91echo
92if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
93 "$CI_ROOT"/script/static-checks/static-checks-coding-style.sh
94else
95 "$CI_ROOT"/script/static-checks/static-checks-coding-style-entire-src-tree.sh
96fi
97if [ "$?" != 0 ]; then
98 echo "Coding style test: FAILURE"
99 ((ERROR_COUNT++))
100else
101 echo "Coding style test: PASS"
102fi
103echo
104
Zelalem219df412020-05-17 19:21:20 -0500105# Check for any Banned API usage
106
107echo 'Checking Banned API usage...'
108echo
109if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
110 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh . patch
111else
112 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh
113fi
114if [ "$?" != 0 ]; then
115 echo "Banned API check: FAILURE"
116 ((ERROR_COUNT++))
117else
118 echo "Banned API check: PASS"
119fi
120echo
121
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100122# Check to ensure newly added source files are detected for Coverity Scan analysis
123
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100124# Check to be executed only on trusted-firmware repository.
Manish V Badarkhe8b846f42021-10-13 15:43:58 +0100125if [ "$REPO_UNDER_TEST" = "trusted-firmware" ] || [ "$REPO_UNDER_TEST" = "trusted-firmware-a" ]; then
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100126 echo 'Checking whether the newly added source files are detected for Coverity Scan analysis...'
127 echo
128 "$CI_ROOT"/script/static-checks/static-checks-detect-newly-added-files.sh
129 if [ "$?" != 0 ]; then
130 echo "Files Detection check: FAILURE"
131 ((ERROR_COUNT++))
132 else
133 echo "Files Detection check: PASS"
134 fi
135 echo
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100136fi
Zelalem219df412020-05-17 19:21:20 -0500137
Fathi Boudra422bf772019-12-02 11:10:16 +0200138# Check error count
139
140if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
141 echo "Some static checks have failed."
142fi
143
144if [ "$ERROR_COUNT" != 0 ]; then
145 exit 1
146fi
147
148exit 0