| #!/bin/bash |
| |
| # ============LICENSE_START=============================================== |
| # Copyright (C) 2021 Nordix Foundation. All rights reserved. |
| # ======================================================================== |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # ============LICENSE_END================================================= |
| # |
| |
| # This script format http endpoint stats generated by testscripts |
| |
| print_usage() { |
| echo "Usage: format_endpoint_stats <log-base-dir> <app-id> <app-description> [tc-id]+ " |
| } |
| |
| SUMMARYFILE="" |
| SUMMARYFILE_TMP="" |
| |
| update_summary() { |
| |
| input=$@ |
| inputarr=(${input// / }) |
| inputp=${inputarr[3]} |
| inputn=${inputarr[4]} |
| inputposarr=(${inputp//\// }) |
| inputnegarr=(${inputn//\// }) |
| > $SUMMARYFILE_TMP |
| found=0 |
| while read -r line; do |
| linearr=(${line// / }) |
| linep=${linearr[3]} |
| linen=${linearr[4]} |
| lineposarr=(${linep//\// }) |
| linenegarr=(${linen//\// }) |
| if [[ ${linearr[1]} == ${inputarr[1]} ]] && [[ ${linearr[2]} == ${inputarr[2]} ]]; then |
| let lineposarr[0]=lineposarr[0]+inputposarr[0] |
| let lineposarr[1]=lineposarr[1]+inputposarr[1] |
| let linenegarr[0]=linenegarr[0]+inputnegarr[0] |
| let linenegarr[1]=linenegarr[1]+inputnegarr[1] |
| found=1 |
| fi |
| printf '%-2s %-10s %-45s %-16s %-16s' "#" "${linearr[1]}" "${linearr[2]}" "${lineposarr[0]}/${lineposarr[1]}" "${linenegarr[0]}/${linenegarr[1]}" >> $SUMMARYFILE_TMP |
| echo "" >> $SUMMARYFILE_TMP |
| done < $SUMMARYFILE |
| if [ $found -eq 0 ]; then |
| printf '%-2s %-10s %-45s %-16s %-16s' "#" "${inputarr[1]}" "${inputarr[2]}" "${inputposarr[0]}/${inputposarr[1]}" "${inputnegarr[0]}/${inputnegarr[1]}" >> $SUMMARYFILE_TMP |
| echo "" >> $SUMMARYFILE_TMP |
| fi |
| cp $SUMMARYFILE_TMP $SUMMARYFILE |
| } |
| |
| if [ $# -lt 4 ]; then |
| print_usage |
| exit 1 |
| fi |
| BASE_DIR=$1 |
| if [ ! -d $BASE_DIR ]; then |
| print_usage |
| echo "<log-base-dir> $BASE_DIR does not exist or is not a dir" |
| exit 1 |
| fi |
| SUMMARYFILE=$BASE_DIR/endpoint_summary.log |
| rm $SUMMARYFILE |
| touch $SUMMARYFILE |
| SUMMARYFILE_TMP=$BASE_DIR/endpoint_summary_tmp.log |
| TC_FAIL=0 |
| shift |
| APP_ID=$1 |
| shift |
| echo "" |
| echo "===================================================" |
| echo "Functional test cases for $1" |
| echo "===================================================" |
| echo |
| shift |
| while [ $# -gt 0 ]; do |
| FTC_DIR=$BASE_DIR/$1 |
| if [ ! -d $FTC_DIR ]; then |
| echo "Dir $FTC_DIR does not exist" |
| exit 1 |
| fi |
| IMAGE_INFO_FILE=$FTC_DIR/imageinfo_$APP_ID".log" |
| if [ -f $IMAGE_INFO_FILE ]; then |
| echo "=== Testscript: $1 ===" |
| echo "Image: "$(cat $IMAGE_INFO_FILE) |
| echo |
| TC_RES_FILE=$FTC_DIR/.result$1.txt |
| if [ -f "$TC_RES_FILE" ]; then |
| TC_RESULT=$(< "$TC_RES_FILE") |
| if [ $TC_RESULT -ne 0 ]; then |
| echo " !!!!! TESTCASE FAILED !!!!!" |
| let TC_FAIL=TC_FAIL+1 |
| fi |
| fi |
| echo "=== Results: positive=2XX http status, negative=non 2XX http status - (ok/total)===" |
| echo "Method Endpoint Positive Negative" |
| grep --no-filename "#" $FTC_DIR/endpoint_$APP_ID* | cut -c 4- |
| for filename in $FTC_DIR/endpoint_$APP_ID* ; do |
| filedata=$(< $filename) |
| update_summary $filedata |
| done |
| echo "===============================" |
| echo |
| else |
| echo "=== No stats collected by Testscript $1 ===" |
| echo "" |
| fi |
| shift |
| done |
| |
| echo "Summary of all testscripts" |
| if [ $TC_FAIL -ne 0 ]; then |
| echo " !!!!! ONE OR MORE TESTCASE(S) FAILED - CHECK INDIVIDUAL TEST RESULT!!!!!" |
| fi |
| echo "=== Results: positive=2XX http status, negative=non 2XX http status - (ok/total)===" |
| echo "Method Endpoint Positive Negative" |
| cat $SUMMARYFILE | cut -c 4- |
| |
| exit 0 |
| |