
    J/Ph}                         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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v Z ej        ed          Z ej        ed          Z  ej!                    Z"e"dv Z# ej        e#d          Z$ej%        &                    dd          dk    Z' ej        e'd          Z( ed          Z) e
d          Z* edd          Z+d Z,d Z-d Z.e$e G d de                                  Z/e$ee G d de                                              Z0e01                                 e$ee G d de                                              Z2e  G d  d!e                      Z3e4d"k    r ej5                     dS 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darwin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                 p    t          dddddd           | dz   }| dz  }| ||f}t          | |||           d S N-exset confirm offcq   Q@)r   printabr   ds       ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/tests/test_gdb_bindings.pyimpl_gdb_callr(   ,   sR     %eS999	AA	DA	
Aq	A	!Q1    c                     t          dddddd           | dz   }| dz  }| ||f}t                       t          | |||           d S r   )r   r   r"   r#   s       r'   impl_gdb_call_w_bpr+   4   s^    U%uc5#>>>	AA	DA	
Aq	A	!Q1r)   c                     t          dddddd           | dz  } t          d          D ]1}| dz   }| dz  }| ||f}t                       t          | |||           2d S )	Nr   r   r   r         r    r!   )r   r   r   r"   )r$   ir%   r   r&   s        r'   (impl_gdb_split_init_and_break_w_parallelr0   =   s    U%uc5#>>>FAAYY  EH1IaAq r)   c                      e Zd ZdZed             Zed             Zed             Zed             Zed             Z	ed             Z
eed                         Zeed	                         Zee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                 r    t                      5  t          d           d d d            d S # 1 swxY w Y   d S N
   )r   r(   selfs    r'   $test_gdb_cmd_lang_cpython_quick_implz5TestGdbBindImpls.test_gdb_cmd_lang_cpython_quick_implU   s     	 	"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   ,00c                     t                      5   t          t                    d           d d d            d S # 1 swxY w Y   d S r4   )r   	_dbg_njitr(   r6   s    r'   %test_gdb_cmd_lang_nopython_quick_implz6TestGdbBindImpls.test_gdb_cmd_lang_nopython_quick_implZ   s     	) 	)$Im$$R(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)   :>>c                     t                      5   t          t                    d           d d d            d S # 1 swxY w Y   d S r4   )r   _dbg_jitr(   r6   s    r'   $test_gdb_cmd_lang_objmode_quick_implz5TestGdbBindImpls.test_gdb_cmd_lang_objmode_quick_impl_   s     	( 	(#H]##B'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(r=   c                 r    t                      5  t          d           d d d            d S # 1 swxY w Y   d S r4   )r   r+   r6   s    r'   *test_gdb_split_init_and_break_cpython_implz;TestGdbBindImpls.test_gdb_split_init_and_break_cpython_impld   s     	# 	#r"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#r9   c                     t                      5   t          t                    d           d d d            d S # 1 swxY w Y   d S r4   )r   r;   r+   r6   s    r'   +test_gdb_split_init_and_break_nopython_implz<TestGdbBindImpls.test_gdb_split_init_and_break_nopython_impli   s     	. 	.)I())"---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.r=   c                     t                      5   t          t                    d           d d d            d S # 1 swxY w Y   d S r4   )r   r?   r+   r6   s    r'   *test_gdb_split_init_and_break_objmode_implz;TestGdbBindImpls.test_gdb_split_init_and_break_objmode_impln   s     	- 	-(H'((,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-r=   c                 r    t                      5  t          d           d d d            d S # 1 swxY w Y   d S r4   )r   r0   r6   s    r'   5test_gdb_split_init_and_break_w_parallel_cpython_implzFTestGdbBindImpls.test_gdb_split_init_and_break_w_parallel_cpython_impls   s      	9 	94R888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9r9   c                     t                      5   t          t                    d           d d d            d S # 1 swxY w Y   d S r4   )r   r;   r0   r6   s    r'   6test_gdb_split_init_and_break_w_parallel_nopython_implzGTestGdbBindImpls.test_gdb_split_init_and_break_w_parallel_nopython_imply   s      	D 	D?I>??CCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Dr=   c                     t                      5   t          t                    d           d d d            d S # 1 swxY w Y   d S r4   )r   r?   r0   r6   s    r'   5test_gdb_split_init_and_break_w_parallel_objmode_implzFTestGdbBindImpls.test_gdb_split_init_and_break_w_parallel_objmode_impl   s      	C 	C>H=>>rBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cr=   N)__name__
__module____qualname____doc__needs_gdb_harnessr8   r<   r@   rB   rD   rF   r   rH   rJ   rL    r)   r'   r2   r2   H   sC            ) ) ) ( ( ( # # # . . . - - - 9 9  9 D D  D C C  C C Cr)   r2   c                   T    e Zd ZdZdZdZd	dZd Zed             Z	e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           	      &  	 t          j        |t           j        t           j        |d          		fd}t          j        d|          }	 |                                 	                                \  }}	j        }|dk    r<t          d|d|	                                d|	                                          |	                                |	                                f|
                                 S # |
                                 w xY w)	NT)stdoutstderrenvshellc                       j                                           j                                                                           d S N)rV   flushrW   kill)popens   r'   r]   z$TestGdbBinding.run_cmd.<locals>.kill   s<    L   L   JJLLLLLr)   g      4@r   zprocess failed with code z: stderr follows
z	
stdout :)
subprocessPopenPIPE	threadingTimerstartcommunicate
returncodeAssertionErrordecodecancel)
r7   cmdlinerX   
kill_is_okr]   timeoutouterrretcoder^   s
            @r'   run_cmdzTestGdbBinding.run_cmd   s    (2(2%('+	- - -	 	 	 	 	 /#t,,	MMOOO((**HC&G!||$n %,GGSZZ\\\\3::<<<IJ J J ::<<-NNGNNs   
BC: :Dc                     t           j                                        }d|d<   d|d<   t          j        dd|g} | j        d                    |          |fi |S )Nr   	NUMBA_OPTr   z-mznumba.runtests )osenvironcopysys
executablerp   join)r7   testkwargsenv_copyrj   s        r'   run_test_in_separate_processz+TestGdbBinding.run_test_in_separate_process   sb    :??$$ #  #>4)94@t|CHHW--xBB6BBBr)   c                    t           j        }t           j        }|                    d          sJ |                    dd          }|d|d|fd}d|v rt          | ||           d S t          | |t          |                     d S )N_impl .c                    |                                \  }}d| d| d}t          j        d|          }|(|                     |                    d                     |                     d||           |                     d||           |                     d	||           |                     d
||           d S )Nz
STDOUT=z
STDERR=
z\.\.\. skipped '(.*?)'r    zGNU gdb)msgOKFAILERROR)r}   researchskipTestgroupassertInassertNotIn)r7   oedbgmsgminjected_methods        r'   test_templatez-TestGdbBinding._inject.<locals>.test_template   s    44_EEDAq222Q222F 	3Q77A}aggajj)))MM)QFM333MM$vM...VQF333WaV44444r)   quick)r2   rN   rM   endswithreplacesetattrr   )clsnamethemodtheclsmethnamer   r   s         @r'   _injectzTestGdbBinding._inject   s    !,!*}}W%%%%%<<,,(.=	5 	5 	5 	5 	5 d??C=11111C<#>#>?????r)   c                     t          t                    D ],}|                    d          r|                     |           -d S )Ntest_gdb)dirr2   
startswithr   )r   r   s     r'   generatezTestGdbBinding.generate   sK    ()) 	" 	"Dz** "D!!!	" 	"r)   N)F)rM   rN   rO   rP   _numba_parallel_test__DEBUGrp   r}   classmethodr   r   rR   r)   r'   rT   rT      s          "F   6C C C @ @ [@2 " " [" " "r)   rT   c                   $    e Zd Zed             ZdS )TestGdbMiscc                      d }d fd}t          t          t          g          D ]\  }} |||          } ||           t          d             } ||           d S )Nc                 0     t            fd            }|S )Nc                  >    d}               d}              | |z   S Nr       rR   )r$   r%   f1f2s     r'   implz:TestGdbMisc.test_call_gdb_twice.<locals>.gen.<locals>.impl   s,    1ur)   )r   )r   r   r   s   `` r'   genz,TestGdbMisc.test_call_gdb_twice.<locals>.gen   s3         T Kr)   z8Calling either numba.gdb() or numba.gdb_init() more thanc                                          t          j                  5 } |              d d d            n# 1 swxY w Y                       t	          |j                             d S r[   )assertRaisesr	   UnsupportedErrorr   str	exception)funcraisesmsg_headr7   s     r'   checkz.TestGdbMisc.test_call_gdb_twice.<locals>.check   s    ""6#:;; v              MM(C(8$9$9:::::s   8<<c                  L    d} t                       d}t                       | |z   S r   )r   r   )r$   r%   s     r'   use_globalsz4TestGdbMisc.test_call_gdb_twice.<locals>.use_globals   s'    AEEEAJJJq5Lr)   )r   r   r   r   )r7   r   r   g1g2r   r   r   s   `      @r'   test_call_gdb_twicezTestGdbMisc.test_call_gdb_twice   s    	 	 	 N	; 	; 	; 	; 	; 	;
 #C?33 	 	FB3r2;;DE$KKKK		 	 
	 	kr)   N)rM   rN   rO   r   r   rR   r)   r'   r   r      s/        
   \  r)   r   c                       e Zd Zd ZdS )TestGdbExceptionsc                 X   d }|t          d          t          fD ]}t          t          fD ]{fd}|                     t
          j                  5 }  ||                       d d d            n# 1 swxY w Y   d}|                     |t          |j	                             |d S )Nc                     | S r[   rR   )xs    r'   nop_compilerz5TestGdbExceptions.test_call_gdb.<locals>.nop_compiler  s    Hr)   T)r   c                                     d S r[   rR   )meths   r'   python_funcz4TestGdbExceptions.test_call_gdb.<locals>.python_func  s    DFFFFFr)   z2gdb support is only available on unix-like systems)
r
   r   r   r   r   r	   TypingErrorr   r   r   )r7   r   compilerr   r   r   r   s         @r'   test_call_gdbzTestGdbExceptions.test_call_gdb  s   	 	 	%sD'9'9'94@ 	: 	:Hh : :    &&v'9:: ,f)HH[))+++, , , , , , , , , , , , , , ,Jc3v'7#8#89999:	: 	:s   A33A7:A7N)rM   rN   rO   r   rR   r)   r'   r   r     s#        
: 
: 
: 
: 
:r)   r   __main__)6rP   rt   platformr   r_   rw   rb   	itertoolsr   numbar   r   r   r   r   
numba.corer	   r
   numba.tests.supportr   r   r   r   numba.tests.gdb_supportr   unittest	_platformr   
_unix_like
skipUnless	unix_onlyskipIfnot_unixmachine
_arch_name_is_armnot_armru   get	_gdb_condrQ   r   r;   r?   r(   r+   r0   r2   rT   r   r   r   rM   mainrR   r)   r'   <module>r      s    
			  				     



     " " " " " " = = = = = = = = = = = = = =            ; ; ; ; ; ; ; ; ; ; ; ; - - - - - -  L	""7++ &%%h//&9$   H
,FGG	8?:'EFFX

-
-
(/'#<
=
=JNN:t,,3	'H'	3FGG s>""Dt	3D)))       	
9C 9C 9C 9C 9Cx 9C 9C  	9Cx 	

N" N" N" N" N"X N" N"   	N"b       	

! ! ! ! !( ! !   	!H 
: : : : : : : 
: zHMOOOOO r)   