]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright (C) 2014-2024 Free Software Foundation, Inc. |
ed3ef339 DE |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # This file is part of the GDB testsuite. | |
17 | # It tests GDB provided ports. | |
18 | ||
19 | load_lib gdb-guile.exp | |
20 | ||
e71b6502 TT |
21 | require allow_guile_tests |
22 | ||
37442ce1 DE |
23 | standard_testfile |
24 | ||
5b362f04 | 25 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { |
37442ce1 DE |
26 | return |
27 | } | |
ed3ef339 | 28 | |
37442ce1 DE |
29 | if ![gdb_guile_runto_main] { |
30 | return | |
31 | } | |
32 | ||
ed3ef339 DE |
33 | gdb_reinitialize_dir $srcdir/$subdir |
34 | ||
35 | gdb_install_guile_utils | |
36 | gdb_install_guile_module | |
37 | ||
37442ce1 DE |
38 | gdb_scm_test_silent_cmd "guile (use-modules (rnrs io ports) (rnrs bytevectors))" \ |
39 | "import (rnrs io ports) (rnrs bytevectors)" | |
40 | ||
ed3ef339 DE |
41 | gdb_test "guile (print (stdio-port? 42))" "= #f" |
42 | gdb_test "guile (print (stdio-port? (%make-void-port \"r\")))" "= #f" | |
43 | gdb_test "guile (print (stdio-port? (input-port)))" "= #t" | |
44 | gdb_test "guile (print (stdio-port? (output-port)))" "= #t" | |
45 | gdb_test "guile (print (stdio-port? (error-port)))" "= #t" | |
37442ce1 DE |
46 | |
47 | # Test memory port open/close. | |
48 | ||
49 | proc test_port { mode } { | |
50 | with_test_prefix "basic $mode tests" { | |
51 | gdb_test_no_output "guile (define my-port (open-memory #:mode \"$mode\"))" \ | |
52 | "create memory port" | |
53 | gdb_test "guile (print (memory-port? my-port))" "= #t" | |
54 | switch -glob $mode { | |
55 | "r+*" { | |
56 | gdb_test "guile (print (input-port? my-port))" "= #t" | |
57 | gdb_test "guile (print (output-port? my-port))" "= #t" | |
58 | } | |
59 | "r*" { | |
60 | gdb_test "guile (print (input-port? my-port))" "= #t" | |
61 | gdb_test "guile (print (output-port? my-port))" "= #f" | |
62 | } | |
63 | "w*" { | |
64 | gdb_test "guile (print (input-port? my-port))" "= #f" | |
65 | gdb_test "guile (print (output-port? my-port))" "= #t" | |
66 | } | |
67 | default { | |
68 | error "bad test mode" | |
69 | } | |
70 | } | |
71 | gdb_test "guile (print (port-closed? my-port))" "= #f" \ | |
72 | "test port-closed? before it's closed" | |
73 | gdb_test "guile (print (close-port my-port))" "= #t" | |
74 | gdb_test "guile (print (port-closed? my-port))" "= #t" \ | |
75 | "test port-closed? after it's closed" | |
76 | } | |
77 | } | |
78 | ||
79 | set port_variations { r w r+ rb wb r+b r0 w0 r+0 } | |
80 | foreach variation $port_variations { | |
81 | test_port $variation | |
82 | } | |
83 | ||
84 | # Test read/write of memory ports. | |
85 | ||
31131df0 SM |
86 | proc test_mem_port_rw { buffered } { |
87 | if $buffered { | |
88 | set mode "r+" | |
37442ce1 | 89 | } else { |
31131df0 | 90 | set mode "r+0" |
37442ce1 | 91 | } |
31131df0 SM |
92 | gdb_test_no_output "guile (define rw-mem-port (open-memory #:mode \"$mode\"))" \ |
93 | "create r/w memory port" | |
94 | gdb_test "guile (print rw-mem-port)" \ | |
95 | "#<input-output: gdb:memory-port 0x0-0xf+>" | |
96 | gdb_test_no_output "guile (define sp-reg (parse-and-eval \"\$sp\"))" \ | |
97 | "get sp reg" | |
98 | # Note: Only use $sp_reg for gdb_test result matching, don't use it in | |
99 | # gdb commands. Otherwise transcript.N becomes unusable. | |
100 | set sp_reg [get_valueof /u "\$sp" 0] | |
101 | gdb_test_no_output "guile (define byte-at-sp (parse-and-eval \"*(char*) \$sp\"))" \ | |
102 | "save current value at sp" | |
103 | # Pass the result of parse-and-eval through value-fetch-lazy!, | |
104 | # otherwise the value gets left as a lazy reference to memory, which | |
105 | # when re-evaluated after we flush the write will yield the newly | |
106 | # written value. PR 18175 | |
107 | gdb_test_no_output "guile (value-fetch-lazy! byte-at-sp)" \ | |
108 | "un-lazyify byte-at-sp" | |
109 | gdb_test "guile (print (seek rw-mem-port (value->integer sp-reg) SEEK_SET))" \ | |
110 | "= $sp_reg" \ | |
111 | "seek to \$sp" | |
112 | gdb_test_no_output "guile (define old-value (value->integer byte-at-sp))" \ | |
113 | "define old-value" | |
114 | gdb_test_no_output "guile (define new-value (logxor old-value 1))" \ | |
115 | "define new-value" | |
116 | gdb_test "guile (print (put-bytevector rw-mem-port (make-bytevector 1 new-value)))" \ | |
117 | "= #<unspecified>" | |
118 | if $buffered { | |
119 | # Value shouldn't be in memory yet. | |
37442ce1 DE |
120 | gdb_test "guile (print (value=? (parse-and-eval \"*(char*) \$sp\") byte-at-sp))" \ |
121 | "= #t" \ | |
31131df0 SM |
122 | "test byte at sp, before flush" |
123 | gdb_test_no_output "guile (force-output rw-mem-port)" \ | |
124 | "flush port" | |
37442ce1 | 125 | } |
31131df0 SM |
126 | # Value should be in memory now. |
127 | gdb_test "guile (print (value=? (parse-and-eval \"*(char*) \$sp\") byte-at-sp))" \ | |
128 | "= #f" \ | |
129 | "test byte at sp, after flush" | |
130 | # Restore the value for cleanliness sake, and to verify close-port | |
131 | # flushes the buffer. | |
132 | gdb_test "guile (print (seek rw-mem-port (value->integer sp-reg) SEEK_SET))" \ | |
133 | "= $sp_reg" \ | |
134 | "seek to \$sp for restore" | |
135 | gdb_test "guile (print (put-bytevector rw-mem-port (make-bytevector 1 old-value)))" \ | |
136 | "= #<unspecified>" | |
137 | gdb_test "guile (print (close-port rw-mem-port))" \ | |
138 | "= #t" | |
139 | gdb_test "guile (print (value=? (parse-and-eval \"*(char*) \$sp\") byte-at-sp))" \ | |
140 | "= #t" \ | |
141 | "test byte at sp, after close" | |
37442ce1 DE |
142 | } |
143 | ||
31131df0 SM |
144 | foreach_with_prefix buffered {1 0} { |
145 | test_mem_port_rw $buffered | |
146 | } | |
37442ce1 DE |
147 | |
148 | # Test zero-length memory ports. | |
149 | ||
150 | gdb_test_no_output "guile (define zero-mem-port (open-memory #:start 0 #:size 0 #:mode \"r+\"))" \ | |
151 | "create zero length memory port" | |
152 | gdb_test "guile (print (read-char zero-mem-port))" \ | |
153 | "= #<eof>" | |
154 | gdb_test "guile (print (write-char #\\a zero-mem-port))" \ | |
155 | "ERROR: .*Out of range: writing beyond end of memory range.*Error while executing Scheme code." | |
156 | gdb_test "guile (print (get-bytevector-n zero-mem-port 0))" \ | |
157 | "= #vu8\\(\\)" | |
158 | gdb_test "guile (print (put-bytevector zero-mem-port (make-bytevector 0)))" \ | |
159 | "= #<unspecified>" | |
160 | gdb_test "guile (print (close-port zero-mem-port))" "= #t" |