blob: 314db3a1fe55b19cbaecac2c6e1dbc0b8ee61ef4 (
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# Copyright (C) 2014-2017 Free Software Foundation, Inc.
# 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 3 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, see <http://www.gnu.org/licenses/>.
# This file is part of the GDB testsuite.
# It tests GDB provided ports.
load_lib gdb-guile.exp
standard_testfile
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
return
}
# Skip all tests if Guile scripting is not enabled.
if { [skip_guile_tests] } { continue }
if ![gdb_guile_runto_main] {
return
}
gdb_reinitialize_dir $srcdir/$subdir
gdb_install_guile_utils
gdb_install_guile_module
gdb_scm_test_silent_cmd "guile (use-modules (rnrs io ports) (rnrs bytevectors))" \
"import (rnrs io ports) (rnrs bytevectors)"
gdb_test "guile (print (stdio-port? 42))" "= #f"
gdb_test "guile (print (stdio-port? (%make-void-port \"r\")))" "= #f"
gdb_test "guile (print (stdio-port? (input-port)))" "= #t"
gdb_test "guile (print (stdio-port? (output-port)))" "= #t"
gdb_test "guile (print (stdio-port? (error-port)))" "= #t"
# Test memory port open/close.
proc test_port { mode } {
with_test_prefix "basic $mode tests" {
gdb_test_no_output "guile (define my-port (open-memory #:mode \"$mode\"))" \
"create memory port"
gdb_test "guile (print (memory-port? my-port))" "= #t"
switch -glob $mode {
"r+*" {
gdb_test "guile (print (input-port? my-port))" "= #t"
gdb_test "guile (print (output-port? my-port))" "= #t"
}
"r*" {
gdb_test "guile (print (input-port? my-port))" "= #t"
gdb_test "guile (print (output-port? my-port))" "= #f"
}
"w*" {
gdb_test "guile (print (input-port? my-port))" "= #f"
gdb_test "guile (print (output-port? my-port))" "= #t"
}
default {
error "bad test mode"
}
}
gdb_test "guile (print (port-closed? my-port))" "= #f" \
"test port-closed? before it's closed"
gdb_test "guile (print (close-port my-port))" "= #t"
gdb_test "guile (print (port-closed? my-port))" "= #t" \
"test port-closed? after it's closed"
}
}
set port_variations { r w r+ rb wb r+b r0 w0 r+0 }
foreach variation $port_variations {
test_port $variation
}
# Test read/write of memory ports.
proc test_mem_port_rw { kind } {
if { "$kind" == "buffered" } {
set buffered 1
} else {
set buffered 0
}
with_test_prefix $kind {
if $buffered {
set mode "r+"
} else {
set mode "r+0"
}
gdb_test_no_output "guile (define rw-mem-port (open-memory #:mode \"$mode\"))" \
"create r/w memory port"
gdb_test "guile (print rw-mem-port)" \
"#<input-output: gdb:memory-port 0x0-0xf+>"
gdb_test_no_output "guile (define sp-reg (parse-and-eval \"\$sp\"))" \
"get sp reg"
# Note: Only use $sp_reg for gdb_test result matching, don't use it in
# gdb commands. Otherwise transcript.N becomes unusable.
set sp_reg [get_integer_valueof "\$sp" 0]
gdb_test_no_output "guile (define byte-at-sp (parse-and-eval \"*(char*) \$sp\"))" \
"save current value at sp"
# Pass the result of parse-and-eval through value-fetch-lazy!,
# otherwise the value gets left as a lazy reference to memory, which
# when re-evaluated after we flush the write will yield the newly
# written value. PR 18175
gdb_test_no_output "guile (value-fetch-lazy! byte-at-sp)" \
"un-lazyify byte-at-sp"
gdb_test "guile (print (seek rw-mem-port (value->integer sp-reg) SEEK_SET))" \
"= $sp_reg" \
"seek to \$sp"
gdb_test_no_output "guile (define old-value (value->integer byte-at-sp))" \
"define old-value"
gdb_test_no_output "guile (define new-value (logxor old-value 1))" \
"define new-value"
gdb_test "guile (print (put-bytevector rw-mem-port (make-bytevector 1 new-value)))" \
"= #<unspecified>"
if $buffered {
# Value shouldn't be in memory yet.
gdb_test "guile (print (value=? (parse-and-eval \"*(char*) \$sp\") byte-at-sp))" \
"= #t" \
"test byte at sp, before flush"
gdb_test_no_output "guile (force-output rw-mem-port)" \
"flush port"
}
# Value should be in memory now.
gdb_test "guile (print (value=? (parse-and-eval \"*(char*) \$sp\") byte-at-sp))" \
"= #f" \
"test byte at sp, after flush"
# Restore the value for cleanliness sake, and to verify close-port
# flushes the buffer.
gdb_test "guile (print (seek rw-mem-port (value->integer sp-reg) SEEK_SET))" \
"= $sp_reg" \
"seek to \$sp for restore"
gdb_test "guile (print (put-bytevector rw-mem-port (make-bytevector 1 old-value)))" \
"= #<unspecified>"
gdb_test "guile (print (close-port rw-mem-port))" \
"= #t"
gdb_test "guile (print (value=? (parse-and-eval \"*(char*) \$sp\") byte-at-sp))" \
"= #t" \
"test byte at sp, after close"
}
}
test_mem_port_rw buffered
test_mem_port_rw unbuffered
# Test zero-length memory ports.
gdb_test_no_output "guile (define zero-mem-port (open-memory #:start 0 #:size 0 #:mode \"r+\"))" \
"create zero length memory port"
gdb_test "guile (print (read-char zero-mem-port))" \
"= #<eof>"
gdb_test "guile (print (write-char #\\a zero-mem-port))" \
"ERROR: .*Out of range: writing beyond end of memory range.*Error while executing Scheme code."
gdb_test "guile (print (get-bytevector-n zero-mem-port 0))" \
"= #vu8\\(\\)"
gdb_test "guile (print (put-bytevector zero-mem-port (make-bytevector 0)))" \
"= #<unspecified>"
gdb_test "guile (print (close-port zero-mem-port))" "= #t"
|