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-tool path-utils real_path "$path")
49 P4PORT=localhost:$P4DPORT
54 export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET
56 db="$TRASH_DIRECTORY/db"
57 cli="$TRASH_DIRECTORY/cli"
58 git="$TRASH_DIRECTORY/git"
59 pidfile="$TRASH_DIRECTORY/p4d.pid"
61 stop_p4d_and_watchdog () {
62 kill -9 $p4d_pid $watchdog_pid
65 # git p4 submit generates a temp file, which will
66 # not get cleaned up if the submission fails. Don't
67 # clutter up /tmp on the test machine.
68 TMPDIR="$TRASH_DIRECTORY"
71 registered_stop_p4d_atexit_handler=
73 # One of the test scripts stops and then re-starts p4d.
74 # Don't register and then run the same atexit handlers several times.
75 if test -z "$registered_stop_p4d_atexit_handler"
77 test_atexit 'stop_p4d_and_watchdog'
78 registered_stop_p4d_atexit_handler=AlreadyDone
81 mkdir -p "$db" "$cli" "$git" &&
86 p4d -q -p $P4DPORT "$@" &
90 p4d_pid=$(cat "$pidfile")
92 # This gives p4d a long time to start up, as it can be
93 # quite slow depending on the machine. Set this environment
94 # variable to something smaller to fail faster in, say,
95 # an automated test setup. If the p4d process dies, that
96 # will be caught with the "kill -0" check below.
97 i=${P4D_START_PATIENCE:-300}
99 nr_tries_left=$P4D_TIMEOUT
102 if test $nr_tries_left -eq 0
108 nr_tries_left=$(($nr_tries_left - 1))
109 done 2>/dev/null 4>&2 &
115 # succeed when p4 client commands start to work
116 if p4 info >/dev/null 2>&1
122 kill -0 $p4d_pid 2>/dev/null || break
123 echo waiting for p4d to start
130 # p4d failed to start
134 # build a p4 user so author@example.com has an entry
138 client_view "//depot/... //client/..." &&
147 Email: $name@example.com
161 retry_until_success () {
162 nr_tries_left=$RETRY_TIMEOUT
163 until "$@" 2>/dev/null || test $nr_tries_left -eq 0
166 nr_tries_left=$(($nr_tries_left - 1))
170 stop_and_cleanup_p4d () {
171 kill -9 $p4d_pid $watchdog_pid
173 rm -rf "$db" "$cli" "$pidfile"
177 retry_until_success rm -r "$git"
178 test_must_fail test -d "$git" &&
179 retry_until_success mkdir "$git"
185 cat >"$TRASH_DIRECTORY/marshal-dump.py" <<-EOF &&
188 instream = getattr(sys.stdin, 'buffer', sys.stdin)
189 for i in range($line):
190 d = marshal.load(instream)
191 print(d[b'$what'].decode('utf-8'))
193 "$PYTHON_PATH" "$TRASH_DIRECTORY/marshal-dump.py"
197 # Construct a client with this list of View lines
203 Description: $P4CLIENT
205 AltRoots: $(native_path "$cli")
213 is_cli_file_writeable () {
214 # cygwin version of p4 does not set read-only attr,
215 # will be marked 444 but -w is true
217 if test_have_prereq CYGWIN && p4 -V | grep -q CYGWIN
219 stat=$(stat --format=%a "$file") &&