#!/bin/csh -f

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

set rev = 0
set devs = ("0")
set tmpdir = ${rootpath}/tmp

echo "Start check for ${#devs} device(s) (revision: ${rev}, device IDs: ${devs})..."

set i = 1
while (${i} <= ${#devs})
    set okfile = ${tmpdir}/device$devs[$i].ok
    set ngfile = ${tmpdir}/device$devs[$i].ng
    (setenv GDEVICE "$devs[$i]" ; \
     setenv GREVISION "${rev}" ; \
     setenv GNDEVICE ${#devs} ; \
     rm ${okfile} ${ngfile} >& /dev/null ; \
     ${rootpath}/gdr/test/checksub ${argv}) &
    sleep 1
    @ i++
end

onintr LABEL_HUP

# wait until all sub programs are done.
set nruns = 1
while (${nruns} > 0)
    set nruns = `ps x | pgrep checksub | wc -l`
    sleep 1
end

set allok = 1
set i = 1
while (${i} <= ${#devs})
    set okfile = ${tmpdir}/device$devs[$i].ok
    set ngfile = ${tmpdir}/device$devs[$i].ng
    if ( -f ${ngfile}) then
        set allok = 0
    else if (! -f ${okfile}) then
        set allok = 0
    endif
    @ i++
end

if (${allok} == 0) then
    echo ""
    echo "Check failed."
    echo ""
    exit 1
endif

cd ${rootpath}
exit 0

LABEL_HUP:
killall checksub s9_gdr s8_gdr >& /dev/null
