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 # this code is based on the unit test code in the o-ran-sc RMR repositiory which
23 # is covered by the original license above, and thus that license governs this
25 # ---------------------------------------------------------------------------------
28 # Parse the .gcov file and discount any unexecuted lines which are in if()
29 # blocks which are testing the result of alloc/malloc calls, or testing for
30 # nil pointers. The feeling is that these might not be possible to drive
31 # and shoudn't contribute to coverage deficiencies.
33 # In verbose mode, the .gcov file is written to stdout and any unexecuted
34 # line which is discounted is marked with ===== replacing the ##### marking
37 # The return value is 0 for pass; non-zero for fail.
39 function discount_ck {
42 mct=80 # force minimum coverage threshold for passing
55 awk -v module_cov_target=$mct \
56 -v cfail=${cfail:-WARN} \
57 -v show_all=$show_all \
61 -v replace_flags=$replace_flags \
63 function spit_line( ) {
69 /-:/ { # skip unexecutable lines
71 seq++ # allow blank lines in a sequence group
76 nexec++ # number of executable lines
89 if( prev_if && prev_malloc ) {
91 #printf( "allow discount: %s\n", $0 )
93 gsub( "#####", " 1", $0 )
94 //gsub( "#####", "=====", $0 )
105 /if[(].*alloc.*{/ { # if( (x = malloc( ... )) != NULL ) or if( (p = sym_alloc(...)) != NULL )
113 /if[(].* == NULL/ { # a nil check likely not easily forced if it wasnt driven
122 if( seq+1 == $2+0 && prev_malloc ) { // malloc on previous line
144 net = unexec - discount
145 orig_cov = ((nexec-unexec)/nexec)*100 # original coverage
146 adj_cov = ((nexec-net)/nexec)*100 # coverage after discount
147 pass_fail = adj_cov < module_cov_target ? cfail : "PASS"
148 rc = adj_cov < module_cov_target ? 1 : 0
149 if( pass_fail == cfail || show_all ) {
151 printf( "[%s] %s executable=%d unexecuted=%d discounted=%d net_unex=%d cov=%d%% ==> %d%% target=%d%%\n",
152 pass_fail, full_name ? full_name : module, nexec, unexec, discount, net, orig_cov, adj_cov, module_cov_target )
154 printf( "[%s] %d%% (%d%%) %s\n", pass_fail, adj_cov, orig_cov, full_name ? full_name : module )
163 # ----------------------------------------------------------------------
164 show_all=1 # turn off to hide passing modules (-q)
165 chatty=0 # -v turns on to provide more info when we do speak
167 while [[ $1 == "-"* ]]
173 *) echo "unrecognised option: $1"
174 echo "usage: $0 [-q] gcov-file-list"