xref: /aosp_15_r20/external/ComputeLibrary/scripts/check_bad_style.sh (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1*c217d954SCole Faust#!/bin/bash
2*c217d954SCole Faust
3*c217d954SCole Faustset -e
4*c217d954SCole Faust
5*c217d954SCole FaustALL_DIRECTORIES="./arm_compute ./src ./examples ./tests ./utils ./support"
6*c217d954SCole Faust
7*c217d954SCole Faust#If no arguments were passed: default to check all the folders:
8*c217d954SCole Faustif [ ! -n "$1" ]
9*c217d954SCole Faustthen
10*c217d954SCole Faust    FILES=$ALL_DIRECTORIES
11*c217d954SCole Faustelse
12*c217d954SCole Faust    #else only check the files that were passed on the command line:
13*c217d954SCole Faust    FILES=$@
14*c217d954SCole Faustfi
15*c217d954SCole Faust
16*c217d954SCole Faustgrep -HrnP --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=arm_gemm --exclude-dir=arm_conv "/\*\*$" $FILES | tee bad_style.log
17*c217d954SCole Faustif (( `cat bad_style.log | wc -l` > 0 ))
18*c217d954SCole Faustthen
19*c217d954SCole Faust    echo ""
20*c217d954SCole Faust    echo "ERROR: Doxygen comments should start on the first line: \"/** My comment\""
21*c217d954SCole Faust    exit -1
22*c217d954SCole Faustfi
23*c217d954SCole Faust
24*c217d954SCole Faustgrep -Hnr --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=arm_gemm --exclude-dir=arm_conv --exclude=Doxyfile "@brief" $FILES | tee bad_style.log
25*c217d954SCole Faustif (( `cat bad_style.log | wc -l` > 0 ))
26*c217d954SCole Faustthen
27*c217d954SCole Faust    echo ""
28*c217d954SCole Faust    echo "ERROR: Doxygen comments shouldn't use '@brief'"
29*c217d954SCole Faust    exit -1
30*c217d954SCole Faustfi
31*c217d954SCole Faust
32*c217d954SCole Faustgrep -HnRE --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=arm_gemm --exclude-dir=dynamic_fusion --exclude-dir=arm_conv "\buint " --exclude-dir=cl_kernels --exclude-dir=cs_shaders $FILES | tee bad_style.log
33*c217d954SCole Faustif [[ $(cat bad_style.log | wc -l) > 0 ]]
34*c217d954SCole Faustthen
35*c217d954SCole Faust    echo ""
36*c217d954SCole Faust    echo "ERROR: C/C++ don't define 'uint'. Use 'unsigned int' instead."
37*c217d954SCole Faust    exit -1
38*c217d954SCole Faustfi
39*c217d954SCole Faust
40*c217d954SCole Faustgrep -HnR --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=arm_gemm --exclude-dir=arm_conv "/^float32_t/" $FILES | tee bad_style.log
41*c217d954SCole Faustif [[ $(cat bad_style.log | wc -l) > 0 ]]
42*c217d954SCole Faustthen
43*c217d954SCole Faust    echo ""
44*c217d954SCole Faust    echo "ERROR: C/C++ don't define 'float32_t'. Use 'float' instead."
45*c217d954SCole Faust    exit -1
46*c217d954SCole Faustfi
47*c217d954SCole Faust
48*c217d954SCole Faustgrep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=arm_gemm --exclude-dir=arm_conv "arm[_ ]\?cv" $FILES | tee bad_style.log
49*c217d954SCole Faustif [[ $(cat bad_style.log | wc -l) > 0 ]]
50*c217d954SCole Faustthen
51*c217d954SCole Faust    echo ""
52*c217d954SCole Faust    echo "ERROR: Reference to arm_cv detected in the files above (Replace with arm_compute)"
53*c217d954SCole Faust    exit -1
54*c217d954SCole Faustfi
55*c217d954SCole Faust
56*c217d954SCole Faustgrep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=arm_gemm --exclude-dir=arm_conv "#.*if.*defined[^(]" $FILES | tee bad_style.log
57*c217d954SCole Faustif [[ $(cat bad_style.log | wc -l) > 0 ]]
58*c217d954SCole Faustthen
59*c217d954SCole Faust    echo ""
60*c217d954SCole Faust    echo "ERROR: use parenthesis after #if defined(MY_PREPROCESSOR)"
61*c217d954SCole Faust    exit -1
62*c217d954SCole Faustfi
63*c217d954SCole Faust
64*c217d954SCole Faustgrep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=arm_gemm --exclude-dir=arm_conv "#else$\|#endif$" $FILES | tee bad_style.log
65*c217d954SCole Faustif [[ $(cat bad_style.log | wc -l) > 0 ]]
66*c217d954SCole Faustthen
67*c217d954SCole Faust    echo ""
68*c217d954SCole Faust    echo "ERROR: #else and #endif should be followed by a comment of the guard they refer to (e.g /* ARM_COMPUTE_AARCH64_V8_2 */ )"
69*c217d954SCole Faust    exit -1
70*c217d954SCole Faustfi
71*c217d954SCole Faust
72*c217d954SCole Faustgrep -Hnir --exclude-dir=assembly --exclude-dir=convolution --exclude-dir=arm_gemm --exclude-dir=arm_conv "ARM_COMPUTE_AARCH64_V8_2" ./tests/validation/CL | tee bad_style.log
73*c217d954SCole Faustif [[ $(cat bad_style.log | wc -l) > 0 ]]
74*c217d954SCole Faustthen
75*c217d954SCole Faust    echo ""
76*c217d954SCole Faust    echo "ERROR: Found ARM_COMPUTE_AARCH64_V8_2 in CL tests though armv8.2 features (FP16) are always supported for OpenCL"
77*c217d954SCole Faust    exit -1
78*c217d954SCole Faustfi
79*c217d954SCole Faust
80*c217d954SCole Faustspdx_missing=0
81*c217d954SCole Faustfor f in $(find $FILES -type f)
82*c217d954SCole Faustdo
83*c217d954SCole Faust    if [[ $(grep SPDX $f | wc -l) == 0 ]]
84*c217d954SCole Faust    then
85*c217d954SCole Faust        # List of exceptions:
86*c217d954SCole Faust        case `basename $f` in
87*c217d954SCole Faust            "arm_compute_version.embed");;
88*c217d954SCole Faust            ".clang-format");;
89*c217d954SCole Faust            ".clang-tidy");;
90*c217d954SCole Faust            "README.md");;
91*c217d954SCole Faust            #It's an error for other files to not contain the MIT header:
92*c217d954SCole Faust            *)
93*c217d954SCole Faust                spdx_missing=1
94*c217d954SCole Faust                echo $f;
95*c217d954SCole Faust                ;;
96*c217d954SCole Faust        esac
97*c217d954SCole Faust    fi;
98*c217d954SCole Faustdone
99*c217d954SCole Faust
100*c217d954SCole Faustif [[ $spdx_missing > 0 ]]
101*c217d954SCole Faustthen
102*c217d954SCole Faust    echo ""
103*c217d954SCole Faust    echo "ERROR: MIT Copyright header missing from the file(s) above."
104*c217d954SCole Faust    exit -1
105*c217d954SCole Faustfi
106