blob: c80f0831284c126d1b42b7980623cf99239b6c75 [file] [log] [blame]
BjornMagnussonXA8fbb2262022-01-24 15:20:15 +01001#!/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
22print_usage() {
23 echo "Usage: format_endpoint_stats <log-base-dir> <app-id> <app-description> [tc-id]+ "
24}
25
26SUMMARYFILE=""
27SUMMARYFILE_TMP=""
28
29update_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
62if [ $# -lt 4 ]; then
63 print_usage
64 exit 1
65fi
66BASE_DIR=$1
67if [ ! -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
71fi
72SUMMARYFILE=$BASE_DIR/endpoint_summary.log
73rm $SUMMARYFILE
74touch $SUMMARYFILE
75SUMMARYFILE_TMP=$BASE_DIR/endpoint_summary_tmp.log
76TC_FAIL=0
77shift
78APP_ID=$1
79shift
80echo ""
81echo "==================================================="
82echo "Functional test cases for $1"
83echo "==================================================="
84echo
85shift
86while [ $# -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
119done
120
121echo "Summary of all testscripts"
122if [ $TC_FAIL -ne 0 ]; then
123 echo " !!!!! ONE OR MORE TESTCASE(S) FAILED - CHECK INDIVIDUAL TEST RESULT!!!!!"
124fi
125echo "=== Results: positive=2XX http status, negative=non 2XX http status - (ok/total)==="
126echo "Method Endpoint Positive Negative"
127cat $SUMMARYFILE | cut -c 4-
128
129exit 0
130