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 12then 13 skip_all='skipping git p4 tests; python not available' 14 test_done 15fi 16( p4 -h&& p4d -h) >/dev/null 2>&1|| { 17 skip_all='skipping git p4 tests; no p4 or p4d' 18 test_done 19} 20 21# On cygwin, the NT version of Perforce can be used. When giving 22# it paths, either on the command-line or in client specifications, 23# be sure to use the native windows form. 24# 25# Older versions of perforce were available compiled natively for 26# cygwin. Those do not accept native windows paths, so make sure 27# not to convert for them. 28native_path() { 29 path="$1"&& 30if test_have_prereq CYGWIN && ! p4 -V|grep-q CYGWIN 31then 32 path=$(cygpath --windows "$path") 33else 34 path=$(test-path-utils real_path "$path") 35fi&& 36echo"$path" 37} 38 39# Try to pick a unique port: guess a large number, then hope 40# no more than one of each test is running. 41# 42# This does not handle the case where somebody else is running the 43# same tests and has chosen the same ports. 44testid=${this_test#t} 45git_p4_test_start=9800 46P4DPORT=$((10669 + ($testid - $git_p4_test_start))) 47 48P4PORT=localhost:$P4DPORT 49P4CLIENT=client 50P4EDITOR=: 51unset P4CHARSET 52export P4PORT P4CLIENT P4EDITOR P4CHARSET 53 54db="$TRASH_DIRECTORY/db" 55cli="$TRASH_DIRECTORY/cli" 56git="$TRASH_DIRECTORY/git" 57pidfile="$TRASH_DIRECTORY/p4d.pid" 58 59start_p4d() { 60mkdir-p"$db""$cli""$git"&& 61rm-f"$pidfile"&& 62( 63cd"$db"&& 64{ 65 p4d -q -p$P4DPORT& 66echo $! >"$pidfile" 67} 68) && 69 70# This gives p4d a long time to start up, as it can be 71# quite slow depending on the machine. Set this environment 72# variable to something smaller to fail faster in, say, 73# an automated test setup. If the p4d process dies, that 74# will be caught with the "kill -0" check below. 75 i=${P4D_START_PATIENCE:-300} 76 pid=$(cat "$pidfile") 77 ready= 78whiletest$i-gt0 79do 80# succeed when p4 client commands start to work 81if p4 info >/dev/null 2>&1 82then 83 ready=true 84break 85fi 86# fail if p4d died 87kill -0$pid2>/dev/null ||break 88echo waiting for p4d to start 89sleep1 90 i=$(( $i - 1 )) 91done 92 93iftest -z"$ready" 94then 95# p4d failed to start 96return1 97fi 98 99# build a client 100 client_view "//depot/... //client/..."&& 101 102return0 103} 104 105kill_p4d() { 106 pid=$(cat "$pidfile") 107# it had better exist for the first kill 108kill$pid&& 109for i in1 2 3 4 5;do 110kill$pid>/dev/null 2>&1||break 111sleep1 112done&& 113# complain if it would not die 114 test_must_fail kill$pid>/dev/null 2>&1&& 115rm-rf"$db""$cli""$pidfile" 116} 117 118cleanup_git() { 119rm-rf"$git"&& 120mkdir"$git" 121} 122 123marshal_dump() { 124 what=$1&& 125 line=${2:-1}&& 126cat>"$TRASH_DIRECTORY/marshal-dump.py"<<-EOF && 127 import marshal 128 import sys 129 for i in range($line): 130 d = marshal.load(sys.stdin) 131 print d['$what'] 132 EOF 133"$PYTHON_PATH""$TRASH_DIRECTORY/marshal-dump.py" 134} 135 136# 137# Construct a client with this list of View lines 138# 139client_view() { 140( 141cat<<-EOF && 142 Client:$P4CLIENT 143 Description:$P4CLIENT 144 Root:$cli 145 AltRoots:$(native_path "$cli") 146 LineEnd: unix 147 View: 148 EOF 149printf"\t%s\n""$@" 150) | p4 client -i 151} 152 153is_cli_file_writeable() { 154# cygwin version of p4 does not set read-only attr, 155# will be marked 444 but -w is true 156file="$1"&& 157if test_have_prereq CYGWIN && p4 -V|grep-q CYGWIN 158then 159 stat=$(stat --format=%a "$file")&& 160test$stat=644 161else 162test -w"$file" 163fi 164}