t / lib-git-p4.shon commit do_for_each_reflog(): use a strbuf to hold logfile name (989c0e5)
   1#
   2# Library code for git p4 tests
   3#
   4
   5. ./test-lib.sh
   6
   7if ! test_have_prereq PYTHON; then
   8        skip_all='skipping git p4 tests; python not available'
   9        test_done
  10fi
  11( p4 -h && p4d -h ) >/dev/null 2>&1 || {
  12        skip_all='skipping git p4 tests; no p4 or p4d'
  13        test_done
  14}
  15
  16# Try to pick a unique port: guess a large number, then hope
  17# no more than one of each test is running.
  18#
  19# This does not handle the case where somebody else is running the
  20# same tests and has chosen the same ports.
  21testid=${this_test#t}
  22git_p4_test_start=9800
  23P4DPORT=$((10669 + ($testid - $git_p4_test_start)))
  24
  25export P4PORT=localhost:$P4DPORT
  26export P4CLIENT=client
  27
  28db="$TRASH_DIRECTORY/db"
  29cli="$TRASH_DIRECTORY/cli"
  30git="$TRASH_DIRECTORY/git"
  31pidfile="$TRASH_DIRECTORY/p4d.pid"
  32
  33start_p4d() {
  34        mkdir -p "$db" "$cli" "$git" &&
  35        (
  36                p4d -q -r "$db" -p $P4DPORT &
  37                echo $! >"$pidfile"
  38        ) &&
  39        for i in 1 2 3 4 5 ; do
  40                p4 info >/dev/null 2>&1 && break || true &&
  41                echo waiting for p4d to start &&
  42                sleep 1
  43        done &&
  44        # complain if it never started
  45        p4 info >/dev/null &&
  46        (
  47                cd "$cli" &&
  48                p4 client -i <<-EOF
  49                Client: client
  50                Description: client
  51                Root: $cli
  52                View: //depot/... //client/...
  53                EOF
  54        )
  55}
  56
  57kill_p4d() {
  58        pid=$(cat "$pidfile")
  59        # it had better exist for the first kill
  60        kill $pid &&
  61        for i in 1 2 3 4 5 ; do
  62                kill $pid >/dev/null 2>&1 || break
  63                sleep 1
  64        done &&
  65        # complain if it would not die
  66        test_must_fail kill $pid >/dev/null 2>&1 &&
  67        rm -rf "$db" "$cli" "$pidfile"
  68}
  69
  70cleanup_git() {
  71        rm -rf "$git"
  72}