Home | History | Annotate | Line # | Download | only in gdb.rocm
      1 # Copyright 2023-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 # This test checks that GDB can debug multiple inferior which uses all
     17 # the ROCm runtime.
     18 
     19 load_lib rocm.exp
     20 
     21 standard_testfile .cpp
     22 
     23 require allow_hipcc_tests
     24 require hip_devices_support_debug_multi_process
     25 
     26 if {[build_executable "failed to prepare" $testfile $srcfile {debug hip}]} {
     27     return
     28 }
     29 
     30 proc do_test {} {
     31     clean_restart $::binfile
     32     gdb_test_no_output "set non-stop on"
     33     gdb_test_no_output "set detach-on-fork off"
     34     gdb_test_no_output "set follow-fork parent"
     35 
     36     with_rocm_gpu_lock {
     37 	gdb_breakpoint [gdb_get_line_number "Break here"]
     38 	gdb_breakpoint kern allow-pending
     39 	gdb_breakpoint [gdb_get_line_number "Last break here"]
     40 
     41 	# Run until we reach the first breakpoint where we can figure
     42 	# out how many children will be spawned.
     43 	gdb_test "run" "hit Breakpoint.*"
     44 
     45 	set num_children [get_integer_valueof "num_devices" 0]
     46 	set bp_to_see $num_children
     47 	set stopped_gpu_threads [list]
     48 
     49 	gdb_test_multiple "continue -a &" "continue to gpu breakpoints" {
     50 	    -re "Continuing\.\r\n$::gdb_prompt " {
     51 		pass $gdb_test_name
     52 	    }
     53 	}
     54 
     55 	gdb_test_multiple "" "wait for gpu stops" {
     56 	    -re "Thread ($::decimal\.$::decimal)\[^\r\n\]* hit Breakpoint\[^\r\n\]*, kern \(\)\[^\r\n\]*\r\n" {
     57 		lappend stopped_gpu_threads $expect_out(1,string)
     58 		incr bp_to_see -1
     59 		if {$bp_to_see != 0} {
     60 		    exp_continue
     61 		} else {
     62 		    pass $gdb_test_name
     63 		}
     64 	    }
     65 	}
     66 
     67 	# Continue all the GPU kernels so all the children processes can reach exit.
     68 	foreach thread $stopped_gpu_threads {
     69 	    set infnumber [lindex [split $thread .] 0]
     70 	    gdb_test "thread $thread" "Switching to thread.*"
     71 	    gdb_test_multiple "continue" "continue inferior $infnumber" {
     72 		-re "\\\[Inferior $infnumber \[^\n\r\]* exited normally\\]\r\n$::gdb_prompt " {
     73 		    pass $gdb_test_name
     74 		}
     75 	    }
     76 	}
     77 
     78 	gdb_test_multiple "" "reach breakpoint in main" {
     79 	    -re "hit Breakpoint.*parent" {
     80 		pass $gdb_test_name
     81 	    }
     82 	}
     83 	# Select main inferior
     84 	gdb_test "inferior 1" "Switching to inferior 1.*"
     85 	gdb_continue_to_end "" "continue -a" 1
     86     }
     87 }
     88 
     89 do_test
     90