diff --git a/tests/enumerate-tests b/tests/enumerate-tests
index 0599b69e..0f37c961 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 () {
diff --git a/tests/tstunt/gpg b/tests/tstunt/gpg
index 679a6b8e..74152bd9 100755
--- a/tests/tstunt/gpg
+++ b/tests/tstunt/gpg
@@ -3,4 +3,4 @@ set -e
 
 exec \
 with-lock-ex -w "$DGIT_TEST_GNUPG_GLOBAL_LOCK" \
-	$tmp "$DGIT_TEST_TROOT"/tstunt/gpg-locked "$@"
+	$tmp "$DGIT_TEST_TROOT"/tstunt/gpg-withagent "$@"
diff --git a/tests/tstunt/gpg-withagent b/tests/tstunt/gpg-withagent
new file mode 100755
index 00000000..4cb5d4e6
--- /dev/null
+++ b/tests/tstunt/gpg-withagent
@@ -0,0 +1,51 @@
+#!/bin/sh
+set -ex
+
+retry_until_ok () {
+	sleeptime=0
+	while ! "$@"; do
+		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
+}
+
+echo >&2 'GPG-WITHAGENT...'
+
+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'
+
+set +e
+$DGIT_TEST_REAL_GPG					\
+	--agent-program=$DGIT_STUNT_AGENT "$@"
+rc=$?
+set -e
+
+echo >&2 'GPG-WITHAGENT... STOPPING'
+
+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
+}
+
+retry_until_ok kill_agent_not_running
+
+echo >&2 'GPG-WITHAGENT... DONE'
+
+exit $rc
