2016-01-07 17:01:45 +01:00
|
|
|
;; Test-suite runner.
|
|
|
|
;;
|
|
|
|
;; Copyright (C) 2016 g10 Code GmbH
|
|
|
|
;;
|
|
|
|
;; This file is part of GnuPG.
|
|
|
|
;;
|
|
|
|
;; GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; GnuPG is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(if (string=? "" (getenv "srcdir"))
|
|
|
|
(begin
|
|
|
|
(echo "Environment variable 'srcdir' not set. Please point it to"
|
|
|
|
"tests/openpgp.")
|
|
|
|
(exit 2)))
|
|
|
|
|
|
|
|
;; Set objdir so that the tests can locate built programs.
|
|
|
|
(setenv "objdir" (getcwd) #f)
|
|
|
|
|
|
|
|
(define test-pool
|
|
|
|
(package
|
|
|
|
(define (new procs)
|
|
|
|
(package
|
|
|
|
(define (add test)
|
|
|
|
(new (cons test procs)))
|
|
|
|
(define (wait)
|
|
|
|
(let ((unfinished (filter (lambda (t) (not t::retcode)) procs)))
|
|
|
|
(if (null? unfinished)
|
|
|
|
(package)
|
|
|
|
(let* ((commands (map (lambda (t) t::command) unfinished))
|
|
|
|
(pids (map (lambda (t) t::pid) unfinished))
|
|
|
|
(results
|
|
|
|
(map (lambda (pid retcode) (list pid retcode))
|
|
|
|
pids
|
|
|
|
(wait-processes (map stringify commands) pids #t))))
|
|
|
|
(new
|
|
|
|
(map (lambda (t)
|
|
|
|
(if t::retcode
|
|
|
|
t
|
|
|
|
(t::set-retcode (cadr (assoc t::pid results)))))
|
|
|
|
procs))))))
|
|
|
|
(define (passed)
|
|
|
|
(filter (lambda (p) (= 0 p::retcode)) procs))
|
|
|
|
(define (skipped)
|
|
|
|
(filter (lambda (p) (= 77 p::retcode)) procs))
|
|
|
|
(define (hard-errored)
|
|
|
|
(filter (lambda (p) (= 99 p::retcode)) procs))
|
|
|
|
(define (failed)
|
|
|
|
(filter (lambda (p)
|
|
|
|
(not (or (= 0 p::retcode) (= 77 p::retcode)
|
|
|
|
(= 99 p::retcode))))
|
|
|
|
procs))
|
|
|
|
(define (report)
|
|
|
|
(echo (length procs) "tests run,"
|
|
|
|
(length (passed)) "succeeded,"
|
|
|
|
(length (failed)) "failed,"
|
|
|
|
(length (skipped)) "skipped.")
|
|
|
|
(length (failed)))))))
|
|
|
|
|
|
|
|
(define (verbosity n)
|
|
|
|
(if (= 0 n) '() (cons '--verbose (verbosity (- n 1)))))
|
|
|
|
|
|
|
|
(define test
|
|
|
|
(package
|
|
|
|
(define (scm name . args)
|
2016-07-26 15:53:50 +02:00
|
|
|
(new name #f `(,*argv0* ,@(verbosity (*verbose*)) ,@args
|
2016-01-07 17:01:45 +01:00
|
|
|
,(in-srcdir name)) #f #f))
|
|
|
|
(define (new name directory command pid retcode)
|
|
|
|
(package
|
|
|
|
(define (set-directory x)
|
|
|
|
(new name x command pid retcode))
|
|
|
|
(define (set-retcode x)
|
|
|
|
(new name directory command pid x))
|
|
|
|
(define (set-pid x)
|
|
|
|
(new name directory command x retcode))
|
2016-09-05 17:17:24 +02:00
|
|
|
(define (run-sync . args)
|
2016-01-07 17:01:45 +01:00
|
|
|
(with-working-directory directory
|
|
|
|
(let* ((p (inbound-pipe))
|
2016-09-20 15:29:57 +02:00
|
|
|
(pid (spawn-process-fd (append command args) 0
|
2016-01-07 17:01:45 +01:00
|
|
|
(:write-end p) (:write-end p))))
|
|
|
|
(close (:write-end p))
|
|
|
|
(splice (:read-end p) STDERR_FILENO)
|
|
|
|
(close (:read-end p))
|
|
|
|
(let ((t' (set-retcode (wait-process name pid #t))))
|
|
|
|
(t'::report)
|
|
|
|
t'))))
|
2016-09-05 17:17:24 +02:00
|
|
|
(define (run-sync-quiet . args)
|
2016-01-07 17:01:45 +01:00
|
|
|
(with-working-directory directory
|
|
|
|
(set-retcode
|
|
|
|
(wait-process
|
2016-09-05 17:17:24 +02:00
|
|
|
name (spawn-process-fd (append command args)
|
|
|
|
CLOSED_FD CLOSED_FD CLOSED_FD) #t))))
|
|
|
|
(define (run-async . args)
|
2016-01-07 17:01:45 +01:00
|
|
|
(with-working-directory directory
|
2016-09-05 17:17:24 +02:00
|
|
|
(set-pid (spawn-process-fd (append command args)
|
|
|
|
CLOSED_FD CLOSED_FD CLOSED_FD))))
|
2016-01-07 17:01:45 +01:00
|
|
|
(define (status)
|
|
|
|
(let ((t (assoc retcode '((0 "PASS") (77 "SKIP") (99 "ERROR")))))
|
|
|
|
(if (not t) "FAIL" (cadr t))))
|
|
|
|
(define (report)
|
|
|
|
(echo (string-append (status retcode) ":") name))))))
|
|
|
|
|
|
|
|
(define (run-tests-parallel-shared setup teardown . tests)
|
|
|
|
(setup::run-sync)
|
|
|
|
(let loop ((pool (test-pool::new '())) (tests' tests))
|
|
|
|
(if (null? tests')
|
|
|
|
(let ((results (pool::wait)))
|
|
|
|
(for-each (lambda (t) (t::report)) results::procs)
|
|
|
|
(teardown::run-sync)
|
|
|
|
(exit (results::report)))
|
|
|
|
(let ((test (car tests')))
|
|
|
|
(loop (pool::add (test::run-async)) (cdr tests'))))))
|
|
|
|
|
|
|
|
(define (run-tests-parallel-isolated setup teardown . tests)
|
2016-09-05 17:17:24 +02:00
|
|
|
(lettmp (gpghome-tar)
|
|
|
|
(setup::run-sync '--create-tarball gpghome-tar)
|
|
|
|
(let loop ((pool (test-pool::new '())) (tests' tests))
|
|
|
|
(if (null? tests')
|
|
|
|
(let ((results (pool::wait)))
|
|
|
|
(for-each (lambda (t)
|
|
|
|
(let ((teardown' (teardown::set-directory
|
|
|
|
t::directory)))
|
|
|
|
(teardown'::run-sync-quiet))
|
|
|
|
(unlink-recursively t::directory)
|
|
|
|
(t::report)) results::procs)
|
|
|
|
(exit (results::report)))
|
|
|
|
(let* ((wd (mkdtemp))
|
|
|
|
(test (car tests'))
|
|
|
|
(test' (test::set-directory wd))
|
|
|
|
(setup' (setup::set-directory wd)))
|
|
|
|
(setup'::run-sync-quiet '--unpack-tarball gpghome-tar)
|
|
|
|
(loop (pool::add (test'::run-async)) (cdr tests')))))))
|
2016-01-07 17:01:45 +01:00
|
|
|
|
|
|
|
(define (run-tests-sequential-shared setup teardown . tests)
|
|
|
|
(let loop ((pool (test-pool::new '()))
|
|
|
|
(tests' `(,setup ,@tests ,teardown)))
|
|
|
|
(if (null? tests')
|
|
|
|
(let ((results (pool::wait)))
|
|
|
|
(exit (results::report)))
|
|
|
|
(let ((test (car tests')))
|
|
|
|
(loop (pool::add (test::run-sync)) (cdr tests'))))))
|
|
|
|
|
|
|
|
(define (run-tests-sequential-isolated setup teardown . tests)
|
2016-09-05 17:17:24 +02:00
|
|
|
(lettmp (gpghome-tar)
|
|
|
|
(setup::run-sync '--create-tarball gpghome-tar)
|
|
|
|
(let loop ((pool (test-pool::new '())) (tests' tests))
|
|
|
|
(if (null? tests')
|
|
|
|
(let ((results (pool::wait)))
|
|
|
|
(for-each (lambda (t)
|
|
|
|
(let ((teardown' (teardown::set-directory
|
|
|
|
t::directory)))
|
|
|
|
(teardown'::run-sync-quiet))
|
|
|
|
(unlink-recursively t::directory))
|
|
|
|
results::procs)
|
|
|
|
(exit (results::report)))
|
|
|
|
(let* ((wd (mkdtemp))
|
|
|
|
(test (car tests'))
|
|
|
|
(test' (test::set-directory wd))
|
|
|
|
(setup' (setup::set-directory wd)))
|
|
|
|
(setup'::run-sync-quiet '--unpack-tarball gpghome-tar)
|
|
|
|
(loop (pool::add (test'::run-sync)) (cdr tests')))))))
|
2016-01-07 17:01:45 +01:00
|
|
|
|
|
|
|
(let* ((runner (if (member "--parallel" *args*)
|
|
|
|
(if (member "--shared" *args*)
|
|
|
|
run-tests-parallel-shared
|
|
|
|
run-tests-parallel-isolated)
|
|
|
|
(if (member "--shared" *args*)
|
|
|
|
run-tests-sequential-shared
|
|
|
|
run-tests-sequential-isolated)))
|
2016-09-20 11:17:10 +02:00
|
|
|
(tests (filter (lambda (arg) (not (string-prefix? arg "--"))) *args*)))
|
2016-01-07 17:01:45 +01:00
|
|
|
(apply runner (append (list (test::scm "setup.scm") (test::scm "finish.scm"))
|
|
|
|
(map test::scm tests))))
|