o *gd@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_nameselfr9,/usr/lib/python3.10/test/libregrtest/main.py__init__6s0  zRegrtest.__init__cCs<t|jt|jBt|jBt|jBt|jBt|jBSN)setr r!r"r#r$r%r7r9r9r: get_executedaszRegrtest.get_executedFc Csv|j}t|ttfs|s|j|j|ft|tr!|j|nYt|t r3|j ||j |nGt|t r?|j |n;t|t rK|j|n/t|tr_|s^|j||j|nt|trk|j|nt|trtd|_ntd||rt|ttfs|j||j}|rddlmm}|D]}z |j||Wq|jyt|tj dwdSdS)NTzinvalid test result: %rrfile)!name isinstancerrr*append duration_secr r rr"r#r r r$r r!r&rr%r) ValueErrorremovexml_dataxml.etree.ElementTreeetree ElementTreer3 fromstring ParseErrorprintsys __stderr__)r8resultr' test_namerGETer9r9r:accumulate_resultfsH            zRegrtest.accumulate_resultrcCs| }|}|durd|dd|}t|j}tt|d\}}t|d\}}d|||f}|d|}|rA|dd}t|dddS) Nz load avg: z.2f <z %d:%02d:%02dT)flush) getloadavgr,r-r.divmodintrM)r8lineemptyload_avg test_timeminssecshoursr9r9r:logs z Regrtest.logcCsh|jjrdS||j|j}t|jt|j}|r'|jjs'|d|}|d|d|dS)N/[z] ) rquietr0r/lenr!r$pgorc)r8 test_indextextr\failsr9r9r:display_progresss zRegrtest.display_progressc Csttjddfi|}|jrgt_|_|j}|dur0ddlm }||j\}}||_||_ t |j |j rU|j \}}}|dksF|dkrUd} t| tjddtd|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).Tr@rX)rrNargvxmlpathrjunit_xml_listr3 worker_argstest.libregrtest.runtest_mprmr6rargs huntrleaksrMstderrexittempdirospath expanduserr) r8kwargsrrsrmrQwarmup repetitions_msgr9r9r: parse_argss&      zRegrtest.parse_argsc Cs||_|jjrDz/Regrtest.rerun_failed_tests..cSrrrrr9r9r:rErz matching: , z Re-running z in verbose mode ()z in verbose mode)r'rz failed again:)rrfailfastverbose3get_tests_resultr(rcrr&clearrAr'rCerrorsfailuresrextendrrrTrBrr!rMrrgrdisplay_result) r8 rerun_listrPrQrr error_names failure_namesorig_match_testsmatchingr9r9r: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:rAllrU)endzOK.T)reversez10 slowest tests: z- %s: %szfailed:z%{} altered the execution environment:rz%s:z re-run testz run no tests:)rrhrMrr)r=rr>rrgrr rfr!r" print_slowr*sortrr$formatr'r%)r8omittedr_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))globalslocalsrPz%s in %sztest.) rrTracer+rNmoduleskeystimeoutrrc enumeraterr,r-rldictrrunctxrrrTrBrstrr r startswithrunloadrrrM)r8r save_modulesr previous_testrirQr.rjcmdrrPr_moduler9r9r:run_tests_sequentialsP             zRegrtest.run_tests_sequentialccs6 |D]}|V|jrdS|jjr|jrdSqqr<)r!rfail_env_changedr$)r8rrQr9r9r: _test_foreverszRegrtest._test_forevercCsxtdtgtjRtdtjdddtjtdtt }|r-td|tdt dt fdS) Nz==T)aliasedz %s-endianz== cwd:z == CPU count:z== encodings: locale=%s, FS=%sF) rMplatformpython_implementationrNversionr byteorderrzgetcwd cpu_countlocalegetpreferredencodinggetfilesystemencoding)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 RUN INTERRUPTEDSUCCESSrz %s then %s) r!rCrrr$anyr r"r)rr()r8rPr9r9r: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!TrnzUsing random seedrz/{}rr)run_tests_multiprocesswin32)WindowsLoadTrackerz%Failed to create WindowsLoadTracker: )"rheaderrhrfrrrurrvrMrNstdoutrrforeverrrrr/r0iterrrguse_mprtrrr6test.libregrtest.win_utilsrr4PermissionErrorcloser)r8r~rrrrrerrorr9r9r: 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) show_missingsummarycoverdirzTotal duration: %szTests result: %szleaks %d)r2r1rwriterzunlinkr+results write_resultsrrrMr,r-r.rrrunleakssystemgetpid)r8rrdurationr9r9r: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)Nr testsuites)rrrwb)rrqr3rHrIrJElementrCr[getrEitemsr=rrzr{rrrr tostringlistr) r8rRroottotalsrkvrqfsr9r9r:save_xml_resultBs,        "zRegrtest.save_xml_resultcCst|jjr |jj|_|js0tr+td|_|jdur!td|_tj|jd|_nt |_tj |j|_dS)N abs_builddirsrcdirbuild) rryr5 sysconfigis_python_buildget_config_varrzr{rtempfile gettempdirabspathr7r9r9r: set_temp_dir[s     zRegrtest.set_temp_dircCsVtj|jddt}|jdurd|}nd|}|tj7}tj |j|}|S)NT)exist_okztest_python_worker_{}ztest_python_{}) rzmakedirsr5rr6rr FS_NONASCIIr{r)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) globrzr{rescaper5rMisdirrrmtreer)r8r<r{rAr9r9r:cleanups     zRegrtest.cleanupNc Ks||||jjr|td|}z&tj|dd||j_ | ||WdWdS1s9wYWdSt y`}zt j tddt|jWYd}~dSd}~ww)NrT)rf)rx)rr5rr@rNrxr;rtemp_cwdry_main SystemExit faulthandlerdump_traceback_later EXIT_TIMEOUTcode)r8rr}r:excr9r9r:mains  &z Regrtest.maincCs.|jdur |jSttdrtdSdS)NrYr)r4rYhasattrrzr7r9r9r:rYs    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...ror)r6rtrKrwaitinputrhrPGO pgo_extended PGO_EXTENDEDrrrrNrxrrrverbose2r!rrr+r)rr$)r8rr}rKr9r9r:rBs8           zRegrtest._main)F)rr<)__name__ __module__ __qualname____doc__r;r>rTrcrlrrrrrrrrrrrrrr+r5r;r@rIrYrBr9r9r9r:rs6+  ' I ,;7  1  rcKstjdd|i|dS)zRun the Python suite.rNr9)rrI)rr}r9r9r:rIsrIr<)-rDrrzrrrrNr/r2r,rtest.libregrtest.cmdlinertest.libregrtest.runtestrrrrrrr r r r r rrrrtest.libregrtest.setuprtest.libregrtest.pgortest.libregrtest.utilsrrrrrr test.supportrrFrrIr9r9r9r:s4 D    D