U
    ,d5$                     @   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re  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 )TestGDBDwarfZ	NUMBA_OPT0c                 C   s    t tdd}| }|  |S )z6Returns True if gdb has NumPy support, False otherwiseF)debug)r   __file__Zsupports_numpyquit)selfZdriverZ	has_numpy r   >/tmp/pip-unpacked-wheel-eu7e0c37/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.ZTesttest)Ztest_moduleZ
test_classZ	test_nameenvvars)Zsubprocess_test_runner_NUMBA_OPT_0_ENV)r   Ztest_modZthemodr   r   r   _subprocess_test_runner   s    
z$TestGDBDwarf._subprocess_test_runnerc                 C   s   |  d d S )N
test_basicr   r   r   r   r   r   &   s    zTestGDBDwarf.test_basicc                 C   s   |  d d S )Ntest_array_argr   r   r   r   r   r   )   s    zTestGDBDwarf.test_array_argc                 C   s   |  d d S )Ntest_conditional_breakpointr   r   r   r   r   r   ,   s    z(TestGDBDwarf.test_conditional_breakpointc                 C   s   |  d d S )Ntest_break_on_symbolr   r   r   r   r   r   /   s    z!TestGDBDwarf.test_break_on_symbolc                 C   s   |  d d S )Ntest_break_on_symbol_versionr   r   r   r   r   r   2   s    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   Z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                    s^   t  t  d}td|| _| j  dd l}G dd d}|  |jf 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   dataZextentbufr   r   r   read_memoryV   s    zETestGDBPrettyPrinterLogic.setUp.<locals>.SelectedInferior.read_memoryN)r!   r"   r#   r-   r   r   r   r   SelectedInferiorT   s   r.   Zselected_inferiorc                      s    S r&   r   r   sir   r   <lambda>[       z1TestGDBPrettyPrinterLogic.setUp.<locals>.<lambda>)r   r   dictpatched_sysstartr%   Zconfigure_mock)r   Zmock_modulesr%   r.   r   r/   r   setUpC   s    
zTestGDBPrettyPrinterLogic.setUpc                 C   s   | j   d S r&   )r4   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   s   || _ || _d S r&   Z_loZ_hir   lohir   r   r   __init__n   s    zCTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrange.__init__c                 S   s   | S r&   r   r   r   r   r   typer   s    z?TestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrange.typec                 S   s   | j | jfS r&   r:   r   r   r   r   rangev   s    z@TestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DISubrange.rangeN)r!   r"   r#   r>   propertyr?   r@   r   r   r   r   
DISubrangem   s   
rB   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 r&   r:   r;   r   r   r   r>   z   s    zJTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DW_TAG_array_type.__init__c                    s    | j | jgS r&   r:   r   rB   r   r   fields}   s    zHTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DW_TAG_array_type.fieldsN)r!   r"   r#   r>   rD   r   rC   r   r   DW_TAG_array_typey   s   rE   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   Z	the_tuplerE   r   r   r>      s    zLTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuple.__init__c                 S   s   | j S r&   )rH   r   r   r   r   r?      s    zHTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuple.typec                 S   s
   | j | S r&   )rI   r   itemr   r   r   __getitem__   s    zOTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DIDerivedType_tuple.__getitem__N)r!   r"   r#   r>   rA   r?   rM   r   rJ   r   r   DIDerivedType_tuple   s   
rN   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   s   || _ || _d S r&   )_arr	_type_str)r   arrtype_strr   r   r   r>      s    zNTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.__init__c                 S   s
   t | |S r&   )getattrrK   r   r   r   rM      s    zQTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.__getitem__c                 S   s
   | j jjS r&   )rO   ctypesr+   r   r   r   r   r+      s    zJTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.datac                 S   s   | j jS r&   )rO   itemsizer   r   r   r   rU      s    zNTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.itemsizec                    s    | j jS r&   )rO   shaper   rN   r   r   rV      s    zKTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.shapec                    s    | j jS r&   )rO   stridesr   rW   r   r   rX      s    zMTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.stridesc                 S   s   | j S r&   )rP   r   r   r   r   r?      s    zJTestGDBPrettyPrinterLogic.get_gdb_repr.<locals>.DICompositeType_Array.typeN)r!   r"   r#   r>   rM   rA   r+   rU   rV   rX   r?   r   rW   r   r   DICompositeType_Array   s   

rY   z ())Z
numba.miscr9   r	   Zdefault_managermodelsZ
ArrayModelr
   Zget_data_typeZstructure_reprZNumbaArrayPrinterZ	to_stringstrip)
r   arrayr9   rY   ZdmmZarray_modelZ	data_typerR   Zfake_gdb_arrprinterr   )rN   rB   rE   r   get_gdb_repra   s    

z&TestGDBPrettyPrinterLogic.get_gdb_reprc                 C   s"   |  |}| t|t| d S r&   )r_   assertEqualstr)r   r]   Z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)	npZint8Zuint16Zint64Zfloat32Z
complex128arangereshaperb   )r   nmdtrQ   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 ]}t jjddt jddd}t t ||}g }|D ]V}t jd|}t j|d t|d |d }t jdd}	t	|||	}
|
|
 qV|t| }| | qd S )N   r   rF         )highsizerd   )rg   randomseedr@   randintrh   prodri   maxsliceappendtuplerb   )r   Zn_tests_rV   tmpZslicesxr5   r7   stepZstrdrQ   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 ]p}t j|| |d||}t j|| |d d|||d< d	t j|| |d d|| |d< | | qLd S )
Nrc   rd   r}   yTZalignFre   d   )rg   rf   int16float64emptyri   rh   rb   )r   rj   rk   ZalignedZ	unalignedrl   rQ   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 )NZabcde)rg   r]   rb   )r   rQ   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 )Nrc   rd   )r}   z<U5r   Tr   re   array[Exception:Unsupported sub-typez[unichr x 5])rg   rf   r   zerosri   r_   assertInr   rj   rk   rl   rQ   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 )Nrc   rd   r}   )   r   Tr   re   r   r   znestedarray(int16)rg   rf   r   r   r   ri   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!   r"   r#   r6   r8   r_   rb   rm   r   r   r   r   r   r   r   r   r   r$   =   s   S	r$   __main__)__doc__Znumba.tests.supportr   r   Znumba.tests.gdb_supportr   r   r   Zunittest.mockr   r   Z
numba.corer	   Znumpyrg   Znumbar
   rT   r'   Zunittestr   r$   r!   mainr   r   r   r   <module>   s    . H