1 # Copyright 2021-2024 Free Software Foundation, Inc. 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 # Testing GDB's implementation of ASSUMED RANK arrays. 17 18 require allow_fortran_tests 19 20 standard_testfile ".f90" 21 load_lib fortran.exp 22 23 # Only gcc version >=11 supports assumed rank arrays. 24 if { [test_compiler_info {gfortran-*} f90] && 25 ![test_compiler_info {gfortran-1[1-9]-*} f90] } { 26 untested "compiler does not support assumed rank" 27 return -1 28 } 29 30 if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} \ 31 {debug f90 additional_flags=-gdwarf-5}]} { 32 return -1 33 } 34 35 if ![fortran_runto_main] { 36 untested "could not run to main" 37 return -1 38 } 39 40 gdb_breakpoint [gdb_get_line_number "Test Breakpoint"] 41 gdb_breakpoint [gdb_get_line_number "Final Breakpoint"] 42 43 # We place a limit on the number of tests that can be run, just in 44 # case something goes wrong, and GDB gets stuck in an loop here. 45 set found_final_breakpoint false 46 set test_count 0 47 while { $test_count < 500 } { 48 with_test_prefix "test $test_count" { 49 incr test_count 50 51 gdb_test_multiple "continue" "continue" { 52 -re -wrap "! Test Breakpoint" { 53 # We can run a test from here. 54 } 55 -re "! Final Breakpoint" { 56 # We're done with the tests. 57 set found_final_breakpoint true 58 } 59 } 60 61 # Currently, flang does not support rank0. 62 if { $test_count == 1 && [test_compiler_info {flang-*} f90] } { 63 unsupported "compiler does not support rank 0" 64 continue 65 } 66 67 if ($found_final_breakpoint) { 68 break 69 } 70 71 # First grab the information from the assumed rank array. 72 set answer_rank [get_valueof "" "rank(answer)" "**unknown**"] 73 set answer_content [get_valueof "" "answer" "**unknown**"] 74 75 # Now move up a frame and find the name of a non-assumed rank array 76 # which we can use to check the values we got above. 77 set test_array "" 78 gdb_test_multiple "up" "" { 79 -re -wrap "\r\n\[0-9\]+\[ \t\]+call test_rank \\((\[^\r\n\]+)\\)" { 80 set test_array $expect_out(1,string) 81 } 82 } 83 gdb_assert { ![string equal $test_array ""] } \ 84 "found the name of a test array to check against" 85 86 # Check we got the correct array rank. 87 gdb_test "p rank($test_array)" " = $answer_rank" 88 89 # Check we got the correct array content. 90 set content [get_valueof "" "$test_array" "**unknown**"] 91 gdb_assert { [string equal $content $answer_content] } \ 92 "answer array contains the expected contents" 93 } 94 } 95 96 # Ensure we reached the final breakpoint. If more tests have been added 97 # to the test script, and this starts failing, then the safety 'while' 98 # loop above might need to be increased. 99 gdb_assert {$found_final_breakpoint} "ran all compiled in tests" 100