Add publish script to lister test set
[ric-app/mc.git] / sidecars / listener / test / publish_cov.ksh
1 #!/usr/bin/env bash
2
3 #==================================================================================
4 #        Copyright (c) 2018-2020 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:       pub_cov.ksh
22 #       Abstract:       This script will push any coverage files (.gcov) in the current
23 #                               directory to the indicated target directory (/tmp/gcov_rpts by
24 #                               default.  Because sonar needs to match the source listed in the
25 #                               .gcov file with what it perceives was analysed by it's code, we
26 #                               must fiddle the name in the .gcov file to be a path relative to
27 #                               the project root.  For example, if the .gcov file has the line:
28 #
29 #                                               0:Source:mc_listener.c
30 #
31 #                               we must change that to be the path of sidecars/listener/src
32 #
33 #       Date:           3 September 2020
34 #       Author:         E. Scott Daniels
35 # -------------------------------------------------------------------------
36
37 sdir=sidecars/listener/src                      # default source directory
38 pdir=/tmp/gcov_rpts                                     # publish directory
39
40 while [[ $1 == -* ]]
41 do
42         case $1 in
43                 -p)     pdir=$2; shift;;
44                 -s) sdir=$2; shift;;
45         esac
46
47         shift
48 done
49
50
51 echo "publishing gcov files to: $pdir"
52
53 for f in *.gcov
54 do
55         echo "publishing: $f to ${pdir}/$f"
56
57         # rel replace will replace things like ../src based on the source directory
58         awk -v sdir="$sdir"  \
59                 -v rel_rep="../${sdir##*/}/" '
60                 /0:Source:/ {
61                         gsub( rel_rep, "", $0 )                 # relative replace must be first
62                         n = split( $0, a, ":" )                 # file name into a[n]
63                         gsub( a[n], sdir "/" a[n], $0 )
64                 }
65
66                 { print }
67         ' $f >${pdir}/$f
68 done