Debian Codegraph @

test-suite/tests/dwarf.test

raw
1 ;;;; dwarf.test -*- scheme -*-
2 ;;;;
3 ;;;; Copyright 2013, 2021 Free Software Foundation, Inc.
4 ;;;;
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
9 ;;;;
10 ;;;; This library 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 GNU
13 ;;;; Lesser General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free Software
17 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19 (define-module (test-suite test-dwarf)
20 #:use-module (test-suite lib)
21 #:use-module (ice-9 match)
22 #:use-module (system base compile)
23 #:use-module (system vm debug)
24 #:use-module (system vm program)
25 #:use-module (system vm loader))
26
27 (define prog
28 (string-concatenate
29 ;; The start of every datum is a possible source location.
30 '("(define (qux f)\n"
31 ;^ 0:0
32 " (+ 32 (f)))\n"
33 ; ^1:2 ^1:8
34 "\n"
35 "(define bar\n"
36 ;^ 3;0
37 " (lambda (a)\n"
38 ; ^ 4:2
39 " 13))\n"
40 ; ^ 5:4
41 "'success\n")
42 ))
43
44 (let* ((port (open-input-string prog))
45 (bv (begin
46 (set-port-filename! port "foo.scm")
47 (read-and-compile port #:to 'bytecode))))
48 (pass-if-equal 'success
49 ((load-thunk-from-memory bv)))
50
51 (pass-if-equal 13 (bar 10))
52
53 (let ((source (find-source-for-addr (program-code qux))))
54 (pass-if-equal "foo.scm" (source-file source))
55 (pass-if-equal 0 (source-line source))
56 (pass-if-equal 1 (source-line-for-user source))
57 (pass-if-equal 0 (source-column source)))
58
59 (let ((source (find-source-for-addr (program-code bar))))
60 (pass-if-equal "foo.scm" (source-file source))
61 (pass-if-equal 4 (source-line source))
62 (pass-if-equal 5 (source-line-for-user source))
63 (pass-if-equal 2 (source-column source)))
64
65 (match (find-program-sources (program-code qux))
66 ((s1 s2 s3)
67 (pass-if-equal "foo.scm" (source-file s1))
68 (pass-if-equal 0 (source-line s1))
69 (pass-if-equal 1 (source-line-for-user s1))
70 (pass-if-equal 0 (source-column s1))
71
72 (pass-if-equal "foo.scm" (source-file s2))
73 (pass-if-equal 1 (source-line s2))
74 (pass-if-equal 2 (source-line-for-user s2))
75 (pass-if-equal 8 (source-column s2))
76
77 (pass-if-equal "foo.scm" (source-file s3))
78 (pass-if-equal 1 (source-line s3))
79 (pass-if-equal 2 (source-line-for-user s3))
80 (pass-if-equal 2 (source-column s3)))
81 (sources
82 (error "unexpected sources" sources)))
83
84 (match (find-program-sources (program-code bar))
85 ((s1 s2)
86 (pass-if-equal "foo.scm" (source-file s1))
87 (pass-if-equal 4 (source-line s1))
88 (pass-if-equal 5 (source-line-for-user s1))
89 (pass-if-equal 2 (source-column s1))
90
91 (pass-if-equal "foo.scm" (source-file s2))
92 (pass-if-equal 5 (source-line s2))
93 (pass-if-equal 6 (source-line-for-user s2))
94 (pass-if-equal 4 (source-column s2)))
95 (sources
96 (error "unexpected sources" sources))))