blob: a8ea6a39df2cecce895dc9ee46488429c0c07ecd [file] [log] [blame]
dongqing.li154e45e2021-11-22 07:47:38 +00001#!/bin/bash
2#
3# author: dongqing.li@amlogic.com
4# 2021.11.22 v1.0 init.
5#
6
7#############
8# function
9#############
10MK_ARGV=""
11NEW_ARGV=""
12COVERITY_PATH="/proj/coverity/cov-analysis-linux64-2020.12/bin"
13COV_IM_DIR="./cov-imdir"
14COV_RESULT_HTML="./result-html"
15HIGH_LEVEL="0"
16PATTERN_PATH=""
17
18#############
19# function
20#############
21function err_exit()
22{
23 echo "Error: $1"
24 exit 1
25}
26
27function check_cov_path() {
28 echo ""
29 echo "check_cov_path ..."
30 echo ""
31 if [ -d "${COV_IM_DIR}" ]; then
32 rm -rf ${COV_IM_DIR}
33 fi
34 mkdir -p ${COV_IM_DIR}
35 if [ -d "${COV_RESULT_HTML}" ]; then
36 rm -rf ${COV_RESULT_HTML}
37 fi
38}
39
40function run_coverity() {
41 echo ""
42 echo -e "\e[1;35m[1] run cov-build ... \e[0m"
43 ${COVERITY_PATH}/cov-build --dir ${COV_IM_DIR} ./mk $@ || err_exit "cov-build error."
44 echo -e "\e[1;35m[1] run cov-build OK. \e[0m"
45
46 echo ""
47 echo -e "\e[1;35m[2] run cov-analyze ... \e[0m"
48 if [ ${HIGH_LEVEL} = "1" ]; then
49 if [ -z "${PATTERN_PATH}" ];then
50 ${COVERITY_PATH}/cov-analyze --dir ../im-dir/ --strip-path $MKPATH --all --aggressiveness-level high --fb-max-mem 3072 || err_exit "cov-analyze high level error."
51 else
52 ${COVERITY_PATH}/cov-analyze --dir ../im-dir/ --strip-path $MKPATH --all --aggressiveness-level high --fb-max-mem 3072 --tu-pattern "file('/${PATTERN_PATH}')" || err_exit "cov-analyze high level error."
53 fi
54 else
55 if [ -z "${PATTERN_PATH}" ];then
56 ${COVERITY_PATH}/cov-analyze --dir ../im-dir/ --strip-path $MKPATH --all || err_exit "cov-analyze normal level error."
57 else
58 ${COVERITY_PATH}/cov-analyze --dir ../im-dir/ --strip-path $MKPATH --all --tu-pattern "file('/${PATTERN_PATH}')" || err_exit "cov-analyze normal level error."
59 fi
60 fi
61 echo -e "\e[1;35m[2] run cov-analyze OK. \e[0m"
62
63 echo ""
64 echo -e "\e[1;35m[3] run cov-format-errors ... \e[0m"
65 ${COVERITY_PATH}/cov-format-errors --dir ../im-dir/ --html-output ${COV_RESULT_HTML} --filesort --strip-path $MKPATH -x || err_exit "cov-format-errors error."
66 echo -e "\e[1;35m[3] run cov-format-errors OK. \e[0m"
67 echo "end."
68
69 rm -rf ${COV_IM_DIR}
70}
71
72function show_coverity_result() {
73 echo ""
74 echo -e "\e[1;35m[html-result] \e[0m"
75 echo "you can open the index.html files through a browser, and view code defects."
76 echo "path: ${MKPATH}/`basename ${COV_RESULT_HTML}`/index.html"
77 echo " "
78}
79
80########
81# mk_script.sh call function here !
82########
83function check_coverity() {
84
85 MK_ARGV=$@
86
87 echo -e "\e[1;35m=========== run check_coverity() ===========\e[0m"
88
89 echo ""
90 echo "coverity raw command : ./mk $@ "
91 # check argv
92 result=$(echo ${MK_ARGV} | grep "\-\-cov-high")
93 if [[ "$result" != "" ]]; then
94 echo "coverity defect level : high"
95 HIGH_LEVEL="1"
96 NEW_ARGV=`echo "${MK_ARGV//--cov-high/ }"`
97 else
98 echo "coverity defect level : normal"
99 HIGH_LEVEL="0"
100 NEW_ARGV=`echo "${MK_ARGV//--cov/ }"`
101 fi
102 echo "coverity new command : ./mk ${NEW_ARGV}"
103 MKPATH=`pwd`
104 echo "coverity run path : $MKPATH"
105
106 # check_cov_path
107 check_cov_path
108
109 # run_coverity
110 run_coverity ${NEW_ARGV}
111
112 # show coverity result info
113 show_coverity_result
114}
115
116
117function show_help() {
118
119 echo -e "\e[1;35m [usage] \e[0m"
120 echo " $0 -c [config_name] -p [pattern_path] -u [update_blx] -t"
121 echo ""
122 echo -e "\e[1;35m [option] \e[0m"
123 echo " -c : config name, eg: t5_ak301_v1, "
124 echo " -p : detect path, only output errors in this path."
125 echo " -t : top level mode,could detect more errors."
126 echo " -d : dump support socs name, when you don't know the soc name, can run it first."
127 echo " -u : build uboot with bl[x]/src source code, eg: bl2 bl2e bl2x bl30 bl31 bl32 "
128 echo " -h : show help"
129 echo ""
130 echo -e "\e[1;35m [example] \e[0m"
131 echo " 1) dump support socs name:"
132 echo " $0 -d"
133 echo " 2) run coverity for bootloader:"
134 echo " $0 -c t5_ak301_v1"
135 echo " 3) run coverity, and filter out errors in the specified directory"
136 echo " $0 -c t5_ak301_v1 -p bl33/v2019/"
137 echo " 4) build uboot with bl[x]/src source code, and use top level mode"
138 echo " $0 -c t5_ak301_v1 -p bl31_1.3/src/ -u bl31 -t"
139 echo ""
140 exit 1
141}
142
143function parser_update_blx() {
144 if [ "${UPDATE}" = "bl2" ];then
145 BLX_NAME="--update-bl2"
146 elif [ "${UPDATE}" = "bl2" ];then
147 BLX_NAME="--update-bl2e"
148 elif [ "${UPDATE}" = "bl2x" ];then
149 BLX_NAME="--update-bl2x"
150 elif [ "${UPDATE}" = "bl30" ];then
151 BLX_NAME="--update-bl30"
152 elif [ "${UPDATE}" = "bl31" ];then
153 BLX_NAME="--update-bl31"
154 elif [ "${UPDATE}" = "bl32" ];then
155 BLX_NAME="--update-bl32"
156 else
157 BLX_NAME=""
158 fi
159}
160
161function main() {
162 if [ $# -lt 1 ]; then
163 show_help
164 exit 1
165 fi
166
167 while getopts c:C:p:P:u:U:tTdDhH opt; do
168 case ${opt} in
169 c|C)
170 CONFIG_NAME=${OPTARG}
171 ;;
172 p|P)
173 PATTERN_PATH=${OPTARG}
174 ;;
175 u|U)
176 UPDATE=${OPTARG}
177 ;;
178 t|T)
179 HIGH_LEVEL="1"
180 ;;
181 d|D)
182 DUMP_FLAG="1"
183 ;;
184 h|H)
185 show_help
186 ;;
187 *)
188 show_help
189 ;;
190 esac
191 done
192
193 if [[ ${DUMP_FLAG} = "1" ]]; then
194 echo ""
195 echo "-----------------------------------------------------------------------------------------"
196 echo "Please select a [config name] below, and try : $0 -c [config name]"
197 echo "-----------------------------------------------------------------------------------------"
198 ./mk --config
199 echo ""
200 exit 1
201 fi
202
203 # parser update blx
204 parser_update_blx
205
206 # check coverity path
207 check_cov_path
208
209 # run_coverity
210 run_coverity ${CONFIG_NAME} ${BLX_NAME}
211
212 # show coverity result path
213 show_coverity_result
214}
215
216#
217# start here.
218#
219MKPATH=`pwd`
220# main $@