Home | History | Annotate | Line # | Download | only in gdb.rocm
      1  1.1  christos # Copyright 2023-2024 Free Software Foundation, Inc.
      2  1.1  christos 
      3  1.1  christos # This program is free software; you can redistribute it and/or modify
      4  1.1  christos # it under the terms of the GNU General Public License as published by
      5  1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6  1.1  christos # (at your option) any later version.
      7  1.1  christos #
      8  1.1  christos # This program is distributed in the hope that it will be useful,
      9  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  1.1  christos # GNU General Public License for more details.
     12  1.1  christos #
     13  1.1  christos # You should have received a copy of the GNU General Public License
     14  1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  1.1  christos 
     16  1.1  christos # This test checks that GDB can debug multiple inferior which uses all
     17  1.1  christos # the ROCm runtime.
     18  1.1  christos 
     19  1.1  christos load_lib rocm.exp
     20  1.1  christos 
     21  1.1  christos standard_testfile .cpp
     22  1.1  christos 
     23  1.1  christos require allow_hipcc_tests
     24  1.1  christos require hip_devices_support_debug_multi_process
     25  1.1  christos 
     26  1.1  christos if {[build_executable "failed to prepare" $testfile $srcfile {debug hip}]} {
     27  1.1  christos     return
     28  1.1  christos }
     29  1.1  christos 
     30  1.1  christos proc do_test {} {
     31  1.1  christos     clean_restart $::binfile
     32  1.1  christos     gdb_test_no_output "set non-stop on"
     33  1.1  christos     gdb_test_no_output "set detach-on-fork off"
     34  1.1  christos     gdb_test_no_output "set follow-fork parent"
     35  1.1  christos 
     36  1.1  christos     with_rocm_gpu_lock {
     37  1.1  christos 	gdb_breakpoint [gdb_get_line_number "Break here"]
     38  1.1  christos 	gdb_breakpoint kern allow-pending
     39  1.1  christos 	gdb_breakpoint [gdb_get_line_number "Last break here"]
     40  1.1  christos 
     41  1.1  christos 	# Run until we reach the first breakpoint where we can figure
     42  1.1  christos 	# out how many children will be spawned.
     43  1.1  christos 	gdb_test "run" "hit Breakpoint.*"
     44  1.1  christos 
     45  1.1  christos 	set num_children [get_integer_valueof "num_devices" 0]
     46  1.1  christos 	set bp_to_see $num_children
     47  1.1  christos 	set stopped_gpu_threads [list]
     48  1.1  christos 
     49  1.1  christos 	gdb_test_multiple "continue -a &" "continue to gpu breakpoints" {
     50  1.1  christos 	    -re "Continuing\.\r\n$::gdb_prompt " {
     51  1.1  christos 		pass $gdb_test_name
     52  1.1  christos 	    }
     53  1.1  christos 	}
     54  1.1  christos 
     55  1.1  christos 	gdb_test_multiple "" "wait for gpu stops" {
     56  1.1  christos 	    -re "Thread ($::decimal\.$::decimal)\[^\r\n\]* hit Breakpoint\[^\r\n\]*, kern \(\)\[^\r\n\]*\r\n" {
     57  1.1  christos 		lappend stopped_gpu_threads $expect_out(1,string)
     58  1.1  christos 		incr bp_to_see -1
     59  1.1  christos 		if {$bp_to_see != 0} {
     60  1.1  christos 		    exp_continue
     61  1.1  christos 		} else {
     62  1.1  christos 		    pass $gdb_test_name
     63  1.1  christos 		}
     64  1.1  christos 	    }
     65  1.1  christos 	}
     66  1.1  christos 
     67  1.1  christos 	# Continue all the GPU kernels so all the children processes can reach exit.
     68  1.1  christos 	foreach thread $stopped_gpu_threads {
     69  1.1  christos 	    set infnumber [lindex [split $thread .] 0]
     70  1.1  christos 	    gdb_test "thread $thread" "Switching to thread.*"
     71  1.1  christos 	    gdb_test_multiple "continue" "continue inferior $infnumber" {
     72  1.1  christos 		-re "\\\[Inferior $infnumber \[^\n\r\]* exited normally\\]\r\n$::gdb_prompt " {
     73  1.1  christos 		    pass $gdb_test_name
     74  1.1  christos 		}
     75  1.1  christos 	    }
     76  1.1  christos 	}
     77  1.1  christos 
     78  1.1  christos 	gdb_test_multiple "" "reach breakpoint in main" {
     79  1.1  christos 	    -re "hit Breakpoint.*parent" {
     80  1.1  christos 		pass $gdb_test_name
     81  1.1  christos 	    }
     82  1.1  christos 	}
     83  1.1  christos 	# Select main inferior
     84  1.1  christos 	gdb_test "inferior 1" "Switching to inferior 1.*"
     85  1.1  christos 	gdb_continue_to_end "" "continue -a" 1
     86  1.1  christos     }
     87  1.1  christos }
     88  1.1  christos 
     89  1.1  christos do_test
     90