CasperSecurity

Current Path : /lib/python3.10/test/libregrtest/__pycache__/
Upload File :
Current File : //lib/python3.10/test/libregrtest/__pycache__/main.cpython-310.pyc

o

`�wi�d�@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZddlm Z ddl!m"Z"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)d	Z*Gd
d�d�Z+ddd
�Z,dS)�N)�_parse_args)�	findtests�runtest�get_abs_module�	is_failed�STDTESTS�NOTTESTS�PROGRESS_MIN_TIME�Passed�Failed�
EnvChanged�Skipped�ResourceDenied�Interrupted�
ChildError�	DidNotRun)�setup_tests)�setup_pgo_tests)�removepy�count�format_duration�	printlist)�support)�	os_helperg^@c@s�eZdZdZdd�Zdd�Zd7dd�Zd8d
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd9d1d2�Zd3d4�Zd5d6�Zd0S):�RegrtestalExecute a test suite.

    This also parses command-line options and modifies its behavior
    accordingly.

    tests -- a list of strings containing test names (optional)
    testdir -- the directory in which to look for tests (optional)

    Users other than the Python test suite will certainly want to
    specify testdir; if it's omitted, the directory containing the
    Python test suite is searched for.

    If the tests argument is omitted, the tests listed on the
    command-line will be used.  If that's empty, too, then all *.py
    files beginning with test_ will be used.

    The other default arguments (verbose, quiet, exclude,
    single, randomize, findleaks, use_resources, trace, coverdir,
    print_slow, and random_seed) allow programmers calling main()
    directly to set the values that would normally be set by flags
    on the command line.
    cCs�d|_g|_g|_g|_g|_g|_g|_g|_g|_g|_	g|_
d|_d|_g|_
d|_t��|_d|_d|_d|_d|_d|_d|_d|_d|_dS)NF��)�ns�tests�selected�good�bad�skipped�resource_denieds�environment_changed�run_no_tests�
need_rerun�rerun�first_result�interrupted�
test_times�tracer�time�	monotonic�
start_time�
test_count�test_count_width�next_single_test�next_single_filename�
testsuite_xml�win_load_tracker�tmp_dir�worker_test_name��self�r9�,/usr/lib/python3.10/test/libregrtest/main.py�__init__6s0

zRegrtest.__init__cCs<t|j�t|j�Bt|j�Bt|j�Bt|j�Bt|j�BS�N)�setr r!r"r#r$r%r7r9r9r:�get_executedas���zRegrtest.get_executedFc	Csv|j}t|ttf�s|s|j�|j|f�t|t�r!|j�|�nYt|t	�r3|j
�|�|j�|�nGt|t�r?|j
�|�n;t|t
�rK|j�|�n/t|t�r_|s^|j�|�|j�|�nt|t�rk|j�|�nt|t�rtd|_ntd|��|r�t|ttf�s�|j�|�|j}|r�ddlmm}|D]}z|j�|�|��Wq�|jy�t|tj d��wdSdS)NTzinvalid test result: %rr��file)!�name�
isinstancerrr*�append�duration_secr
r rr"r#r
rr$rr!r&rr%r)�
ValueError�remove�xml_data�xml.etree.ElementTree�etree�ElementTreer3�
fromstring�
ParseError�print�sys�
__stderr__)r8�resultr'�	test_namerG�ET�er9r9r:�accumulate_resultfsH




�

��zRegrtest.accumulate_resultrcCs�|}|��}|durd|d�d|��}t��|j}tt|�d�\}}t|d�\}}d|||f}|�d|��}|rA|dd�}t|dd�dS)	Nz
load avg: z.2f� �<z%d:%02d:%02d���T)�flush)�
getloadavgr,r-r.�divmod�intrM)r8�line�empty�load_avg�	test_time�mins�secs�hoursr9r9r:�log�szRegrtest.logcCsh|jjrdS||j��|j��}t|j�t|j�}|r'|jjs'|�d|��}|�d|�d|���dS)N�/�[z] )	r�quietr0r/�lenr!r$�pgorc)r8�
test_index�textr\�failsr9r9r:�display_progress�szRegrtest.display_progressc
Cs�ttjdd�fi|��}|jrgt_|_|j}|dur0ddlm	}||j�\}}||_||_
t|j�|j
rU|j
\}}}|dksF|dkrUd}	t|	tjdd�t�d�|jr`tj�|j�|_||_dS)Nrr)�parse_worker_argszwInvalid values for the --huntrleaks/-R parameters. The number of warmups and repetitions must be at least 1 each (1:1).T�r@rX�)rrN�argv�xmlpathr�junit_xml_listr3�worker_args�test.libregrtest.runtest_mprmr6r�args�
huntrleaksrM�stderr�exit�tempdir�os�path�
expanduserr)
r8�kwargsrrsrmrQ�warmup�repetitions�_�msgr9r9r:�
parse_args�s&


zRegrtest.parse_argscCs�||_|jjr<tj�|jd�|_z"t|jd��}|�	��
�}|g|_Wd�n1s,wYWn	ty;Ynw|jjr�g|_t
�d�}ttj�tj|jj���*}|D]}|�dd�d}|�
�}|�|�}|durv|j�|���qWWd�n1s�wYt|j�|jjr�t|j�tdd�}t��}|jjr�|jjD]}	|	|vr�|�|	�|�|	�q�g|j_|jjr�t |jjt!�t"��}
nt |jj||�}
|jjs�|jp�|jjp�|
|_#n|j|_#|jj�r|j#dd�|_#z|
�$|j#d�}|
|d|_%Wn
t&�y
Ynw|jj'�r7z|j#d|j#�$|jj'��=Wnt(�y6t)d|jj't*j+d�Ynw|jj,�rY|jj-du�rJt.�/d	�|j_-t.�0|jj-�t.�1|j#�dSdS)
N�
pynexttest�rz\btest_[a-zA-Z0-9_]+\b�#rrz1Couldn't find starting test (%s), using all testsr?i���)2rr�singlerzr{�joinr5r2�open�read�strip�OSError�fromfile�re�compiler�SAVEDCWD�split�searchrC�grouprrhrrr�copy�excluderurF�add�testdirr�listr=r�indexr1�
IndexError�startrErMrNrw�	randomize�random_seed�random�	randrange�seed�shuffle)r8r�fp�	next_test�regexr\�match�stdtests�nottests�arg�alltests�posr9r9r:�
find_tests�s�
���

���



�
�
��
�zRegrtest.find_testscCs|jD]}t|�qdSr<)rrM)r8rAr9r9r:�
list_testss

�zRegrtest.list_testscCsX|D]'}t|tjj�rqt|tj�r|�|�qt|tj�r)t�|�r)t	|�
��qdSr<)rB�unittest�loader�_FailedTest�	TestSuite�_list_cases�TestCaser�
match_testrM�id)r8�suite�testr9r9r:r�s
��zRegrtest._list_casesc	Cs�dt_t�|jj|jj�|jD]%}t|j|�}z
tj	�
|�}|�|�Wqtjy5|j
�|�Yqw|j
rWttjd�ttt|j
�d�dtjd�t|j
tjd�dSdS)NFr?r��skipped:)r�verbose�set_match_testsr�match_tests�ignore_testsrrr��defaultTestLoader�loadTestsFromNamer��SkipTestr"rCrMrNrwrrgr)r8rQ�abstestr�r9r9r:�
list_cases"s
��zRegrtest.list_casesc
Cs|d|j_d|j_d|j_|��|_|��|�d�t|j�}|j�	�|D]~}|j
}|j�|�|j
p5g}|jp:g}dd�|D�}dd�|D�}d|j_|jj}|sU|r�|jjdur_g|j_|jj�|�|jj�|�dd�|jj�}	|�d	|�d
|	�d��n	|�d	|�d��t|j|�}||j_|j|dd
�t|t�r�nq&|jr�ttt|j�d�d�t|j�|��dS)NTFz'Re-running failed tests in verbose modecS�g|]^}}|�d�d�qS�rUr�r���.0�test_full_namer�r9r9r:�
<listcomp>D�z/Regrtest.rerun_failed_tests.<locals>.<listcomp>cSr�r�r�r�r9r9r:r�Er�z
matching: �, zRe-running z in verbose mode (�)z in verbose mode)r'r�z
failed again:)rr��failfast�verbose3�get_tests_resultr(rcr�r&�clearrAr'rC�errors�failuresr��extendr�rrTrBrr!rMrrgr�display_result)
r8�
rerun_listrPrQr�r��error_names�
failure_names�orig_match_tests�matchingr9r9r:�rerun_failed_tests3sF






�
zRegrtest.rerun_failed_testscCs|jjrdSt�td|���|jrtd�t|j�|��}|r4t�ttt	|�d�d�t
|�|jr_|jjs_t�|j
sT|jsT|jsTt	|j�dkrTtddd�ttt	|j�d�d	�|jjr�|jjd
d�t�td�|jdd
�D]\}}td|t|�f�qx|j
r�t�ttt	|j
�d�d�t
|j
�|jr�t�td�tt	|j�d���t
|j�|jr�|jjs�t�ttt	|j�d�d�t
|j�|jr�t�tdtt	|j�d��t
|j�|jr�t�ttt	|j�d�d�t
|j�dSdS)Nz== Tests result: %s ==z(Test suite interrupted by signal SIGINT.r�zomitted:r�AllrU)�endzOK.T)�reversez10 slowest tests:�
z- %s: %szfailed:z%{} altered the execution environment:r�z%s:zre-run testz
run no tests:)rrhrMr�r)r=rr>rrgrr rfr!r"�
print_slowr*�sortrr$�formatr'r%)r8�omittedr_r�r9r9r:r�_sd��
�


�zRegrtest.display_resultcCs�|jjrddl}|jddd�|_tj��}d}|jjr%|dt|jj�7}|�	|�d}t
|jd�D]�\}}t�
�}|}|rDd||f}|�||�|jrcd	}	tt��}
|jj|	t�|
d
�|
d}nt|j|�}|�|�t|t�runAt|�}t�
�|}|tkr�d|t|�f}nt|t�r�d}tj��D]}
|
|vr�|
�d
�r�t�|
�q�|jjr�t||j�r�nq2|r�t|�dSdS)NrFT)�tracerzRun tests sequentiallyz (timeout: %s)rz%s -- %szDresult = runtest(self.ns, test_name); self.accumulate_result(result))�globals�localsrPz%s in %sztest.) rr��Tracer+rN�modules�keys�timeoutrrc�	enumeraterr,r-rl�dictr��runctxr�rrTrBr�strr	r
�
startswithr�unloadr�rrM)r8r��save_modulesr��
previous_testrirQr.rj�cmdrrPr_�moduler9r9r:�run_tests_sequential�sP







���zRegrtest.run_tests_sequentialccs6�	|D]}|V|jrdS|jjr|jrdSqqr<)r!r�fail_env_changedr$)r8rrQr9r9r:�
_test_forever�s���zRegrtest._test_forevercCsxtdt��gtj���R�tdtjdd�dtj�tdt���t�	�}|r-td|�tdt
�d�t��f�dS)	Nz==T)�aliasedz	%s-endianz== cwd:z
== CPU count:z== encodings: locale=%s, FS=%sF)
rM�platform�python_implementationrN�versionr��	byteorderrz�getcwd�	cpu_count�locale�getpreferredencoding�getfilesystemencoding)r8r�r9r9r:�display_header�s�
�
�zRegrtest.display_headercCs�g}|jr|�d�n |jjr|jr|�d�nt|j|j|j|j|jf�s+|�d�|jr3|�d�|s:|�d�d�	|�}|j
rId|j
|f}|S)N�FAILUREzENV CHANGEDzNO TEST RUN�INTERRUPTED�SUCCESSr�z
%s then %s)r!rCrr�r$�anyr r"r)r�r()r8rPr9r9r:r��s"�



zRegrtest.get_tests_resultc
Cs�|jjs|jjs|jjs|jjs|js|jjs|��|jjr4|jj\}}}|dkr4d}t	|t
jdd�|jjr?t	d|jj
�|jjrS|�t|j��|_d|_d|_nt|j�|_d�t|j��|_t|j�d|_|jjr�d	d
lm}t
jdkr�|jdur�d	dlm}z|�|_Wnty�}z
t	d
|���WYd}~nd}~wwz||�W|jdur�|j� �d|_dSdS|jdur�|j� �d|_w|�!�dS)N�zhWARNING: Running tests with --huntrleaks/-R and less than 3 warmup repetitions can give false positives!TrnzUsing random seedrz/{}rr)�run_tests_multiprocess�win32)�WindowsLoadTrackerz%Failed to create WindowsLoadTracker: )"r�headerrhrfr�rrur�rvrMrN�stdoutr�r��foreverr�r�rr/r0�iterr�rg�use_mprtrr�r6�test.libregrtest.win_utilsrr4�PermissionError�closer�)r8r~rr�r�rr�errorr9r9r:�	run_tests�sZ�������



�
zRegrtest.run_testscCs�|jr+|jr%t|jd��}|�|jd�Wd�n1swYnt�|j�|jr=|j��}|jdd|j	j
d�t�t�
�|j}tdt|��td|���|j	jrft�dt���dSdS)N�w�
T)�show_missing�summary�coverdirzTotal duration: %szTests result: %szleaks %d)r2r1r��writerz�unlinkr+�results�
write_resultsrrrMr,r-r.rr��runleaks�system�getpid)r8r�r��durationr9r9r:�finalize-s&��
��zRegrtest.finalizec

Cs|jjs	|js	dSddlmm}|�d�}dddd�}|jD]%}|�|�|D]}z||t|�	|d��7<Wq)t
yDYq)wq |��D]\}}|�|t
|��qJtj�tj|jj�}t|d��}|�|�D]}	|�|	�qlWd�dS1swYdS)Nr�
testsuites)rr�r��wb)rrqr3rHrIrJ�ElementrCr[�getrE�itemsr=r�rzr{r�rr�r��tostringlistr)
r8rR�root�totalsr��k�vrq�f�sr9r9r:�save_xml_resultBs,


 ���"�zRegrtest.save_xml_resultcCst|jjr	|jj|_|js0t��r+t�d�|_|jdur!t�d�|_tj�|jd�|_nt	�
�|_tj�|j�|_dS)N�abs_builddir�srcdir�build)rryr5�	sysconfig�is_python_build�get_config_varrzr{r��tempfile�
gettempdir�abspathr7r9r9r:�set_temp_dir[s


zRegrtest.set_temp_dircCsVtj|jdd�t��}|jdurd�|�}nd�|�}|tj7}tj�	|j|�}|S)NT)�exist_okztest_python_worker_{}ztest_python_{})
rz�makedirsr5rr6r�r�FS_NONASCIIr{r�)r8�pid�test_cwdr9r9r:�create_temp_dirqs


zRegrtest.create_temp_dircCszddl}tj�|�|j�d�}td|j�|�|�D]}tj�|�r/td|�t�	|�qtd|�t�
|�qdS)Nrz
test_python_*zCleanup %s directoryzRemove directory: %szRemove file: %s)�globrzr{r��escaper5rM�isdirr�rmtreer)r8r<r{rAr9r9r:�cleanup�s�zRegrtest.cleanupNc
Ks�|�|�|��|jjr|��t�d�|��}z&tj|dd��||j_	|�
||�Wd�WdS1s9wYWdSty`}ztj
tdd�t�|j�WYd}~dSd}~ww)NrT)rf)rx)r�r5rr@rNrxr;r�temp_cwdry�_main�
SystemExit�faulthandler�dump_traceback_later�EXIT_TIMEOUT�code)r8rr}r:�excr9r9r:�main�s 

&���z
Regrtest.maincCs.|jdur
|j��Sttd�rt��dSdS)NrYr)r4rY�hasattrrzr7r9r9r:rY�s



zRegrtest.getloadavgcCs|jdurddlm}||j|j�|jjrtd�|jjt_|jj	t_
t|j�|�|�|jj
r;|�
�t�d�|jjrH|��t�d�|��|��|jjr[|jr[|��|��|��|jrkt�d�|jrst�d�|jjr|jrt�d�t�d�dS)Nr)�run_tests_workerzPress any key to continue...ro�r)r6rtrKr�wait�inputrhr�PGO�pgo_extended�PGO_EXTENDEDrr�r�rNrxr�rr��verbose2r!r�rr+r)r�r$)r8rr}rKr9r9r:rB�s8









zRegrtest._main)F)rr<)�__name__�
__module__�__qualname__�__doc__r;r>rTrcrlr�r�r�r�r�r�r�r�r�r�r�rrr+r5r;r@rIrYrBr9r9r9r:rs6+

'I
,;7	
1

	rcKst�jdd|i|��dS)zRun the Python suite.rNr9)rrI)rr}r9r9r:rI�srIr<)-rDr�rzr�r�r�rNr/r2r,r��test.libregrtest.cmdliner�test.libregrtest.runtestrrrrrrr	r
rrr
rrrr�test.libregrtest.setupr�test.libregrtest.pgor�test.libregrtest.utilsrrrrr�r�test.supportrrFrrIr9r9r9r:�<module>s4DD
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY