1 # Copyright 2022-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test a binary that uses SVE and exercise changing the SVE vector length.
18 require allow_aarch64_sve_tests
21 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
25 set linespec ${srcfile}:[gdb_get_line_number "break here"]
27 if ![runto ${linespec}] {
31 # Count number of lines in "info registers" output.
32 proc count_info_registers {} {
36 gdb_test_multiple "info all-registers" "" {
37 -re ".*$gdb_prompt $" {
38 set ret [count_newlines $expect_out(buffer)]
45 proc get_register_value {register} {
49 gdb_test_multiple "print \$${register}" "" {
50 -re ". = \[0-9\]+\r\n$gdb_prompt $" {
51 regexp {. = ([0-9]+)} $expect_out(buffer) matched ret
53 -re ".*$gdb_prompt $" {
60 # The test executable halves the vector length in a loop, so loop along
62 for {set i [get_register_value "vg"]} {$i > 1} {set i [expr $i / 2]} {
63 set lines_before [count_info_registers]
65 gdb_test "next" ".*if .res < 0." "step over prctl vg = ${i}"
67 set lines_after [count_info_registers]
69 # There was a bug where GDB would lose track of some registers when the
70 # vector length changed. Make sure they're still all there.
71 if {${lines_before} == ${lines_after}} {
72 pass "same number of registers vg = ${i}"
74 fail "same number of registers vg = ${i}"
77 gdb_test "print \$vg" ". = ${i}" "vg was changed to ${i}"
79 set size_after [expr {$i * 8}]
81 for {set j 0} {$j < 32} {set j [incr j]} {
82 gdb_test "print sizeof(\$z$j)" ". = ${size_after}" "z$j has ${size_after} bytes"
85 gdb_test_multiple "continue" "" {
86 -re ".*Breakpoint $decimal, do_sve_ioctl_test .*$gdb_prompt $" {
89 -re "Inferior 1 .* exited normally.*$gdb_prompt $" {
94 fail "unexpected output"