2 # vim: ts=4 sw=4 noet :
4 #==================================================================================
5 # Copyright (c) 2020 Nokia
6 # Copyright (c) 2020 AT&T Intellectual Property.
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #==================================================================================
22 # Parse the .gcov file and discount any unexecuted lines which are in if()
23 # blocks which are testing the result of alloc/malloc calls, or testing for
24 # nil pointers. The feeling is that these might not be possible to drive
25 # and shoudn't contribute to coverage deficiencies.
27 # In verbose mode, the .gcov file is written to stdout and any unexecuted
28 # line which is discounted is marked with ===== replacing the ##### marking
31 # The return value is 0 for pass; non-zero for fail.
33 function discount_ck {
36 mct=80 # force minimum coverage threshold for passing
49 awk -v module_cov_target=$mct \
50 -v cfail=${cfail:-WARN} \
51 -v show_all=$show_all \
55 -v replace_flags=$replace_flags \
57 function spit_line( ) {
63 /-:/ { # skip unexecutable lines
65 seq++ # allow blank lines in a sequence group
70 nexec++ # number of executable lines
83 if( prev_if && prev_malloc ) {
85 #printf( "allow discount: %s\n", $0 )
87 gsub( "#####", " 1", $0 )
88 //gsub( "#####", "=====", $0 )
99 /if[(].*alloc.*{/ { # if( (x = malloc( ... )) != NULL ) or if( (p = sym_alloc(...)) != NULL )
107 /if[(].* == NULL/ { # a nil check likely not easily forced if it wasnt driven
116 if( seq+1 == $2+0 && prev_malloc ) { // malloc on previous line
138 net = unexec - discount
139 orig_cov = ((nexec-unexec)/nexec)*100 # original coverage
140 adj_cov = ((nexec-net)/nexec)*100 # coverage after discount
141 pass_fail = adj_cov < module_cov_target ? cfail : "PASS"
142 rc = adj_cov < module_cov_target ? 1 : 0
143 if( pass_fail == cfail || show_all ) {
145 printf( "[%s] %s executable=%d unexecuted=%d discounted=%d net_unex=%d cov=%d%% ==> %d%% target=%d%%\n",
146 pass_fail, full_name ? full_name : module, nexec, unexec, discount, net, orig_cov, adj_cov, module_cov_target )
148 printf( "[%s] %d%% (%d%%) %s\n", pass_fail, adj_cov, orig_cov, full_name ? full_name : module )
157 # ----------------------------------------------------------------------
158 show_all=1 # turn off to hide passing modules (-q)
159 chatty=0 # -v turns on to provide more info when we do speak
161 while [[ $1 == "-"* ]]
167 *) echo "unrecognised option: $1"
168 echo "usage: $0 [-q] gcov-file-list"