Updates for F release
[nonrtric.git] / test / common / format_endpoint_stats.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2021 Nordix Foundation. All rights reserved.
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 #  ============LICENSE_END=================================================
18 #
19
20 # This script format http endpoint stats generated by testscripts
21
22 print_usage() {
23   echo "Usage: format_endpoint_stats <log-base-dir> <app-id> <app-description> [tc-id]+ "
24 }
25
26 SUMMARYFILE=""
27 SUMMARYFILE_TMP=""
28
29 update_summary() {
30
31   input=$@
32   inputarr=(${input// / })
33   inputp=${inputarr[3]}
34   inputn=${inputarr[4]}
35   inputposarr=(${inputp//\// })
36   inputnegarr=(${inputn//\// })
37   >  $SUMMARYFILE_TMP
38   found=0
39   while read -r line; do
40     linearr=(${line// / })
41     linep=${linearr[3]}
42     linen=${linearr[4]}
43     lineposarr=(${linep//\// })
44     linenegarr=(${linen//\// })
45     if [[ ${linearr[1]} == ${inputarr[1]} ]] && [[ ${linearr[2]} == ${inputarr[2]} ]]; then
46       let lineposarr[0]=lineposarr[0]+inputposarr[0]
47       let lineposarr[1]=lineposarr[1]+inputposarr[1]
48       let linenegarr[0]=linenegarr[0]+inputnegarr[0]
49       let linenegarr[1]=linenegarr[1]+inputnegarr[1]
50       found=1
51     fi
52     printf '%-2s %-10s %-45s %-16s %-16s' "#" "${linearr[1]}" "${linearr[2]}" "${lineposarr[0]}/${lineposarr[1]}" "${linenegarr[0]}/${linenegarr[1]}" >> $SUMMARYFILE_TMP
53     echo "" >> $SUMMARYFILE_TMP
54   done < $SUMMARYFILE
55   if [ $found -eq 0 ]; then
56     printf '%-2s %-10s %-45s %-16s %-16s' "#" "${inputarr[1]}" "${inputarr[2]}" "${inputposarr[0]}/${inputposarr[1]}" "${inputnegarr[0]}/${inputnegarr[1]}" >> $SUMMARYFILE_TMP
57     echo "" >> $SUMMARYFILE_TMP
58   fi
59   cp $SUMMARYFILE_TMP $SUMMARYFILE
60 }
61
62 if [ $# -lt 4 ]; then
63   print_usage
64   exit 1
65 fi
66 BASE_DIR=$1
67 if [ ! -d $BASE_DIR ]; then
68   print_usage
69   echo "<log-base-dir> $BASE_DIR does not exist or is not a dir"
70   exit 1
71 fi
72 SUMMARYFILE=$BASE_DIR/endpoint_summary.log
73 rm $SUMMARYFILE
74 touch $SUMMARYFILE
75 SUMMARYFILE_TMP=$BASE_DIR/endpoint_summary_tmp.log
76 TC_FAIL=0
77 shift
78 APP_ID=$1
79 shift
80 echo ""
81 echo "==================================================="
82 echo "Functional test cases for $1"
83 echo "==================================================="
84 echo
85 shift
86 while [ $# -gt 0 ]; do
87   FTC_DIR=$BASE_DIR/$1
88   if [ ! -d $FTC_DIR ]; then
89     echo "Dir $FTC_DIR does not exist"
90     exit 1
91   fi
92   IMAGE_INFO_FILE=$FTC_DIR/imageinfo_$APP_ID".log"
93   if [ -f $IMAGE_INFO_FILE ]; then
94     echo "===  Testscript: $1  ==="
95     echo "Image: "$(cat $IMAGE_INFO_FILE)
96     echo
97     TC_RES_FILE=$FTC_DIR/.result$1.txt
98     if [ -f "$TC_RES_FILE" ]; then
99       TC_RESULT=$(< "$TC_RES_FILE")
100       if [ $TC_RESULT -ne 0 ]; then
101         echo " !!!!! TESTCASE FAILED !!!!!"
102         let TC_FAIL=TC_FAIL+1
103       fi
104     fi
105     echo "===  Results: positive=2XX http status, negative=non 2XX http status - (ok/total)==="
106     echo "Method     Endpoint                                      Positive         Negative"
107     grep --no-filename "#" $FTC_DIR/endpoint_$APP_ID* | cut -c 4-
108     for filename in $FTC_DIR/endpoint_$APP_ID* ; do
109       filedata=$(< $filename)
110       update_summary $filedata
111     done
112     echo "==============================="
113     echo
114   else
115     echo "===  No stats collected by Testscript $1  ==="
116     echo ""
117   fi
118   shift
119 done
120
121 echo "Summary of all testscripts"
122 if [ $TC_FAIL -ne 0 ]; then
123   echo " !!!!! ONE OR MORE TESTCASE(S) FAILED - CHECK INDIVIDUAL TEST RESULT!!!!!"
124 fi
125 echo "===  Results: positive=2XX http status, negative=non 2XX http status - (ok/total)==="
126 echo "Method     Endpoint                                      Positive         Negative"
127 cat $SUMMARYFILE | cut -c 4-
128
129 exit 0
130