Improve style of read_trs_files bash script

The script is now shellcheck-clean.

Incidentally, fix a bug in the counting of xfailed tests when there are several
such tests in a single .mod file.
time-shift
Sébastien Villemot 2018-09-13 15:21:48 +02:00
parent 5c4efbda94
commit 8ba9918652
1 changed files with 61 additions and 72 deletions

View File

@ -1,102 +1,91 @@
#!/bin/bash #!/bin/bash
declare -i total=0; declare -i total=0
declare -i total_xfail=0; declare -i total_xfail=0
declare -i failed=0; declare -i failed=0
declare -i xpassed=0; declare -i xpassed=0
declare -a failed_tests=(""); declare -a failed_tests=()
declare -a xpassed_tests=(""); declare -a xpassed_tests=()
# Parse TRS Files # Parse TRS Files
tosort="" tosort=""
for file in $1 ; do for file in $1 ; do
# Find number of tests run in trs file # Find number of tests run in trs file
((total += `grep number-tests $file | cut -d: -f3`)) ((total += $(grep ^:number-tests: "$file" | cut -d: -f3)))
# Find number of tests failed in trs file # Find number of tests failed in trs file
numfailed=`grep number-failed-tests $file | cut -d: -f3` numfailed=$(grep ^:number-failed-tests: "$file" | cut -d: -f3)
if [ $numfailed -ne 0 ] ; then if ((numfailed != 0)) ; then
((failed += $numfailed)) ((failed += numfailed))
for failedfile in `grep list-of-failed-tests $file | cut -d: -f3` ; do failed_tests+=($(grep ^:list-of-failed-tests: "$file" | cut -d: -f3))
failed_tests=("${failed_tests[@]}" "$failedfile");
done
fi fi
time=`grep elapsed-time $file | cut -d: -f3` time=$(grep ^:elapsed-time: "$file" | cut -d: -f3)
tosort=`echo $tosort\| $file ' - ' $time:` tosort="$tosort| $file - $time:"
done done
((passed=$total-$failed)); ((passed = total - failed))
# Parse XFAIL TRS Files # Parse XFAIL TRS Files
for file in $2 ; do for file in $2 ; do
# Find number of tests run in xfail trs file # Find number of tests run in xfail trs file
((xfail = `grep number-tests $file | cut -d: -f3`)) xfail=$(grep ^:number-tests: "$file" | cut -d: -f3)
((total_xfail += $xfail)) ((total_xfail += xfail))
# Find number of tests failed in trs file # Find number of tests failed in trs file
numpassed=`grep number-failed-tests $file | cut -d: -f3` numfailed=$(grep ^:number-failed-tests: "$file" | cut -d: -f3)
if [ $numpassed -eq 0 ] ; then if ((numfailed != xfail)) ; then
((xpassed += (($xfail - $numpassed)))) ((xpassed += xfail - numfailed))
for xpassedfile in `grep list-of-passed-tests $file | cut -d: -f3` ; do xpassed_tests+=($(grep ^:list-of-passed-tests: "$file" | cut -d: -f3))
xpassed_tests=("${xpassed_tests[@]}" "$xpassedfile");
done
fi fi
time=`grep elapsed-time $file | cut -d: -f3` time=$(grep ^:elapsed-time: "$file" | cut -d: -f3)
tosort=`echo $tosort\| $file ' - ' $time:` tosort="$tosort| $file - $time:"
done done
((xfailed=$total_xfail-$xpassed)); ((xfailed = total_xfail - xpassed))
((total+=$total_xfail)); ((total += total_xfail))
timing=`echo $tosort | tr ":" "\n" | sort -rn -k4 | sed -e 's/$/:/' | head -n10` timing=$(echo "$tosort" | tr ":" "\n" | sort -rn -k4 | sed -e 's/$/:/' | head -n10)
# Determine if we are parsing Matlab or Octave trs files # Determine if we are parsing Matlab or Octave trs files
if [ `grep -c '.m.trs' <<< $1` -eq 0 ]; then if (($(grep -c '.m.trs' <<< "$1") == 0)); then
prg='OCTAVE'; prg=OCTAVE
outfile='run_test_octave_output.txt' outfile=run_test_octave_output.txt
else else
prg='MATLAB'; prg=MATLAB
outfile='run_test_matlab_output.txt' outfile=run_test_matlab_output.txt
fi fi
# Print Output # Print Output
echo '================================' > $outfile {
echo 'DYNARE MAKE CHECK '$prg' RESULTS' >> $outfile echo '================================'
echo '================================' >> $outfile echo "DYNARE MAKE CHECK $prg RESULTS"
echo '| TOTAL: '$total >> $outfile echo '================================'
echo '| PASS: '$passed >> $outfile echo "| TOTAL: $total"
echo '| FAIL: '$failed >> $outfile echo "| PASS: $passed"
echo '| XFAIL: '$xfailed >> $outfile echo "| FAIL: $failed"
echo '| XPASS: '$xpassed >> $outfile echo "| XFAIL: $xfailed"
if [ $failed -gt 0 ] ; then echo "| XPASS: $xpassed"
echo '| LIST OF FAILED TESTS:' >> $outfile if ((failed > 0)) ; then
for file in ${failed_tests[@]} ; do echo '|'
if [ "$prg" == "MATLAB" ]; then echo '| LIST OF FAILED TESTS:'
modfile=`sed 's/\.m\.trs/\.mod/g' <<< $file` >> $outfile for file in "${failed_tests[@]}" ; do
else echo "| * $file"
modfile=`sed 's/\.o\.trs/\.mod/g' <<< $file` >> $outfile done
fi fi
echo '| * '$modfile >> $outfile if ((xpassed > 0)) ; then
done echo '|'
fi echo '| LIST OF XPASSED TESTS:'
if [ $xpassed -gt 0 ] ; then for file in "${xpassed_tests[@]}" ; do
echo '| LIST OF XPASSED TESTS:' >> $outfile echo "| * $file"
for file in ${xpassed_tests[@]} ; do done
if [ "$prg" == "MATLAB" ]; then
modfile=`sed 's/\.m\.trs/\.mod/g' <<< $file` >> $outfile
else
modfile=`sed 's/\.o\.trs/\.mod/g' <<< $file` >> $outfile
fi fi
echo '| * '$modfile >> $outfile echo '|'
done echo '| LIST OF 10 SLOWEST TESTS:'
fi if [[ $prg == MATLAB ]]; then
echo '|' >> $outfile timing=$(sed 's/\.m\.trs/\.mod/g' <<< "$timing")
echo '| LIST OF 10 SLOWEST TESTS:' >> $outfile else
if [ "$prg" == "MATLAB" ]; then timing=$(sed 's/\.o\.trs/\.mod/g' <<< "$timing")
timing=`sed 's/\.m\.trs/\.mod/g' <<< $timing` fi
else echo "$timing" | tr ':' '\n' | sed -e 's/^[ \t]*//;/^$/d;s/^|[ ]/| * /'
timing=`sed 's/\.o\.trs/\.mod/g' <<< $timing` echo
fi } > $outfile
echo $timing | tr ':' '\n' | sed -e 's/^[ \t]*//' | \
sed '/^$/d' | sed -e 's/^|[ ]/| * /' >> $outfile
echo >> $outfile