diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/enumerate-tests | 2 | ||||
-rw-r--r-- | tests/lib | 1 | ||||
-rwxr-xr-x | tests/setup/gnupg | 6 | ||||
-rwxr-xr-x | tests/tstunt/gpg | 18 | ||||
-rwxr-xr-x | tests/tstunt/gpg-withagent | 68 |
5 files changed, 91 insertions, 4 deletions
diff --git a/tests/enumerate-tests b/tests/enumerate-tests index 0599b69..0f37c96 100755 --- a/tests/enumerate-tests +++ b/tests/enumerate-tests @@ -42,7 +42,7 @@ finish- () { test-begin-gencontrol () { restrictions='' - dependencies='dgit, dgit-infrastructure, devscripts, debhelper (>=8), fakeroot, build-essential, chiark-utils-bin' + dependencies='dgit, dgit-infrastructure, devscripts, debhelper (>=8), fakeroot, build-essential, chiark-utils-bin, bc' } restriction-gencontrol () { @@ -41,6 +41,7 @@ export DGIT_TEST_TROOT=$troot tmp=$ADTTMP if [ x"$tmp" = x ]; then + export DGIT_TEST_BYHAND=1 mkdir -p tests/tmp tmpbase=$troot/tmp tmp=tests/tmp/$testname diff --git a/tests/setup/gnupg b/tests/setup/gnupg index c88d40b..7a164ef 100755 --- a/tests/setup/gnupg +++ b/tests/setup/gnupg @@ -7,10 +7,11 @@ cp $troot/gnupg/* $tmp/gnupg chmod go-rw $tmp/gnupg/* export DGIT_TEST_GNUPG_GLOBAL_LOCK=$tmp/gnupg/dgit-test-global-lock +export DGIT_TEST_GNUPG_LOG=$tmp/gnupg-workarounds.log setup=' export GNUPGHOME=$tmp/gnupg - export DGIT_TEST_GNUPG_GLOBAL_LOCK + export DGIT_TEST_GNUPG_GLOBAL_LOCK DGIT_TEST_GNUPG_LOG cat >$tmp/gnupg/gpg-agent.conf <<END log-file $tmp/gnupg/AGENT.log @@ -27,6 +28,7 @@ eval "$setup" gpg --list-secret -t-setup-done 'DGIT_TEST_GNUPG_GLOBAL_LOCK' 'gnupg' "$setup" +t-setup-done 'DGIT_TEST_GNUPG_GLOBAL_LOCK DGIT_TEST_GNUPG_LOG' \ + 'gnupg' "$setup" t-ok diff --git a/tests/tstunt/gpg b/tests/tstunt/gpg index 679a6b8..4214b4a 100755 --- a/tests/tstunt/gpg +++ b/tests/tstunt/gpg @@ -3,4 +3,20 @@ set -e exec \ with-lock-ex -w "$DGIT_TEST_GNUPG_GLOBAL_LOCK" \ - $tmp "$DGIT_TEST_TROOT"/tstunt/gpg-locked "$@" + sh -c ' + "$@" 9>&2 2>>"$DGIT_TEST_GNUPG_LOG" + rc=$? + if [ $rc = 0 ]; then exit 0; fi + if [ "x$DGIT_TEST_BYHAND" != x ]; then + echo >&2 "BYHAND, not dumping $DGIT_TEST_GNUPG_LOG" + else + echo >&2 "########################################" + echo >&2 "$DGIT_TEST_GNUPG_LOG" + sed '\''s/^/\[gnupg-workarounds] /'\'' >&2 \ + "$DGIT_TEST_GNUPG_LOG" + echo >&2 "end of $DGIT_TEST_GNUPG_LOG" + echo >&2 "########################################" + fi + exit $rc + ' x \ + "$DGIT_TEST_TROOT"/tstunt/gpg-withagent "$@" diff --git a/tests/tstunt/gpg-withagent b/tests/tstunt/gpg-withagent new file mode 100755 index 0000000..b7b8bfd --- /dev/null +++ b/tests/tstunt/gpg-withagent @@ -0,0 +1,68 @@ +#!/bin/sh +set -ex + +d () { + date --iso-8601=ns >&2 + ps -ef | grep gpg-agent >&2 ||: +} + +d + +retry_until_ok () { + sleeptime=0 + d + while ! "$@"; do + d + case $sleeptime in + ??.*) + echo >&2 "$0: GPG AGENT STARTP $@ TIMED OUT" + exit 127 + ;; + esac + sleep $sleeptime + sleeptime=$(echo "($sleeptime + 0.001) * 2" | bc -l) + done +} + +kill_agent_not_running () { + LC_MESSAGES=C gpg-connect-agent --no-autostart </dev/null \ + KILLAGENT /bye 2>&1 \ + | tee -a /dev/stderr \ + | grep 'no gpg-agent running' >&2 +} + +echo >&2 'GPG-WITHAGENT... PRE-STOPPING' + +retry_until_ok kill_agent_not_running + +agent_is_running () { + gpg-connect-agent --no-autostart </dev/null \ + '/echo dgit-gpg-agent-ok' /bye 2>&1 \ + | grep dgit-gpg-agent-ok >&2 +} + + +$DGIT_STUNT_AGENT --daemon </dev/null >&2 +retry_until_ok agent_is_running + +echo >&2 'GPG-WITHAGENT... RUNNING' + +d + +set +e +$DGIT_TEST_REAL_GPG \ + --agent-program=$DGIT_STUNT_AGENT "$@" 2>&9 +rc=$? +set -e + +d + +echo >&2 'GPG-WITHAGENT... STOPPING' + +retry_until_ok kill_agent_not_running + +echo >&2 'GPG-WITHAGENT... DONE' + +d + +exit $rc |