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