#!/bin/csh -f
#
# PCTEST - test PPC
#
# Source Version: 2.0
# Software Release #92-0043
#
# include "cpyright.h"
#
if (-e ../manager/noipc) exit(0)

set System = `../manager/system-id`
set BinDir = ../dev/$System/bin
set ERROR  = "FALSE"
set FAIL   = "NO"
set status = 0

set FrontEnd = ""
set DP       = FALSE
set DPE      = `which pact-dpe`
if ("$DPE" != "") then
   if (-e "$DPE[1]") then
      source $DPE
      set DP = TRUE
   endif
endif

source ../manager/env-$System

set PCEXEC = "$FrontEnd $BinDir/pcexec"

if (-e ../dev/$System/include/ppc.h) then

   touch test.error

   rm -f pctest.debug
   echo `../manager/pwhich pact` >& pctest.debug
   echo `../manager/pwhich cc` >>& pctest.debug
   echo $BinDir >>& pctest.debug

   echo ""
   echo "PPC TEST..."

   echo ""
   echo -n "                    Building PPC Test Programs ..... "
   pact Cstd >& test.error

# START of large loop ++++++++++++++++++++++++++++++++++++++++++++++++++
   if ($status != 0) then
      echo ""
      cat test.error
      echo "                    Can't build Standard PPC Test Programs"
      set ERROR = "TRUE"

# ELSE of large loop +++++++++++++++++++++++++++++++++++++++++++++++++++
   else

   echo "DONE"

   unalias ls
   set TEST = "cat DISCLAIMER"

   echo ""
   echo -n "                    PPC Pipe Test ........."
   rm -f pcexec.refi pcexec.refp
   $PCEXEC -c 30 -i -p $TEST > pcexec.refp
   set PipeStatP = $status
   if ($PipeStatP != 0) then
      echo ""
      echo "                         Polling test died ($PipeStatP)"
      set FAIL  = "YES"
   endif
   $PCEXEC -c 30 -p $TEST > pcexec.refi
   set PipeStatI = $status
   if ($PipeStatI != 0) then
      echo ""
      echo "                         Interrupt driven test died ($PipeStatI)"
      set FAIL  = "YES"
   endif
   if ($FAIL == "YES") then
      echo "                    PPC Pipe Test .....     FAILED"
      set ERROR = "TRUE"
   else
      echo " PASSED"
   endif

   set FAIL = "NO"
   echo ""
   echo -n "                    PPC Socket Test ......."
   rm -f pcexec.sockp pcexec.socki
   $PCEXEC -c 30 -i -s $TEST > pcexec.sockp
   set SockStatP = $status
   if ($SockStatP != 0) then
      echo ""
      echo "                         Polling test died ($SockStatP)"
      set FAIL  = "YES"
   endif
   $PCEXEC -c 30 -s $TEST > pcexec.socki
   set SockStatI = $status
   if ($SockStatI != 0) then
      echo ""
      echo "                         Interrupt driven test died ($SockStatI)"
      set FAIL  = "YES"
   endif
   if ($FAIL == "YES") then
      echo "                    PPC Socket Test .....   FAILED"
      set ERROR = "FALSE"
   else
      diff pcexec.refi pcexec.socki > pcexec.diffi
      set Files = `find . -name "pcexec.diffi" -size 0c -print`
      diff pcexec.refp pcexec.sockp > pcexec.diffp
      set Files = `find . -name "pcexec.diffp" -size 0c -print`
      if ($#Files == 0) then
         echo "                    PPC Socket Test .....   FAILED"
         set ERROR = "TRUE"
      else
         echo " PASSED"
         rm pcexec.diff* pcexec.sock*
      endif
   endif

   set FAIL = "NO"

# this test fails too often on DP machines so don't run there
   if ($DP == FALSE) then
      echo ""
      echo -n "                    PPC PTY Test .........."
      rm -f pcexec.ptyi pcexec.ptyp
      $PCEXEC -c 30 -i -t $TEST | tr -d "\015" > pcexec.ptyp
      set PtyStatP = $status
      if ($PtyStatP != 0) then
         if ($PtyStatP != 123) then
            echo ""
            echo "                         Polling test died ($PtyStatP)"
         else
            echo ""
            echo "                         Polling test timed out ($PtyStatP)"
         endif
      endif
      $PCEXEC -c 30 -t $TEST | tr -d "\015" > pcexec.ptyi
      set PtyStatI = $status
      if ($PtyStatI != 0) then
         if ($PtyStatI != 123) then
            echo ""
            echo "                         Interrupt driven test died ($PtyStatI)"
         else
            echo ""
            echo "                         Interrupt driven test timed out ($PtyStatI)"
         endif
      endif

# NOTE: timeout = exit(123)
# don't consider a timeout a failure
      if ((($PtyStatP != 0) && ($PtyStatP != 123)) || \
          (($PtyStatI != 0) && ($PtyStatI != 123)) || ) then
         echo "                    PPC PTY Test .....      FAILED"
         stty sane
         set ERROR = "FALSE"
      else if (($PtyStatI == 123) || ($PtyStatP == 123)) then
         echo "                    PPC PTY Test .....      PASSED"
      else
         diff pcexec.refi pcexec.ptyi > pcexec.diffi
         set Files = `find . -name "pcexec.diffi" -size 0c -print`
         diff pcexec.refp pcexec.ptyp > pcexec.diffp
         set Files = `find . -name "pcexec.diffp" -size 0c -print`
         if ($#Files == 0) then
            echo ""
            echo "                         File Differences"
            echo "                    PPC PTY Test .....      FAILED"
            set ERROR = "TRUE"
         else
            echo " PASSED"
            rm -f pcexec.diff* pcexec.pty* pcexec.ref*
         endif
      endif
   endif

   set FAIL = "NO"

# this test fails too often on DP machines so don't run there
   if ($DP == FALSE) then
      echo ""
      echo -n "                    PPC Binary Test ......."
      rm -rf pcbtst.res
      (echo "hello" ; echo "end") | $BinDir/pcbtst > pcbtst.res
      set BinaryStat = $status
      if ($BinaryStat != 0) then
         if ($BinaryStat != 123) then
            echo ""
            echo "                         Binary test died ($BinaryStat)"
         else
            echo ""
            echo "                         Binary test timed out ($BinaryStat)"
         endif
      endif

# don't consider a timeout a failure
      if ($BinaryStat != 0 && $BinaryStat != 123) then
         echo "                    PPC Binary Test .....   FAILED"
         set ERROR = "TRUE"
      else if ($BinaryStat == 123) then
         echo "                    PPC Binary Test .....   PASSED"
      else
         echo " PASSED"
      endif
   endif

   set FAIL = "NO"

   echo ""
   echo -n "                    PPC Multiple Test ....."

   rm -rf pcmtst.resp
   (echo "1 a" ; \
    echo "2 b" ; \
    echo "3 c" ; \
    echo "3 end" ; \
    echo "1 end" ; \
    echo "2 d" ; \
    echo "2 end" ) | $BinDir/pcmtst -c 30 -i -n 3 > pcmtst.resp
   set MultipleStatP = $status
   if ($MultipleStatP != 0) then
      if ($MultipleStatP != 123) then
         echo ""
         echo "                         Polling test died ($MultipleStatP)"
      else
         echo ""
         echo "                         Polling test timed out ($MultipleStatP)"
      endif
   endif

   rm -rf pcmtst.resi
   (echo "1 a" ; \
    echo "2 b" ; \
    echo "3 c" ; \
    echo "3 end" ; \
    echo "1 end" ; \
    echo "2 d" ; \
    echo "2 end" ) | $BinDir/pcmtst -c 30 -n 3 > pcmtst.resi
   set MultipleStatI = $status
   if ($MultipleStatI != 0) then
      if ($MultipleStatI != 123) then
         echo ""
         echo "                         Interrupt driven test died ($MultipleStatI)"
      else
         echo ""
         echo "                         Interrupt driven test timed out ($MultipleStatI)"
      endif
   endif

# NOTE: timeout = exit(123)
# don't consider a timeout a failure
   if ((($MultipleStatI != 0) && ($MultipleStatI != 123)) || \
       (($MultipleStatP != 0) && ($MultipleStatP != 123)) || ) then
      echo "                    PPC Multiple Test ..... FAILED"
      set ERROR = "TRUE"
   else if (($MultipleStatI == 123) || ($MultipleStatP == 123)) then
      echo "                    PPC Multiple Test ..... PASSED"
   else
      echo " PASSED"
      rm pcmtst.resi pcmtst.resp
   endif

# END of large loop ++++++++++++++++++++++++++++++++++++++++++++++++++++
   endif

   rm test.error

   echo ""
   if ($ERROR == "TRUE") then
      echo ""
      echo "Debug:"
      echo " (Which PACT; which CC; current BinDir)"
      cat pctest.debug
      echo ""
      echo "PPC TEST...FAILED"
   else
      echo "PPC TEST...PASSED"
   endif

   echo ""
   echo " --------------------------------------------------------"

endif

set xstatus = 0
if ($ERROR == "TRUE") then
   set xstatus = 1
endif

exit($xstatus)

