Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /tests/rtest/scripts/run_sh.in
ViewVC logotype

View of /tests/rtest/scripts/run_sh.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5064 - (download) (annotate)
Fri Jul 14 15:34:41 2017 UTC (22 months ago) by jhr
File size: 4562 byte(s)
parallel target support for Makefile tests
#!/bin/ksh
#
# A script for running the Diderot regression tests.
#
# usage:
#	scripts/run.sh [diderotc] [diderotc-flags] [-- runtime-flags]
#
# Tests live in the "tests" subdirectory. For a test named "foo", we should have
#
#	tests/foo			-- the test directory
#	tests/foo/foo.diderot		-- the test source code
#	tests/foo/assess.sh		-- an assessment script that should either return a
#					   numeric result representing the difference, or one
#					   of "ok" or "fail".
#	tests/foo/correct.{nrrd,txt}	-- the correct output.  Usually a nrrd file, but
#					   some tests produce textual output
#       tests/Makefile                  -- optional makefile for building the application
#	tests/foo/run.sh		-- optional script for running the application
#
# @configure_input@
#

# set up the path so that we can find unu
#
PATH=/bin:/usr/bin:@TEEM_DIR@/bin

function usage {
  echo "usage:"
  echo "  scripts/run.sh [diderotc] [diderotc-flags] [-- runtime-flags]"
  exit $1
}

# function to cleanup 
# function to report success
#
# usage: success <test> <result>
function success {
  t=$1
  result=$2
  echo "result is good ($result)" >> $REPORT
  echo "ok" >> $LOG
  echo "$t is okay"
  if [ -f Makefile ] ; then
    make clean
  else
    rm -f $t $t.o $t.cxx $t.cl $t.log out.nrrd out.txt
  fi
}

# function to report test failure
function failure {
  t=$1
  result=$2
  echo "result is bad ($result)" >> $REPORT
  echo "fail ($result)" >> $LOG
  echo "$t failed"
  rm -f $t.cxx $t.o $t
}

# this script should be run from the rtest directory
#
HERE=$(pwd)
if [ ! -d $HERE/tests ] ; then
  echo "run script from rtest directory"
  exit 1
fi

# process command-line arguments
#
DIDEROTC="@DIDEROTC@"
DIDEROTC_FLAGS=""
RUNTIME_FLAGS=""
PARALLEL="no"
if [ $# -ne 0 ] ; then
  # first we check for the diderotc command
  case $1 in
    -*) ;; # no diderot command
    /*) DIDEROTC=$1; shift ;; # absolute path
    *) DIDEROTC=$HERE/$1; shift ;; #relative path
  esac
  # get diderotc flags
  while [ $# -ne 0 ] ; do
    case $1 in
      --) shift; break ;; # switch modes
      --target=pthread|--target=parallel)
        PARALLEL=yes
        DIDEROTC_FLAGS="$DIDEROTC_FLAGS $1"
      ;;
      -*) DIDEROTC_FLAGS="$DIDEROTC_FLAGS $1" ;;
      *) echo "unrecognized argument"
        usage 1
      ;;
    esac
    shift
  done
  # get runtime flags
  while [ $# -ne 0 ] ; do
    case $1 in
      -*) RUNTIME_FLAGS="$RUNTIME_FLAGS $1" ;;
      *) echo "unrecognized argument"
        usage 1
      ;;
    esac
    shift
  done
fi

#
# check that the diderotc path is valid
#
if [ ! -x $DIDEROTC ] ; then
  echo "$DIDEROTC is not executable or does not exist"
  exit 1
fi

# get a list of all of the tests (one per directory)
#
TESTS=$(cd tests; ls)

DATE=$( date +"%F-%H-%M-%S" )
LOG=$HERE/log.$DATE
REPORT=$HERE/report.$DATE

NUMTESTS=0
NUMFAILS=0
echo "testing $DIDEROTC $DIDEROTC_FLAGS" > $REPORT
for t in $TESTS ; do
  cd $HERE/tests/$t;
  NUMTESTS=$(($NUMTESTS+1))
  echo "********** $t **********" >> $LOG
  echo -n "checking $t ... " >> $REPORT
  if [ -f Makefile ] ; then
    echo "make DIDEROTC_FLAGS=$DIDEROTC_FLAGS PARALLEL=$PARALLEL" >> $LOG
    make DIDEROTC_FLAGS="$DIDEROTC_FLAGS" PARALLEL="$PARALLEL" 2>> $LOG 1>> $LOG
  else
    echo "$DIDEROTC --exec $DIDEROTC_FLAGS $t.diderot" >> $LOG
    $DIDEROTC --exec $DIDEROTC_FLAGS $t.diderot 2>> $LOG 1>> $LOG
  fi
  if [ "$?" -eq "0" ] ; then
    echo -n "compile succeeded ... " >> $REPORT
    if [ -x ./run.sh ] ; then
      # test has run.sh script
      STS=$?
      echo "./run.sh $RUNTIME_FLAGS" >> $LOG
      ./run.sh $RUNTIME_FLAGS 2>> $LOG 1>> $LOG
      STS=$?
    else
      echo "./$t $RUNTIME_FLAGS" >> $LOG
      ./$t $RUNTIME_FLAGS 2>> $LOG 1>> $LOG
      STS=$?
    fi
    if [ "$STS" -eq "0" ] ; then
      echo -n "execution succeeded ... " >> $REPORT
      result=$(./assess.sh)
      case $result in
	ok) success $t $result ;;
	fail)
	  NUMFAILS=$(($NUMFAILS+1))
	  failure $t $result
	;;
	*)
	  if (($result < 1.0)) ; then
	    success $t $result
	  else
	    NUMFAILS=$(($NUMFAILS+1))
	    failure $t $result
	  fi
	;;
      esac
    else
      let NUMFAILS=$(($NUMFAILS+1))
      echo "execution failed" >> $REPORT
      echo "$t failed"
    fi
  else
    let NUMFAILS=$(($NUMFAILS+1))
    echo "compile failed" >> $REPORT
    echo "$t failed"
  fi
  echo "**********" >> $LOG
done
cd $HERE

if (($NUMFAILS == 0)) ; then
  echo "**** all $NUMTESTS tests passed; complete report at $REPORT"
else
  echo "!!!! $NUMFAILS out of $NUMTESTS tests failed; complete report at $REPORT"
fi

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0