U
    iâËdŠ  ã                   @   sÄ  d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZmZmZmZ ddlmZ ddlZejZe d	¡p¸e d
¡p¸dekZe ed¡Ze ed¡Ze  ¡ Z!e!dkZ"e e"d¡Z#ej$ %dd¡dkZ&e e&d¡Z'edƒZ(e	dd�Z)eddd�Z*dd„ Z+dd„ Z,dd„ Z-e#eG dd„ deƒƒƒZ.e#eeG dd „ d eƒƒƒƒZ/e/ 0¡  e#eeG d!d"„ d"eƒƒƒƒZ1eG d#d$„ d$eƒƒZ2e3d%k�rÀe 4¡  dS )&z
Tests gdb bindings
é    N)Úpermutations)ÚnjitÚgdbÚgdb_initÚgdb_breakpointÚprange)Úerrors)Újit)ÚTestCaseÚcaptured_stdoutÚtagÚskip_parfors_unsupported)Ú	needs_gdbÚlinuxÚdarwinZbsdzunix-like OS is requiredznon unix-like OS is required>   Úarmv7lÚaarch64ztesting disabled on ARMÚGDB_TESTÚ1zneeds gdb harnessÚlong_runningT)Údebug)Úforceobjr   c                 C   s>   t ddddddƒ | d }| d }| ||f}t| |||ƒ d S ©Nú-exúset confirm offÚcÚqé   ç¸…ëQ¸@)r   Úprint©ÚaÚbr   Úd© r$   úV/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/tests/test_gdb_bindings.pyÚimpl_gdb_call+   s
    
r&   c                 C   sD   t ddddddƒ | d }| d }| ||f}tƒ  t| |||ƒ d S r   )r   r   r   r    r$   r$   r%   Úimpl_gdb_call_w_bp3   s    
r'   c                 C   sZ   t ddddddƒ | d7 } tdƒD ]2}| d }| d }| ||f}tƒ  t| |||ƒ q"d S )	Nr   r   r   r   é   é   r   r   )r   r   r   r   )r!   Úir"   r   r#   r$   r$   r%   Ú(impl_gdb_split_init_and_break_w_parallel<   s    
r+   c                   @   sˆ   e Zd ZdZedd„ ƒZedd„ ƒZedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
eedd„ ƒƒZeedd„ ƒƒZeedd„ ƒƒZdS )ÚTestGdbBindImplsa  
    Contains unit test implementations for gdb binding testing. Test must be
    decorated with `@needs_gdb_harness` to prevent their running under normal
    test conditions, the test methods must also end with `_impl` to be
    considered for execution. The tests themselves are invoked by the
    `TestGdbBinding` test class through the parsing of this class for test
    methods and then running the discovered tests in a separate process. Test
    names not including the word `quick` will be tagged as @tag('long_running')
    c              	   C   s   t ƒ � tdƒ W 5 Q R X d S ©Né
   )r   r&   ©Úselfr$   r$   r%   Ú$test_gdb_cmd_lang_cpython_quick_implT   s    z5TestGdbBindImpls.test_gdb_cmd_lang_cpython_quick_implc              	   C   s"   t ƒ � ttƒdƒ W 5 Q R X d S r-   )r   Ú	_dbg_njitr&   r/   r$   r$   r%   Ú%test_gdb_cmd_lang_nopython_quick_implY   s    z6TestGdbBindImpls.test_gdb_cmd_lang_nopython_quick_implc              	   C   s"   t ƒ � ttƒdƒ W 5 Q R X d S r-   )r   Ú_dbg_jitr&   r/   r$   r$   r%   Ú$test_gdb_cmd_lang_objmode_quick_impl^   s    z5TestGdbBindImpls.test_gdb_cmd_lang_objmode_quick_implc              	   C   s   t ƒ � tdƒ W 5 Q R X d S r-   )r   r'   r/   r$   r$   r%   Ú*test_gdb_split_init_and_break_cpython_implc   s    z;TestGdbBindImpls.test_gdb_split_init_and_break_cpython_implc              	   C   s"   t ƒ � ttƒdƒ W 5 Q R X d S r-   )r   r2   r'   r/   r$   r$   r%   Ú+test_gdb_split_init_and_break_nopython_implh   s    z<TestGdbBindImpls.test_gdb_split_init_and_break_nopython_implc              	   C   s"   t ƒ � ttƒdƒ W 5 Q R X d S r-   )r   r4   r'   r/   r$   r$   r%   Ú*test_gdb_split_init_and_break_objmode_implm   s    z;TestGdbBindImpls.test_gdb_split_init_and_break_objmode_implc              	   C   s   t ƒ � tdƒ W 5 Q R X d S r-   )r   r+   r/   r$   r$   r%   Ú5test_gdb_split_init_and_break_w_parallel_cpython_implr   s    zFTestGdbBindImpls.test_gdb_split_init_and_break_w_parallel_cpython_implc              	   C   s"   t ƒ � ttƒdƒ W 5 Q R X d S r-   )r   r2   r+   r/   r$   r$   r%   Ú6test_gdb_split_init_and_break_w_parallel_nopython_implx   s    zGTestGdbBindImpls.test_gdb_split_init_and_break_w_parallel_nopython_implc              	   C   s"   t ƒ � ttƒdƒ W 5 Q R X d S r-   )r   r4   r+   r/   r$   r$   r%   Ú5test_gdb_split_init_and_break_w_parallel_objmode_impl~   s    zFTestGdbBindImpls.test_gdb_split_init_and_break_w_parallel_objmode_implN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úneeds_gdb_harnessr1   r3   r5   r6   r7   r8   r   r9   r:   r;   r$   r$   r$   r%   r,   G   s,   






r,   c                   @   sB   e Zd ZdZdZdZddd„Zdd„ Zedd	„ ƒZ	ed
d„ ƒZ
dS )ÚTestGdbBindingz¿
    This test class is used to generate tests which will run the test cases
    defined in TestGdbBindImpls in isolated subprocesses, this is for safety
    in case something goes awry.
    FTc           	         s�   t j|t jt j|dd�‰ ‡ fdd„}t d|¡}zP| ¡  ˆ  ¡ \}}ˆ j}|dkrnt	d|| 
¡ | 
¡ f ƒ‚| 
¡ | 
¡ fW ¢S | ¡  X dS )	NT)ÚstdoutÚstderrÚenvÚshellc                      s    ˆ j  ¡  ˆ j ¡  ˆ  ¡  d S ©N)rB   ÚflushrC   Úkillr$   ©Úpopenr$   r%   rH   œ   s    

z$TestGdbBinding.run_cmd.<locals>.killg      4@r   z9process failed with code %s: stderr follows
%s
stdout :%s)NN)Ú
subprocessÚPopenÚPIPEÚ	threadingÚTimerÚcancelÚstartÚcommunicateÚ
returncodeÚAssertionErrorÚdecode)	r0   ÚcmdlinerD   Z
kill_is_okrH   ÚtimeoutÚoutÚerrÚretcoder$   rI   r%   Úrun_cmd”   s*    üþÿ
zTestGdbBinding.run_cmdc                 K   s>   t j ¡ }d|d< d|d< tjdd|g}| jd |¡|f|ŽS )Nr   Z	NUMBA_OPTr   z-mznumba.runtestsú )ÚosÚenvironÚcopyÚsysÚ
executabler[   Újoin)r0   ÚtestÚkwargsZenv_copyrV   r$   r$   r%   Úrun_test_in_separate_process¯   s
    
z+TestGdbBinding.run_test_in_separate_processc                    sj   t j}t j}| d¡st‚| dd¡}d|||f ‰ ‡ fdd„}d|krVt| ||ƒ nt| |t|ƒƒ d S )NÚ_implÚ z%s.%s.%sc                    sd   |   ˆ ¡\}}d|› d|› d�}| jd||d� | jd||d� | jd||d� | jd||d� d S )	Nz
STDOUT=z
STDERR=Ú
zGNU gdb)ÚmsgÚOKÚFAILÚERROR)re   ÚassertInZassertNotIn)r0   ÚoÚeZdbgmsg©Zinjected_methodr$   r%   Útest_templateÁ   s    z-TestGdbBinding._inject.<locals>.test_templateZquick)r,   r=   r<   ÚendswithrT   ÚreplaceÚsetattrr   )ÚclsÚnameZthemodZtheclsZmethnamerq   r$   rp   r%   Ú_inject¸   s    zTestGdbBinding._injectc                 C   s&   t tƒD ]}| d¡r|  |¡ qd S )NZtest_gdb)Údirr,   Ú
startswithrw   )ru   rv   r$   r$   r%   ÚgenerateÍ   s    
zTestGdbBinding.generateN)F)r<   r=   r>   r?   Z_numba_parallel_test_Ú_DEBUGr[   re   Úclassmethodrw   rz   r$   r$   r$   r%   rA   …   s   
	
rA   c                   @   s   e Zd Zedd„ ƒZdS )ÚTestGdbMiscc                    sZ   dd„ }d‰ ‡ ‡fdd„}t ttgƒD ]\}}|||ƒ}||ƒ q&tdd„ ƒ}||ƒ d S )Nc                    s   t ‡ ‡fdd„ƒ}|S )Nc                     s   d} ˆ ƒ  d}ˆƒ  | | S ©Nr   é   r$   ©r!   r"   ©Úf1Úf2r$   r%   Úimplß   s
    z:TestGdbMisc.test_call_gdb_twice.<locals>.gen.<locals>.impl)r   )r‚   rƒ   r„   r$   r�   r%   ÚgenÞ   s    z,TestGdbMisc.test_call_gdb_twice.<locals>.genz8Calling either numba.gdb() or numba.gdb_init() more thanc              	      s4   ˆ  tj¡�}| ƒ  W 5 Q R X ˆ ˆ t|jƒ¡ d S rF   )ÚassertRaisesr   ZUnsupportedErrorrm   ÚstrÚ	exception)ÚfuncÚraises©Zmsg_headr0   r$   r%   Úcheckê   s    z.TestGdbMisc.test_call_gdb_twice.<locals>.checkc                  S   s   d} t ƒ  d}tƒ  | | S r~   )r   r   r€   r$   r$   r%   Úuse_globalsó   s
    z4TestGdbMisc.test_call_gdb_twice.<locals>.use_globals)r   r   r   r   )r0   r…   rŒ   Úg1Úg2r‰   r�   r$   r‹   r%   Útest_call_gdb_twiceÜ   s    



zTestGdbMisc.test_call_gdb_twiceN)r<   r=   r>   r   r�   r$   r$   r$   r%   r}   ×   s   r}   c                   @   s   e Zd Zdd„ ZdS )ÚTestGdbExceptionsc                    st   dd„ }|t dd�tfD ]V}ttfD ]H‰ ‡ fdd„}|  tj¡�}||ƒƒ  W 5 Q R X d}|  |t|j	ƒ¡ q$qd S )Nc                 S   s   | S rF   r$   )Úxr$   r$   r%   Únop_compiler  s    z5TestGdbExceptions.test_call_gdb.<locals>.nop_compilerT)r   c                      s
   ˆ ƒ  d S rF   r$   r$   ©Úmethr$   r%   Úpython_func  s    z4TestGdbExceptions.test_call_gdb.<locals>.python_funcz2gdb support is only available on unix-like systems)
r	   r   r   r   r†   r   ZTypingErrorrm   r‡   rˆ   )r0   r“   Úcompilerr–   rŠ   ri   r$   r”   r%   Útest_call_gdb  s    zTestGdbExceptions.test_call_gdbN)r<   r=   r>   r˜   r$   r$   r$   r%   r‘   þ   s   r‘   Ú__main__)5r?   r]   ÚplatformrK   r`   rN   Ú	itertoolsr   Znumbar   r   r   r   r   Z
numba.corer   r	   Znumba.tests.supportr
   r   r   r   Znumba.tests.gdb_supportr   ZunittestÚ	_platformry   Z
_unix_likeZ
skipUnlessZ	unix_onlyZskipIfZnot_unixÚmachineZ
_arch_nameZ_is_armZnot_armr^   ÚgetZ	_gdb_condr@   r   r2   r4   r&   r'   r+   r,   rA   rz   r}   r‘   r<   Úmainr$   r$   r$   r%   Ú<module>   s^   
ÿþ
	<L$
