mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
tests: Speed up the test suite.
* tests/openpgp/run-tests.scm (test::run-sync): Pass additional arguments to the test. (test::run-sync-quiet): Likewise. (test::run-async): Likewise. (run-tests-{parallel,sequential}-isolated): Create a tarball of the gnupghome, then extract it for each test. * tests/openpgp/setup.scm: Refactor into functions, add an interface to tar-up the created environment, and untar it multiple times. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
c97bde2dfe
commit
46c4333c37
@ -82,10 +82,10 @@
|
|||||||
(new name directory command pid x))
|
(new name directory command pid x))
|
||||||
(define (set-pid x)
|
(define (set-pid x)
|
||||||
(new name directory command x retcode))
|
(new name directory command x retcode))
|
||||||
(define (run-sync)
|
(define (run-sync . args)
|
||||||
(with-working-directory directory
|
(with-working-directory directory
|
||||||
(let* ((p (inbound-pipe))
|
(let* ((p (inbound-pipe))
|
||||||
(pid (spawn-process-fd command CLOSED_FD
|
(pid (spawn-process-fd (append command args) CLOSED_FD
|
||||||
(:write-end p) (:write-end p))))
|
(:write-end p) (:write-end p))))
|
||||||
(close (:write-end p))
|
(close (:write-end p))
|
||||||
(splice (:read-end p) STDERR_FILENO)
|
(splice (:read-end p) STDERR_FILENO)
|
||||||
@ -93,14 +93,16 @@
|
|||||||
(let ((t' (set-retcode (wait-process name pid #t))))
|
(let ((t' (set-retcode (wait-process name pid #t))))
|
||||||
(t'::report)
|
(t'::report)
|
||||||
t'))))
|
t'))))
|
||||||
(define (run-sync-quiet)
|
(define (run-sync-quiet . args)
|
||||||
(with-working-directory directory
|
(with-working-directory directory
|
||||||
(set-retcode
|
(set-retcode
|
||||||
(wait-process
|
(wait-process
|
||||||
name (spawn-process-fd command CLOSED_FD CLOSED_FD CLOSED_FD) #t))))
|
name (spawn-process-fd (append command args)
|
||||||
(define (run-async)
|
CLOSED_FD CLOSED_FD CLOSED_FD) #t))))
|
||||||
|
(define (run-async . args)
|
||||||
(with-working-directory directory
|
(with-working-directory directory
|
||||||
(set-pid (spawn-process-fd command CLOSED_FD CLOSED_FD CLOSED_FD))))
|
(set-pid (spawn-process-fd (append command args)
|
||||||
|
CLOSED_FD CLOSED_FD CLOSED_FD))))
|
||||||
(define (status)
|
(define (status)
|
||||||
(let ((t (assoc retcode '((0 "PASS") (77 "SKIP") (99 "ERROR")))))
|
(let ((t (assoc retcode '((0 "PASS") (77 "SKIP") (99 "ERROR")))))
|
||||||
(if (not t) "FAIL" (cadr t))))
|
(if (not t) "FAIL" (cadr t))))
|
||||||
@ -119,11 +121,14 @@
|
|||||||
(loop (pool::add (test::run-async)) (cdr tests'))))))
|
(loop (pool::add (test::run-async)) (cdr tests'))))))
|
||||||
|
|
||||||
(define (run-tests-parallel-isolated setup teardown . tests)
|
(define (run-tests-parallel-isolated setup teardown . tests)
|
||||||
|
(lettmp (gpghome-tar)
|
||||||
|
(setup::run-sync '--create-tarball gpghome-tar)
|
||||||
(let loop ((pool (test-pool::new '())) (tests' tests))
|
(let loop ((pool (test-pool::new '())) (tests' tests))
|
||||||
(if (null? tests')
|
(if (null? tests')
|
||||||
(let ((results (pool::wait)))
|
(let ((results (pool::wait)))
|
||||||
(for-each (lambda (t)
|
(for-each (lambda (t)
|
||||||
(let ((teardown' (teardown::set-directory t::directory)))
|
(let ((teardown' (teardown::set-directory
|
||||||
|
t::directory)))
|
||||||
(teardown'::run-sync-quiet))
|
(teardown'::run-sync-quiet))
|
||||||
(unlink-recursively t::directory)
|
(unlink-recursively t::directory)
|
||||||
(t::report)) results::procs)
|
(t::report)) results::procs)
|
||||||
@ -132,8 +137,8 @@
|
|||||||
(test (car tests'))
|
(test (car tests'))
|
||||||
(test' (test::set-directory wd))
|
(test' (test::set-directory wd))
|
||||||
(setup' (setup::set-directory wd)))
|
(setup' (setup::set-directory wd)))
|
||||||
(setup'::run-sync-quiet)
|
(setup'::run-sync-quiet '--unpack-tarball gpghome-tar)
|
||||||
(loop (pool::add (test'::run-async)) (cdr tests'))))))
|
(loop (pool::add (test'::run-async)) (cdr tests')))))))
|
||||||
|
|
||||||
(define (run-tests-sequential-shared setup teardown . tests)
|
(define (run-tests-sequential-shared setup teardown . tests)
|
||||||
(let loop ((pool (test-pool::new '()))
|
(let loop ((pool (test-pool::new '()))
|
||||||
@ -145,11 +150,14 @@
|
|||||||
(loop (pool::add (test::run-sync)) (cdr tests'))))))
|
(loop (pool::add (test::run-sync)) (cdr tests'))))))
|
||||||
|
|
||||||
(define (run-tests-sequential-isolated setup teardown . tests)
|
(define (run-tests-sequential-isolated setup teardown . tests)
|
||||||
|
(lettmp (gpghome-tar)
|
||||||
|
(setup::run-sync '--create-tarball gpghome-tar)
|
||||||
(let loop ((pool (test-pool::new '())) (tests' tests))
|
(let loop ((pool (test-pool::new '())) (tests' tests))
|
||||||
(if (null? tests')
|
(if (null? tests')
|
||||||
(let ((results (pool::wait)))
|
(let ((results (pool::wait)))
|
||||||
(for-each (lambda (t)
|
(for-each (lambda (t)
|
||||||
(let ((teardown' (teardown::set-directory t::directory)))
|
(let ((teardown' (teardown::set-directory
|
||||||
|
t::directory)))
|
||||||
(teardown'::run-sync-quiet))
|
(teardown'::run-sync-quiet))
|
||||||
(unlink-recursively t::directory))
|
(unlink-recursively t::directory))
|
||||||
results::procs)
|
results::procs)
|
||||||
@ -158,8 +166,8 @@
|
|||||||
(test (car tests'))
|
(test (car tests'))
|
||||||
(test' (test::set-directory wd))
|
(test' (test::set-directory wd))
|
||||||
(setup' (setup::set-directory wd)))
|
(setup' (setup::set-directory wd)))
|
||||||
(setup'::run-sync-quiet)
|
(setup'::run-sync-quiet '--unpack-tarball gpghome-tar)
|
||||||
(loop (pool::add (test'::run-sync)) (cdr tests'))))))
|
(loop (pool::add (test'::run-sync)) (cdr tests')))))))
|
||||||
|
|
||||||
(define all-tests
|
(define all-tests
|
||||||
'("version.scm"
|
'("version.scm"
|
||||||
|
@ -19,12 +19,13 @@
|
|||||||
|
|
||||||
(load (with-path "defs.scm"))
|
(load (with-path "defs.scm"))
|
||||||
|
|
||||||
(echo "Creating test environment...")
|
(define (create-gpghome)
|
||||||
|
(echo "Creating test environment...")
|
||||||
|
|
||||||
(letfd ((fd (open "random_seed" (logior O_WRONLY O_CREAT O_BINARY) #o600)))
|
(letfd ((fd (open "random_seed" (logior O_WRONLY O_CREAT O_BINARY) #o600)))
|
||||||
(call-with-fds (list (tool 'mktdata) "600") CLOSED_FD fd STDERR_FILENO))
|
(call-with-fds (list (tool 'mktdata) "600") CLOSED_FD fd STDERR_FILENO))
|
||||||
|
|
||||||
(for-each-p
|
(for-each-p
|
||||||
"Creating configuration files"
|
"Creating configuration files"
|
||||||
(lambda (name)
|
(lambda (name)
|
||||||
(file-copy (in-srcdir (string-append name ".tmpl")) name)
|
(file-copy (in-srcdir (string-append name ".tmpl")) name)
|
||||||
@ -41,13 +42,7 @@
|
|||||||
(display (string-append "pinentry-program " PINENTRY "\n") p)))))
|
(display (string-append "pinentry-program " PINENTRY "\n") p)))))
|
||||||
'("gpg.conf" "gpg-agent.conf"))
|
'("gpg.conf" "gpg-agent.conf"))
|
||||||
|
|
||||||
(echo "Starting gpg-agent...")
|
(for-each-p "Creating sample data files"
|
||||||
(call-check `(,(tool 'gpg-connect-agent) --verbose
|
|
||||||
,(string-append "--agent-program=" (tool 'gpg-agent)
|
|
||||||
"|--debug-quick-random")
|
|
||||||
/bye))
|
|
||||||
|
|
||||||
(for-each-p "Creating sample data files"
|
|
||||||
(lambda (size)
|
(lambda (size)
|
||||||
(letfd ((fd (open (string-append "data-" (number->string size))
|
(letfd ((fd (open (string-append "data-" (number->string size))
|
||||||
(logior O_WRONLY O_CREAT O_BINARY) #o600)))
|
(logior O_WRONLY O_CREAT O_BINARY) #o600)))
|
||||||
@ -55,17 +50,17 @@
|
|||||||
CLOSED_FD fd STDERR_FILENO)))
|
CLOSED_FD fd STDERR_FILENO)))
|
||||||
'(500 9000 32000 80000))
|
'(500 9000 32000 80000))
|
||||||
|
|
||||||
(for-each-p "Unpacking samples"
|
(for-each-p "Unpacking samples"
|
||||||
(lambda (name)
|
(lambda (name)
|
||||||
(dearmor (in-srcdir (string-append name "o.asc")) name))
|
(dearmor (in-srcdir (string-append name "o.asc")) name))
|
||||||
'("plain-1" "plain-2" "plain-3" "plain-large"))
|
'("plain-1" "plain-2" "plain-3" "plain-large"))
|
||||||
|
|
||||||
;; XXX implement cleanup
|
;; XXX implement cleanup
|
||||||
(catch '()
|
(catch '()
|
||||||
(mkdir "private-keys-v1.d" "-rwx"))
|
(mkdir "private-keys-v1.d" "-rwx"))
|
||||||
|
|
||||||
(define counter (make-counter))
|
(define counter (make-counter))
|
||||||
(for-each-p' "Storing private keys"
|
(for-each-p' "Storing private keys"
|
||||||
(lambda (name)
|
(lambda (name)
|
||||||
(dearmor (in-srcdir (string-append "/privkeys/" name ".asc"))
|
(dearmor (in-srcdir (string-append "/privkeys/" name ".asc"))
|
||||||
(string-append "private-keys-v1.d/" name ".key")))
|
(string-append "private-keys-v1.d/" name ".key")))
|
||||||
@ -89,33 +84,54 @@
|
|||||||
"C6A6390E9388CDBAD71EAEA698233FE5E04F001E"
|
"C6A6390E9388CDBAD71EAEA698233FE5E04F001E"
|
||||||
"D69102E0F5AC6B6DB8E4D16DA8E18CF46D88CAE3"))
|
"D69102E0F5AC6B6DB8E4D16DA8E18CF46D88CAE3"))
|
||||||
|
|
||||||
(info "Importing public demo and test keys")
|
(info "Importing public demo and test keys")
|
||||||
(call-check `(,@GPG --yes --import
|
(call-check `(,@GPG --yes --import
|
||||||
,(in-srcdir "pubdemo.asc")
|
,(in-srcdir "pubdemo.asc")
|
||||||
,(in-srcdir "pubring.asc")
|
,(in-srcdir "pubring.asc")
|
||||||
,(in-srcdir key-file1)))
|
,(in-srcdir key-file1)))
|
||||||
;; (letfd ((source (open (in-srcdir "pubring.pkr.asc") O_RDONLY)))
|
(pipe:do
|
||||||
;; ((gpg-pipe '(--dearmor) '(--yes --import) STDERR_FILENO)
|
|
||||||
;; source CLOSED_FD))
|
|
||||||
(pipe:do
|
|
||||||
(pipe:open (in-srcdir "pubring.pkr.asc") (logior O_RDONLY O_BINARY))
|
(pipe:open (in-srcdir "pubring.pkr.asc") (logior O_RDONLY O_BINARY))
|
||||||
(pipe:spawn `(,@GPG --dearmor))
|
(pipe:spawn `(,@GPG --dearmor))
|
||||||
(pipe:spawn `(,@GPG --yes --import)))
|
(pipe:spawn `(,@GPG --yes --import))))
|
||||||
|
|
||||||
(info "Preset passphrases")
|
(define (start-agent)
|
||||||
;; one@example.com
|
(echo "Starting gpg-agent...")
|
||||||
(call-check `(,(tool 'gpg-preset-passphrase)
|
(call-check `(,(tool 'gpg-connect-agent) --verbose
|
||||||
|
,(string-append "--agent-program=" (tool 'gpg-agent)
|
||||||
|
"|--debug-quick-random")
|
||||||
|
/bye))
|
||||||
|
|
||||||
|
(info "Preset passphrases")
|
||||||
|
;; one@example.com
|
||||||
|
(call-check `(,(tool 'gpg-preset-passphrase)
|
||||||
--preset --passphrase def
|
--preset --passphrase def
|
||||||
"50B2D4FA4122C212611048BC5FC31BD44393626E"))
|
"50B2D4FA4122C212611048BC5FC31BD44393626E"))
|
||||||
(call-check `(,(tool 'gpg-preset-passphrase)
|
(call-check `(,(tool 'gpg-preset-passphrase)
|
||||||
--preset --passphrase def
|
--preset --passphrase def
|
||||||
"7E201E28B6FEB2927B321F443205F4724EBE637E"))
|
"7E201E28B6FEB2927B321F443205F4724EBE637E"))
|
||||||
;; alpha@example.net
|
;; alpha@example.net
|
||||||
(call-check `(,(tool 'gpg-preset-passphrase)
|
(call-check `(,(tool 'gpg-preset-passphrase)
|
||||||
--preset --passphrase abc
|
--preset --passphrase abc
|
||||||
"76F7E2B35832976B50A27A282D9B87E44577EB66"))
|
"76F7E2B35832976B50A27A282D9B87E44577EB66"))
|
||||||
(call-check `(,(tool 'gpg-preset-passphrase)
|
(call-check `(,(tool 'gpg-preset-passphrase)
|
||||||
--preset --passphrase abc
|
--preset --passphrase abc
|
||||||
"A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD"))
|
"A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD"))
|
||||||
|
(echo "All set up."))
|
||||||
|
|
||||||
(echo "All set up.")
|
(define (kill-agent)
|
||||||
|
(call-check `(,(tool 'gpg-connect-agent) --verbose killagent /bye)))
|
||||||
|
|
||||||
|
(cond
|
||||||
|
((member "--create-tarball" *args*)
|
||||||
|
(with-temporary-working-directory
|
||||||
|
(setenv "GNUPGHOME" (getcwd) #t)
|
||||||
|
(create-gpghome)
|
||||||
|
(kill-agent)
|
||||||
|
(call-check `(,(tool 'gpgtar) --create --output ,(cadr *args*)
|
||||||
|
,@(glob "*")))))
|
||||||
|
((member "--unpack-tarball" *args*)
|
||||||
|
(call-check `(,(tool 'gpgtar) --extract --directory=. ,(cadr *args*)))
|
||||||
|
(start-agent))
|
||||||
|
(else
|
||||||
|
(create-gpghome)
|
||||||
|
(start-agent)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user