
    xKg5$                         d Z ddlmZmZ ddlmZmZmZ ddlm	Z	m
Z
 ddlmZ ddlZddlmZ ddlZddlZeee G d d	e                           Z G d
 de      Zedk(  r ej.                          yy)z8Tests for gdb interacting with the DWARF numba generates    )TestCase
linux_only)	needs_gdbskip_unless_pexpectGdbMIDriver)patchMock)	datamodelN)typeofc                   D    e Zd ZddiZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zy)TestGDBDwarf	NUMBA_OPT0c                 h    t        t        d      }|j                         }|j                          |S )z6Returns True if gdb has NumPy support, False otherwiseF)debug)r   __file__supports_numpyquit)selfdriver	has_numpys      ^/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/tests/test_gdb_dwarf.py_gdb_has_numpyzTestGDBDwarf._gdb_has_numpy   s+    XU4))+	    c                 L    d| }| j                  |dd| j                         y )Nznumba.tests.gdb.Testtest)test_module
test_class	test_nameenvvars)subprocess_test_runner_NUMBA_OPT_0_ENV)r   test_modthemods      r   _subprocess_test_runnerz$TestGDBDwarf._subprocess_test_runner   s3    #H:.##/5.4,0,A,A 	$ 	Cr   c                 &    | j                  d       y )N
test_basicr&   r   s    r   r(   zTestGDBDwarf.test_basic&   s    $$\2r   c                 &    | j                  d       y )Ntest_array_argr)   r*   s    r   r,   zTestGDBDwarf.test_array_arg)   s    $$%56r   c                 &    | j                  d       y )Ntest_conditional_breakpointr)   r*   s    r   r.   z(TestGDBDwarf.test_conditional_breakpoint,   s    $$%BCr   c                 &    | j                  d       y )Ntest_break_on_symbolr)   r*   s    r   r0   z!TestGDBDwarf.test_break_on_symbol/   s    $$%;<r   c                 &    | j                  d       y )Ntest_break_on_symbol_versionr)   r*   s    r   r2   z)TestGDBDwarf.test_break_on_symbol_version2   s    $$%CDr   c                 l    | j                         sd}| j                  |       | j                  d       y )Nz"Cannot find gdb with NumPy supporttest_pretty_print)r   skipTestr&   )r   _msgs     r   r4   zTestGDBDwarf.test_pretty_print5   s.    ""$7DMM$$$%89r   N)__name__
__module____qualname__r#   r   r&   r(   r,   r.   r0   r2   r4    r   r   r   r      s:     $S)C37D=E:r   r   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestGDBPrettyPrinterLogicc                     t               t               d}t        j                  d|      | _        | j                  j	                          dd l} G d d      } |        |j                  di dfdi y )	N)gdbzgdb.printingzsys.modulesr   c                       e Zd Zd Zy)9TestGDBPrettyPrinterLogic.setUp.<locals>.SelectedInferiorc                 ^    t         j                  |z  j                  |      }|j                  S N)ctc_charfrom_addressraw)r   dataextentbufs       r   read_memoryzETestGDBPrettyPrinterLogic.setUp.<locals>.SelectedInferior.read_memoryV   s$    yy6)77=wwr   N)r7   r8   r9   rJ   r:   r   r   SelectedInferiorr@   T   s    r   rK   selected_inferiorc                       S rB   r:   )sis   r   <lambda>z1TestGDBPrettyPrinterLogic.setUp.<locals>.<lambda>[   s    2r   r:   )r	   r   dictpatched_sysstartr>   configure_mock)r   mock_modulesr>   rK   rN   s       @r   setUpzTestGDBPrettyPrinterLogic.setUpC   sm    
  $v(,0 ::m\B  		 	 ?1:>?r   c                 8    | j                   j                          y rB   )rQ   stopr*   s    r   tearDownz"TestGDBPrettyPrinterLogic.tearDown]   s    r   c                   
 ddl m}  G d d       G fdd       G fdd      
 G 
fd	d
      }t        j                  }t        j                  j                  |t        |            }|j                         }t        |       d|j                          d} |||      }|j                  |      }	|	j                         j                         S )Nr   )gdb_print_extensionc                   (    e Zd Zd Zed        Zd Zy):TestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrangec                      || _         || _        y rB   _lo_hir   lohis      r   __init__zCTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrange.__init__n   s    r   c                     | S rB   r:   r*   s    r   typez?TestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrange.typer   s    r   c                 2    | j                   | j                  fS rB   r^   r*   s    r   rangez@TestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrange.rangev   s    xx))r   N)r7   r8   r9   rd   propertyrf   rh   r:   r   r   
DISubranger\   m   s       *r   rj   c                       e Zd Zd Z fdZy)ATestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DW_TAG_array_typec                 "    ||c| _         | _        y rB   r^   ra   s      r   rd   zJTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DW_TAG_array_type.__init__z   s    %'"$(r   c                 @     | j                   | j                        gS rB   r^   )r   rj   s    r   fieldszHTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DW_TAG_array_type.fields}   s    "488TXX688r   N)r7   r8   r9   rd   ro   )rj   s   r   DW_TAG_array_typerl   y   s    ,9r   rp   c                   .    e Zd Z fdZed        Zd Zy)CTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuplec                 H     dt        |      dz
        | _        || _        y )Nr      )len_type_tuple)r   	the_tuplerp   s     r   rd   zLTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuple.__init__   s!    .q#i.12DE
'r   c                     | j                   S rB   )rv   r*   s    r   rf   zHTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuple.type   s    zz!r   c                      | j                   |   S rB   )rw   r   items     r   __getitem__zOTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuple.__getitem__   s    {{4((r   N)r7   r8   r9   rd   ri   rf   r}   )rp   s   r   DIDerivedType_tuplerr      s!    ( " ")r   r~   c                   r    e Zd Zd Zd Zed        Zed        Ze fd       Ze fd       Z	ed        Z
y)	ETestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Arrayc                      || _         || _        y rB   )_arr	_type_str)r   arrtype_strs      r   rd   zNTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.__init__   s    	!)r   c                     t        | |      S rB   )getattrr{   s     r   r}   zQTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.__getitem__   s    tT**r   c                 B    | j                   j                  j                  S rB   )r   ctypesrG   r*   s    r   rG   zJTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.data   s    yy'',,,r   c                 .    | j                   j                  S rB   )r   itemsizer*   s    r   r   zNTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.itemsize   s    yy)))r   c                 <     | j                   j                        S rB   )r   shaper   r~   s    r   r   zKTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.shape   s    *499??;;r   c                 <     | j                   j                        S rB   )r   stridesr   s    r   r   zMTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.strides   s    *499+<+<==r   c                     | j                   S rB   )r   r*   s    r   rf   zJTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.type   s    ~~%r   N)r7   r8   r9   rd   r}   ri   rG   r   r   r   rf   )r~   s   r   DICompositeType_Arrayr      sq    *+ - - * * < < > > & &r   r   z ())
numba.miscrZ   r
   default_managermodels
ArrayModelr   get_data_typestructure_reprNumbaArrayPrinter	to_stringstrip)r   arrayrZ   r   dmmarray_model	data_typer   fake_gdb_arrprinterr~   rj   rp   s             @@@r   get_gdb_reprz&TestGDBPrettyPrinterLogic.get_gdb_repra   s     	3
	* 
	*	9 	9
	) 
	)	& 	&< ''&&11#ve}E--/	Um_By'?'?'A&B!D,UH=%77E  "((**r   c                 n    | j                  |      }| j                  t        |      t        |             y rB   )r   assertEqualstr)r   r   gdb_printeds      r   checkzTestGDBPrettyPrinterLogic.check   s+    ''.[)3u:6r   c                 &   d}d}t         j                  t         j                  t         j                  t         j                  t         j
                  fD ]=  }t        j                  ||z  |      j                  ||      }| j                  |       ? y )N      dtype)	npint8uint16int64float32
complex128arangereshaper   )r   nmdtr   s        r   *test_np_array_printer_simple_numeric_typeszDTestGDBPrettyPrinterLogic.test_np_array_printer_simple_numeric_types   sb    77BIIrxxR]]KB))AE,44Q:CJJsO Lr   c           
         d}t         j                  j                  d       t        |      D ]3  }t         j                  j	                  ddt         j                  j	                  dd            }t        j
                  t        j                  |            j                  |      }g }|D ]  }t         j                  j	                  d|      }t         j                  j	                  |dz   t        |dz   |dz               }t         j                  j	                  dd      }	t        |||	      }
|j                  |
        |t        |         }| j                  |       6 y )N   r   rt         )highsizer   )r   randomseedrh   randintr   prodr   maxsliceappendtupler   )r   n_tests_r   tmpslicesxrR   rW   stepstrdr   s               r   2test_np_array_printer_simple_numeric_types_stridedzLTestGDBPrettyPrinterLogic.test_np_array_printer_simple_numeric_types_strided   s   
		qwAII%%abryy7H7HA7N%OE))BGGEN+33E:CF		))!Q/ yy((C	1q54IJyy((A.UD$/d#  eFm$CJJsO!  r   c                 >   d}d}t        j                  dt         j                  fdt         j                  fgd      }t        j                  dt         j                  fdt         j                  fgd      }||fD ]  }t        j                  ||z  |      j                  ||      }t        j                  ||z  |d         j                  ||      |d<   d	t        j                  ||z  |d         j                  ||      z  |d<   | j                  |        y )
Nr   r   r   yTalignFr   d   )r   r   int16float64emptyr   r   r   )r   r   r   aligned	unalignedr   r   s          r   -test_np_array_printer_simple_structured_dtypezGTestGDBPrettyPrinterLogic.test_np_array_printer_simple_structured_dtype   s    ((S"((Oc2::->?tLHHsBHHoRZZ/@AO	I&B((1q5+33Aq9CyyQbg6>>q!DCHRYYq1uBsG<DDQJJCHJJsO	 'r   c                 R    t        j                  dg      }| j                  |       y )Nabcde)r   r   r   )r   r   s     r   test_np_array_printer_chr_arrayz9TestGDBPrettyPrinterLogic.test_np_array_printer_chr_array   s    hhy!

3r   c                 @   d}d}t        j                  ddt         j                  fgd      }t        j                  ||z  |      j	                  ||      }| j                  |      }| j                  d|       | j                  d	|       | j                  d
|       y )Nr   r   )r   z<U5r   Tr   r   array[Exception:Unsupported sub-typez[unichr x 5])r   r   r   zerosr   r   assertInr   r   r   r   r   reps         r   -test_np_array_printer_unichr_structured_dtypezGTestGDBPrettyPrinterLogic.test_np_array_printer_unichr_structured_dtype   s    XX|c2::%67tDhhq1uB'//15$(#.,c2nc*r   c                 b   d}d}t        j                  dt         j                  dfdt         j                  fgd      }t        j                  ||z  |      j                  ||      }| j                  |      }| j                  d	|       | j                  d
|       | j                  d|       y )Nr   r   r   )   r   Tr   r   r   r   znestedarray(int16)r   r   r   r   r   r   r   r   r   s         r   3test_np_array_printer_nested_array_structured_dtypezMTestGDBPrettyPrinterLogic.test_np_array_printer_nested_array_structured_dtype   s    XXRXXt,sBJJ.?@Mhhq1uB'//15$(#.,c2)3/r   N)r7   r8   r9   rU   rX   r   r   r   r   r   r   r   r   r:   r   r   r<   r<   =   s7    @4 Q+f7.

+
0r   r<   __main__)__doc__numba.tests.supportr   r   numba.tests.gdb_supportr   r   r   unittest.mockr   r	   
numba.corer
   numpyr   numbar   r   rC   unittestr   r<   r7   mainr:   r   r   <module>r      sx    > 4 O O %       
+:8 +:   +:\D0 D0N zHMMO r   