1 ;;; run-vm-tests.scm -- Run Guile-VM's test suite.
3 ;;; Copyright 2005, 2009, 2010, 2013 Free Software Foundation, Inc.
5 ;;; This program is free software; you can redistribute it and/or
6 ;;; modify it under the terms of the GNU Lesser General Public License
7 ;;; as published by the Free Software Foundation; either version 3 of
8 ;;; the License, or (at your option) any later version.
10 ;;; This program is distributed in the hope that it will be useful,
11 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;; GNU Lesser General Public License for more details.
15 ;;; You should have received a copy of the GNU Lesser General Public License
16 ;;; along with this program; if not, write to the Free Software
17 ;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 (use-modules (system vm vm)
24 (system base language)
29 (define (fetch-sexp-from-file file)
30 (with-input-from-file file
32 (let loop ((sexp (read))
34 (if (eof-object? sexp)
35 (cons 'begin (reverse result))
36 (loop (read) (cons sexp result)))))))
38 (define (compile-to-objcode sexp)
39 "Compile the expression @var{sexp} into a VM program and return it."
40 (compile sexp #:from 'scheme #:to 'rtl))
42 (define (run-vm-program bv)
43 "Run VM program contained into @var{bv}."
44 ((load-thunk-from-memory bv)))
46 (define (compile/run-test-from-file file)
47 "Run test from source file @var{file} and return a value indicating whether
49 (run-vm-program (compile-to-objcode (fetch-sexp-from-file file))))
52 (define-macro (watch-proc proc-name str)
53 `(let ((orig-proc ,proc-name))
56 (format #t (string-append ,str "... "))
57 (apply orig-proc args)))))
59 (watch-proc fetch-sexp-from-file "reading")
60 (watch-proc compile-to-objcode "compiling")
61 (watch-proc run-vm-program "running")
66 (define (run-vm-tests files)
67 "For each file listed in @var{files}, load it and run it through both the
68 interpreter and the VM (after having it compiled). Both results must be
69 equal in the sense of @code{equal?}."
70 (let* ((res (map (lambda (file)
71 (format #t "running `~a'... " file)
74 (equal? (compile/run-test-from-file file)
75 (primitive-eval (fetch-sexp-from-file file))))
77 (format #t "[~a/~a] " key args)
80 (begin (format #t "FAILED~%") #f)))
82 (total (length files))
83 (failed (length (filter not res))))
88 (format #t "~%~a tests failed out of ~a~%"