1# 2# Library code for git p4 tests 3# 4 5# p4 tests never use the top-level repo; always build/clone into 6# a subdirectory called "$git" 7TEST_NO_CREATE_REPO=NoThanks 8 9. ./test-lib.sh 10 11if! test_have_prereq PYTHON;then 12 skip_all='skipping git p4 tests; python not available' 13 test_done 14fi 15( p4 -h&& p4d -h) >/dev/null 2>&1|| { 16 skip_all='skipping git p4 tests; no p4 or p4d' 17 test_done 18} 19 20# Try to pick a unique port: guess a large number, then hope 21# no more than one of each test is running. 22# 23# This does not handle the case where somebody else is running the 24# same tests and has chosen the same ports. 25testid=${this_test#t} 26git_p4_test_start=9800 27P4DPORT=$((10669 + ($testid - $git_p4_test_start))) 28 29export P4PORT=localhost:$P4DPORT 30export P4CLIENT=client 31export P4EDITOR=: 32 33db="$TRASH_DIRECTORY/db" 34cli=$(test-path-utils real_path "$TRASH_DIRECTORY/cli") 35git="$TRASH_DIRECTORY/git" 36pidfile="$TRASH_DIRECTORY/p4d.pid" 37 38start_p4d() { 39mkdir-p"$db""$cli""$git"&& 40rm-f"$pidfile"&& 41( 42 p4d -q -r"$db"-p$P4DPORT& 43echo $! >"$pidfile" 44) && 45 46# This gives p4d a long time to start up, as it can be 47# quite slow depending on the machine. Set this environment 48# variable to something smaller to fail faster in, say, 49# an automated test setup. If the p4d process dies, that 50# will be caught with the "kill -0" check below. 51 i=${P4D_START_PATIENCE:-300} 52 pid=$(cat "$pidfile") 53 ready= 54whiletest$i-gt0 55do 56# succeed when p4 client commands start to work 57if p4 info >/dev/null 2>&1 58then 59 ready=true 60break 61fi 62# fail if p4d died 63kill -0$pid2>/dev/null ||break 64echo waiting for p4d to start 65sleep1 66 i=$(( $i - 1 )) 67done 68 69iftest -z"$ready" 70then 71# p4d failed to start 72return1 73fi 74 75# build a client 76( 77cd"$cli"&& 78 p4 client -i<<-EOF 79 Client: client 80 Description: client 81 Root:$cli 82 View: //depot/... //client/... 83 EOF 84) 85return0 86} 87 88kill_p4d() { 89 pid=$(cat "$pidfile") 90# it had better exist for the first kill 91kill$pid&& 92for i in1 2 3 4 5;do 93kill$pid>/dev/null 2>&1||break 94sleep1 95done&& 96# complain if it would not die 97 test_must_fail kill$pid>/dev/null 2>&1&& 98rm-rf"$db""$cli""$pidfile" 99} 100 101cleanup_git() { 102rm-rf"$git"&& 103mkdir"$git" 104}