diff --git a/tests/gpgme/gpgme-defs.scm b/tests/gpgme/gpgme-defs.scm index a74a174f7..be6b0f191 100644 --- a/tests/gpgme/gpgme-defs.scm +++ b/tests/gpgme/gpgme-defs.scm @@ -1,181 +1,123 @@ #!/usr/bin/env gpgscm ;; 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 . (load (in-srcdir "tests" "openpgp" "defs.scm")) (define gpgme-srcdir (getenv "XTEST_GPGME_SRCDIR")) (when (string=? "" gpgme-srcdir) (info "SKIP: Environment variable 'XTEST_GPGME_SRCDIR' not set. Please" "point it to a recent GPGME source tree to run the GPGME test suite.") (exit 0)) (define (in-gpgme-srcdir . names) (canonical-path (apply path-join (cons gpgme-srcdir names)))) (define gpgme-builddir (getenv "XTEST_GPGME_BUILDDIR")) (when (string=? "" gpgme-builddir) (info "SKIP: Environment variable 'XTEST_GPGME_BUILDDIR' not set. Please" "point it to a recent GPGME build tree to run the GPGME test suite.") (exit 0)) ;; Make sure that GPGME picks up our gpgconf. This makes GPGME use ;; and thus executes the tests with GnuPG components from the build ;; tree. (setenv "PATH" (string-append (path-join (getenv "GNUPG_BUILDDIR") "tools") (string *pathsep*) (getenv "PATH")) #t) ;; The tests expect the pinentry to return the passphrase "abc". (setenv "PINENTRY_USER_DATA" "abc" #t) (define (create-gpgmehome . path) ;; Support for various environments. (define mode (cond ((equal? path '("lang" "python" "tests")) (set! path '("tests" "gpg")) ;; Mostly uses files from tests/gpg. 'python) (else 'gpg))) (create-file "gpg.conf" "no-force-v3-sigs" (string-append "agent-program " (tool 'gpg-agent) "|--debug-quick-random\n")) (create-file "gpg-agent.conf" (string-append "pinentry-program " (tool 'pinentry))) (start-agent) (log "Storing private keys") (for-each (lambda (name) (file-copy (apply in-gpgme-srcdir `(,@path ,name)) (path-join "private-keys-v1.d" (string-append name ".key")))) '("13CD0F3BDF24BE53FE192D62F18737256FF6E4FD" "76F7E2B35832976B50A27A282D9B87E44577EB66" "A0747D5F9425E6664F4FFBEED20FBCA79FDED2BD" "13CBE3758AFE42B5E5E2AE4CED27AFA455E3F87F" "7A030357C0F253A5BBCD282FFC4E521B37558F5C")) (log "Importing public demo and test keys") (for-each (lambda (file) (call-check `(,@GPG --yes --import ,(apply in-gpgme-srcdir `(,@path ,file))))) (list "pubdemo.asc" "secdemo.asc")) (when (equal? mode 'python) (log "Importing extra keys for Python tests") (for-each (lambda (file) (call-check `(,@GPG --yes --import ,(apply in-gpgme-srcdir `("lang" "python" "tests" ,file))))) (list "encrypt-only.asc" "sign-only.asc")) (log "Marking key as trusted") (pipe:do (pipe:echo "A0FF4590BB6122EDEF6E3C542D727CC768697734:6:\n") (pipe:spawn `(,(tool 'gpg) --import-ownertrust)))) (stop-agent)) ;; Initialize the test environment, install appropriate configuration ;; and start the agent, with the keys from the legacy test suite. (define (setup-gpgme-environment . path) (if (member "--unpack-tarball" *args*) (begin (call-check `(,(tool 'gpgtar) --extract --directory=. ,(cadr *args*))) (start-agent)) (apply create-gpgme-gpghome path))) -(define (parse-makefile port key) - (define (is-continuation? tokens) - (string=? (last tokens) "\\")) - (define (valid-token? s) - (< 0 (string-length s))) - (define (drop-continuations tokens) - (let loop ((acc '()) (tks tokens)) - (if (null? tks) - (reverse acc) - (loop (if (string=? "\\" (car tks)) - acc - (cons (car tks) acc)) (cdr tks))))) - (let next ((acc '()) (found #f)) - (let ((line (read-line port))) - (if (eof-object? line) - acc - (let ((tokens (filter valid-token? - (string-splitp (string-trim char-whitespace? - line) - char-whitespace? -1)))) - (cond - ((or (null? tokens) - (string-prefix? (car tokens) "#") - (and (not found) (not (and (string=? key (car tokens)) - (string=? "=" (cadr tokens)))))) - (next acc found)) - ((not found) - (assert (and (string=? key (car tokens)) - (string=? "=" (cadr tokens)))) - (if (is-continuation? tokens) - (next (drop-continuations (cddr tokens)) #t) - (drop-continuations (cddr tokens)))) - (else - (assert found) - (if (is-continuation? tokens) - (next (append acc (drop-continuations tokens)) found) - (append acc (drop-continuations tokens)))))))))) - -(define (parse-makefile-expand filename expand key) - (define (variable? v) - (and (string-prefix? v "$(") (string-suffix? v ")"))) - - (let expand-all ((values (parse-makefile (open-input-file filename) key))) - (if (any variable? values) - (expand-all - (let expand-one ((acc '()) (v values)) - (cond - ((null? v) - acc) - ((variable? (car v)) - (let ((makefile (open-input-file filename)) - (key (substring (car v) 2 (- (string-length (car v)) 1)))) - (expand-one (append acc (expand filename makefile key)) - (cdr v)))) - (else - (expand-one (append acc (list (car v))) (cdr v)))))) - values))) - (define python (let loop ((pythons (list "python" "python2" "python3"))) (if (null? pythons) #f (catch (loop (cdr pythons)) (unless (file-exists? (path-join gpgme-builddir "lang" "python" (string-append (car pythons) "-gpg"))) (throw "next please")) (path-expand (car pythons) (string-split (getenv "PATH") *pathsep*)))))) (define (run-python-tests?) (not (not python))) diff --git a/tests/gpgscm/Makefile.am b/tests/gpgscm/Makefile.am index 1bdd3737b..44d7b3f96 100644 --- a/tests/gpgscm/Makefile.am +++ b/tests/gpgscm/Makefile.am @@ -1,63 +1,64 @@ # TinyScheme-based test driver. # # 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 . EXTRA_DIST = \ LICENSE.TinySCHEME \ Manual.txt \ ffi.scm \ init.scm \ lib.scm \ + makefile.scm \ repl.scm \ t-child.scm \ xml.scm \ tests.scm \ gnupg.scm \ time.scm AM_CPPFLAGS = -I$(top_srcdir)/common include $(top_srcdir)/am/cmacros.am AM_CFLAGS = CLEANFILES = bin_PROGRAMS = gpgscm noinst_PROGRAMS = t-child common_libs = ../$(libcommon) commonpth_libs = ../$(libcommonpth) gpgscm_CFLAGS = -imacros scheme-config.h \ $(LIBGCRYPT_CFLAGS) $(LIBASSUAN_CFLAGS) $(GPG_ERROR_CFLAGS) gpgscm_SOURCES = main.c private.h ffi.c ffi.h ffi-private.h \ scheme-config.h scheme.c scheme.h scheme-private.h \ opdefines.h small-integers.h gpgscm_LDADD = $(LDADD) $(common_libs) \ $(NETLIBS) $(LIBICONV) $(LIBREADLINE) $(LIBINTL) \ $(LIBGCRYPT_LIBS) $(GPG_ERROR_LIBS) t_child_SOURCES = t-child.c # Make sure that all libs are build before we use them. This is # important for things like make -j2. $(PROGRAMS): $(common_libs) check-local: gpgscm$(EXEEXT) t-child$(EXEEXT) EXEEXT=$(EXEEXT) GPGSCM_PATH=$(srcdir) \ ./gpgscm$(EXEEXT) $(srcdir)/t-child.scm diff --git a/tests/gpgscm/makefile.scm b/tests/gpgscm/makefile.scm new file mode 100644 index 000000000..32fae3a89 --- /dev/null +++ b/tests/gpgscm/makefile.scm @@ -0,0 +1,76 @@ +;; Support for parsing Makefiles +;; +;; 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 . + +(define (parse-makefile port key) + (define (is-continuation? tokens) + (string=? (last tokens) "\\")) + (define (valid-token? s) + (< 0 (string-length s))) + (define (drop-continuations tokens) + (let loop ((acc '()) (tks tokens)) + (if (null? tks) + (reverse acc) + (loop (if (string=? "\\" (car tks)) + acc + (cons (car tks) acc)) (cdr tks))))) + (let next ((acc '()) (found #f)) + (let ((line (read-line port))) + (if (eof-object? line) + acc + (let ((tokens (filter valid-token? + (string-splitp (string-trim char-whitespace? + line) + char-whitespace? -1)))) + (cond + ((or (null? tokens) + (string-prefix? (car tokens) "#") + (and (not found) (not (and (string=? key (car tokens)) + (string=? "=" (cadr tokens)))))) + (next acc found)) + ((not found) + (assert (and (string=? key (car tokens)) + (string=? "=" (cadr tokens)))) + (if (is-continuation? tokens) + (next (drop-continuations (cddr tokens)) #t) + (drop-continuations (cddr tokens)))) + (else + (assert found) + (if (is-continuation? tokens) + (next (append acc (drop-continuations tokens)) found) + (append acc (drop-continuations tokens)))))))))) + +(define (parse-makefile-expand filename expand key) + (define (variable? v) + (and (string-prefix? v "$(") (string-suffix? v ")"))) + + (let expand-all ((values (parse-makefile (open-input-file filename) key))) + (if (any variable? values) + (expand-all + (let expand-one ((acc '()) (v values)) + (cond + ((null? v) + acc) + ((variable? (car v)) + (let ((makefile (open-input-file filename)) + (key (substring (car v) 2 (- (string-length (car v)) 1)))) + (expand-one (append acc (expand filename makefile key)) + (cdr v)))) + (else + (expand-one (append acc (list (car v))) (cdr v)))))) + values)))