p4sanity_check.sh #1

  • //
  • guest/
  • perforce_software/
  • sdp/
  • dev/
  • Server/
  • Unix/
  • p4/
  • common/
  • bin/
  • p4sanity_check.sh
  • View
  • Commits
  • Open Download .zip Download (1014 B)
#!/bin/bash
#==============================================================================
# Copyright and license info is available in the LICENSE file included with
# the Server Deployment Package (SDP), and also available online:
# https://swarm.workshop.perforce.com/projects/perforce-software-sdp/view/main/LICENSE
#------------------------------------------------------------------------------

export SDP_INSTANCE=${SDP_INSTANCE:-Unset} 
export SDP_INSTANCE=${1:-$SDP_INSTANCE} 
if [[ $SDP_INSTANCE == Unset ]]; then 
   echo "Instance parameter not supplied." 
   echo "You must supply the Perforce instance as a parameter to this script." 
   exit 1 
fi 

source /p4/common/bin/p4_vars $SDP_INSTANCE

echo -e "\nPerforce settings are:\n"

p4 set

echo -e "\nPerforce server info:\n"

p4 info

if [[ $? -ne 0 ]]; then
   printf "\nERROR: p4d is not reachable with the given settings.\n\n"
   exit 1
fi

echo -e "\nScanning recent changelists.\nEnsure output below looks reasonable:\n"
p4 changes -t -m 10
# Change User Description Committed
#7 32718 Mark Zinthefer Fix two typos in p4sanity_check.sh and logging.lib

p4sanity_check.sh:
- Line 139: Fixed typo 'addtional' -> 'additional' in user-facing error
  message shown when too many positional arguments are passed.

logging.lib:
- Line 10: Fixed typo 'runctions' -> 'functions' in library file comment.
#6 32710 Mark Zinthefer Bug hunt with Claude

Justification:

p4sanity_check.sh � ThisScript variable strips too aggressively

declare ThisScript=${0##*}

The glob ##* strips everything up to and including the last * character � which in bash glob matching means it strips everything, leaving an empty string. The correct idiom to get the basename is ${0##*/} (strip up to last slash). As written, $ThisScript will always be empty, causing the usage and log messages to display a blank script name. This is a clear bug, just a cosmetic/diagnostic one.
#5 32707 Mark Zinthefer Bug hunt with Claude

Justification:

p4sanity_check.sh � Typo in error message causes silent false-positive

grep -q '^info: Change' "$CmdLog" ||\
   errmsg "No changelists detecgted in the output."

"detecgted" is a typo, but more importantly the grep pattern '^info: Change' is brittle � p4 -s changes prefixes each output line with info:, but the pattern is anchored to the beginning of the line and relies on the exact tagged output format. If output format varies (e.g. warnings, server messages prepend), this check silently passes when it shouldn't. The typo itself won't cause a runtime failure but indicates the error path is undertested.

Claude went on to suggest the following to make the grep more robust. I haven't made this change but here is the suggestion:

grep -qE '^info: Change [0-9]+ on [0-9]{4}/[0-9]{2}/[0-9]{2}' "$CmdLog" ||\
   errmsg "No changelists detected in the output."
#4 31243 C. Thomas Tyler Fixed typo in error message.
#3 30442 C. Thomas Tyler Fixed usage typo.
#2 30281 C. Thomas Tyler p4sanity_check.sh 2.0.0:
* Added '-p4config' option to ran sanity check against an arbitrary p4d server.
* Added check that at least one changelist exists.
* Added documentation and standard usage options '-h' and '-man'.
* Added proper exit codes.

#review-30282
#1 20313 C. Thomas Tyler Added p4sanity_check.sh script from Battle School (slightly updated).