o =?hd@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m 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) findtestsruntestget_abs_module is_failedSTDTESTSNOTTESTSPROGRESS_MIN_TIMEPassedFailed EnvChangedSkippedResourceDenied Interrupted ChildError DidNotRun) setup_tests)setup_pgo_tests)removepycountformat_duration printlist)support) os_helperg^@c@seZdZdZddZddZd7ddZd8d d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd9d1d2Zd3d4Zd5d6Zd0S):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. cCsd|_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)nstestsselectedgoodbadskippedresource_deniedsenvironment_changed run_no_tests need_rerunrerun first_result interrupted test_timestracertime monotonic start_time test_counttest_count_widthnext_single_testnext_single_filename testsuite_xmlwin_load_trackertmp_dirworker_test_nameselfr9Dz/Regrtest.rerun_failed_tests..cSrrrrr9r9r:rErz matching: , z Re-running z in verbose mode ()z in verbose mode)r'rz failed again:)rrfailfastZverbose3get_tests_resultr(r\rr&clearrAr'rCerrorsfailuresrextendr}rrQrBrr!rJrr`rdisplay_result) r8Z rerun_listrMrNrrZ error_namesZ failure_namesZorig_match_testsZmatchingr9r9r:rerun_failed_tests3sF            zRegrtest.rerun_failed_testscCs|jjrdSttd||jrtdt|j|}|r4tttt |ddt ||j r_|jj s_t|j sT|jsT|jsTt |j dkrTtdddttt |j dd |jjr|jjd d ttd |jdd D]\}}td|t|fqx|j rtttt |j ddt |j |jrttdtt |jdt |j|jr|jj stttt |jddt |j|jrttdtt |jdt |j|jrtttt |jddt |jdSdS)Nz== Tests result: %s ==z(Test suite interrupted by signal SIGINT.rzomitted:rZAllrR)endzOK.T)reversez10 slowest tests: z- %s: %szfailed:z%{} altered the execution environment:rz%s:z re-run testz run no tests:)rrarJrr)r=rr>rr`rr r_r!r"Z print_slowr*sortrr$formatr'r%)r8Zomittedr[rr9r9r:r_sd     zRegrtest.display_resultcCs|jjrddl}|jddd|_tj}d}|jjr%|dt|jj7}| |d}t |j dD]\}}t }|}|rDd||f}||||jrcd } tt} |jj| t| d | d } n t|j|} || t| trunAt| }t |} | tkrd |t| f}nt| trd}tjD]} | |vr| d rt| q|jjrt| |jrnq2|rt|dSdS)NrFT)tracerzRun tests sequentiallyz (timeout: %s)rz%s -- %szDresult = runtest(self.ns, test_name); self.accumulate_result(result))globalslocalsrMz%s in %sztest.) rrZTracer+rKmoduleskeysZtimeoutrr\ enumeraterr,r-rddictrZrunctxrrrQrBrstrr r startswithrZunloadrrrJ)r8rZ save_modulesrxZ previous_testrbrNr.rccmdrrMr[moduler9r9r:run_tests_sequentialsP             zRegrtest.run_tests_sequentialccs6 |D]}|V|jrdS|jjr|jrdSqqr<)r!rfail_env_changedr$)r8rrNr9r9r: _test_foreverszRegrtest._test_forevercCsxtdtgtjRtdtjdddtjtdtt }|r-td|tdt dt fdS) Nz==T)Zaliasedz %s-endianz== cwd:z == CPU count:z== encodings: locale=%s, FS=%sF) rJplatformZpython_implementationrKversionr byteorderrqgetcwd cpu_countlocaleZgetpreferredencodinggetfilesystemencoding)r8rr9r9r:display_headers  zRegrtest.display_headercCsg}|jr |dn |jjr|jr|dnt|j|j|j|j|jfs+|d|jr3|d|s:|dd |}|j rId|j |f}|S)NFAILUREz ENV CHANGEDz NO TEST RUNZ INTERRUPTEDSUCCESSrz %s then %s) r!rCrrr$anyr r"r)r}r()r8rMr9r9r:rs"      zRegrtest.get_tests_resultc Cs|jjs|jjs|jjs|jjs|js|jjs||jjr4|jj\}}}|dkr4d}t |t j dd|jj r?t d|jj |jjrS|t|j|_d|_d|_nt|j|_dt|j|_t|jd|_|jjrd d lm}t jd kr|jdurd d lm}z||_Wnty}z t d |WYd}~nd}~wwz||W|jdur|j d|_dSdS|jdur|j d|_w|!dS)NzhWARNING: Running tests with --huntrleaks/-R and less than 3 warmup repetitions can give false positives!TrfzUsing random seedrz/{}rr)run_tests_multiprocessZwin32)WindowsLoadTrackerz%Failed to create WindowsLoadTracker: )"rheaderrar_r|rrlrrmrJrKstdoutrrZforeverrrrr/r0iterrr`Zuse_mprkrrr6Ztest.libregrtest.win_utilsrr4PermissionErrorcloser)r8rurvrwrxrrerrorr9r9r: run_testssZ          zRegrtest.run_testscCs|jr+|jr%t|jd}||jdWdn1swYnt|j|jr=|j}|jdd|j j dt t |j}t dt|t d||j jrftdtdSdS)Nw T)Z show_missingZsummarycoverdirzTotal duration: %szTests result: %szleaks %d)r2r1r~writerqunlinkr+ZresultsZ write_resultsrrrJr,r-r.rrZrunleakssystemgetpid)r8rrzZdurationr9r9r:finalize-s&  zRegrtest.finalizec Cs |jjs |js dSddlmm}|d}dddd}|jD]%}|||D]}z||t| |d7<Wq)t yDYq)wq | D] \}}| |t |qJtjtj|jj}t|d}||D]} || qlWddS1swYdS)NrZ testsuites)rrrwb)rrir3rGrHrIZElementrCrXgetrDitemsr=rrqrrr}rrr~Z tostringlistr) r8rOrootZtotalsrkvrifsr9r9r:save_xml_resultBs,        "zRegrtest.save_xml_resultcCst|jjr |jj|_|js0tr+td|_|jdur!td|_tj|jd|_nt |_tj |j|_dS)NZ abs_builddirZsrcdirZbuild) rrpr5 sysconfigZis_python_buildZget_config_varrqrrr}tempfileZ gettempdirabspathr7r9r9r: set_temp_dir[s     zRegrtest.set_temp_dircCsVtj|jddt}|jdurd|}nd|}|tj7}tj |j|}|S)NT)exist_okztest_python_worker_{}ztest_python_{}) rqmakedirsr5rr6rrZ FS_NONASCIIrrr})r8pidtest_cwdr9r9r:create_temp_dirqs    zRegrtest.create_temp_dircCszddl}tj||jd}td|j||D]}tj|r/td|t |qtd|t |qdS)Nrz test_python_*zCleanup %s directoryzRemove directory: %szRemove file: %s) globrqrrr}escaper5rJisdirrZrmtreer)r8rrrrAr9r9r:cleanups     zRegrtest.cleanupNc Ks||||jjr|td|}z&tj|dd||j_ | ||WdWdS1s9wYWdSt y`}zt j tddt|jWYd}~dSd}~ww)NrT)r_)ro)ryrrrrKrorrZtemp_cwdrp_main SystemExit faulthandlerZdump_traceback_later EXIT_TIMEOUTcode)r8rrtrexcr9r9r:mains  &z Regrtest.maincCs.|jdur |jSttdrtdSdS)NrVr)r4rVhasattrrqr7r9r9r:rVs    zRegrtest.getloadavgcCs |jdurddlm}||j|j|jjrtd|jjt_|jj t_ t |j| ||jj r;| td|jjrH|td|||jjr[|jr[||||jrktd|jrstd|jjr|jrtdtddS)Nr)run_tests_workerzPress any key to continue...rgr)r6rkrrwaitinputrarZPGOZ pgo_extendedZ PGO_EXTENDEDrrrrKrorrrZverbose2r!rrrr)rr$)r8rrtrr9r9r:rs8           zRegrtest._main)F)rr<)__name__ __module__ __qualname____doc__r;r>rQr\rdryrrrrrrrrrrrrrrrrrrVrr9r9r9r:rs6+  ' I ,;7  1  rcKstjdd|i|dS)zRun the Python suite.rNr9)rr)rrtr9r9r:rsrr<)-rrrqrrrrKrrr,rZtest.libregrtest.cmdlinerZtest.libregrtest.runtestrrrrrrr r r r r rrrrZtest.libregrtest.setuprZtest.libregrtest.pgorZtest.libregrtest.utilsrrrrrrZ test.supportrrrrr9r9r9r:s4 D    D