
    J/Ph3                        d dl Z d dlZd dlZd dlm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Zd dl
mZmZmZ  G d de
j                  Zee
_        d Z G d de          Z G d	 d
e j                  Z G d dej                  Z G d dej                  Zd Z G d dej                  Z G d de          Z G d de          Z G d de          Z G d dej                  Z 	 d dl!Z!	  e!j"                     dS # e#$ r1Z$dZ% ej&        e%'                    e$                     Y dZ$[$dS dZ$[$ww xY w# e($ r Y dS w xY w)    N)StringIO)resultrunnersignalsc                   V     e Zd ZdZdZdZdZ fdZ fdZ fdZ	 fdZ
 fdZ xZS )NumbaTestProgramz
    A TestProgram subclass adding the following options:
    * a -R option to enable reference leak detection
    * a --profile option to enable profiling of the test run

    Currently the options are only added in 3.4+.
    Fc                     |                     dd           | _        t          j                            d            t          t          |           j        |i | d S )Nsuitez:x)popdiscovered_suitesyswarnoptionsappendsuperr   __init__)selfargskwargs	__class__s      X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/llvmlite/tests/customize.pyr   zNumbaTestProgram.__init__!   sZ     &

7D 9 9 	t$$$.%%.??????    c                     | j         | j         | _        d S t          t          |                                            d S N)r   testr   r   createTests)r   r   s    r   r   zNumbaTestProgram.createTests(   s=     ,-DIII"D))5577777r   c                     t          t          |                                           }| j        |                    ddddd           |                    ddd	dd
           |                    dddd           |S )N-Rz	--refleakrefleak
store_truezDetect reference / memory leaks)destactionhelp-mz--multiprocessmultiprocesszParallelize testsz	--profileprofilezProfile the test run)r   r   _getParentArgParser
testRunneradd_argument)r   parserr   s     r   r&   z$NumbaTestProgram._getParentArgParser.   s     '..BBDD?"k	'3%F   H H H 	D"2#/!4 	 	6 	6 	6 	Ki#/!7 	 	9 	9 	9 r   c                     t           j        dk     r@d|v r|                    d           d| _        d|v r|                    d           d| _        t          t          |                               |           | j        dk    r	d| _	        d S d S )N)      r   Tr#   r   )
r   version_inforemover   r$   r   r   	parseArgs	verbositybuffer)r   argvr   s     r   r/   zNumbaTestProgram.parseArgs?   s    f$$t||D!!!#t||D!!!$(!%%//555>Q DKKK r   c                      j         r6t           _        t          t          d          st          j        d           n j        t          j         _         j	        r,t           j         j         j         j                   _         fd} j        r t          j                            t          j                            t          j        d         j                            d         dz   }t+          j        t.          j                  }|                                 	 |                    |           |                                 t9          d	|           |                    |           d S # |                                 t9          d	|           |                    |           w xY w |             d S )
Ngettotalrefcountz^detecting reference leaks requires a debug build of Python, only memory leaks will be detected)r0   failfastr1   c                  V    t          t                                                     d S r   )r   r   runTests)r   r   s   r   run_tests_realz1NumbaTestProgram.runTests.<locals>.run_tests_real`   s&    "D))2244444r   __main__r   z.prof)timerzWriting test profile data into )r   RefleakTestRunnerr'   hasattrr   warningswarnunittestTextTestRunnerr$   ParallelTestRunnerr0   r5   r1   r%   ospathsplitextbasenamemodules__file__cProfileProfiletimeperf_counterenableruncalldisableprint
dump_stats)r   r8   filenamepr   s   `   r   r7   zNumbaTestProgram.runTestsN   s   < 		6/DO3 233 * ) * * * _$&5DO 	E0;?>:>-8<E E EDO
	5 	5 	5 	5 	5 	5 < 	w''  Z!8!ABB H  t'8999AHHJJJ'		.)))		XXGHHHX&&&&& 		XXGHHHX&&&&Ns   'E9 9=F6)__name__
__module____qualname____doc__r   r%   r$   r   r   r&   r/   r7   __classcell__r   s   @r   r   r      s          GGL@ @ @ @ @8 8 8 8 8    "    " " " " " " " " "r   r   c                     	 t           j        } n# t          $ r d } Y nw xY w	 t           j        }n# t          $ r d }Y nw xY wt           j        t           j        t           j        t           j        fD ]}||                                 t          j	                     t          j                      |              |            fS )Nc                      dS N*    r]   r   r   func1z_refleak_cleanup.<locals>.func1       2r   c                      dS r[   r]   r]   r   r   func2z_refleak_cleanup.<locals>.func2   r_   r   )r   getallocatedblocksAttributeErrorr4   stdoutstderr
__stdout__
__stderr__flush_clear_type_cachegccollect)r^   ra   streams      r   _refleak_cleanuprm   {   s    &   	 	 	 	 	$   	 	 	 	 	 :sz3>3>J  LLNNNJLLL577EEGGs    0 A A c                       e Zd ZdS )ReferenceLeakErrorN)rS   rT   rU   r]   r   r   ro   ro      s        Dr   ro   c                       e Zd Zd ZdS )IntPoolc                     |S r   r]   )r   keys     r   __missing__zIntPool.__missing__   s    
r   N)rS   rT   rU   rt   r]   r   r   rq   rq      s#            r   rq   c                   ,     e Zd ZdZdZd Z fdZ xZS )RefleakTestResultr+      c                 x   | j                                          | j        }| j        }dg||z
  z  }dg||z
  z  }t	                      }t          dd          D ]
}||          dx}}	t          |          D ]}t          j                    }
|                    |
           |
	                                sE| j
                            |
j
                   | j                            |
j                   t          ~
t                      \  }}||k    r"|||	z
           |||z
  <   |||z
           |||z
  <   ||}	}||fS )Nr   i8   )rl   rh   repetitionswarmuprq   ranger   
TestResultrunwasSuccessfulfailuresextenderrorsAssertionErrorrm   )r   r   repcountnwarmup	rc_deltasalloc_deltas	_int_poolialloc_before	rc_beforeresalloc_afterrc_afters                r   
_huntLeakszRefleakTestResult._huntLeaks   sq   #+C8g-.	sh01 II	tS!! 	 	AaLLL#$$yx 	< 	<A#%%CHHSMMM $$&& %$$S\222""3:...$$$4$6$6!KG||)28i3G)H	!g+&(1+2>3? )@ Q$% & '28)LL,&&r   c           
      B   	 |                      |          \  }}n'# t          $ r |                                 rJ Y d S w xY wd }d }d}|d|f|d|ffD ]\  }}}	 |	|          r|d|d|dt          |          }
d	}	 t	          |
          # t
          $ r t          j                    }Y nw xY w| j        r | j	        
                    |d
|d           |                     ||           |s*t          t          |                               |           d S d S )Nc                      t          |           S r   )anydeltass    r   check_rc_deltasz5RefleakTestResult.addSuccess.<locals>.check_rc_deltas   s    v;;r   c                     d|                      d          z  t          |           k     rdS t          |           t          d          k    sdS dS )Nr+   r   T)   r   F)countlensetr   s    r   check_alloc_deltasz8RefleakTestResult.addSuccess.<locals>.check_alloc_deltas   sH    6<<??"S[[00tv;;#j//11t5r   F
referenceszmemory blocksz leaked  z, sum=Tz = )r   r   r   sumro   	Exceptionr   exc_infoshowAllrl   write
addFailurer   rv   
addSuccess)r   r   r   r   r   r   failedr   	item_namecheckermsgr   r   s               r   r   zRefleakTestResult.addSuccess   s   	&*ood&;&;#I|| 	 	 	))+++++FF		 	 		 	 	  o60BC+E 	0 	0&FIw wv 
0DD&&&)))S[[[:.,S111  . . ."|~~HHH.< HK%%IIIvvv&FGGGh/// 	<#T**55d;;;;;	< 	<s      A A BB21B2)rS   rT   rU   r{   rz   r   r   rW   rX   s   @r   rv   rv      sR        FK '  '  'D'< '< '< '< '< '< '< '< '<r   rv   c                       e Zd ZeZdS )r;   N)rS   rT   rU   rv   resultclassr]   r   r   r;   r;      s        #KKKr   r;   c                     t          | t          j                  r+g }| D ]$}|                    t	          |                     %|S | gS )z$Expand suite into list of tests
    )
isinstancer?   	TestSuiter   _flatten_suite)r   testsxs      r   r   r      sV     $*++  	, 	,ALL**++++vr   c                       e Zd ZdZd ZdS )ParallelTestResultzA
    A TestResult able to inject results from other results.
    c                    | j                             |j                                                    | j                                          | xj        |j        z  c_        | j                            |j                   | j                            |j                   | j                            |j                   | j	                            |j	                   | j
                            |j
                   dS )zI
        Add the results from the other *result* to this result.
        N)rl   r   getvaluerh   testsRunr   r   r   skippedexpectedFailuresunexpectedSuccesses)r   r   s     r   add_resultszParallelTestResult.add_results  s     	&-0022333(V_---6=)))FN+++$$V%<=== ''(BCCCCCr   N)rS   rT   rU   rV   r   r]   r   r   r   r      s2         D D D D Dr   r   c                   "    e Zd ZdZdZd Zd ZdS )_MinimalResultz7
    A minimal, picklable TestResult-alike object.
    )r   r   r   r   r   rl   
shouldStopr   c                     d|_         dS )zR
        Remove any unpicklable attributes from TestCase instance *case*.
        N)_outcomeForDoCleanups)r   cases     r   
fixup_casez_MinimalResult.fixup_case  s    
 &*"""r   c           	      $   | j         D ]!}t          | |t          ||                     "| j        D ]\  }}|                     |           | j        D ]\  }}|                     |           | j        D ]\  }}|                     |           d S r   )	__slots__setattrgetattrr   r   r   r   )r   original_resultattrr   _s        r   r   z_MinimalResult.__init__"  s    N 	@ 	@DD$ > >????, 	" 	"GD!OOD!!!!{ 	" 	"GD!OOD!!!!} 	" 	"GD!OOD!!!!	" 	"r   N)rS   rT   rU   rV   r   r   r   r]   r   r   r   r     sD         CI* * *" " " " "r   r   c                       e Zd ZdZd Zd ZdS )_FakeStringIOz:
    A trivial picklable StringIO-alike for Python 2.
    c                     || _         d S r   _value)r   values     r   r   z_FakeStringIO.__init__2  s    r   c                     | j         S r   r   )r   s    r   r   z_FakeStringIO.getvalue5  s
    {r   N)rS   rT   rU   rV   r   r   r]   r   r   r   r   -  s<               r   r   c                   >    e Zd ZdZd Zd Zej        d             ZdS )_MinimalRunnerzu
    A minimal picklable object able to instantiate a runner in a
    child process and run a test case with it.
    c                 "    || _         || _        d S r   )
runner_clsrunner_args)r   r   r   s      r   r   z_MinimalRunner.__init__?  s    $&r   c                    | j         }t                      |d<    | j        di |} |j                    }t	          j                     t	          j        |           |j        |_        |j        |_        | 	                    |          5   ||           d d d            n# 1 swxY w Y   t          |j                                                  |_        t          |          S )Nrl   r]   )r   r   r   _makeResultr   installHandlerregisterResultr5   r1   cleanup_objectr   rl   r   r   )r   r   r   r   r   s        r   __call__z_MinimalRunner.__call__F  s   ! $::x **6**##%%   v&&& /  && 	 	DLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 &fm&<&<&>&>??f%%%s   	B!!B%(B%c              #      K   t          |j                  }	 |V  t          |j                  |z
  }|D ]
}|j        |= dS # t          |j                  |z
  }|D ]
}|j        |= w xY w)zu
        A context manager which cleans up unwanted attributes on a test case
        (or any other object).
        N)r   __dict__)r   r   vanilla_attrsspurious_attrsnames        r   r   z_MinimalRunner.cleanup_objectY  s       DM**	(JJJ //-?N& ( (M$''( ( !//-?N& ( (M$''(s   A &A(N)	rS   rT   rU   rV   r   r   
contextlibcontextmanagerr   r]   r   r   r   r   9  s[         
' ' '& & && ( ( ( ( (r   r   c                   2     e Zd ZdZeZd Zd Z fdZ xZ	S )rA   z\
    A test runner which delegates the actual running to a pool of child
    processes.
    c                 P    t          j        j        | fi | || _        || _        d S r   )r   r@   r   r   r   )r   r   r   s      r   r   zParallelTestRunner.__init__p  s3    &t66v666$!r   c                 t   t          | j        | j                  }t          j                    }|j        }	  ||| j                  D ]} |j        |           |j        r n||	                                 |
                                 S # |	                                 |
                                 w xY wr   )r   r   r   multiprocessingPoolimap_unordered
_test_listr   r   	terminatejoin)r   r   child_runnerpoolimapchild_results         r   
_run_innerzParallelTestRunner._run_inneru  s     &dot7GHH#%%"		 $\4? C C  ""<000* E NNIIKKKK NNIIKKKKs   .B *B7c                     t          |          | _        t          t          |                               | j                  S r   )r   r   r   rA   r~   r   )r   r   r   s     r   r~   zParallelTestRunner.run  s5    (.. '..224?CCCr   )
rS   rT   rU   rV   r   r   r   r   r~   rW   rX   s   @r   rA   rA   h  sp         
 %K" " "
  "D D D D D D D D Dr   rA   z+Failed to enable faulthandler due to:
{err})err))collectionsr   rH   ior   rj   rB   r   r   rJ   r?   r=   r   r   r   mainr   rm   RuntimeErrorro   defaultdictrq   TextTestResultrv   r@   r;   r   r   objectr   r   r   rA   faulthandlerrL   BaseExceptioner   r>   formatImportErrorr]   r   r   <module>r      sA                  				 				     



    , , , , , , , , , ,\ \ \ \ \x} \ \ \B !  2	 	 	 	 	 	 	 	    k%   N< N< N< N< N<- N< N< N<b$ $ $ $ $- $ $ $	 	 	D D D D D. D D D&" " " " "V " " "6	 	 	 	 	F 	 	 	,( ,( ,( ,( ,(V ,( ,( ,(^"D "D "D "D "D. "D "D "DJ
)) ) ) )<cjjQj''((((((((()  	 	 	DD	s*   1E  6D D=&D88D= E	E	