soc/intel/xeon_sp: Drop uncore_fill_ssdt
[coreboot2.git] / util / lint / lint
blob56edaa65c4d0e591a84034347f6a9f6730e0cc6e
1 #!/usr/bin/env sh
4 # SPDX-License-Identifier: GPL-2.0-only
6 #set -x # uncomment for debug
8 JUNIT=0
9 INVERT=0
11 usage () {
12 printf "Usage: %s <sub-command> [Options]\n" "$0"
13 printf " Sub-commands:\n"
14 printf " lint-stable : Run standard lint tests - should pass\n"
15 printf " lint-extended : Run extended lint tests - should pass\n"
16 printf " lint : Run full lint tests - Not expected to pass\n\n"
18 printf " Options:\n"
19 printf " -h | --help : Show this help message\n"
20 printf " -I | --invert : Invert results - used for testing linters\n"
21 printf " -J | --junit : Send test output to a JUnit file\n"
22 printf "\n"
25 #write to the junit xml file if --junit was specified
26 junit_write () {
27 if [ "$JUNIT" -eq 1 ]; then
28 echo "$1" >> "$XMLFILE"
32 # Look if we have getopt. If not, build it.
33 if [ "$(uname)" = "Darwin" ]; then
34 GETOPT="getopt hIJ"
35 else
36 GETOPT="getopt -l help,junit,invert -o hIJ"
39 if ! cmd_args="$($GETOPT -- "$@")"; then
40 usage
41 exit 0
43 eval set -- "${cmd_args}"
45 while true; do
46 case "$1" in
47 -h | --help)
48 usage
49 exit 0
51 -I | --invert)
52 INVERT=1
54 -J | --junit)
55 echo "selected junit"
56 JUNIT=1
58 --) shift; break ;;
59 *) break ;;
60 esac
61 shift
62 done
64 #verify the first command line parameter
65 if [ -z "$1" ]; then
66 echo "Error: A sub-command is needed."
67 usage
68 exit 1
69 elif [ "$1" != "lint" ] && [ "$1" != "lint-stable" ] &&
70 [ "$1" != "lint-extended" ]; then
71 echo "Error: $1 is not a valid sub-command."
72 usage
73 exit 1
76 LINTLOG=$(mktemp .tmpconfig.lintXXXXXX);
77 XMLFILE="$(dirname "$0")/junit.xml"
78 if [ "$1" = "lint-extended" ]; then
79 XMLFILE="$(dirname "$0")/extended-junit.xml"
81 FAILED=0;
83 if [ "${JUNIT}" -eq 1 ]; then
84 echo '<?xml version="1.0" encoding="utf-8"?>' > "$XMLFILE"
85 junit_write '<testsuite>'
88 #run all scripts of the requested type
89 for script in "$(dirname "$0")/${1}-"*; do
90 printf "%s " "$(grep '^# DESCR:' "$script" | sed 's,.*DESCR: *,,')"
91 printf "(%s): " "$(basename "$script")"
92 junit_write " <testcase classname='lint' name='$(basename "$script")'>"
93 $script | tee "$LINTLOG"
95 #if the lint script gives any output, that's a failure
96 if [ "${INVERT}" -eq 1 ] && [ "$(wc -l < "$LINTLOG")" -ne 0 ]; then
97 echo "success"
98 junit_write " <system-out><![CDATA[success]]></system-out>"
99 elif [ "${INVERT}" -eq 0 ] && [ "$(wc -l < "$LINTLOG")" -eq 0 ]; then
100 echo "success"
101 junit_write " <system-out><![CDATA[success]]></system-out>"
102 else
103 echo "test failed"
104 junit_write " <failure type='testFailed'><![CDATA["
105 junit_write "$(cat "$LINTLOG")"
106 junit_write "]]></failure>"
107 rm -f "$LINTLOG"
108 FAILED=$(( FAILED + 1 ))
110 junit_write ' </testcase>'
111 done
113 rm -f "$LINTLOG"
114 junit_write '</testsuite>'
115 test $FAILED -eq 0 || { echo "ERROR: $FAILED test(s) failed."; exit 1; };