/#!/bin/bash
# this has to be /bin/bash, because of $[ 1+2 ] syntax
# some simple cil regression tests; ideally, everyone can run
# this before committing


# ---------------------------------------------------------
# Adapted from a shell script used in Cil

# default values for user parameters
skip=0
contin=0
perf=0
blast="pblast.opt"
block=""

# counters
curtest=0
success=0
failure=0
unexSuccess=0
unexFailure=0
dies=0

usage() {
cat <<EOF
usage: $0 [options]
  -skip n      skip the first n tests
  -perf	       do performance evaluation
  -contin      keep going even after a test fails (or succeeds) unexpectedly
  -extra str   add "str" to every blast command
  -help        print this message
  -block s     run the tests in block s (default "all")
  -all         run all the tests
EOF
}

# process args
while [ "$1" != "" ]; do
  case "$1" in
    -skip)
      shift
      skip="$1"
      ;;

    -perf)
      perf=1
      ;;

    -contin)
      contin=1
      ;;

    -extra)       
      shift
      blast="$blast $1"
      ;;

    -help)
      usage
      exit 0
      ;;

    -block)
      shift
      block="$block$1"
     ;;
     
    -all)
     block="all"
     ;;
     
    *)
      echo "unknown arg: $1"
      usage
      exit 2
      ;;
  esac

  shift
done

# clear the logfile
log=regrtest.log
stat=regrtest.stat
rm -f *.log # we clear all logfiles from individual tests as well
rm -f regrtest.stat
# write something to terminal and log
log() {
  echo "$@"
  echo "$@" >> $log
}

#takes  no args -- just does a bunch of greps on the test_*.log file
getstats() {
echo "getting stats"
echo "[$curtest]" >> $stat 
echo `grep "TOTAL" test_${curtest}_full.log` >> $stat
echo `grep "Nb iterations of outer while loop" test_${curtest}_full.log` >> $stat
echo `grep "Total number of queries" test_${curtest}_full.log` >> $stat
echo "" >> $stat
echo `grep "Total foci queries" test_${curtest}_full.log`  >> $stat
echo "" >> $stat
echo `grep "Nb iterations of reachability" test_${curtest}_full.log` >> $stat
echo "Ticks" `grep "tick" test_${curtest}_full.log | wc`"\n"  >> $stat
echo `grep "Tree " test_${curtest}_full.log`"\n"  >> $stat
echo "Refines"`grep "Hit err" test_${curtest}_full.log | wc`  >> $stat
echo "TreeCheck"`grep "Bad transition" test_${curtest}_full.log`"\n"  >> $stat
echo "" >> $stat
echo "" >> $stat
}

# bail, unless asked to continue
bail() {
  if [ $contin -eq 0 ]; then
    exit 2
  fi
}

# run a single test, and bail if it fails
runTest() {
  if ! runTestInternal "$@"; then
    bail
  fi
}

# run a single test, and return 0 if it succeeds
runTestInternal() {
  #result=0
  rm -f test_${curtest}*.log
  if [ "$curtest" -lt "$skip" ]; then
    echo "[$curtest]: skipping $*"
  else
    # print a visually distinct banner
    echo "------------ [$curtest] $* ------------"

    "$@" > test_${curtest}_full.log 2>&1
    #result=$?
    if grep ":-(" test_${curtest}_full.log ; then
      unexFailure=$[ $unexFailure + 1 ]
      echo ""
      log  "[$curtest] A regression test command failed:"
      log  "  $*"
      tail -200 test_${curtest}_full.log >test_${curtest}.log
      rm test_${curtest}_full.log
    else
      if grep ":-)" test_${curtest}_full.log ; then
	log "[$curtest] $@ succeeds"
        success=$[ $success + 1 ]
	getstats
	echo `grep "Total number of queries" test_${curtest}_full.log`
	echo `grep "Nb iterations of outer while loop" test_${curtest}_full.log`
	echo `grep "Nb iterations of reachability" test_${curtest}_full.log`
        rm test_${curtest}_full.log
        if [ "$perf" -eq 1 ]; then 
          echo "Now running performace tests"
          rm -f tmp
#          for n in 1 2 3 4 5; do
          for n in 1 ; do
            if (time "$@" >test_${curtest}_${n}.log 2>&1) 2>times.out; then
              cat times.out | grep real | sed 's/real	0m/    /' \
                        | sed 's/s$//' | tee -a tmp
              rm times.out test_${curtest}_${n}.log
            else
              echo "Run $n of $@ failed."
              exit 4
            fi
         done

            # games with awk are to make sure sorting happens properly even when
            # the input times don't all have same # of digits (e.g. 9s vs 10s)
         log "    median:"`awk '{ printf("%9.3fs\n", $1); }' <tmp | sort | head -3 | tail -1`
         rm tmp
        fi
      else
        echo ""
	log "[$curtest] $@ Unexpected error"
	tail -200 test_${curtest}_full.log >test_${curtest}.log
	rm test_${curtest}_full.log
	dies=$[ $dies + 1]
      fi
    fi


  fi

  curtest=$[ $curtest + 1 ]
  return $result
}


# run a test that is expected to fail
failTest() {
  reason="$1"
  shift
  rm -f test_${curtest}*.log
  if [ "$curtest" -lt "$skip" ]; then
    echo "[$curtest]: (fail) skipping $*"
  else
    echo "------------ [$curtest] (fail) $* ------------"
    "$@" > test_${curtest}_full.log 2>&1
    if grep ":-)" test_${curtest}_full.log; then
      unexSuccess=$[ $unexSuccess + 1 ]
      echo ""
      log  "[$curtest] BAD NEWS: A regression test that should fail ($reason) now succeeds:"
      log  "  $*"
      tail -200 test_${curtest}_full.log >test_${curtest}.log
      rm test_${curtest}_full.log
      if [ $contin = 0 ]; then
        exit 2
      fi
    else
      if grep ":-(" test_${curtest}_full.log; then
        failure=$[ $failure + 1 ]
        echo "Failed as expected: $reason"
	log "[$curtest] $@ fails as expected"
	getstats
	echo `grep "Total number of queries" test_${curtest}_full.log`
	echo `grep "Nb iterations of outer while loop" test_${curtest}_full.log`
	echo `grep "Nb iterations of reachability" test_${curtest}_full.log`
        rm -f test_${curtest}_full.log

        if [ "$perf" -eq 1 ]; then 
          echo "Now running performance tests"
          rm -f tmp
          for n in 1 2 3 4 5; do
            if (time "$@" >test_${curtest}_${n}.log 2>&1) 2>times.out; then
              cat times.out | grep real | sed 's/real	0m/    /' \
                        | sed 's/s$//' | tee -a tmp
              rm times.out test_${curtest}_${n}.log
            else
              echo "Run $n of $@ failed."
              exit 4
            fi
         done

            # games with awk are to make sure sorting happens properly even when
            # the input times don't all have same # of digits (e.g. 9s vs 10s)
         log "    median:"`awk '{ printf("%9.3fs\n", $1); }' <tmp | sort | head -3 | tail -1`
         rm tmp
        fi
      else
        echo "Unexpected error"
        log "[$curtest] $@ Unexpected error"
	tail -200 test_${curtest}_full.log >test_${curtest}.log
	rm test_${curtest}_full.log
	dies=$[ $dies + 1]
      fi
    fi
  fi

  curtest=$[ $curtest + 1 ]
}


rw="-rw"

# self-contained tests of specific examples 

# easy microbenchmarks
blockMICRO(){
runTest $blast -bddmin driver.c -craig 1 -scope
runTest $blast -bddmin sr.c  -craig 1 -scope
runTest $blast -bddmin funcall-hard.c -craig 1 -scope

#runTest $blast -bddmin qpmouse.i -pred qpmpreds -craig 1 -scope
#runTest $blast tlan.i -pred tlan.preds -craig 1 -scope -nocache
}


# aliasing examples (swap)
blockALIAS(){
runTest $blast alias/alias1.c -alias bdd -craig 1 -scope -cref   "$@"
failTest "UNSAFE" $blast alias/alias1-bug.c -alias bdd -craig 1 -scope  -cref  "$@"
runTest $blast alias/alias2.c -alias bdd -craig 1 -scope  -cref  "$@"
runTest $blast alias/ptest0.c -alias bdd -craig 1 -scope  -cref  "$@"
failTest "UNSAFE" $blast alias/ptest0-bug.c -alias bdd -craig 1 -scope  -cref  "$@"
runTest $blast alias/ptest1.c -alias bdd -craig 1 -scope  -cref  "$@"
runTest $blast alias/ptest2.c -alias bdd -craig 1 -scope  -cref  "$@"
runTest $blast alias/swap.c -alias bdd -craig 1 -scope  -cref  "$@"
runTest $blast alias/swap1.c -alias bdd -craig 1 -scope  -cref  "$@"
runTest $blast alias/swap2.c -alias bdd -craig 1 -scope   -cref "$@"
runTest $blast alias/swap3.c -alias bdd -craig 1 -scope   -cref "$@"
runTest $blast alias/swap3a.c -alias bdd -craig 1 -scope   -cref "$@"
runTest $blast -craig 1 -quiet -alias bdd -tproj tproject/test6.c  -cref "$@"
#runTest $blast alias/swap1-add.c -alias bdd -craig 1 -scope -cref  
failTest "UNSAFE" $blast alias/swap-bug.c -alias bdd -craig 1 -scope -cref  "$@"
failTest "Error: Foci bug" $blast alias/swap1-bug.c -alias bdd -craig 1 -scope -cref -nocf "$@"
failTest "Error: Foci bug" $blast alias/swap2-bug.c -alias bdd -craig 1 -scope -cref -nocf "$@"
failTest "Error: Foci bug" $blast alias/swap3-bug.c -alias bdd -craig 1 -scope -cref -nocf "$@"
failTest "Error: Foci bug" $blast alias/swap4-bug.c -alias bdd -craig 1 -scope -cref -nocf "$@"
failTest "UNSAFE" $blast alias/alias1-unsafe.c -alias bdd -craig 1 -scope -cref -nocf "$@"
failTest "UNSAFE" $blast alias/alias2-unsafe.c -alias bdd -craig 1 -scope -cref -nocf "$@"
failTest "UNSAFE" $blast alias/ptest0-unsafe.c -alias bdd -craig 1 -scope -cref -nocf "$@"
failTest "UNSAFE" $blast alias/ptest1-unsafe.c -alias bdd -craig 1 -scope -cref -nocf "$@"
failTest "UNSAFE" $blast alias/ptest2-unsafe.c -alias bdd -craig 1 -scope -cref -nocf "$@"

runTest $blast incref2.c -alias bdd -incref -craig 1 -scope    "$@"
runTest $blast incref.c -alias bdd -incref -craig 1 -scope    "$@"

runTest $blast tproject/test7.c -craig 1 -alias bdd -incref "$@"
runTest $blast tproject/test8.c -craig 1 -alias bdd -incref "$@"
runTest $blast tproject/test9.c -craig 1 -alias bdd -incref "$@"
}

blockALIASLONG(){
failTest "UNSAFE" $blast incref3.c -alias bdd -incref -craig 1 -scope   "$@"
failTest "UNSAFE" $blast incref3.c -alias bdd -incref -craig 1 -cf -scope   "$@"

runTest $blast -cf -craig 1 -quiet cftest/manyswap.c #v.long
runTest $blast alias/swap3a.c -alias bdd -craig 1 -scope   "$@"
failTest "Error: Foci bug" $blast alias/swap2-bug.c -alias bdd -craig 1 -scope   "$@"
failTest "Error: Foci bug" $blast alias/swap3-bug.c -alias bdd -craig 1 -scope   "$@"
failTest "Error: Foci bug" $blast alias/swap4-bug.c -alias bdd -craig 1 -scope   "$@"
runTest $blast pointertest.c -alias bdd -craig 1 -scope "$@"
failTest "Bug" $blast pointertest-bug.c -alias bdd -incref "$@"
runTest $blast tfwdbwd.c -alias bdd -craig 1 -scope "$@"
}


# NT drivers with IRP completion property
blockIRP(){
failTest "Bug" $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/cdaudio.i -incref -bfs
runTest $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/kbfiltr.i -incref -bfs
runTest $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/floppy.i  -incref -bfs
runTest $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/parport.i  -incref -bfs
runTest $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/parclass.i  -incref -bfs
failTest "UNSAFE"  $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/parclass.BUG.i  -incref -bfs
# runTest $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/mouclass.i -bfs
# runTest $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/mouclass.i -block -bfs
}

# SSH examples sent by Chaki
blockCHAKI(){
runTest $blast -bddmin -nofp -predH 7 ssh/s3_clnt.blast.1.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_clnt.blast.2.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_clnt.blast.3.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_clnt.blast.4.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.1.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.2.c   -craig 1 -scope -bfs 
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.3.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.4.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.5.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.6.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.7.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.8.c   -craig 1 -scope -bfs
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.9.c   -craig 2 
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.10.c   -craig 2 
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.11.c   -craig 2 
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.12.c   -craig 2 
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.13.c   -craig 2 
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.14.c   -craig 2 
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.15.c   -craig 2 
runTest $blast -bddmin -nofp -predH 7 ssh/s3_srvr.blast.16.c   -craig 2 -alias bdd
}


# BFS search examples
blockBFS(){
runTest $blast -bfs -bddmin driver.c 
runTest $blast -bfs -bddmin sr.c   
runTest $blast -bfs -bddmin funcall-hard.c   
runTest $blast -bfs -bddmin qpmouse.i -pred qpmpreds  
runTest $blast -bfs -bddmin -pred tlan.preds tlan.i
runTest $blast -bfs -bddmin -msvc -nofp -block -predH 7 -scope -craig 1 ntdrivers/floppy.i 
}

blockCF(){
# CF test examples
runTest $blast -cf -craig 1 -quiet cftest/calltest.c
runTest $blast -cf -craig 1 -quiet cftest/driver-simple.c
runTest $blast -cf -craig 1 -quiet cftest/funcall-hard.c
failTest "UNSAFE" $blast -cf -craig 1 -quiet cftest/funcall-missing.c
runTest $blast -cf -craig 1 -quiet cftest/funcall-rec.c
runTest $blast -cf -craig 1 -quiet cftest/funcall1.c
runTest $blast -cf -craig 1 -quiet cftest/funcall2-global.c
#runTest $blast -cf -craig 1 -quiet cftest/manyswap.c
failTest "UNSAFE"  $blast -cf -craig 1 -quiet cftest/funcall-rec-unsafe.c #shocking, but blast works on this!
failTest "UNSAFE"  $blast -cf -craig 1 -quiet cftest/funcall3.c
runTest $blast -cf -craig 1 -quiet cftest/funcall4.c
runTest $blast -cf -craig 1 -quiet cftest/global.c
runTest $blast -cf -craig 1 -quiet cftest/global2.c
runTest $blast -cf -craig 1 -quiet cftest/rec1.c
runTest $blast -cf -craig 1 -quiet cftest/rec2.c
runTest $blast -cf -craig 1 -quiet cftest/twocalls.c
runTest $blast -cf -craig 1 -quiet cftest/simpbug.c
failTest "UNSAFE"  $blast -cf -craig 1 -quiet cftest/twocalls-unsafe.c
failTest "UNSAFE"  $blast -cf -craig 1 -quiet cftest/fac.c
}

# tproject examples 
blockTPROJ(){
runTest $blast -craig 1 -quiet -tproj -projfun tproject/projfun.c
runTest $blast -craig 1 -quiet -tproj tproject/test.c
runTest $blast -craig 1 -quiet -tproj tproject/test1.c
runTest $blast -craig 1 -quiet -tproj tproject/test2.c
runTest $blast -craig 1 -quiet -tproj tproject/test4.c
runTest $blast -craig 1 -quiet -tproj tproject/test5.c
runTest $blast -craig 1 -quiet -alias bdd -tproj tproject/test6.c

failTest "UNSAFE" $blast -craig 1 -quiet -tproj tproject/test-unsafe.c
failTest "UNSAFE" $blast -craig 1 -quiet -tproj tproject/test2-unsafe.c
failTest "UNSAFE" $blast -craig 1 -quiet -tproj tproject/test3.c
failTest "UNSAFE" $blast -craig 1 -quiet -tproj tproject/test5-unsafe.c

runTest $blast -cf -craig 1 -tproj cftest/calltest.c
runTest $blast -cf -craig 1 -tproj cftest/driver.c
runTest $blast -cf -craig 1 -tproj cftest/funcall-hard.c
failTest "UNSAFE" $blast -cf -craig 1 -tproj cftest/funcall-missing.c
runTest $blast -cf -craig 1 -tproj cftest/funcall-rec.c
runTest $blast -cf -craig 1 -tproj cftest/funcall1.c
runTest $blast -cf -craig 1 cftest/funcall2-global.c
failTest "UNSAFE" $blast -cf -craig 1 cftest/funcall2-global-unsafe.c 
failTest "UNSAFE" $blast -cf -craig 1 -tproj cftest/funcall-rec-unsafe.c
#shocking, but blast works on the above!

#ADD MORE ...
#failTest $blast -craig 1 -quiet -tproj tproject/test-unsafe.c

runTest $blast tproject/test7.c -craig 1 -alias bdd -incref -tproj "$@"
runTest $blast tproject/test8.c -craig 1 -alias bdd -incref -tproj "$@"
runTest $blast tproject/test9.c -craig 1 -alias bdd -incref -tproj "$@"
}

# aliasing examples (swap) with CF
blockALIASCF(){
blockALIAS -cf
}

# NT drivers with IRP completion property
blockIRPCF(){
runTest $blast -bddmin -cf -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/cdaudio.i -incref -bfs
runTest $blast -bddmin -cf -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/kbfiltr.i -incref -bfs
runTest $blast -bddmin -cf -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/floppy.i  -incref -bfs
runTest $blast -bddmin -cf -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/parport.i  -incref -bfs
runTest $blast -bddmin -cf -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/parclass.i  -incref -bfs
failTest "UNSAFE"  $blast -bddmin -cf -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/parclass.BUG.i  -incref -bfs
}



# NT drivers with IRP completion property
blockIRPCFTP(){
runTest $blast -bddmin -cf -tproj -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/cdaudio.i -incref -bfs
runTest $blast -bddmin -cf -tproj -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/kbfiltr.i -incref -bfs
runTest $blast -bddmin -cf -tproj -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/floppy.i  -incref -bfs
runTest $blast -bddmin -cf -tproj -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/parport.i  -incref -bfs
runTest $blast -bddmin -cf -tproj -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/parclass.i  -incref -bfs
failTest "UNSAFE"  $blast -bddmin -cf -tproj -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/parclass.BUG.i  -incref -bfs
}

# File open close on large programs
blockFILE() {

runTest $blast -craig 1 -scope -alias bdd -incref -cf -tproj file_io_test.c # fails

#$spec fileopenclose/file_openclose.spc file_openclose/fcron-2.9.5.c
#runTest $blast -nofp -predH 7 -craig 1 -scope -alias bdd -incref -cf -tproj file_openclose/instrumented.c 
#$spec fileopenclose/file_openclose.spc file_openclose/fcrondyn-2.9.5.c
#runTest $blast -nofp -predH 7 -craig 1 -scope -alias bdd -incref -cf -tproj file_openclose/instrumented.c 
#$spec fileopenclose/file_openclose.spc file_openclose/pfinger
#runTest $blast -nofp -predH 7 -craig 1 -scope -alias bdd -incref -cf -tproj file_openclose/instrumented.c 
}




# Finally tests that should succeed but fail now for various reasons
blockMISC(){
echo ""
echo "Now running tests that should succeed but fail due to various reasons"
failTest "foci does not reason about field offsets" $blast pointertest-bug.c -alias bdd -craig 1 -scope
failTest "foci does not reason about memory well!" $blast tfwdbwd.c -craig 1 -scope -bfs
#failTest "fails because we treat fields of a structure together" $blast test1/race2.c -init test1/init -pred test1/pred -inv test1/inv $rw
}

runShortRegress(){

    blockMICRO
    
    blockALIAS -bfs

    blockTPROJ

    blockCF

    blockALIAS -cf
   
    blockFILE 
 
# run the first three tests of the IRP block, since they complete quickly
runTest $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/cdaudio.i -incref -bfs
runTest $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/kbfiltr.i -incref -bfs
runTest $blast -bddmin -msvc -nofp -predH 7 -craig 1 -scope -alias bdd -pred ntdrivers/irpMaf.preds ntdrivers/floppy.i  -incref -bfs

}

#must be called with -fmc, -fmcc
blockFMCAC(){
echo "Running FMC tests"
runTest $blast -alias bdd -bfs "$@"  -pred stest0.pred stest0.c
# test1,test2 fail with fmcc ...but succeed with vanilla blast -- craig 1
runTest $blast -alias bdd -bfs "$@"  -pred test1.pred test1.c
runTest $blast -alias bdd -bfs "$@"  -pred test2.pred test2.c
runTest $blast -alias bdd -bfs "$@"  -pred loop.pred loop.c
runTest $blast -alias bdd -bfs "$@"  -pred loop1.pred loop1.c
failTest "UNSAFE" $blast -alias bdd -bfs "$@"  -pred loop.pred loop-unsafe.c
failTest "UNSAFE" $blast -alias bdd -bfs "$@"  -pred loop1.pred loop1-unsafe.c
#runTest $blast -alias bdd -bfs "$@" -loadabs alias1.abs alias1.c
failTest "UNSAFE" $blast -alias bdd "$@" -pred stest0.pred stest0-unsafe.c
runTest $blast -alias bdd -bfs "$@" -pred ucltest1.pred ucltest1.c
runTest $blast -alias bdd -bfs "$@" -pred copy1.pred copy1.c
runTest $blast -alias bdd -bfs "$@" -pred test4.pred test4.c
runTest $blast -alias bdd -bfs "$@" -pred test5.pred  test5.c
runTest $blast -alias bdd -bfs "$@" -pred test6.pred test6.c
failTest "UNSAFE (but FOCI Crashes)" $blast -alias bdd "$@" -pred test6.pred test6-unsafe.c
runTest $blast -alias bdd -bfs -fociUF "$@" -pred test7.pred test7.c
}


blockFMCHARD(){
echo "Running FMC hard tests"
runTest $blast -fmc -alias bdd -bfs "$@" -pred prooftest3.pred prooftest3-flat.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred prooftest3.pred prooftest3-flat2.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred prooftest3.pred prooftest3-flat-split.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred prooftest3.pred prooftest3-flat2-split.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred prooftest3.pred prooftest3.c
}

blockFMC(){
blockFMCAC -fmc
}
blockFMCC(){
blockFMCAC -fmcc
runTest $blast -bfs -alias bdd -fmcc alias1.c
failTest "UNSAFE" $blast -bfs -alias bdd -fmcc test3.c
runTest $blast -bfs -alias bdd -fmcc test4.c
runTest $blast -bfs -alias bdd -fmcc test5.c
runTest $blast -bfs -alias bdd -fmcc test6.c
runTest $blast -bfs -alias bdd -fmcc test7.c
runTest $blast -bfs -alias bdd -fmcc test8.c
runTest $blast -bfs -alias bdd -fmcc test9.c

}

blockFMCSCULL(){
echo "Running FMC scull tests"
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" scull/scull_pp1.c
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" scull/scull_pp2.c
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" scull/scull_pp3.c
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" -pred scull/scull_pp4.pred scull/scull_pp4.c
}

blockFMCCAV05(){
echo "Running FMC tests for CAV05"
runTest $blast -fmc -alias bdd -bfs "$@"  -pred loop.pred loop.c
runTest $blast -fmc -alias bdd -bfs "$@"  -pred loop1.pred loop1.c
failTest "UNSAFE" $blast -fmc -alias bdd -bfs "$@"  -pred loop.pred loop-unsafe.c
failTest "UNSAFE" $blast -fmc -alias bdd -bfs "$@"  -pred loop1.pred loop1-unsafe.c
failTest "UNSAFE" $blast -fmc -alias bdd "$@" -pred stest0.pred stest0-unsafe.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred ucltest1.pred ucltest1.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred copy1.pred copy1.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred test4.pred test4.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred test5.pred  test5.c
failTest "UNSAFE" $blast -alias bdd "$@" -pred test6.pred test6-unsafe.c
runTest $blast -alias bdd -bfs -fociUF "$@" -pred test7.pred test7.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred prooftest3.pred prooftest3-flat.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred prooftest3.pred prooftest3-flat2.c
runTest $blast -fmc -alias bdd -bfs "$@" -pred prooftest3.pred prooftest3.c
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" scull/scull_pp1.c
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" scull/scull_pp2.c
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" scull/scull_pp3.c
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" -pred scull/scull_pp4.pred scull/scull_pp4.c
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" -pred list.pred list.c
}

blockFMCLIST(){
runTest $blast -fmc -alias bdd -bfs -cref -fociUF "$@" -pred list.pred list.c
}


runAllTests(){

    blockMICRO
    
    blockALIAS 

    blockTPROJ

    blockALIASCF
    
    blockIRP

    blockCHAKI

    blockBFS

    blockCF
    
    blockIRPCF
     
    blockIRPCFTP

    blockFILE
     
    blockMISC
}
#RJ: I don't really follow the deal with contin...




# process args
#while [ "$block" != "" ]; do
  case "$block" in
      FMC)
	  shift
	  blockFMC
	  ;;
      FMCC)
	  shift
	  blockFMCC
	  ;;
      FMCAC)
	  shift
	  blockFMCAC
	  ;;
      FMCHARD)
      	  shift
	  blockFMCHARD
	  ;;
      FMCSCULL)
      	  shift
	  blockFMCSCULL
	  ;;
      FMCCAV05)
      	  shift
	  blockFMCCAV05
	  ;;
      FMCLIST)
      	  shift
	  blockFMCLIST
	  ;;
      MICRO)
	  shift
	  blockMICRO
	  ;;
      
      ALIAS)
	  blockALIAS -bfs
	  ;;
      
      IRP)
	  blockIRP
	  ;;
    
      TPROJ)
	  blockTPROJ
	  ;;

      CHAKI)
	  blockCHAKI
	  ;;
	  
      BFS)
	  blockBFS
	  ;;

      CF)
	  blockCF
	  ;;

      IRPCF)
	  blockIRPCF
	  ;;

      IRPCFTP)
	  blockIRPCFTP
	  ;;
      FILE)
	  blockFILE
	  ;;

      MISC)
	  blockMISC
	  ;;

      SHORT_REGRESS)
	  runShortRegress
	  ;;

      ALL)
	  runAllTests
	  ;;

      *)
      echo "unknown block!: $block"
      usage
      exit 2
      ;;
  esac
  
  shift
#done

# final arithmetic to report result
rm -f test.log err.log
    if [ -f "$log" ]; then
    cat "$log"
    fi
echo ""
echo "Successful tests:      $success"
echo "Failed as expected:    $failure"    
echo "Unexpected success:    $unexSuccess"
echo "Unexpected failure:    $unexFailure"
echo "No Answer:             $dies"



 
