1313
1414from  numba_dpex .tests ._helper  import  skip_no_gdb 
1515
16- from  .gdb  import  breakpoint_by_function ,  breakpoint_by_mark ,  setup_breakpoint 
16+ from  .gdb  import  gdb 
1717
1818pytestmark  =  skip_no_gdb 
1919
2020
21- side_by_side_breakpoint  =  breakpoint_by_function (
22-     "side-by-side.py" , "common_loop_body" 
21+ @pytest .mark .parametrize ( 
22+     "breakpoint" , 
23+     [ 
24+         "side-by-side.py:16" , 
25+         "common_loop_body" , 
26+         "side-by-side.py:common_loop_body" , 
27+     ], 
2328) 
24- 
25- simple_sum_condition_breakpoint  =  breakpoint_by_mark (
26-     "simple_sum.py" , "Condition breakpoint location" 
29+ @pytest .mark .parametrize ( 
30+     "api" , 
31+     [ 
32+         "numba" , 
33+         "numba-ndpx-kernel" , 
34+     ], 
2735) 
28- 
29- common_loop_body_native_function_name  =  {
30-     "numba" : "common_loop_body" ,
31-     "numba-ndpx-kernel" : "common_loop_body" ,
32- }
33- 
34- breakpoint_api_cases  =  [
35-     (side_by_side_breakpoint , "numba" ),
36-     (side_by_side_breakpoint , "numba-ndpx-kernel" ),
37-     * ((fn , api ) for  api , fn  in  common_loop_body_native_function_name .items ()),
38-     * (
39-         (f"side-by-side.py:{ fn }  " , api )
40-         for  api , fn  in  common_loop_body_native_function_name .items ()
41-     ),
42- ]
43- 
44- 
45- @pytest .mark .parametrize ("breakpoint, api" , breakpoint_api_cases ) 
46- def  test_breakpoint_with_condition_by_function_argument (app , breakpoint , api ):
36+ @pytest .mark .parametrize ( 
37+     "condition, exp_var, exp_val" , 
38+     [ 
39+         ("param_a == 3" , "param_a" , 3 ), 
40+         ("param_a == 7" , "param_a" , 7 ), 
41+         (None , "param_a" , r"[0-9]+" ),  # No condition  
42+     ], 
43+ ) 
44+ def  test_device_func_breakpoint (
45+     app : gdb , breakpoint , api , condition , exp_var , exp_val 
46+ ):
4747    """Function breakpoints and argument initializing 
4848
4949    Test that it is possible to set conditional breakpoint at the beginning 
@@ -56,71 +56,40 @@ def test_breakpoint_with_condition_by_function_argument(app, breakpoint, api):
5656    SAT-4449 
5757    """ 
5858
59-     if  api  ==  "numba-ndpx-kernel" :
60-         if  (
61-             breakpoint  ==  "side-by-side.py:common_loop_body" 
62-             or  breakpoint  ==  "common_loop_body" 
63-         ):
64-             pytest .xfail (
65-                 "Breakpoint by function name not working for numba-dpex." 
66-             )  # TODO: https://github.com/IntelPython/numba-dpex/issues/1242 
59+     if  api  ==  "numba-ndpx-kernel"  and  breakpoint  !=  "side-by-side.py:16" :
60+         pytest .skip (
61+             "Breakpoint by function name not working for numba-dpex." 
62+         )  # TODO: https://github.com/IntelPython/numba-dpex/issues/1242 
6763
68-     variable_name  =  "param_a" 
69-     variable_value  =  "3" 
70-     condition  =  f"{ variable_name }   == { variable_value }  " 
71- 
72-     app .breakpoint (f"{ breakpoint }   if { condition }  " )
64+     app .breakpoint (breakpoint , condition = condition )
7365    app .run (f"side-by-side.py --api={ api }  " )
74- 
75-     app .child .expect (
76-         rf"Thread .* hit Breakpoint .* at { side_by_side_breakpoint }  " 
77-     )
78- 
79-     app .print (variable_name )
80- 
81-     app .child .expect (rf"\$1 = { variable_value }  " )
66+     app .expect_hit_breakpoint ("side-by-side.py:16" )
67+     if  exp_var  is  not   None :
68+         app .print (exp_var , expected = exp_val )
8269
8370
8471@pytest .mark .parametrize ( 
85-     "breakpoint, script " , 
72+     "condition, exp_var, exp_val " , 
8673    [ 
87-         # location specified by file name and function name  
88-         # commands/break_file_func # noqa: E800  
89-         ("simple_sum.py:data_parallel_sum" , None ), 
90-         # location specified by function name  
91-         # commands/break_func # noqa: E800  
92-         ("data_parallel_sum" , "simple_sum.py" ), 
93-         # location specified by file name and nested function name  
94-         # commands/break_nested_func # noqa: E800  
95-         ("simple_dpex_func.py:func_sum" , None ), 
74+         ("i == 3" , "i" , 3 ), 
75+         (None , "i" , r"[0-9]+" ),  # No condition  
9676    ], 
9777) 
98- def  test_breakpoint_common (app , breakpoint , script ):
99-     """Set a breakpoint in the given script.""" 
100- 
101-     pytest .xfail (
102-         "Breakpoint by function name not working for numba-dpex." 
103-     )  # TODO: https://github.com/IntelPython/numba-dpex/issues/1242 
104-     setup_breakpoint (app , breakpoint , script = script )
105- 
78+ def  test_kernel_breakpoint (app : gdb , condition , exp_var , exp_val ):
79+     """Function breakpoints and argument initializing 
10680
107- @pytest .mark .parametrize ( 
108-     "breakpoint, variable_name, variable_value" , 
109-     [ 
110-         # commands/break_conditional # noqa: E800  
111-         (f"{ simple_sum_condition_breakpoint }   if i == 1" , "i" , "1" ), 
112-     ], 
113- ) 
114- def  test_breakpoint_with_condition_common (
115-     app ,
116-     breakpoint ,
117-     variable_name ,
118-     variable_value ,
119- ):
120-     """Set a breakpoint with condition and check value of variable.""" 
81+     Test that it is possible to set conditional breakpoint at the beginning 
82+     of the function and use a function argument in the condition. 
12183
122-     setup_breakpoint (app , breakpoint )
84+     It is important that breakpoint by function name hits at the first line in 
85+     the function body and not at the function definition line. 
12386
124-     app .print (variable_name )
87+     Test for https://github.com/numba/numba/issues/7415 
88+     SAT-4449 
89+     """ 
12590
126-     app .child .expect (rf"\$1 = { variable_value }  " )
91+     app .breakpoint ("simple_sum.py:13" , condition = condition )
92+     app .run ("simple_sum.py" )
93+     app .expect_hit_breakpoint ("simple_sum.py:13" )
94+     if  exp_var  is  not   None :
95+         app .print (exp_var , expected = exp_val )
0 commit comments