aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.arch/s390-vregs.exp
blob: c1e85b4c914309e7da3dab803ff4a194f56f1aee (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# Copyright 2015-2016 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/>.

# Test vector register access for s390 platforms.

if { ![istarget s390-*-*] && ![istarget s390x-*-* ] } {
    verbose "Skipping s390 vector register tests."
    return
}

standard_testfile .S

if [isnative] {
    # Create a temporary directory, to take a core dump there later.
    set coredir [standard_output_file ${testfile}.d]
    remote_exec build "rm -rf $coredir"
    remote_exec build "mkdir $coredir"
}

if { [prepare_for_testing ${testfile}.exp $testfile $srcfile \
	  [list "additional_flags=-mzarch"]] } {
    return -1
}

if ![runto_main] {
    untested "could not run to main"
    return -1
}

# Run to the first vector instruction and step it.  If the inferior
# doesn't crash, we have vector support.

gdb_breakpoint "check_vx"
gdb_continue_to_breakpoint "first vector insn"
set before_pc 0
gdb_test_multiple "x/i \$pc" "get PC at vector insn" {
    -re "(0x\\S+)\\s+\\S+\\s+vlr\\s+.*$gdb_prompt $" {
	set before_pc $expect_out(1,string)
    }
}

gdb_test_multiple "stepi" "check for vector support" {
    -re "Program received signal SIGILL,.*\r\n$gdb_prompt $" {
	unsupported "no vector support."
	return
    }
    -re "\[0-9\]+.*\r\n$gdb_prompt $" {
	pass "vector support available"
    }
    -re "$gdb_prompt $" {
	fail "no vector support (unknown error)"
	return
    }
}

# Has the PC advanced by the expected amount?  The kernel may do
# something special for the first vector insn in the process.

set after_pc 0
gdb_test_multiple "x/i \$pc" "get PC after vector insn" {
    -re "(0x\\S+)\\s+.*$gdb_prompt $" {
	set after_pc $expect_out(1,string)
    }
}

if [expr $before_pc + 6 != $after_pc] {
    fail "stepping first vector insn"
}

# Lift the core file limit, if possible, and change into the temporary
# directory.

if { $coredir != "" } {
    gdb_test {print setrlimit (4, &(unsigned long [2]){~0UL, ~0UL})} \
	" = .*" "setrlimit"
    gdb_test "print chdir (\"${coredir}\")" " = 0" "chdir"
}

# Initialize all vector registers with GDB "set" commands, using
# distinct values.  Handle left and right halves separately, in
# pseudo-random order.

set a_high 1
set a_low 2
set b_high 3
set b_low 5

set a [expr ($a_high << 32) | $a_low]
set b [expr ($b_high << 32) | $b_low]

for {set j 0} {$j < 32} {incr j 1} {
    set i [expr 17 * $j % 32]
    gdb_test_no_output \
	"set \$v$i.v2_int64\[0\] = [expr $a * ($i + 1)]" \
	"set v$i left"
    set i [expr 19 * (31 - $j) % 32]
    gdb_test_no_output \
	"set \$v$i.v2_int64\[1\] = [expr $b * (32 - $i)]" \
	"set v$i right"
}

# Verify a vector register's union members.

gdb_test "info register v0 v31" \
    "v4_float .* v2_double .* v16_int8 .* v8_int16 .* v4_int32 .* v2_int64 .* uint128\
     .*v4_float .* v2_double .* v16_int8 .* v8_int16 .* v4_int32 .* v2_int64 .* uint128 .*"

# Let the inferior store all vector registers in a buffer, then dump
# the buffer and check it.

gdb_continue_to_breakpoint "store vrs"
set vregs [capture_command_output "x/64xg &save_area" ""]

set i 0
foreach {- left right} [regexp -all -inline -line {^.*:\s+(\w+)\s+(\w+)} $vregs] {
    if [expr $left != $a * ($i + 1) || $right != $b * (32 - $i)] {
	fail "verify \$v$i after set"
    }
    if { $i < 16 } {
	# Check that the FP register was updated accordingly.
	gdb_test "info register f$i" "raw ${left}.*"
    }
    incr i 1
}

if { $i != 32 } {
    fail "dump save area (bad output)"
}

# Let the inferior change all VRs according to a simple algorithm,
# then print all VRs and compare their values with our result of the
# same algorithm.

gdb_continue_to_breakpoint "change vrs"
set vregs [capture_command_output "info registers vector" ""]

set j 1
foreach {- r i val} [regexp -all -inline -line \
			 {^(\D*)(\d+)\s+.*?uint128 = 0x([0-9a-f]+?)} $vregs] {
    if { $r ne "v" } {
	fail "info registers vector: bad line $j"
    } elseif { $val ne [format %08x%08x%08x%08x \
			    [expr $a_high * ($i + 1) * $a_high ] \
			    [expr $a_low * ($i + 1) * $a_low ] \
			    [expr $b_high * (32 - $i) * $b_high * 32] \
			    [expr $b_low * (32 - $i) * $b_low * 32] ] } {
	fail "compare \$v$i"
    }
    incr j 1
}

if { $j != 33 } {
    fail "info registers vector"
}

if { $coredir == "" } {
    return
}

# Take a core dump.

gdb_test "signal SIGABRT" "Program terminated with signal SIGABRT, .*"
gdb_exit

# Find the core file and rename it (avoid accumulating core files).

set cores [glob -nocomplain -directory $coredir *core*]
if {[llength $cores] != 1} {
    untested "core file not found"
    remote_exec build "rm -rf $coredir"
    return -1
}
set destcore [standard_output_file ${testfile}.core]
remote_exec build "mv [file join $coredir [lindex $cores 0]] $destcore"
remote_exec build "rm -rf $coredir"

# Restart gdb and load the core file.  Compare the VRs.

clean_restart ${testfile}

with_test_prefix "core" {
    set core_loaded [gdb_core_cmd $destcore "load"]
    if { $core_loaded != -1 } {
	set vregs_from_core [capture_command_output "info registers vector" ""]
	if { $vregs_from_core eq $vregs } {
	    pass "compare vector registers"
	} else {
	    fail "vector registers mismatch"
	}
    }
}