From ae07b8e70bfc53220d7017bb7edcdb6c329d5bd5 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Thu, 3 Oct 2013 16:13:56 +0200 Subject: [PATCH] Add source location test * test-suite/tests/dwarf.test: New test, testing that source location information survives the round-trip through the compiler, back out to the (system vm debug) interfaces. --- test-suite/Makefile.am | 1 + test-suite/tests/dwarf.test | 88 +++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 test-suite/tests/dwarf.test diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index c4e4d1f55..19789db86 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -42,6 +42,7 @@ SCM_TESTS = tests/00-initial-env.test \ tests/coverage.test \ tests/cse.test \ tests/curried-definitions.test \ + tests/dwarf.test \ tests/ecmascript.test \ tests/elisp.test \ tests/elisp-compiler.test \ diff --git a/test-suite/tests/dwarf.test b/test-suite/tests/dwarf.test new file mode 100644 index 000000000..b999ab13e --- /dev/null +++ b/test-suite/tests/dwarf.test @@ -0,0 +1,88 @@ +;;;; dwarf.test -*- scheme -*- +;;;; +;;;; Copyright 2013 Free Software Foundation, Inc. +;;;; +;;;; This library is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU Lesser General Public +;;;; License as published by the Free Software Foundation; either +;;;; version 3 of the License, or (at your option) any later version. +;;;; +;;;; This library 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 +;;;; Lesser General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU Lesser General Public +;;;; License along with this library; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +(define-module (test-suite test-dwarf) + #:use-module (test-suite lib) + #:use-module (ice-9 match) + #:use-module (system base compile) + #:use-module (system vm debug) + #:use-module (system vm program) + #:use-module (system vm objcode)) + +(define prog + (string-concatenate + ;; Every open parenthesis is a possible source location. + '("(define (qux f)\n" + ;^ 0:0 + " (+ 32 (f)))\n" + ; ^1:2 ^1:8 + "\n" + "(define bar\n" + ;^ 3;0 + " (lambda (a)\n" + ; ^ 4:2 + " 13))\n" + "'success\n") + )) + +(let* ((port (open-input-string prog)) + (bv (begin + (set-port-filename! port "foo.scm") + (read-and-compile port #:to 'rtl)))) + (pass-if-equal 'success + ((load-thunk-from-memory bv))) + + (pass-if-equal 13 (bar 10)) + + (let ((source (find-source-for-addr (rtl-program-code qux)))) + (pass-if-equal "foo.scm" (source-file source)) + (pass-if-equal 0 (source-line source)) + (pass-if-equal 1 (source-line-for-user source)) + (pass-if-equal 0 (source-column source))) + + (let ((source (find-source-for-addr (rtl-program-code bar)))) + (pass-if-equal "foo.scm" (source-file source)) + (pass-if-equal 4 (source-line source)) + (pass-if-equal 5 (source-line-for-user source)) + (pass-if-equal 2 (source-column source))) + + (match (find-program-sources (rtl-program-code qux)) + ((s1 s2) + (pass-if-equal "foo.scm" (source-file s1)) + (pass-if-equal 0 (source-line s1)) + (pass-if-equal 1 (source-line-for-user s1)) + (pass-if-equal 0 (source-column s1)) + + ;; FIXME: For some reason the source location for the + isn't + ;; getting propagated. + + (pass-if-equal "foo.scm" (source-file s2)) + (pass-if-equal 1 (source-line s2)) + (pass-if-equal 2 (source-line-for-user s2)) + (pass-if-equal 8 (source-column s2))) + (sources + (error "unexpected sources" sources))) + + (match (find-program-sources (rtl-program-code bar)) + ((source) + (pass-if-equal "foo.scm" (source-file source)) + (pass-if-equal 4 (source-line source)) + (pass-if-equal 5 (source-line-for-user source)) + (pass-if-equal 2 (source-column source))) + (sources + (error "unexpected sources" sources))))