ti.sh #1

  • //
  • cbd/
  • main/
  • test/
  • ti.sh
  • View
  • Commits
  • Open Download .zip Download (6 KB)
#!/bin/bash
# This is a tool for doing basic sanity tests on CBD tests.
# Similar code in test_cbd.sh actually executes automated tests.

set -u

cd shared
echo -e "\nChecking command line test data in $PWD."

#------------------------------------------------------------------------------
# This code simulates what test_cbd.sh does.  It should NOT be copy/pasted
# into test_cbd.sh.
declare CfgFile=test_cbd.$(hostname -s).cfg
source $CfgFile || { echo BAILING; exit 1; }
declare p4Exe=$SampleDepotHome/p4
declare p4dExe=$SampleDepotHome/p4d
declare p4brokerExe=$SampleDepotHome/p4broker
declare p4="$p4Exe -p $SampleDepotBrokerPort"
declare p4c="$p4 -u bruno -c $TestWS"

#------------------------------------------------------------------------------
# This following sample code may be copy/pasted in whole or in part into
# test_cbd.sh
declare P4TestCmd=
declare ExpectedExit=
declare -i ExpectedExitCode
declare ExpectedString=
declare Comments=
declare AllTestDataOK=1
declare CLITestDataFile=cli_tests.cfg
declare BITestCfgFile=bit.cfg
declare BITFile=
declare ScriptedTestCfgFile=scripted_tests.cfg
declare TestScript=
declare User=
declare Workspace=
declare -i Line=0
declare -i OverallReturnStatus=0
declare -i TestCount=0
declare -i GoodTestCount=0
declare -i BadTestCount=0

while read entry; do
   Line=$((Line+1))
   [[ -z "$(echo $entry)" ]] && continue
   [[ $entry == "#"* ]] && continue
   P4TestCmd=${entry%%|*}
   ExpectedExit=${entry#*|}
   ExpectedExit=${ExpectedExit%%|*}
   ExpectedString=${entry%|*}
   ExpectedString=${ExpectedString##*|}
   TestCount=$((TestCount+1))
   Comments=${entry##*|}

   if [[ $P4TestCmd == "p4 "* ]]; then
      P4TestCmd=${P4TestCmd/p4 /$p4c }
   elif [[ $P4TestCmd == "p4:"* ]]; then
      # Parse entries like: "p4:user:client command args ..."
      User=${P4TestCmd#p4:}
      User=${User%%:*}
      Workspace=${P4TestCmd#p4:}
      Workspace=${Workspace#*:}
      Workspace=${Workspace%% *}
      P4TestCmd=${P4TestCmd/p4:$User:$Workspace /$p4 -u $User -c $Workspace }
   else
      echo -e "Error: Entry on line $Line of $CLITestDataFile has a bogus 'p4' command.  Must start with 'p4 '.  Skipping this test."
      AllTestDataOK=0
      continue
   fi

   if [[ $ExpectedExit == U ]]; then
      ExpectedExit=Undefined
   else
      if [[ $ExpectedExit =~ [0-9]+ ]]; then
         ExpectedExitCode=$ExpectedExit
      else
         echo -e "Error: Entry on line $Line of $CLITestDataFile has a bogus exit code.  Must be numeric or 'U', value is $ExpectedExit. Skipping this test."
         AllTestDataOK=0
         BadTestCount=$((BadTestCount+1))
         continue
      fi
   fi

   echo -e "Command:[$P4TestCmd]\nE:[$ExpectedExit] S:[$ExpectedString]\nComments: $Comments"
   GoodTestCount=$((GoodTestCount+1))
done < $CLITestDataFile

echo -e "\nChecking broker input test data."

Line=0
while read entry; do
   Line=$((Line+1))
   [[ -z "$(echo $entry)" ]] && continue
   [[ $entry == "#"* ]] && continue
   TestCount=$((TestCount+1))

   BITFile=${entry%%|*}

   ExpectedExit=${entry#*|}
   ExpectedExit=${ExpectedExit%%|*}
   ExpectedString=${entry%|*}
   ExpectedString=${ExpectedString##*|}

   # If the ExpectedString from the data file is prefixed with 'LOG:',
   # set ExpectedStringInOutput=0, indicating the cbd.log file shoudl be
   # searched instead of the command outpout.
   if [[ "$ExpectedString" == "LOG:"* ]]; then
      ExpectedString=${ExpectedString#LOG:}
      ExpectedStringInOutput=0
   else
      ExpectedStringInOutput=1
   fi

   if [[ $ExpectedExit == U ]]; then
      ExpectedExit=Undefined
   else
      if [[ $ExpectedExit =~ [0-9]+ ]]; then
         ExpectedExitCode=$ExpectedExit
      else
         echo -e "Error: Entry on line $Line of $BITestCfgFile has a bogus exit code.  Must be numeric or 'U', value is $ExpectedExit. Skipping this test."
         AllTestDataOK=0
         BadTestCount=$((BadTestCount+1))
         continue
      fi
   fi

   Comments=${entry##*|}

   if [[ ! -r $BITFile ]]; then
      echo -e "Error: Missing Broker Input Test file [$BITFile]."
      AllTestDataOK=0
      BadTestCount=$((BadTestCount+1))
      continue
   fi

   echo -e "F:[$BITFile] E:[$ExpectedExit] S:[$ExpectedString]\nComments: $Comments"
   GoodTestCount=$((GoodTestCount+1))
done < $BITestCfgFile

echo -e "\nChecking scripted test data."

Line=0
while read entry; do
   Line=$((Line+1))
   [[ -z "$(echo $entry)" ]] && continue
   [[ $entry == "#"* ]] && continue
   TestCount=$((TestCount+1))

   TestScript=${entry%%|*}

   ExpectedExit=${entry#*|}
   ExpectedExit=${ExpectedExit%%|*}
   ExpectedString=${entry%|*}
   ExpectedString=${ExpectedString##*|}

   # If the ExpectedString from the data file is prefixed with 'LOG:',
   # set ExpectedStringInOutput=0, indicating the cbd.log file shoudl be
   # searched instead of the command outpout.
   if [[ "$ExpectedString" == "LOG:"* ]]; then
      ExpectedString=${ExpectedString#LOG:}
      ExpectedStringInOutput=0
   else
      ExpectedStringInOutput=1
   fi

   if [[ $ExpectedExit == U ]]; then
      ExpectedExit=Undefined
   else
      if [[ $ExpectedExit =~ [0-9]+ ]]; then
         ExpectedExitCode=$ExpectedExit
      else
         echo -e "Error: Entry on line $Line of $ScriptedTestCfgFile has a bogus exit code.  Must be numeric or 'U', value is $ExpectedExit. Skipping this test."
         AllTestDataOK=0
         BadTestCount=$((BadTestCount+1))
         continue
      fi
   fi

   Comments=${entry##*|}

   if [[ ! -r $TestScript ]]; then
      echo -e "Error: Missing Test Script file [$TestScript]."
      AllTestDataOK=0
      BadTestCount=$((BadTestCount+1))
      continue
   fi

   echo -e "S:[$TestScript] E:[$ExpectedExit] S:[$ExpectedString]\nComments: $Comments"
   GoodTestCount=$((GoodTestCount+1))
done < $ScriptedTestCfgFile

if [[ $AllTestDataOK -eq 1 ]]; then
   echo -e "\nVerified: All $TestCount test entries are OK.\n"
else
   echo -e "\nError: $BadTestCount of $TestCount tests were skipped due to invalid entries in $CLITestDataFile.\n"
   OverallReturnStatus=1
fi

# See the terminate() function, which is really where this script exits.
exit $OverallReturnStatus
# Change User Description Committed
#1 21633 C. Thomas Tyler Populate -o //guest/perforce_software/cbd/main/...
//cbd/main/....
//guest/perforce_software/cbd/main/test/ti.sh
#3 15273 C. Thomas Tyler Copy Up using 'p4 copy -r -b perforce_software-cbd-ntx64'.
Stabilization changes.
Test suite enhancements.
#2 15169 C. Thomas Tyler Copy Up using 'p4 copy -r -b perforce_software-cbd-ntx64'.
Holding off promote of SSTemplateUpdate.ply for now.
#1 15009 C. Thomas Tyler Promoted CBD development work to main from dev.
//guest/perforce_software/cbd/dev/test/ti.sh
#3 14981 C. Thomas Tyler Enhanced broker input simulation testing to account for testing
with SDP, by parameterizing previously hard-coded test data
fields.
#2 14844 C. Thomas Tyler Overhauled regression test suite.

Added various command line tests.

Enhanced test suite to allow entries in the test data file to specify
alternate user and workspaces (differing from defaults defined in
the test test configuration files, test_cbd.*.cfg) for certain
tests.

Added new testing method, broker input testing, to augment existing
       command line testing.

       This test method simulates having 'p4d' call the CBD broker sync
       script by feeding handcrafted/simulated broker input files to the CBD
       engine, simulating the way p4d uses stdin to feed the broker
       parameters when a user makes a request.

       This enables more diverse testing and better simulation of Window
       and P4V-side testing.
#1 14199 C. Thomas Tyler Added test suite.