#!/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 | 21706 | Sven Erik Knop |
Populate //cbd/main/... .... |