o
    ۾i5$                     @   s   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	 d	eZG d
d deZedkrTe  dS dS )z8Tests for gdb interacting with the DWARF numba generates    )TestCase
linux_only)	needs_gdbskip_unless_pexpectGdbMIDriver)patchMock)	datamodelN)typeofc                   @   sT   e Zd ZddiZdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )TestGDBDwarf	NUMBA_OPT0c                 C   s    t tdd}| }|  |S )z6Returns True if gdb has NumPy support, False otherwiseF)debug)r   __file__supports_numpyquit)selfdriver	has_numpy r   N/home/ubuntu/.local/lib/python3.10/site-packages/numba/tests/test_gdb_dwarf.py_gdb_has_numpy   s   zTestGDBDwarf._gdb_has_numpyc                 C   s"   d| }| j |dd| jd d S )Nznumba.tests.gdb.Testtest)test_module
test_class	test_nameenvvars)subprocess_test_runner_NUMBA_OPT_0_ENV)r   test_modthemodr   r   r   _subprocess_test_runner   s   

z$TestGDBDwarf._subprocess_test_runnerc                 C      |  d d S )N
test_basicr"   r   r   r   r   r$   &      zTestGDBDwarf.test_basicc                 C   r#   )Ntest_array_argr%   r&   r   r   r   r(   )   r'   zTestGDBDwarf.test_array_argc                 C   r#   )Ntest_conditional_breakpointr%   r&   r   r   r   r)   ,   r'   z(TestGDBDwarf.test_conditional_breakpointc                 C   r#   )Ntest_break_on_symbolr%   r&   r   r   r   r*   /   r'   z!TestGDBDwarf.test_break_on_symbolc                 C   r#   )Ntest_break_on_symbol_versionr%   r&   r   r   r   r+   2   r'   z)TestGDBDwarf.test_break_on_symbol_versionc                 C   s$   |   sd}| | | d d S )Nz"Cannot find gdb with NumPy supporttest_pretty_print)r   skipTestr"   )r   _msgr   r   r   r,   5   s   
zTestGDBDwarf.test_pretty_printN)__name__
__module____qualname__r   r   r"   r$   r(   r)   r*   r+   r,   r   r   r   r   r      s    
r   c                   @   s\   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd ZdS )TestGDBPrettyPrinterLogicc                    sb   t  t  d}td|| _| j  dd l}G dd d}|  |jd	i d fddi d S )
N)gdbzgdb.printingzsys.modulesr   c                   @   s   e Zd Zdd ZdS )z9TestGDBPrettyPrinterLogic.setUp.<locals>.SelectedInferiorc                 S   s   t j| |}|jS N)ctc_charfrom_addressraw)r   dataextentbufr   r   r   read_memoryV   s   zETestGDBPrettyPrinterLogic.setUp.<locals>.SelectedInferior.read_memoryN)r/   r0   r1   r<   r   r   r   r   SelectedInferiorT   s    r=   selected_inferiorc                      s    S r4   r   r   sir   r   <lambda>[   s    z1TestGDBPrettyPrinterLogic.setUp.<locals>.<lambda>r   )r   r   dictpatched_sysstartr3   configure_mock)r   mock_modulesr3   r=   r   r?   r   setUpC   s   
 zTestGDBPrettyPrinterLogic.setUpc                 C   s   | j   d S r4   )rC   stopr&   r   r   r   tearDown]   s   z"TestGDBPrettyPrinterLogic.tearDownc           
         s   ddl m} G dd dG fdddG fddd G  fd	d
d
}tj}tj|t|}| }t| d|  d}|||}|	|}	|	
  S )Nr   )gdb_print_extensionc                   @   s(   e Zd Zdd Zedd Zdd ZdS )z:TestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrangec                 S      || _ || _d S r4   _lo_hir   lohir   r   r   __init__n      
zCTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrange.__init__c                 S   s   | S r4   r   r&   r   r   r   typer   s   z?TestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrange.typec                 S   s   | j | jfS r4   rL   r&   r   r   r   rangev   s   z@TestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrange.rangeN)r/   r0   r1   rR   propertyrT   rU   r   r   r   r   
DISubrangem   s
    
rW   c                       s    e Zd Zdd Z fddZdS )zATestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DW_TAG_array_typec                 S   s   ||| _ | _d S r4   rL   rO   r   r   r   rR   z   s   zJTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DW_TAG_array_type.__init__c                    s    | j | jgS r4   rL   r&   rW   r   r   fields}   s   zHTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DW_TAG_array_type.fieldsN)r/   r0   r1   rR   rY   r   rX   r   r   DW_TAG_array_typey   s    rZ   c                       s,   e Zd Z fddZedd Zdd ZdS )zCTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuplec                    s    dt |d | _|| _d S )Nr      )len_type_tuple)r   	the_tuplerZ   r   r   rR      s   
zLTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuple.__init__c                 S      | j S r4   )r]   r&   r   r   r   rT         zHTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuple.typec                 S   s
   | j | S r4   )r^   r   itemr   r   r   __getitem__      
zOTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuple.__getitem__N)r/   r0   r1   rR   rV   rT   re   r   r`   r   r   DIDerivedType_tuple   s
    
rg   c                       s`   e Zd Zdd Zdd Zedd Zedd Ze fd	d
Ze fddZ	edd Z
dS )zETestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Arrayc                 S   rK   r4   )_arr	_type_str)r   arrtype_strr   r   r   rR      rS   zNTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.__init__c                 S   s
   t | |S r4   )getattrrc   r   r   r   re      rf   zQTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.__getitem__c                 S   s
   | j jjS r4   )rh   ctypesr9   r&   r   r   r   r9      s   
zJTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.datac                 S   s   | j jS r4   )rh   itemsizer&   r   r   r   rn      s   zNTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.itemsizec                        | j jS r4   )rh   shaper&   rg   r   r   rp         zKTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.shapec                    ro   r4   )rh   stridesr&   rq   r   r   rs      rr   zMTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.stridesc                 S   ra   r4   )ri   r&   r   r   r   rT      rb   zJTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.typeN)r/   r0   r1   rR   re   rV   r9   rn   rp   rs   rT   r   rq   r   r   DICompositeType_Array   s    

rt   z ())
numba.miscrJ   r	   default_managermodels
ArrayModelr
   get_data_typestructure_reprNumbaArrayPrinter	to_stringstrip)
r   arrayrJ   rt   dmmarray_model	data_typerk   fake_gdb_arrprinterr   )rg   rW   rZ   r   get_gdb_repra   s   

z&TestGDBPrettyPrinterLogic.get_gdb_reprc                 C   s"   |  |}| t|t| d S r4   )r   assertEqualstr)r   r   gdb_printedr   r   r   check   s   
zTestGDBPrettyPrinterLogic.checkc                 C   sN   d}d}t jt jt jt jt jfD ]}t j|| |d||}| | qd S )N      dtype)	npint8uint16int64float32
complex128arangereshaper   )r   nmdtrj   r   r   r   *test_np_array_printer_simple_numeric_types   s   zDTestGDBPrettyPrinterLogic.test_np_array_printer_simple_numeric_typesc              	   C   s   d}t jd t|D ]V}t jjddt jddd}t t ||}g }|D ]+}t jd|}t j|d t|d |d }t jdd}	t	|||	}
|
|
 q+|t| }| | qd S )N   r   r[         )highsizer   )r   randomseedrU   randintr   prodr   maxsliceappendtupler   )r   n_tests_rp   tmpslicesxrD   rH   stepstrdrj   r   r   r   2test_np_array_printer_simple_numeric_types_strided   s    zLTestGDBPrettyPrinterLogic.test_np_array_printer_simple_numeric_types_stridedc                 C   s   d}d}t jdt jfdt jfgdd}t jdt jfdt jfgdd}||fD ]8}t j|| |d||}t j|| |d d|||d< d	t j|| |d d|| |d< | | q&d S )
Nr   r   r   yTalignFr   d   )r   r   int16float64emptyr   r   r   )r   r   r   aligned	unalignedr   rj   r   r   r   -test_np_array_printer_simple_structured_dtype   s   "&zGTestGDBPrettyPrinterLogic.test_np_array_printer_simple_structured_dtypec                 C   s   t dg}| | d S )Nabcde)r   r   r   )r   rj   r   r   r   test_np_array_printer_chr_array   s   z9TestGDBPrettyPrinterLogic.test_np_array_printer_chr_arrayc                 C   sl   d}d}t jddt jfgdd}t j|| |d||}| |}| d| | d	| | d
| d S )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   rj   repr   r   r   -test_np_array_printer_unichr_structured_dtype   s   
zGTestGDBPrettyPrinterLogic.test_np_array_printer_unichr_structured_dtypec                 C   st   d}d}t jdt jdfdt jfgdd}t j|| |d||}| |}| d	| | d
| | d| d S )Nr   r   r   )   r   Tr   r   r   r   znestedarray(int16)r   r   r   r   r   r   r   r   r   r   r   r   3test_np_array_printer_nested_array_structured_dtype   s    
zMTestGDBPrettyPrinterLogic.test_np_array_printer_nested_array_structured_dtypeN)r/   r0   r1   rG   rI   r   r   r   r   r   r   r   r   r   r   r   r   r2   =   s    S	r2   __main__)__doc__numba.tests.supportr   r   numba.tests.gdb_supportr   r   r   unittest.mockr   r   
numba.corer	   numpyr   numbar
   rm   r5   unittestr   r2   r/   mainr   r   r   r   <module>   s$    . H