tests: Rework environment setup.

* tests/gpgscm/tests.scm (test::scm): Add a setup argument.
(test::binary): Likewise.
(run-tests-parallel): Remove setup parameter.
(run-tests-sequential): Likewise.
(make-environment-cache): New function that handles the cache
protocol.
* tests/gpgme/run-tests.scm: Adapt accordingly.
* tests/gpgsm/run-tests.scm: Likewise.
* tests/migrations/run-tests.scm: Likewise.
* tests/openpgp/run-tests.scm: Likewise.
--
This change allows us to have different environments for tests.  This
is needed to run more GPGME tests, and to increase concurrency while
running all tests.

Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
Justus Winter 2017-03-09 13:26:06 +01:00
parent ed5575ec55
commit cca91a3f8f
No known key found for this signature in database
GPG Key ID: DD1A52F9DA8C9020
5 changed files with 58 additions and 48 deletions

View File

@ -39,9 +39,10 @@
(let* ((runner (if (member "--parallel" *args*) (let* ((runner (if (member "--parallel" *args*)
run-tests-parallel run-tests-parallel
run-tests-sequential)) run-tests-sequential))
(setup-c (make-environment-cache
(test::scm #f "setup.scm" (in-srcdir "setup.scm") "--" "tests" "gpg")))
(tests (filter (lambda (arg) (not (string-prefix? arg "--"))) *args*))) (tests (filter (lambda (arg) (not (string-prefix? arg "--"))) *args*)))
(runner (runner
(test::scm "setup.scm" (in-srcdir "setup.scm") "--" "tests" "gpg")
(apply (apply
append append
(map (lambda (cmpnts) (map (lambda (cmpnts)
@ -50,6 +51,7 @@
(string-suffix? name ".test")))) (string-suffix? name ".test"))))
(define :path car) (define :path car)
(define :key cadr) (define :key cadr)
(define :setup caddr)
(define (find-test name) (define (find-test name)
(apply path-join (apply path-join
`(,(if (compiled? name) `(,(if (compiled? name)
@ -59,11 +61,12 @@
"Makefile.am")))) "Makefile.am"))))
(map (lambda (name) (map (lambda (name)
(apply test::scm (apply test::scm
`(,name ,(in-srcdir "wrap.scm") --executable `(,(:setup cmpnts)
,(find-test name) ,name ,(in-srcdir "wrap.scm") --executable
-- ,@(:path cmpnts)))) ,(find-test name)
-- ,@(:path cmpnts))))
(if (null? tests) (all-tests makefile (:key cmpnts)) tests)))) (if (null? tests) (all-tests makefile (:key cmpnts)) tests))))
'((("tests" "gpg") "c_tests") `((("tests" "gpg") "c_tests" ,setup-c)
;; XXX: Not yet. ;; XXX: Not yet.
;; (("lang" "python" "tests") "py_tests") ;; (("lang" "python" "tests") "py_tests")
(("lang" "qt" "tests") "TESTS")))))) (("lang" "qt" "tests") "TESTS" ,setup-c))))))

View File

@ -551,18 +551,20 @@
;; A single test. ;; A single test.
(define test (define test
(package (package
(define (scm name path . args) (define (scm setup name path . args)
;; Start the process. ;; Start the process.
(define (spawn-scm args' in out err) (define (spawn-scm args' in out err)
(spawn-process-fd `(,*argv0* ,@(verbosity (*verbose*)) (spawn-process-fd `(,*argv0* ,@(verbosity (*verbose*))
,(locate-test path) ,(locate-test path)
,@(if setup (force setup) '())
,@args' ,@args) in out err)) ,@args' ,@args) in out err))
(new name #f spawn-scm #f #f CLOSED_FD)) (new name #f spawn-scm #f #f CLOSED_FD))
(define (binary name path . args) (define (binary setup name path . args)
;; Start the process. ;; Start the process.
(define (spawn-binary args' in out err) (define (spawn-binary args' in out err)
(spawn-process-fd `(,path ,@args' ,@args) in out err)) (spawn-process-fd `(,path ,@(if setup (force setup) '()) ,@args' ,@args)
in out err))
(new name #f spawn-binary #f #f CLOSED_FD)) (new name #f spawn-binary #f #f CLOSED_FD))
(define (new name directory spawn pid retcode logfd) (define (new name directory spawn pid retcode logfd)
@ -613,41 +615,47 @@
;; Run the setup target to create an environment, then run all given ;; Run the setup target to create an environment, then run all given
;; tests in parallel. ;; tests in parallel.
(define (run-tests-parallel setup tests) (define (run-tests-parallel tests)
(lettmp (gpghome-tar) (let loop ((pool (test-pool::new '())) (tests' tests))
(setup::run-sync '--create-tarball gpghome-tar) (if (null? tests')
(let loop ((pool (test-pool::new '())) (tests' tests)) (let ((results (pool::wait)))
(if (null? tests') (for-each (lambda (t)
(let ((results (pool::wait))) (catch (echo "Removing" t::directory "failed:" *error*)
(for-each (lambda (t) (unlink-recursively t::directory))
(catch (echo "Removing" t::directory "failed:" *error*) (t::report)) (reverse results::procs))
(unlink-recursively t::directory)) (exit (results::report)))
(t::report)) (reverse results::procs)) (let* ((wd (mkdtemp))
(exit (results::report))) (test (car tests'))
(let* ((wd (mkdtemp)) (test' (test::set-directory wd)))
(test (car tests')) (loop (pool::add (test'::run-async))
(test' (test::set-directory wd))) (cdr tests'))))))
(loop (pool::add (test'::run-async '--unpack-tarball gpghome-tar))
(cdr tests')))))))
;; Run the setup target to create an environment, then run all given ;; Run the setup target to create an environment, then run all given
;; tests in sequence. ;; tests in sequence.
(define (run-tests-sequential setup tests) (define (run-tests-sequential tests)
(lettmp (gpghome-tar) (let loop ((pool (test-pool::new '())) (tests' tests))
(setup::run-sync '--create-tarball gpghome-tar) (if (null? tests')
(let loop ((pool (test-pool::new '())) (tests' tests)) (let ((results (pool::wait)))
(if (null? tests') (for-each (lambda (t)
(let ((results (pool::wait))) (catch (echo "Removing" t::directory "failed:" *error*)
(for-each (lambda (t) (unlink-recursively t::directory)))
(catch (echo "Removing" t::directory "failed:" *error*) results::procs)
(unlink-recursively t::directory))) (exit (results::report)))
results::procs) (let* ((wd (mkdtemp))
(exit (results::report))) (test (car tests'))
(let* ((wd (mkdtemp)) (test' (test::set-directory wd)))
(test (car tests')) (loop (pool::add (test'::run-sync))
(test' (test::set-directory wd))) (cdr tests'))))))
(loop (pool::add (test'::run-sync '--unpack-tarball gpghome-tar))
(cdr tests'))))))) ;; Helper to create environment caches from test functions. SETUP
;; must be a test implementing the producer side cache protocol.
;; Returns a promise containing the arguments that must be passed to a
;; test implementing the consumer side of the cache protocol.
(define (make-environment-cache setup)
(delay (let* ((tarball (make-temporary-file "environment-cache")))
(atexit (lambda () (remove-temporary-file tarball)))
(setup::run-sync '--create-tarball tarball)
`(--unpack-tarball ,tarball))))
;; Command line flag handling. Returns the elements following KEY in ;; Command line flag handling. Returns the elements following KEY in
;; ARGUMENTS up to the next argument, or #f if KEY is not in ;; ARGUMENTS up to the next argument, or #f if KEY is not in

View File

@ -20,13 +20,13 @@
(if (string=? "" (getenv "srcdir")) (if (string=? "" (getenv "srcdir"))
(begin (begin
(echo "Environment variable 'srcdir' not set. Please point it to" (echo "Environment variable 'srcdir' not set. Please point it to"
"tests/openpgp.") "tests/gpgsm.")
(exit 2))) (exit 2)))
(let* ((tests (filter (lambda (arg) (not (string-prefix? arg "--"))) *args*)) (let* ((tests (filter (lambda (arg) (not (string-prefix? arg "--"))) *args*))
(setup (make-environment-cache (test::scm #f "setup.scm" "setup.scm")))
(runner (if (and (member "--parallel" *args*) (runner (if (and (member "--parallel" *args*)
(> (length tests) 1)) (> (length tests) 1))
run-tests-parallel run-tests-parallel
run-tests-sequential))) run-tests-sequential)))
(runner (test::scm "setup.scm" "setup.scm") (runner (map (lambda (t) (test::scm setup t t)) tests)))
(map (lambda (t) (test::scm t t)) tests)))

View File

@ -22,5 +22,4 @@
(> (length tests) 1)) (> (length tests) 1))
run-tests-parallel run-tests-parallel
run-tests-sequential))) run-tests-sequential)))
(runner (test::scm "setup.scm" "setup.scm") (runner (map (lambda (t) (test::scm #f t t)) tests)))
(map (lambda (t) (test::scm t t)) tests)))

View File

@ -27,9 +27,9 @@
(setenv "objdir" (getcwd) #f) (setenv "objdir" (getcwd) #f)
(let* ((tests (filter (lambda (arg) (not (string-prefix? arg "--"))) *args*)) (let* ((tests (filter (lambda (arg) (not (string-prefix? arg "--"))) *args*))
(setup (make-environment-cache (test::scm #f "setup.scm" "setup.scm")))
(runner (if (and (member "--parallel" *args*) (runner (if (and (member "--parallel" *args*)
(> (length tests) 1)) (> (length tests) 1))
run-tests-parallel run-tests-parallel
run-tests-sequential))) run-tests-sequential)))
(runner (test::scm "setup.scm" "setup.scm") (runner (map (lambda (t) (test::scm setup t t)) tests))))
(map (lambda (t) (test::scm t t)) tests)))