2 # Library code for git p4 tests
5 # p4 tests never use the top-level repo; always build/clone into
6 # a subdirectory called "$git"
7 TEST_NO_CREATE_REPO
=NoThanks
9 # Some operations require multiple attempts to be successful. Define
10 # here the maximal retry timeout in seconds.
13 # Sometimes p4d seems to hang. Terminate the p4d process automatically after
14 # the defined timeout in seconds.
19 if ! test_have_prereq PYTHON
21 skip_all
='skipping git p4 tests; python not available'
24 ( p4
-h && p4d
-h ) >/dev
/null
2>&1 ||
{
25 skip_all
='skipping git p4 tests; no p4 or p4d'
29 # On cygwin, the NT version of Perforce can be used. When giving
30 # it paths, either on the command-line or in client specifications,
31 # be sure to use the native windows form.
33 # Older versions of perforce were available compiled natively for
34 # cygwin. Those do not accept native windows paths, so make sure
35 # not to convert for them.
38 if test_have_prereq CYGWIN
&& ! p4
-V |
grep -q CYGWIN
40 path
=$
(cygpath
--windows "$path")
42 path
=$
(test-path-utils real_path
"$path")
47 # On Solaris the 'date +%s' function is not supported and therefore we
48 # need this replacement.
49 # Attention: This function is not safe again against time offset updates
50 # at runtime (e.g. via NTP). The 'clock_gettime(CLOCK_MONOTONIC)'
51 # function could fix that but it is not in Python until 3.3.
53 python
-c 'import time; print int(time.time())'
56 # Try to pick a unique port: guess a large number, then hope
57 # no more than one of each test is running.
59 # This does not handle the case where somebody else is running the
60 # same tests and has chosen the same ports.
62 git_p4_test_start
=9800
63 P4DPORT
=$
((10669 + ($testid - $git_p4_test_start)))
65 P4PORT
=localhost
:$P4DPORT
70 export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET
72 db
="$TRASH_DIRECTORY/db"
73 cli
="$TRASH_DIRECTORY/cli"
74 git
="$TRASH_DIRECTORY/git"
75 pidfile
="$TRASH_DIRECTORY/p4d.pid"
77 # Sometimes "prove" seems to hang on exit because p4d is still running
81 kill -9 $
(cat "$pidfile") 2>/dev
/null
&& exit 255
86 # git p4 submit generates a temp file, which will
87 # not get cleaned up if the submission fails. Don't
88 # clutter up /tmp on the test machine.
89 TMPDIR
="$TRASH_DIRECTORY"
93 mkdir
-p "$db" "$cli" "$git" &&
98 p4d
-q -p $P4DPORT "$@" &
103 # This gives p4d a long time to start up, as it can be
104 # quite slow depending on the machine. Set this environment
105 # variable to something smaller to fail faster in, say,
106 # an automated test setup. If the p4d process dies, that
107 # will be caught with the "kill -0" check below.
108 i
=${P4D_START_PATIENCE:-300}
109 pid
=$
(cat "$pidfile")
111 timeout
=$
(($
(time_in_seconds
) + $P4D_TIMEOUT))
114 if test $
(time_in_seconds
) -gt $timeout
126 # succeed when p4 client commands start to work
127 if p4 info
>/dev
/null
2>&1
133 kill -0 $pid 2>/dev
/null ||
break
134 echo waiting
for p4d to start
141 # p4d failed to start
145 # build a p4 user so author@example.com has an entry
149 client_view
"//depot/... //client/..." &&
158 Email: $name@example.com
172 retry_until_success
() {
173 timeout
=$
(($
(time_in_seconds
) + $RETRY_TIMEOUT))
174 until "$@" 2>/dev
/null ||
test $
(time_in_seconds
) -gt $timeout
180 retry_until_fail
() {
181 timeout
=$
(($
(time_in_seconds
) + $RETRY_TIMEOUT))
182 until ! "$@" 2>/dev
/null ||
test $
(time_in_seconds
) -gt $timeout
189 pid
=$
(cat "$pidfile")
190 retry_until_fail
kill $pid
191 retry_until_fail
kill -9 $pid
192 # complain if it would not die
193 test_must_fail
kill $pid >/dev
/null
2>&1 &&
194 rm -rf "$db" "$cli" "$pidfile" &&
195 retry_until_fail
kill -9 $watchdog_pid
199 retry_until_success
rm -r "$git"
200 test_must_fail
test -d "$git" &&
201 retry_until_success mkdir
"$git"
207 cat >"$TRASH_DIRECTORY/marshal-dump.py" <<-EOF &&
210 for i in range($line):
211 d = marshal.load(sys.stdin)
214 "$PYTHON_PATH" "$TRASH_DIRECTORY/marshal-dump.py"
218 # Construct a client with this list of View lines
224 Description: $P4CLIENT
226 AltRoots: $(native_path "$cli")
234 is_cli_file_writeable
() {
235 # cygwin version of p4 does not set read-only attr,
236 # will be marked 444 but -w is true
238 if test_have_prereq CYGWIN
&& p4
-V |
grep -q CYGWIN
240 stat
=$
(stat
--format=%a
"$file") &&