Add publish script to lister test set
[ric-app/mc.git] / sidecars / listener / test / show_coverage.ksh
1 #!/usr/bin/env bash
2
3 #==================================================================================
4 #        Copyright (c) 2018-2019 AT&T Intellectual Property.
5 #
6 #   Licensed under the Apache License, Version 2.0 (the "License");
7 #   you may not use this file except in compliance with the License.
8 #   You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #   Unless required by applicable law or agreed to in writing, software
13 #   distributed under the License is distributed on an "AS IS" BASIS,
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #   See the License for the specific language governing permissions and
16 #   limitations under the License.
17 #==================================================================================
18
19
20 #
21 #       Mnemonic:       show_coverage.ksh
22 #       Abstract:       This script parses the coverage file associated with the .c file
23 #                               listed on the command line and displays a more readable summary.
24 #
25 #       Date:           10 December 2019
26 #       Author:         E. Scott Daniels
27 # -------------------------------------------------------------------------
28
29 show_all=0
30 ignore_list="main"
31 module_cov_target=80
32 chatty=0
33 show_all=0
34 cfail="DCHK"
35
36 gcov  -f $1 | sed "s/'//g" | awk \
37                 -v cfail=$cfail \
38                 -v show_all=$show_all \
39                 -v ignore_list="$iflist" \
40                 -v module_cov_target=$module_cov_target \
41                 -v chatty=$verbose \
42                 '
43                 BEGIN {
44                         announce_target = 1;
45                         nignore = split( ignore_list, ignore, " " )
46                         for( i = 1; i <= nignore; i++ ) {
47                                 imap[ignore[i]] = 1
48                         }
49
50                         exit_code = 0           # assume good
51                 }
52
53                 /^TARGET:/ {
54                         if( NF > 1 ) {
55                                 target[$2] = $NF
56                         }
57                         next;
58                 }
59
60                 /File.*_test/ || /File.*test_/ {                # dont report on test files
61                         skip = 1
62                         file = 1
63                         fname = $2
64                         next
65                 }
66
67                 /File/ {
68                         skip = 0
69                         file = 1
70                         fname = $2
71                         next
72                 }
73
74                 /Function/ {
75                         fname = $2
76                         file = 0
77                         if( imap[fname] ) {
78                                 fname = "skipped: " fname               # should never see and make it smell if we do
79                                 skip = 1
80                         } else {
81                                 skip = 0
82                         }
83                         next
84                 }
85
86                 skip { next }
87
88                 /Lines executed/ {
89                         split( $0, a, ":" )
90                         pct = a[2]+0
91
92                         if( file ) {
93                                 if( announce_target ) {                         # announce default once at start
94                                         announce_target = 0;
95                                         printf( "\n[INFO] default target coverage for modules is %d%%\n", module_cov_target )
96                                 }
97
98                                 if( target[fname] ) {
99                                         mct = target[fname]
100                                         announce_target = 1;
101                                 } else {
102                                         mct = module_cov_target
103                                 }
104
105                                 if( announce_target ) {                                 # annoucne for module if different from default
106                                         printf( "[INFO] target coverage for %s is %d%%\n", fname, mct )
107                                 }
108
109                                 if( pct < mct ) {
110                                         printf( "[%s] %3d%% %s\n", cfail, pct, fname )  # CAUTION: write only 3 things  here
111                                         exit_code = 1
112                                 } else {
113                                         printf( "[PASS] %3d%% %s\n", pct, fname )
114                                 }
115
116                                 announce_target = 0;
117                         } else {
118                                 if( pct < 70 ) {
119                                         printf( "[LOW]  %3d%% %s\n", pct, fname )
120                                 } else {
121                                         if( pct < 80 ) {
122                                                 printf( "[MARG] %3d%% %s\n", pct, fname )
123                                         } else {
124                                                 if( show_all ) {
125                                                         printf( "[OK]   %3d%% %s\n", pct, fname )
126                                                 }
127                                         }
128                                 }
129                         }
130
131                 }
132
133                 END {
134                         printf( "\n" );
135                         exit( exit_code )
136                 }
137         '