blob: 9958fbd9520879e3a1ac2c785f2641f5314a11b8 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Leonardo Sandoval579c7372020-10-23 15:23:32 -05003# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# Check the coding style of the entire source tree against the Linux coding
9# style using the checkpatch.pl script from the Linux kernel source tree.
10
11TEST_CASE="Coding style of entire source tree"
12
13echo "# Check coding style of the entire source tree"
14
15LOG_FILE=$(mktemp -t coding-style-check.XXXX)
16
17# Passing V=1 to 'make checkcodebase' will make it generate a per-file summary
18CHECKPATCH=$CI_ROOT/script/static-checks/checkpatch.pl \
19 make checkcodebase V=1 &> "$LOG_FILE"
20RES=$?
21
22if [[ "$RES" == 0 ]]; then
23 # Ignore warnings, only mark the test as failed if there are errors.
24 # We'll get as many 'total:' lines as the number of files in the source tree.
25 # Search for lines that show a non-null number of errors.
26 grep --quiet 'total: [^0][0-9]* errors' "$LOG_FILE"
27 # grep returns 0 when it founds the pattern, which means there is an error
28 RES=$?
29else
30 RES=0
31fi
32
33if [[ "$RES" == 0 ]]; then
34 EXIT_VALUE=1
35else
36 EXIT_VALUE=0
37fi
38
39echo >> "$LOG_TEST_FILENAME"
40echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME"
41echo >> "$LOG_TEST_FILENAME"
42if [[ "$EXIT_VALUE" == 0 ]]; then
43 echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME"
44else
45 echo "Result : FAILURE" >> "$LOG_TEST_FILENAME"
46fi
47# Always print the script output to show the warnings
48echo >> "$LOG_TEST_FILENAME"
49cat "$LOG_FILE" >> "$LOG_TEST_FILENAME"
50echo >> "$LOG_TEST_FILENAME"
51
52rm -f "$LOG_FILE"
53
54exit "$EXIT_VALUE"