a
    –§»a"   ã                   @   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 ddlmZmZmZmZ ddlZejZe d	¡p¸e d
¡p¸dev Ze ed¡Ze ed¡Ze  ¡ Z!e!dv Z"e e"d¡Z#ej$ %dd¡dkZ&e e&d¡Z'zeƒ  dZ(W n e)�y2   dZ(Y n0 dZ*e e(e*¡Z+edƒZ,e	dd�Z-eddd�Z.dd„ Z/dd„ Z0dd„ Z1e#eG dd „ d eƒƒƒZ2e#ee+G d!d"„ d"eƒƒƒƒZ3e3 4¡  e#ee+G d#d$„ d$eƒƒƒƒZ5eG d%d&„ d&eƒƒZ6e7d'k�røe 8¡  dS )(z
Tests gdb bindings
é    N)Úpermutations)ÚnjitÚgdbÚgdb_initÚgdb_breakpointÚprange)Úerrors)Újit)Ú_confirm_gdb)ÚTestCaseÚcaptured_stdoutÚtagÚskip_parfors_unsupportedÚ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 harnessTFz;functioning gdb with correct ptrace permissions is requiredÚlong_running)Ú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$   úN/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numba/tests/test_gdb.pyÚimpl_gdb_call4   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_bp<   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_parallelE   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   s2   t ƒ � tdƒ W d   ƒ n1 s$0    Y  d S ©Né
   )r   r&   ©Úselfr$   r$   r%   Ú$test_gdb_cmd_lang_cpython_quick_impl]   s    z5TestGdbBindImpls.test_gdb_cmd_lang_cpython_quick_implc                 C   s6   t ƒ � ttƒdƒ W d   ƒ n1 s(0    Y  d S r-   )r   Ú	_dbg_njitr&   r/   r$   r$   r%   Ú%test_gdb_cmd_lang_nopython_quick_implb   s    z6TestGdbBindImpls.test_gdb_cmd_lang_nopython_quick_implc                 C   s6   t ƒ � ttƒdƒ W d   ƒ n1 s(0    Y  d S r-   )r   Ú_dbg_jitr&   r/   r$   r$   r%   Ú$test_gdb_cmd_lang_objmode_quick_implg   s    z5TestGdbBindImpls.test_gdb_cmd_lang_objmode_quick_implc                 C   s2   t ƒ � tdƒ W d   ƒ n1 s$0    Y  d S r-   )r   r'   r/   r$   r$   r%   Ú*test_gdb_split_init_and_break_cpython_impll   s    z;TestGdbBindImpls.test_gdb_split_init_and_break_cpython_implc                 C   s6   t ƒ � ttƒdƒ W d   ƒ n1 s(0    Y  d S r-   )r   r2   r'   r/   r$   r$   r%   Ú+test_gdb_split_init_and_break_nopython_implq   s    z<TestGdbBindImpls.test_gdb_split_init_and_break_nopython_implc                 C   s6   t ƒ � ttƒdƒ W d   ƒ n1 s(0    Y  d S r-   )r   r4   r'   r/   r$   r$   r%   Ú*test_gdb_split_init_and_break_objmode_implv   s    z;TestGdbBindImpls.test_gdb_split_init_and_break_objmode_implc                 C   s2   t ƒ � tdƒ W d   ƒ n1 s$0    Y  d S r-   )r   r+   r/   r$   r$   r%   Ú5test_gdb_split_init_and_break_w_parallel_cpython_impl{   s    zFTestGdbBindImpls.test_gdb_split_init_and_break_w_parallel_cpython_implc                 C   s6   t ƒ � ttƒdƒ W d   ƒ n1 s(0    Y  d S r-   )r   r2   r+   r/   r$   r$   r%   Ú6test_gdb_split_init_and_break_w_parallel_nopython_impl�   s    zGTestGdbBindImpls.test_gdb_split_init_and_break_w_parallel_nopython_implc                 C   s6   t ƒ � ttƒdƒ W d   ƒ n1 s(0    Y  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,   P   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|¡}zV| ¡  ˆ  ¡ \}}ˆ j}|dkrntd|| 	¡ | 	¡ f ƒ‚| 	¡ | 	¡ fW | 
¡  S | 
¡  0 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ÚstartÚcommunicateÚ
returncodeÚAssertionErrorÚdecodeÚcancel)	r0   ÚcmdlinerD   Z
kill_is_okrH   ÚtimeoutÚoutÚerrÚretcoder$   rI   r%   Úrun_cmd�   s.    üþÿþ
zTestGdbBinding.run_cmdc                 K   sB   t j ¡ }d|d< d|d< tjdd|g}| jd |¡|fi |¤Ž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J ‚| dd¡}d|||f ‰ ‡ fdd„}d|v rVt| ||ƒ nt| |t|ƒƒ d S )NÚ_implÚ z%s.%s.%sc                    sF   |   ˆ ¡\}}|  d|¡ |  d|¡ |  d|v¡ |  d|v¡ d S )NzGNU gdbÚOKÚFAILÚERROR)re   ÚassertInÚ
assertTrue)r0   ÚoÚe©Zinjected_methodr$   r%   Útest_templateÊ   s
    z-TestGdbBinding._inject.<locals>.test_templateZquick)r,   r=   r<   ÚendswithÚreplaceÚsetattrr   )ÚclsÚnameZthemodZtheclsZmethnamerp   r$   ro   r%   Ú_injectÁ   s    zTestGdbBinding._injectc                 C   s&   t tƒD ]}| d¡r|  |¡ qd S )NZtest_gdb)Údirr,   Ú
startswithrv   )rt   ru   r$   r$   r%   ÚgenerateÕ   s    
zTestGdbBinding.generateN)F)r<   r=   r>   r?   Z_numba_parallel_test_Z_DEBUGr[   re   Úclassmethodrv   ry   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                    sH   ˆ  tj¡�}| ƒ  W d   ƒ n1 s(0    Y  ˆ ˆ t|jƒ¡ d S rF   )ÚassertRaisesr   ZUnsupportedErrorrk   Ú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Š   Zg1Z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              
      sˆ   dd„ }|t dd�tfD ]j}ttfD ]\‰ ‡ fdd„}|  tj¡�}||ƒƒ  W d   ƒ n1 s`0    Y  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TypingErrorrk   r…   r†   )r0   r�   Úcompilerr’   rˆ   Úmsgr$   r�   r%   Útest_call_gdb	  s    (zTestGdbExceptions.test_call_gdbN)r<   r=   r>   r•   r$   r$   r$   r%   r�     s   r�   Ú__main__)9r?   r]   ÚplatformrK   r`   rN   Ú	itertoolsr   Znumbar   r   r   r   r   Z
numba.corer   r	   Znumba.misc.gdb_hookr
   Znumba.tests.supportr   r   r   r   ZunittestÚ	_platformrx   Z
_unix_likeZ
skipUnlessZ	unix_onlyZskipIfZnot_unixÚmachineZ
_arch_nameZ_is_armZnot_armr^   ÚgetZ	_gdb_condr@   Z	_HAVE_GDBÚ	ExceptionÚ_msgZ	needs_gdbr   r2   r4   r&   r'   r+   r,   rA   ry   r{   r�   r<   Úmainr$   r$   r$   r%   Ú<module>   sl   
ÿþ

	<K$
