#!/bin/csh -f
cat << DESC_END
-----------------------------------------------
 GRAPE check program
 usage: check [-n|-noexec] [args...]
-----------------------------------------------
DESC_END

set cmdname  = $0:t;
set rootpath = $0:h/..
pushd $rootpath > /dev/null
set rootpath = `pwd`
popd > /dev/null

if ("$1" == "-n" || "$1" == "--noexec") then
  shift
  set doexec = 0
else
  set doexec = 1
endif

set devid = 0
if ( $?GDEVICE ) then
    # set the device ID of the 1st card to 'devid'.
    set devid = `echo $GDEVICE | sed 's/\([0-9]\).*$/\1/g'`
endif

set gtype = `${rootpath}/hibutil/lsgrape -d ${devid} | \
             grep -v devid | \
             sed 's/[^a-zA-Z]*\(GRAPE[^(]*\).*$/\1/g' |\
             sed 's/.*\(null\).*$/\1/g'`

echo GRAPE product ID : ${gtype}

switch (${gtype})
  case GRAPE-9
    set testdir = ${rootpath}/g9/test
    breaksw
  case GRAPE-DR
    set testdir = ${rootpath}/gdr/test
    breaksw
  case GRAPE-7
    set testdir = ${rootpath}/g7/test
    breaksw
  case *:
    echo ''
    echo "No GRAPE product ID found in 'board_info' register of device ${devid}."
    echo "Try grapepkg/gdr/test/${cmdname} or grapepkg/g7/test/${cmdname}."
    echo ''
    exit 1
    breaksw
endsw

echo "run ${testdir}/check ${argv}"
if ($doexec == 1) then
  ${testdir}/check ${argv}
endif

exit 0
