ti.sh #1

  • //
  • guest/
  • perforce_software/
  • cbd/
  • main/
  • test/
  • ti.sh
  • View
  • Commits
  • Open Download .zip Download (4 KB)
#!/bin/bash
# This is a tool for manual testing.
# Similar code is included in test_cbd.sh for automated testing.

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 CLITestDataOK=1
declare CLITestDataFile=cli_tests.txt
declare BITestCfgFile=bit.cfg
declare User=
declare Workspace=
declare -i Line=0
declare -i OverallReturnStatus=0

while read entry; do
   Line=$((Line+1))
   [[ -z "$(echo $entry)" ]] && continue
   [[ $entry == "#"* ]] && continue
   P4TestCmd=${entry%%|*}
   ExpectedExit=${entry#*|}
   ExpectedExit=${ExpectedExit%%|*}
   ExpectedString=${entry%|*}
   ExpectedString=${ExpectedString##*|}
   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 "Warning: Entry on line $Line of $CLITestDataFile has a bogus 'p4' command.  Must start with 'p4 '.  Skipping this test."
      CLITestDataOK=0
      continue
   fi

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

   echo "C:[$P4TestCmd] E:[$ExpectedExit] S:[$ExpectedString] Comments: $Comments"
done < $CLITestDataFile

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

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

   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 "Warning: Entry on line $Line of $BITestCfgFile has a bogus exit code.  Must be numeric or 'U', value is $ExpectedExit. Skipping this test."
         CLITestDataOK=0
         continue
      fi
   fi

   Comments=${entry##*|}

   echo "F:[$BITFile] E:[$ExpectedExit] S:[$ExpectedString] Comments: $Comments"
done < $BITestCfgFile


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

echo -e "That took about $(($SECONDS/3600)) hours $(($SECONDS%3600/60)) minutes $(($SECONDS%60)) seconds.\n"

# See the terminate() function, which is really where this script exits.
exit $OverallReturnStatus
# Change User Description Committed
#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.