diff options
author | Justus Winter <justus@g10code.com> | 2016-11-07 16:21:21 +0100 |
---|---|---|
committer | Justus Winter <justus@g10code.com> | 2016-11-07 16:36:36 +0100 |
commit | a55393cb5f4b331cb3a715c7d9a8b91f7606f337 (patch) | |
tree | 7e19d86a3271b4a3acade27c1509bd7f2b504478 /tests/openpgp/defs.scm | |
parent | tests: Do not allow tests to be run in a shared environment. (diff) | |
download | gnupg2-a55393cb5f4b331cb3a715c7d9a8b91f7606f337.tar.xz gnupg2-a55393cb5f4b331cb3a715c7d9a8b91f7606f337.zip |
tests: Move environment creation and teardown into each test.
* tests/gpgscm/tests.scm (log): New function.
* tests/openpgp/run-tests.scm (run-tests-parallel): Do not run the
startup and teardown scripts.
(run-tests-sequential): Likewise.
* tests/openpgp/setup.scm: Move all functions...
* tests/openpgp/defs.scm: ... here and make them less verbose.
(setup-environment): New function.
(setup-legacy-environment): Likewise.
(start-agent): Make less verbose, run 'stop-agent' at interpreter
exit.
(stop-agent): Make less verbose.
* tests/openpgp/finish.scm: Drop file.
* tests/openpgp/Makefile.am (EXTRA_DIST): Drop removed file.
* tests/openpgp/4gb-packet.scm: Use 'setup-environment' or
'setup-legacy-environment' as appropriate.
* tests/openpgp/armdetach.scm: Likewise.
* tests/openpgp/armdetachm.scm: Likewise.
* tests/openpgp/armencrypt.scm: Likewise.
* tests/openpgp/armencryptp.scm: Likewise.
* tests/openpgp/armor.scm: Likewise.
* tests/openpgp/armsignencrypt.scm: Likewise.
* tests/openpgp/armsigs.scm: Likewise.
* tests/openpgp/clearsig.scm: Likewise.
* tests/openpgp/conventional-mdc.scm: Likewise.
* tests/openpgp/conventional.scm: Likewise.
* tests/openpgp/decrypt-dsa.scm: Likewise.
* tests/openpgp/decrypt.scm: Likewise.
* tests/openpgp/default-key.scm: Likewise.
* tests/openpgp/detach.scm: Likewise.
* tests/openpgp/detachm.scm: Likewise.
* tests/openpgp/ecc.scm: Likewise.
* tests/openpgp/encrypt-dsa.scm: Likewise.
* tests/openpgp/encrypt.scm: Likewise.
* tests/openpgp/encryptp.scm: Likewise.
* tests/openpgp/export.scm: Likewise.
* tests/openpgp/finish.scm: Likewise.
* tests/openpgp/genkey1024.scm: Likewise.
* tests/openpgp/gpgtar.scm: Likewise.
* tests/openpgp/gpgv-forged-keyring.scm: Likewise.
* tests/openpgp/import.scm: Likewise.
* tests/openpgp/issue2015.scm: Likewise.
* tests/openpgp/issue2417.scm: Likewise.
* tests/openpgp/issue2419.scm: Likewise.
* tests/openpgp/key-selection.scm: Likewise.
* tests/openpgp/mds.scm: Likewise.
* tests/openpgp/multisig.scm: Likewise.
* tests/openpgp/quick-key-manipulation.scm: Likewise.
* tests/openpgp/seat.scm: Likewise.
* tests/openpgp/shell.scm: Likewise.
* tests/openpgp/signencrypt-dsa.scm: Likewise.
* tests/openpgp/signencrypt.scm: Likewise.
* tests/openpgp/sigs-dsa.scm: Likewise.
* tests/openpgp/sigs.scm: Likewise.
* tests/openpgp/ssh.scm: Likewise.
* tests/openpgp/tofu.scm: Likewise.
* tests/openpgp/use-exact-key.scm: Likewise.
* tests/openpgp/verify.scm: Likewise.
* tests/openpgp/version.scm: Likewise.
* tests/openpgp/issue2346.scm: Likewise and simplify.
--
The previous Bourne Shell-based test suite created the environment
before running all tests, and tore it down after executing them. When
we created the Scheme-based test suite, we kept this design at first,
but introduced a way to run each test in its own environment to
prevent tests from interfering with each other. Nevertheless, every
test started out with the same environment.
Move the creation of the test environment into each test. This gives
us finer control over the environment each test is run in. It also
makes it possible to run each test by simply executing it using gpgscm
without the use of the runner. Furthermore, it has the neat
side-effect of speeding up the test suite if run in parallel.
Signed-off-by: Justus Winter <justus@g10code.com>
Diffstat (limited to 'tests/openpgp/defs.scm')
-rw-r--r-- | tests/openpgp/defs.scm | 130 |
1 files changed, 126 insertions, 4 deletions
diff --git a/tests/openpgp/defs.scm b/tests/openpgp/defs.scm index 62bd1e2fc..09c313b2a 100644 --- a/tests/openpgp/defs.scm +++ b/tests/openpgp/defs.scm @@ -146,10 +146,132 @@ (if (number? verbose) (*set-verbose!* verbose))) +;; +;; Support for test environment creation and teardown. +;; + +(define (make-test-data filename size) + (call-with-binary-output-file + filename + (lambda (port) + (display (make-random-string size) port)))) + +(define (create-gpghome) + (log "Creating test environment...") + + (srandom (getpid)) + (make-test-data "random_seed" 600) + + (log "Creating configuration files") + (for-each + (lambda (name) + (file-copy (in-srcdir (string-append name ".tmpl")) name) + (let ((p (open-input-output-file name))) + (cond + ((string=? "gpg.conf" name) + (if have-opt-always-trust + (display "no-auto-check-trustdb\n" p)) + (display (string-append "agent-program " + (tool 'gpg-agent) + "|--debug-quick-random\n") p) + (display "allow-weak-digest-algos\n" p)) + ((string=? "gpg-agent.conf" name) + (display (string-append "pinentry-program " PINENTRY "\n") p))))) + '("gpg.conf" "gpg-agent.conf"))) + +;; Initialize the test environment, install appropriate configuration +;; and start the agent, without any keys. +(define (setup-environment) + (create-gpghome) + (start-agent)) + +(define (create-legacy-gpghome) + (log "Creating sample data files") + (for-each + (lambda (size) + (make-test-data (string-append "data-" (number->string size)) + size)) + '(500 9000 32000 80000)) + + (log "Unpacking samples") + (for-each + (lambda (name) + (dearmor (in-srcdir (string-append name "o.asc")) name)) + '("plain-1" "plain-2" "plain-3" "plain-large")) + + (mkdir "private-keys-v1.d" "-rwx") + + (log "Storing private keys") + (for-each + (lambda (name) + (dearmor (in-srcdir (string-append "/privkeys/" name ".asc")) + (string-append "private-keys-v1.d/" name ".key"))) + '("50B2D4FA4122C212611048BC5FC31BD44393626E" + "7E201E28B6FEB2927B321F443205F4724EBE637E" + "13FDB8809B17C5547779F9D205C45F47CE0217CE" + "343D8AF79796EE107D645A2787A9D9252F924E6F" + "8B5ABF3EF9EB8D96B91A0B8C2C4401C91C834C34" + "0D6F6AD4C4C803B25470F9104E9F4E6A4CA64255" + "FD692BD59D6640A84C8422573D469F84F3B98E53" + "76F7E2B35832976B50A27A282D9B87E44577EB66" + "A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD" + "00FE67F28A52A8AA08FFAED20AF832DA916D1985" + "1DF48228FEFF3EC2481B106E0ACA8C465C662CC5" + "A2832820DC9F40751BDCD375BB0945BA33EC6B4C" + "ADE710D74409777B7729A7653373D820F67892E0" + "CEFC51AF91F68A2904FBFF62C4F075A4785B803F" + "1E28F20E41B54C2D1234D896096495FF57E08D18" + "EB33B687EB8581AB64D04852A54453E85F3DF62D" + "C6A6390E9388CDBAD71EAEA698233FE5E04F001E" + "D69102E0F5AC6B6DB8E4D16DA8E18CF46D88CAE3")) + + (log "Importing public demo and test keys") + (for-each + (lambda (file) + (call-check `(,@GPG --yes --import ,(in-srcdir file)))) + (list "pubdemo.asc" "pubring.asc" key-file1)) + + (pipe:do + (pipe:open (in-srcdir "pubring.pkr.asc") (logior O_RDONLY O_BINARY)) + (pipe:spawn `(,@GPG --dearmor)) + (pipe:spawn `(,@GPG --yes --import)))) + +(define (preset-passphrases) + (log "Presetting passphrases") + ;; one@example.com + (call-check `(,(tool 'gpg-preset-passphrase) + --preset --passphrase def + "50B2D4FA4122C212611048BC5FC31BD44393626E")) + (call-check `(,(tool 'gpg-preset-passphrase) + --preset --passphrase def + "7E201E28B6FEB2927B321F443205F4724EBE637E")) + ;; alpha@example.net + (call-check `(,(tool 'gpg-preset-passphrase) + --preset --passphrase abc + "76F7E2B35832976B50A27A282D9B87E44577EB66")) + (call-check `(,(tool 'gpg-preset-passphrase) + --preset --passphrase abc + "A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD"))) + +;; Initialize the test environment, install appropriate configuration +;; and start the agent, with the keys from the legacy test suite. +(define (setup-legacy-environment) + (setup-environment) + (if (member "--unpack-tarball" *args*) + (begin + (call-check `(,(tool 'gpgtar) --extract --directory=. ,(cadr *args*))) + (start-agent)) + (begin + (create-gpghome) + (start-agent) + (create-legacy-gpghome))) + (preset-passphrases)) + ;; Create the socket dir and start the agent. (define (start-agent) - (echo "Starting gpg-agent...") - (catch (echo "Warning: Creating socket directory failed:" (car *error*)) + (log "Starting gpg-agent...") + (atexit stop-agent) + (catch (log "Warning: Creating socket directory failed:" (car *error*)) (call-popen `(,(tool 'gpgconf) --create-socketdir) "")) (call-check `(,(tool 'gpg-connect-agent) --verbose ,(string-append "--agent-program=" (tool 'gpg-agent) @@ -158,8 +280,8 @@ ;; Stop the agent and remove the socket dir. (define (stop-agent) - (echo "Stopping gpg-agent...") - (catch (echo "Warning: Removing socket directory failed.") + (log "Stopping gpg-agent...") + (catch (log "Warning: Removing socket directory failed.") (call-popen `(,(tool 'gpgconf) --remove-socketdir) "")) (call-check `(,(tool 'gpg-connect-agent) --verbose --no-autostart killagent /bye))) |