Bash scripting – I think I earned 5 stars… Well, 4.5.

January 25th, 2011 | Tags:

if [ -e $compare_table_file ]; then
        echo “Compare table found, comparing results”
        ### TODO, create two dimensional array from report and static table”
        ### Compare the tables
        threshold=5 ### if more than 5% less than const, the test would FAIL
        frames_tested=( `cat $report_name | grep -A 50 “Throughput and Latency results” | grep -A 30 “Frame” | grep -G “[0-9]”| grep -v “Run” | awk {‘print $1″ “$3’}` )
        frames_compared_to=( `cat $compare_table_file | sed ‘s/\”//’ | grep -A 30 “Frame” | grep -G “[0-9]”| grep -v “Run” | awk {‘print $1″ “$3’}` )

        let test_frames_tested=${#frames_tested[*]}/2
        let test_frames_comprated=${#frames_compared_to[*]}/2

        if [ $test_frames_tested -eq 1 ]; then
                echo “wrong count of frames and results”
                reportSuccess=”FAIL”
                return
        fi

        if [ $test_frames_comprated -eq 1 ]; then
                echo “wrong count of frames and consts”
                reportSuccess=”FAIL”
                return
        fi

        ## Ugly solution to solve the bad output

        let runtime1=${#frames_tested[*]}-1
        let runtime2=${#frames_compared_to[*]}-1

        echo -e “====\t ==========\t ========\t ========”
        echo -e “Size\t Throughput\t Constant\t Variance”
        echo -e “====\t ==========\t ========\t ========”
        #for i in `seq 0 2 ${#frames_tested[*]}`; do
        for i in `seq 0 2 $runtime1`; do
        #for b in `seq 0 2 ${#frames_compared_to[*]}`; do
                for b in `seq 0 2 $runtime2`; do
                if [ “${frames_tested[$i]}” == “${frames_compared_to[$b]}” ]; then
                calc=$(echo “scale=2; -1 * (100 – (100 * ${frames_tested[$i+1]} / ${frames_compared_to[$b+1]}))” | bc)
                rounded=$(echo “scale=0; -1 * (100 – (100 * ${frames_tested[$i+1]} / ${frames_compared_to[$b+1]}))” | bc)
                echo -e “${frames_tested[$i]}\t ${frames_tested[$i+1]}%\t ${frames_compared_to[$b+1]}%\t $calc%”
                        abs_rounded=${rounded#-}
                        if [ $abs_rounded -le $threshold ]; then
                                reportSuccess=”SUCCESS”
                        else
                                reportSuccess=”FAIL”
                                fail=1
                        fi
                fi
                done
        done

        if [ “$fail” == “1” ]; then
                reportSuccess=”FAIL”
        else
                reportSuccess=”SUCCESS”
        fi
else
        return
fi

No comments yet.

*