run-vm-tests.scm 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; run-vm-tests.scm -- Run Guile-VM's test suite.
  2. ;;;
  3. ;;; Copyright 2005, 2009, 2010, 2013 Free Software Foundation, Inc.
  4. ;;;
  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.
  9. ;;;
  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.
  14. ;;;
  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
  18. (use-modules (system vm vm)
  19. (system vm loader)
  20. (system vm program)
  21. (system base compile)
  22. (system base language)
  23. (srfi srfi-1)
  24. (ice-9 r5rs))
  25. (define (fetch-sexp-from-file file)
  26. (with-input-from-file file
  27. (lambda ()
  28. (let loop ((sexp (read))
  29. (result '()))
  30. (if (eof-object? sexp)
  31. (cons 'begin (reverse result))
  32. (loop (read) (cons sexp result)))))))
  33. (define (compile-to-objcode sexp)
  34. "Compile the expression @var{sexp} into a VM program and return it."
  35. (compile sexp #:from 'scheme #:to 'bytecode))
  36. (define (run-vm-program bv)
  37. "Run VM program contained into @var{bv}."
  38. ((load-thunk-from-memory bv)))
  39. (define (compile/run-test-from-file file)
  40. "Run test from source file @var{file} and return a value indicating whether
  41. it succeeded."
  42. (run-vm-program (compile-to-objcode (fetch-sexp-from-file file))))
  43. (define-macro (watch-proc proc-name str)
  44. `(let ((orig-proc ,proc-name))
  45. (set! ,proc-name
  46. (lambda args
  47. (format #t (string-append ,str "... "))
  48. (apply orig-proc args)))))
  49. (watch-proc fetch-sexp-from-file "reading")
  50. (watch-proc compile-to-objcode "compiling")
  51. (watch-proc run-vm-program "running")
  52. ;; The program.
  53. (define (run-vm-tests files)
  54. "For each file listed in @var{files}, load it and run it through both the
  55. interpreter and the VM (after having it compiled). Both results must be
  56. equal in the sense of @code{equal?}."
  57. (let* ((res (map (lambda (file)
  58. (format #t "running `~a'... " file)
  59. (if (catch #t
  60. (lambda ()
  61. (equal? (compile/run-test-from-file file)
  62. (primitive-eval (fetch-sexp-from-file file))))
  63. (lambda (key . args)
  64. (format #t "[~a/~a] " key args)
  65. #f))
  66. (format #t "ok~%")
  67. (begin (format #t "FAILED~%") #f)))
  68. files))
  69. (total (length files))
  70. (failed (length (filter not res))))
  71. (if (= 0 failed)
  72. (exit 0)
  73. (begin
  74. (format #t "~%~a tests failed out of ~a~%"
  75. failed total)
  76. (exit failed)))))