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 29P4PORT=localhost:$P4DPORT 30P4CLIENT=client 31P4EDITOR=: 32export P4PORT P4CLIENT P4EDITOR 33 34db="$TRASH_DIRECTORY/db" 35cli=$(test-path-utils real_path "$TRASH_DIRECTORY/cli") 36git="$TRASH_DIRECTORY/git" 37pidfile="$TRASH_DIRECTORY/p4d.pid" 38 39start_p4d() { 40mkdir-p"$db""$cli""$git"&& 41rm-f"$pidfile"&& 42( 43 p4d -q -r"$db"-p$P4DPORT& 44echo $! >"$pidfile" 45) && 46 47# This gives p4d a long time to start up, as it can be 48# quite slow depending on the machine. Set this environment 49# variable to something smaller to fail faster in, say, 50# an automated test setup. If the p4d process dies, that 51# will be caught with the "kill -0" check below. 52 i=${P4D_START_PATIENCE:-300} 53 pid=$(cat "$pidfile") 54 ready= 55whiletest$i-gt0 56do 57# succeed when p4 client commands start to work 58if p4 info >/dev/null 2>&1 59then 60 ready=true 61break 62fi 63# fail if p4d died 64kill -0$pid2>/dev/null ||break 65echo waiting for p4d to start 66sleep1 67 i=$(( $i - 1 )) 68done 69 70iftest -z"$ready" 71then 72# p4d failed to start 73return1 74fi 75 76# build a client 77( 78cd"$cli"&& 79 p4 client -i<<-EOF 80 Client: client 81 Description: client 82 Root:$cli 83 View: //depot/... //client/... 84 EOF 85) 86return0 87} 88 89kill_p4d() { 90 pid=$(cat "$pidfile") 91# it had better exist for the first kill 92kill$pid&& 93for i in1 2 3 4 5;do 94kill$pid>/dev/null 2>&1||break 95sleep1 96done&& 97# complain if it would not die 98 test_must_fail kill$pid>/dev/null 2>&1&& 99rm-rf"$db""$cli""$pidfile" 100} 101 102cleanup_git() { 103rm-rf"$git"&& 104mkdir"$git" 105} 106 107marshal_dump() { 108 what=$1&& 109 line=${2:-1}&& 110cat>"$TRASH_DIRECTORY/marshal-dump.py"<<-EOF && 111 import marshal 112 import sys 113 for i in range($line): 114 d = marshal.load(sys.stdin) 115 print d['$what'] 116 EOF 117"$PYTHON_PATH""$TRASH_DIRECTORY/marshal-dump.py" 118} 119 120# 121# Construct a client with this list of View lines 122# 123client_view() { 124( 125cat<<-EOF && 126 Client: client 127 Description: client 128 Root:$cli 129 View: 130 EOF 131for arg ;do 132printf"\t$arg\n" 133done 134) | p4 client -i 135}