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.
15 if ! test_have_prereq PYTHON
17 skip_all
='skipping git p4 tests; python not available'
20 ( p4
-h && p4d
-h ) >/dev
/null
2>&1 ||
{
21 skip_all
='skipping git p4 tests; no p4 or p4d'
25 # On cygwin, the NT version of Perforce can be used. When giving
26 # it paths, either on the command-line or in client specifications,
27 # be sure to use the native windows form.
29 # Older versions of perforce were available compiled natively for
30 # cygwin. Those do not accept native windows paths, so make sure
31 # not to convert for them.
34 if test_have_prereq CYGWIN
&& ! p4
-V |
grep -q CYGWIN
36 path
=$
(cygpath
--windows "$path")
38 path
=$
(test-path-utils real_path
"$path")
43 # On Solaris the 'date +%s' function is not supported and therefore we
44 # need this replacement.
45 # Attention: This function is not safe again against time offset updates
46 # at runtime (e.g. via NTP). The 'clock_gettime(CLOCK_MONOTONIC)'
47 # function could fix that but it is not in Python until 3.3.
49 python
-c 'import time; print int(time.time())'
52 # Try to pick a unique port: guess a large number, then hope
53 # no more than one of each test is running.
55 # This does not handle the case where somebody else is running the
56 # same tests and has chosen the same ports.
58 git_p4_test_start
=9800
59 P4DPORT
=$
((10669 + ($testid - $git_p4_test_start)))
61 P4PORT
=localhost
:$P4DPORT
66 export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET
68 db
="$TRASH_DIRECTORY/db"
69 cli
="$TRASH_DIRECTORY/cli"
70 git
="$TRASH_DIRECTORY/git"
71 pidfile
="$TRASH_DIRECTORY/p4d.pid"
73 # git p4 submit generates a temp file, which will
74 # not get cleaned up if the submission fails. Don't
75 # clutter up /tmp on the test machine.
76 TMPDIR
="$TRASH_DIRECTORY"
80 mkdir
-p "$db" "$cli" "$git" &&
85 p4d
-q -p $P4DPORT "$@" &
90 # This gives p4d a long time to start up, as it can be
91 # quite slow depending on the machine. Set this environment
92 # variable to something smaller to fail faster in, say,
93 # an automated test setup. If the p4d process dies, that
94 # will be caught with the "kill -0" check below.
95 i
=${P4D_START_PATIENCE:-300}
100 # succeed when p4 client commands start to work
101 if p4 info
>/dev
/null
2>&1
107 kill -0 $pid 2>/dev
/null ||
break
108 echo waiting
for p4d to start
115 # p4d failed to start
119 # build a p4 user so author@example.com has an entry
123 client_view
"//depot/... //client/..." &&
132 Email: $name@example.com
137 retry_until_success
() {
138 timeout
=$
(($
(time_in_seconds
) + $RETRY_TIMEOUT))
139 until "$@" 2>/dev
/null ||
test $
(time_in_seconds
) -gt $timeout
146 timeout
=$
(($
(time_in_seconds
) + $RETRY_TIMEOUT))
147 until ! "$@" 2>/dev
/null ||
test $
(time_in_seconds
) -gt $timeout
154 pid
=$
(cat "$pidfile")
155 retry_until_fail
kill $pid
156 retry_until_fail
kill -9 $pid
157 # complain if it would not die
158 test_must_fail
kill $pid >/dev
/null
2>&1 &&
159 rm -rf "$db" "$cli" "$pidfile"
163 retry_until_success
rm -r "$git"
164 test_must_fail
test -d "$git" &&
165 retry_until_success mkdir
"$git"
171 cat >"$TRASH_DIRECTORY/marshal-dump.py" <<-EOF &&
174 for i in range($line):
175 d = marshal.load(sys.stdin)
178 "$PYTHON_PATH" "$TRASH_DIRECTORY/marshal-dump.py"
182 # Construct a client with this list of View lines
188 Description: $P4CLIENT
190 AltRoots: $(native_path "$cli")
198 is_cli_file_writeable
() {
199 # cygwin version of p4 does not set read-only attr,
200 # will be marked 444 but -w is true
202 if test_have_prereq CYGWIN
&& p4
-V |
grep -q CYGWIN
204 stat
=$
(stat
--format=%a
"$file") &&