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