summaryrefslogtreecommitdiff
path: root/testsuite/run-vm-tests.scm
blob: 64568b17127b34d88fce639a864fce6376f740fe (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
;;; run-vm-tests.scm -- Run Guile-VM's test suite.
;;;
;;; Copyright 2005  Ludovic Court�s <ludovic.courtes@laas.fr>
;;;
;;;
;;; This program 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 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program 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, write to the Free Software
;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA


(use-modules (system vm core)
	     (system vm disasm)
	     (system base compile)
	     (system base language)

	     (srfi srfi-1)
	     (ice-9 r5rs))


(define %scheme (lookup-language 'scheme))

(define (fetch-sexp-from-file file)
  (with-input-from-file file
    (lambda ()
      (let loop ((sexp (read))
		 (result '()))
	(if (eof-object? sexp)
	    (cons 'begin (reverse result))
	    (loop (read) (cons sexp result)))))))

(define (compile-to-objcode sexp)
  "Compile the expression @var{sexp} into a VM program and return it."
  (compile-in sexp (current-module) %scheme))

(define (run-vm-program objcode)
  "Run VM program contained into @var{objcode}."
  (vm-load (the-vm) objcode))

(define (compile/run-test-from-file file)
  "Run test from source file @var{file} and return a value indicating whether
it succeeded."
  (run-vm-program (compile-to-objcode (fetch-sexp-from-file file))))


(define-macro (watch-proc proc-name str)
  `(let ((orig-proc ,proc-name))
     (set! ,proc-name
	   (lambda args
	     (format #t (string-append ,str "...  "))
	     (apply orig-proc args)))))

(watch-proc fetch-sexp-from-file  "reading")
(watch-proc compile-to-objcode    "compiling")
(watch-proc run-vm-program        "running")


;; The program.

(define (run-vm-tests files)
  "For each file listed in @var{files}, load it and run it through both the
interpreter and the VM (after having it compiled).  Both results must be
equal in the sense of @var{equal?}."
  (let* ((res (map (lambda (file)
		     (format #t "running `~a'...  " file)
		     (if (catch #t
				(lambda ()
				  (equal? (compile/run-test-from-file file)
					  (eval (fetch-sexp-from-file file)
						(interaction-environment))))
				(lambda (key . args)
				  (format #t "[~a/~a] " key args)
				  #f))
			 (format #t "ok~%")
			 (begin (format #t "FAILED~%") #f)))
		   files))
	 (total (length files))
	 (failed (length (filter not res))))

    (if (= 0 failed)
	(begin
	  (format #t "~%All ~a tests passed~%" total)
	  (exit 0))
	(begin
	  (format #t "~%~a tests failed out of ~a~%"
		  failed total)
	  (exit failed)))))