
    sKg3                        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j0                        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j0                        Z 	 d dl!Z!	  e!jD                          y# e#$ r.Z$dZ% ejL                  e%jO                  e$             Y dZ$[$ydZ$[$ww xY w# e($ r Y y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                     |j                  dd       | _        t        j                  j	                  d       t        t        |   |i | y )Nsuitez:x)popdiscovered_suitesyswarnoptionsappendsuperr   __init__)selfargskwargs	__class__s      \/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/llvmlite/tests/customize.pyr   zNumbaTestProgram.__init__!   s?     &

7D 9 	t$.??    c                 f    | j                   | j                   | _        y t        t        |           y N)r   testr   r   createTests)r   r   s    r   r   zNumbaTestProgram.createTests(   s*      ,--DI"D57r   c                     t         t        |          }| j                  |j	                  ddddd       |j	                  ddd	dd
       |j	                  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D??"k	'3%F   H 	D"2#/!4 	 	6 	Ki#/!7 	 	9 r   c                     t         j                  dk  r8d|v r|j                  d       d| _        d|v r|j                  d       d| _        t
        t        |   |       | j                  dk  rd| _	        y y )N)      r   Tr#   r   )
r   version_inforemover   r$   r   r   	parseArgs	verbositybuffer)r   argvr   s     r   r/   zNumbaTestProgram.parseArgs?   sp    f$t|D!#t|D!$(!/5>>Q DK r   c                      j                   r1t         _        t        t        d      s7t        j                  d       n! j                  t        j                   _         j                  r<t         j                   j                   j                   j                         _         fd} j                  rt        j                   j#                  t        j                   j%                  t        j&                  d   j(                              d   dz   }t+        j,                  t.        j0                        }|j3                          	 |j5                  |       |j7                          t9        d	|       |j;                  |       y  |        y # |j7                          t9        d	|       |j;                  |       w xY w)
Ngettotalrefcountz^detecting reference leaks requires a debug build of Python, only memory leaks will be detected)r0   failfastr1   c                  *    t         t                  y r   )r   r   runTests)r   r   s   r   run_tests_realz1NumbaTestProgram.runTests.<locals>.run_tests_real`   s    "D2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   sF   <</DO3 23 ) * __$&55DO0;?>>:>--8<EDO
	5 <<ww''  Z!8!A!ABH   t'8'89AHHJ'		.)		XGHX&	 		XGHX&s   F 1G)__name__
__module____qualname____doc__r   r%   r$   r   r   r&   r/   r7   __classcell__r   s   @r   r   r      s8     GGL@8"" "r   r   c                     	 t         j                  } 	 t         j                  }t         j                  t         j
                  t         j                  t         j                  fD ]  }||j                           t        j                          t        j                           |         |       fS # t        $ r d } Y w xY w# t        $ r d }Y w xY w)Nc                       yN*    r]   r   r   func1z_refleak_cleanup.<locals>.func1       r   c                       y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    &&$$ ::szz3>>3>>JLLN K JJL7EG%  	
  	s"   B/ C /B>=B>CCc                       e Zd Zy)ReferenceLeakErrorN)rS   rT   rU   r]   r   r   ro   ro      s    r   ro   c                       e Zd Zd Zy)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                 j   | j                   j                          | j                  }| j                  }dg||z
  z  }dg||z
  z  }t	               }t        dd      D ]  }||    	 dx}}	t        |      D ]  }t        j                         }
|j                  |
       |
j                         sP| j                  j                  |
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   sJ   ##++C8g-.	sh01 I	tS!AaL " $%$yxA##%CHHSM $$&$$S\\2""3::.$$$4$6!KG|)28i3G)H	!g+&(1+2>3? )@ Q$% & '28)L# !$ ,&&r   c           
         	 | j                  |      \  }}d }d }d}|d|f|d|ffD ]2  \  }}}	 |	|      s|d|d|dt        |      }
d	}	 t	        |
       |st        t        | ;  |       y y # t        $ r | j                         rJ Y y w xY w# t
        $ r t        j                         }Y nw xY w| j                  r!| j                  j                  |d
|d       | j                  ||       )Nc                     t        |       S r   )anydeltass    r   check_rc_deltasz5RefleakTestResult.addSuccess.<locals>.check_rc_deltas   s    v;r   c                 v    d| j                  d      z  t        |       k  ryt        |       t        d      k  syy)Nr+   r   T)   r   F)countlensetr   s    r   check_alloc_deltasz8RefleakTestResult.addSuccess.<locals>.check_alloc_deltas   s4    6<<?"S[0v;#j/1r   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|		  o60BC+E&FIw v&)S[:.,S11+E #T5d; G  	))+++	: ! ."||~H.<<KK%%Iv&FGh/s#   A5 B5BBB65B6)rS   rT   rU   r{   rz   r   r   rW   rX   s   @r   rv   rv      s    FK 'D'< '<r   rv   c                       e Zd ZeZy)r;   N)rS   rT   rU   rv   resultclassr]   r   r   r;   r;      s    #Kr   r;   c                     t        | t        j                        r%g }| D ]  }|j                  t	        |              |S | gS )z$Expand suite into list of tests
    )
isinstancer?   	TestSuiter   _flatten_suite)r   testsxs      r   r   r      s@     $**+ALL*+ vr   c                       e Zd ZdZd Zy)ParallelTestResultzA
    A TestResult able to inject results from other results.
    c                 N   | j                   j                  |j                   j                                | j                   j                          | xj                  |j                  z  c_        | j
                  j                  |j
                         | j                  j                  |j                         | j                  j                  |j                         | j                  j                  |j                         | j                  j                  |j                         y)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3(V__-6==)FNN+$$V%<%<=  ''(B(BCr   N)rS   rT   rU   rV   r   r]   r   r   r   r      s    Dr   r   c                        e Zd ZdZdZd Zd Zy)_MinimalResultz7
    A minimal, picklable TestResult-alike object.
    )r   r   r   r   r   rl   
shouldStopr   c                     d|_         y)zR
        Remove any unpicklable attributes from TestCase instance *case*.
        N)_outcomeForDoCleanups)r   cases     r   
fixup_casez_MinimalResult.fixup_case  s    
 &*"r   c           	      2   | j                   D ]  }t        | |t        ||              | j                  D ]  \  }}| j	                  |        | j
                  D ]  \  }}| j	                  |        | j                  D ]  \  }}| j	                  |        y r   )	__slots__setattrgetattrr   r   r   r   )r   original_resultattrr   _s        r   r   z_MinimalResult.__init__"  s    NNDD$ >? #,,GD!OOD! -{{GD!OOD! #}}GD!OOD! %r   N)rS   rT   rU   rV   r   r   r   r]   r   r   r   r     s    CI*"r   r   c                       e Zd ZdZd Zd Zy)_FakeStringIOz:
    A trivial picklable StringIO-alike for Python 2.
    c                     || _         y 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y)_MinimalRunnerzu
    A minimal picklable object able to instantiate a runner in a
    child process and run a test case with it.
    c                      || _         || _        y 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                  |_        | j                  |      5   ||       d d d        t        |j                  j                               |_        t        |      S # 1 sw Y   <xY w)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& //  &L ' &fmm&<&<&>?f%%	 '&s   	CC&c              #      K   t        |j                        }	 | t        |j                        |z
  }|D ]  }|j                  |=  y# t        |j                        |z
  }|D ]  }|j                  |=  w xY w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  su      DMM*	(J /-?N&MM$' ' !/-?N&MM$' 's   A;A
 -A;
.A88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                 `    t        j                  j                  | fi | || _        || _        y r   )r   r@   r   r   r   )r   r   r   s      r   r   zParallelTestRunner.__init__p  s*    &&t6v6$!r   c                    t        | j                  | j                        }t        j                         }|j
                  }	  ||| j                        D ]"  } |j                  |       |j                  s" n ||j                          |j                          S # |j                          |j                          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     &doot7G7GH##%""		 $\4?? C"""<0** !D  NNIIK NNIIKs   4B 7B "B>c                 ^    t        |      | _        t        t        |   | j
                        S r   )r   r   r   rA   r~   r   )r   r   r   s     r   r~   zParallelTestRunner.run  s(    (. '24??CCr   )
rS   rT   rU   rV   r   r   r   r   r~   rW   rX   s   @r   rA   rA   h  s%    
 %K"
"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      sF       	 	  
    , ,\x}} \B !2	 	k%% N<-- N<b$-- $	D.. D&"V "6	F 	,(V ,(^"D.. "DJ
)) )<cjjQj'(()  		s*   1D> 6D D;$D66D;>EE