#!/bin/ksh ####################################################### ## Parse the arguments to the script ####################################################### if [ $# -lt 2 ]; then echo usage: $0 fullPath/codeDirectory fullPath/testcaseDirectory exit 1 else ## CODE_DIR should be set tothe directory containing the Makefile ## and sources to produce cs450words CODE_DIR=$1 #if the working directory does not exist then create it if [ ! -d $CODE_DIR ]; then echo $CODE_DIR does not exist exit 1 fi echo Testing $CODE_DIR ## TESTS_DIR should be set to the directory where the *.command ## *.input and *.output are TESTS_DIR=$2 #if the working directory does not exist then create it if [ ! -d $TESTS_DIR ]; then echo $TESTS_DIR does not exist exit 1 fi echo Tests in $TESTS_DIR fi ################################################################### # Will compute the difference between two times ################################################################# #=================================================================== s_interval()# (c) RHReepe. Returns a time difference (HH:MM:SS) #=================================================================== # Arg_1 = start_time (Format - See s_time) # Arg_2 = stop_time (Format - See s_time) { # Get Start Hour h1=`echo $1 | cut -c1-2` # Get Start Minute m1=`echo $1 | cut -c3-4` # Get Start Second s1=`echo $1 | cut -c5-6` # Get Stop Hour h2=`echo $2 | cut -c1-2` # Get Stop Minute m2=`echo $2 | cut -c3-4` # Get Stop Second s2=`echo $2 | cut -c5-6` # Calculate Second Difference s3=`expr $s2 - $s1` # Test for Negative Seconds if [ $s3 -lt 0 ]; then # If yes - add one minute... s3=`expr $s3 + 60` # ... and to subtractor m1=`expr $m1 + 1` fi # Calculate Minute Difference m3=`expr $m2 - $m1` # Test for Negative Minutes if [ $m3 -lt 0 ]; then # If yes - add one hour... m3=`expr $m3 + 60` # ... and to subtractor h1=`expr $h1 + 1` fi # Calculate Hour Difference h3=`expr $h2 - $h1` # Test for Negative Hours then if [ $h3 -lt 0 ]; then # If yes - add one day h3=`expr $h3 + 24` fi # Loop through numbers... for number in $h3 $m3 $s3; do # If number is single digit...then if [ $number -lt 10 ]; then # ... add leading zero echo "0$number\c" else # ... else - don't echo "$number\c" fi done # Terminate the string echo "" } ######################################################################## # Prepare to test ####################################################################### #we expect make to produce an execuable of this name executable=cs450words #where the output to be tested will be placed outfile=$CODE_DIR/temp.out sortedOutfile=$CODE_DIR/sortedTemp.out sortedGoldfile=$CODE_DIR/sortedGold.out if [ -e $outfile ]; then echo Warning: file $outfile exists and will be clobbered to hold temporary results fi cd $CODE_DIR make clean if [ -e $executable ]; then echo SUMMARY $CODE_DIR: Executable $executable should not exist after make clean but before make exit 1 fi make if [ ! -e $executable ]; then make clean echo SUMMARY $CODE_DIR Executable $executable does not exist exit 1 fi echo "Executable produced; beginning testing..." # The current directory must be in our path PATH=$PATH:. # We are going to count both the total tests and the number # of successful tests successfulTests=0 failedTests=0 unexaminedTests=0 totalTests=0 totalTime=0 testsMissingInput=0 #Record the time we began testing startTotalTime=$( date +%H%M%S ) ######################################################## ### Loop over each test (i.e. each *.command in TESTS_DIR) ######################################################## for test in $TESTS_DIR/*.command; do # this is an ugly line but wha it does is pulls # off the .command part of the test name # Example: if $test = foo.command $testRoot = foo testRoot=`ls $test | sed 's/\(.*\).command\(.*\)/ \1/'` if [ ! -e $testRoot.input ]; then echo "******************* Warning *****************" echo "Missing input for test $testRoot" testsMissingInput=`expr $testsMissingInput + 1` else totalTests=`expr $totalTests + 1` echo "******************* Test $totalTests *****************" echo Test $totalTests is $testRoot #the command file must be executable chmod u+x $test #remove any previous temporary output file if [ -e $outfile ]; then /bin/rm $outfile fi if [ -e $sortedOutfile ]; then /bin/rm $sortedOutfile fi if [ -e $sortedGoldfile ]; then /bin/rm $sortedGoldfile fi #################################### # Actually run the test #################################### thisTestStartTime=$( date +%H%M%S ) cat $testRoot.input | $test > $outfile thisTestStopTime=$( date +%H%M%S ) ################################### # Compute how long this test took ################################### thisTestTime=`s_interval $thisTestStartTime $thisTestStopTime` ################################### # Output information about this test ################################## echo Running test $testRoot echo Command is: cat $testRoot.command echo if [ -e $testRoot.output ]; then #################################### # Compare the output produced to the # correct output ################################### #Note for stress tests just don't do the diff # -b ingnores trailing blanks sort $outfile > $sortedOutfile sort $testRoot.output > $sortedGoldfile # diffOutput=`diff -b $testRoot.output $outfile` diffOutput=`diff -b $sortedOutfile $sortedGoldfile` # $? is set to the result of the diff command # diff returns 0 if no differnces and non zero otherwise if [ $? -eq 0 ] ; then successfulTests=`expr $successfulTests + 1` echo Passed $testRoot in time $thisTestTime else echo Failed $testRoot failedTests=`expr $failedTests + 1` #Do the diff again so that the output is #sent to stdout diff -b $testRoot.output $outfile fi else unexaminedTests=`expr $unexaminedTests + 1` echo Test $testRoot run in time $thisTestTime Output not compared for correctness fi #Does the input exist fi #for each test done if [ $totalTests -eq 0 ]; then echo There were no tests in $TEST_DIR else echo "******************* Tests complete *****************" fi if [ -e $outfile ]; then /bin/rm $outfile fi if [ -e $sortedOutfile ]; then /bin/rm $sortedOutfile fi if [ -e $sortedGoldfile ]; then /bin/rm $sortedGoldfile fi make clean if [ -e $executable ]; then echo SUMMARY $CODE_DIR: Executable $executable should not exist after make clean fi #Record the time we began testing stopTotalTime=$( date +%H%M%S ) #Compute the time it took for all the tests to run totalTime=`s_interval $startTotalTime $stopTotalTime` echo SUMMARY $CODE_DIR SuccessfulTests: $successfulTests FailedTests: $failedTests UnexaminedTests: $unexaminedTests TotalTests: $totalTests TotalTime: $totalTime if [ ! $testsMissingInput -eq 0 ]; then echo WARNING THere were $testsMissingInput tests missing input fi