## simtest.pro : automatic full-suite simulated IPP test : -*- sh -*-

macro simtest
  if ($0 != 5)
    echo "USAGE: simtest (testroot) (dbname) (hostname) (init)"
    echo " if (init) == 0, just run the analysis tasks"
    echo " if (init) == 1, (re)create the database and (re)inject the images"
    echo " if (init) == 2, restart completely from scratch"
    break
  end

  $testroot = $1
  $dbname = $2
  $hostname = $3
 
  if ($4 > 0)
    # XXX this will fail and exit the script if the db does not exist or is old...
    exec pxadmin -delete -dbname $dbname

    # XXX this gives warnings if the db exists...
    exec pxadmin -create -dbname $dbname

    if ($4 == 2)
      # the labels "wait" and "proc" are special names used in automate.pro
      exec ppSimSequence $MODULES:0/$testroot.config $testroot.mkimages $testroot.inject -path raw -workdir work -dbname $dbname -label wait -dvodb DVO -tess_id TESS
      exec source $testroot.mkimages

      file TESS/Images.dat found
      if ($found == 0)
        exec skycells 8 -scale 0.2 -D CATDIR TESS
      end
    end

    exec chiptool -dbname $dbname -block -label wait
    exec source $testroot.inject
  end

  module pantasks.pro
  module automate.pro

  module.tasks

  controller host add $hostname
  add.database $dbname

  automate.load simtest.auto $dbname
  run
end

# XXX add a test function to pxadmin to check for db existence
