a XC?h5d@s ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZddl m!Z!ddl"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(dZ)Gd d d Z*d d 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)supportg^@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_nameselfr8:/opt/alt/python39/lib64/python3.9/test/libregrtest/main.py__init__6s0 zRegrtest.__init__cCs<t|jt|jBt|jBt|jBt|jBt|jBSN)setrr r!r"r#r$r6r8r8r9 get_executedaszRegrtest.get_executedFc Cs|j}t|ttfs*|s*|j|j|ft|trB|j|nt|t rf|j ||j |nt|t r~|j |nvt|t r|j|n^t|tr|s|j||j|n6t|tr|j|nt|trd|_n td||rt|ttfs|j||j}|r~ddlmm}|D]D}z|j||Wn&|jyxt|tj dYn0q8dS)NTzinvalid test result: %rrfile)!name isinstancerrr)appendZ duration_secr rrr!r"r r r#r r r%rr$r( ValueErrorremovexml_dataxml.etree.ElementTreeetree ElementTreer2Z fromstringZ ParseErrorprintsys __stderr__)r7resultr& test_namerEETer8r8r9accumulate_resultfs@           zRegrtest.accumulate_resultrcCst| }|}|dur(d|dd|}t|j}tjt|d}|d|}|rd|dd}t|dddS)Nz load avg: z.2f )ZsecondsT)flush) getloadavgr+r,r-datetimeZ timedeltaintrI)r7lineemptyZload_avg test_timer8r8r9logs z Regrtest.logcCsh|jjr dS||j|j}t|jt|j}|rN|jjsN|d|}|d|d|dS)N/[z] ) rquietr/r.lenr r#pgorZ)r7 test_indextextrWZfailsr8r8r9display_progresss zRegrtest.display_progressc Csttjddfi|}|jr,gt_|_|j}|dur`ddlm }||j\}}||_||_ t |j |j r|j \}}}|dks|dkrd} t| tjddtd|jrtj|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?rS)rrJargvxmlpathrZjunit_xml_listr2 worker_argstest.libregrtest.runtest_mprcr5rargs huntrleaksrIstderrexittempdirospath expanduserr) r7kwargsrrhrcrMwarmup repetitions_msgr8r8r9 parse_argss&     zRegrtest.parse_argsc Cs||_|jjrxtj|jd|_zDt|jd$}| }|g|_Wdn1sX0YWnt yvYn0|jj rg|_t d}ttjtj|jj T}|D]>}|ddd}| }||}|dur|j|qWdn1s0Yt|j|jjr.t|jtdd}t}|jjr|jjD]$} | |vrl|| || qTg|j_|jjrt |jjt!t"} nt |jj||} |jj s|jp|jjp| |_#n|j|_#|jjr0|j#dd|_#z"| $|j#d} | | d|_%Wnt&y.Yn0|jj'rz|j#d|j#$|jj'=Wn*t(yt)d|jj't*j+dYn0|jj,r|jj-durt./d |j_-t.0|jj-t.1|j#dS) NZ pynexttestrz\btest_[a-zA-Z0-9_]+\b#rrz1Couldn't find starting test (%s), using all testsr>i)2rrsinglerorpjoinr4r1openreadstripOSErrorZfromfilerecompilerSAVEDCWDsplitsearchrBgrouprr_rrrcopyZexcluderjrDaddZtestdirrlistr<rindexr0 IndexErrorstartrCrIrJrl randomize random_seedrandomZ randrangeZseedZshuffle) r7rfpZ next_testZregexrWmatchZstdtestsZnottestsargZalltestsposr8r8r9 find_testssr *    2              zRegrtest.find_testscCs|jD] }t|qdSr;)rrI)r7r@r8r8r9 list_testss zRegrtest.list_testscCsX|D]N}t|tjjrqt|tjr0||qt|tjrt|rt | qdSr;) rAunittestloaderZ _FailedTestZ TestSuite _list_casesZTestCaserZ match_testrIid)r7suitetestr8r8r9rs    zRegrtest._list_casesc Csdt_t|jj|jj|jD]L}t|j|}ztj |}| |Wq tj yj|j |Yq 0q |j rttjdttt|j ddtjdt|j tjddS)NFr>rskipped:)rverboseZset_match_testsr match_testsZ ignore_testsrrrZdefaultTestLoaderZloadTestsFromNamerZSkipTestr!rBrIrJrlrr^r)r7rMZabstestrr8r8r9 list_casess    zRegrtest.list_casesc Csd|j_d|j_d|j_||_||dt|j}|j |D]}|j }|j ||j plg}|jpvg}dd|D}dd|D}d|j_|jj}|s|r |jjdurg|j_|jj||jj|dd|jj} |d |d | d n|d |d t|j|}||j_|j|dd t|trLqPqL|jrxttt|jddt|j|dS)NTFz'Re-running failed tests in verbose modecSsg|]^}}|ddqSrQrr.0Ztest_full_namerur8r8r9 Az/Regrtest.rerun_failed_tests..cSsg|]^}}|ddqSrrrr8r8r9rBrz matching: , z Re-running z in verbose mode ()z in verbose mode)r&rz failed again:)rrfailfastZverbose3get_tests_resultr'rZrr%clearr@r&rBerrorsfailuresrextendr{rrPrArr rIrr^rdisplay_result) r7Z rerun_listrLrMrrZ error_namesZ failure_namesZorig_match_testsZmatchingr8r8r9rerun_failed_tests0sD             zRegrtest.rerun_failed_testscCs |jjr dSttd||jr0tdt|j|}|rhtttt |ddt ||j r|jj st|j s|js|jst |j dkrtdddttt |j dd |jjr|jjd d ttd |jdd D]\}}td|t|fq|j r>tttt |j ddt |j |jrpttdtt |jdt |j|jr|jj stttt |jddt |j|jrttdtt |jdt |j|jrtttt |jddt |jdS)Nz== Tests result: %s ==z(Test suite interrupted by signal SIGINT.rzomitted:rZAllrQ)endzOK.T)reversez10 slowest tests: z- %s: %szfailed:z%{} altered the execution environment:rz%s:z re-run testz run no tests:)rr_rIrr(r<rr=rr^rrr]r r!Z print_slowr)sortrr#formatr&r$)r7ZomittedrYrr8r8r9r\sd       zRegrtest.display_resultcCs|jjr ddl}|jddd|_tj}d}|jjrJ|dt|jj7}| |d}t |j dD]\}}t }|}|rd||f}||||jrd } tt} |jj| t| d | d } nt|j|} || t| trq|t| }t |} | tkrd |t| f}nt| tr.d}tjD]&} | |vr8| d r8t| q8|jjrdt| |jrdq|qd|rt|dS)NrFT)tracerzRun tests sequentiallyz (timeout: %s)rz%s -- %szDresult = runtest(self.ns, test_name); self.accumulate_result(result))globalslocalsrLz%s in %sztest.) rrZTracer*rJmoduleskeysZtimeoutrrZ enumeraterr+r,rbdictrZrunctxrrrPrArstrr r startswithrZunloadrrrI)r7rZ save_modulesrvZ previous_testr`rMr-racmdrrLrYmoduler8r8r9run_tests_sequentialsJ            zRegrtest.run_tests_sequentialccs6|D]*}|V|jrdS|jjr|jrdSqqdSr;)r rfail_env_changedr#)r7rrMr8r8r9 _test_forevers zRegrtest._test_forevercCsxtdtgtjRtdtjdddtjtdtt }|rZtd|tdt dt fdS) Nz==T)Zaliasedz %s-endianz== cwd:z == CPU count:z== encodings: locale=%s, FS=%sF) rIplatformZpython_implementationrJversionr byteorderrogetcwd cpu_countlocaleZgetpreferredencodinggetfilesystemencoding)r7rr8r8r9display_headers zRegrtest.display_headercCsg}|jr|dn@|jjr0|jr0|dn&t|j|j|j|j|jfsV|d|jrf|d|st|dd |}|j rd|j |f}|S)NFAILUREz ENV CHANGEDz NO TEST RUNZ INTERRUPTEDSUCCESSrz %s then %s) r rBrrr#anyrr!r(r{r')r7rLr8r8r9rs"      zRegrtest.get_tests_resultc Cs|jjs.|jjs6|jjs6|jjs6|js6|jjs6||jjrh|jj\}}}|dkrhd}t |t j dd|jj r~t d|jj |jjr|t|j|_d|_d|_n.t|j|_dt|j|_t|jd|_|jjrd d lm}t jd krP|jdurPd d lm}z ||_Wn4tyN}zt d |WYd}~n d}~00z(||W|jdur|j d|_n|jdur|j d|_0n|!dS)NzhWARNING: Running tests with --huntrleaks/-R and less than 3 warmup repetitions can give false positives!TrdzUsing random seedrz/{}rr)run_tests_multiprocessZwin32)WindowsLoadTrackerz%Failed to create WindowsLoadTracker: )"rheaderr_r]rzrrjrrkrIrJstdoutrrZforeverrrrr.r/iterrr^Zuse_mprirrr5Ztest.libregrtest.win_utilsrr3PermissionErrorcloser)r7rsrtrurvrrerrorr8r8r9 run_testssV     $      zRegrtest.run_testscCs|jrV|jrJt|jd }||jdWdqV1s>0Yn t|j|jrz|j}|jdd|j j dt t |j}t dt|t d||j jrtdtdS)Nw T)Z show_missingZsummarycoverdirzTotal duration: %szTests result: %szleaks %d)r1r0r|writerounlinkr*ZresultsZ write_resultsrrrIr+r,r-rrZrunleakssystemgetpid)r7rrxZdurationr8r8r9finalize*s 0  zRegrtest.finalizec Cs |jjs|jsdSddlmm}|d}dddd}|jD]L}|||D]8}z ||t| |d7<WqRt yYqR0qRq@| D]\}}| |t |qtjtj|jj}t|d*}||D]} || qWdn1s0YdS)NrZ testsuites)rrrwb)rrgr2rFrGrHZElementrBrVgetrCitemsr<rrorpr{rrr|Z tostringlistr) r7rNrootZtotalsrkvrgfsr8r8r9save_xml_result?s$        zRegrtest.save_xml_resultcCst|jjr|jj|_|js`trVtd|_|jdurBtd|_tj|jd|_n t |_tj |j|_dS)NZ abs_builddirZsrcdirZbuild) rrnr4 sysconfigZis_python_buildZget_config_varrorpr{tempfileZ gettempdirabspathr6r8r8r9 set_temp_dirXs     zRegrtest.set_temp_dircCsVtj|jddt}|jdur.d|}n d|}|tj7}tj |j|}|S)NT)exist_okztest_python_worker_{}ztest_python_{}) romakedirsr4rr5rrZ FS_NONASCIIrpr{)r7pidtest_cwdr8r8r9create_temp_dirns    zRegrtest.create_temp_dircCszddl}tj||jd}td|j||D]>}tj|r^td|t |q6td|t |q6dS)Nrz test_python_*zCleanup %s directoryzRemove directory: %szRemove file: %s) globrorpr{escaper4rIisdirrZrmtreer)r7rrpr@r8r8r9cleanup}s    zRegrtest.cleanupNc Ks||||jjr,|td|}zFtj|dd$||j_ | ||Wdn1sn0YWn>t y}z&t j tddt|jWYd}~n d}~00dS)NrT)r])rm)rwrrrrJrmrrZtemp_cwdrn_main SystemExit faulthandlerZdump_traceback_later EXIT_TIMEOUTcode)r7rrrrexcr8r8r9mains  .z Regrtest.maincCs.|jdur|jSttdr*tdSdS)NrTr)r3rThasattrror6r8r8r9rTs     zRegrtest.getloadavgcCs |jdur$ddlm}||j|j|jjr4td|jjt_|jj t_ t |j| ||jj rv| td|jjr|td|||jjr|jr||||jrtd|jrtd|jjr|jrtdtddS)Nr)run_tests_workerzPress any key to continue...rer)r5rirrwaitinputr_rZPGOZ pgo_extendedZ PGO_EXTENDEDrrrrJrmrrrZverbose2r rrrr(rr#)r7rrrrr8r8r9rs8           zRegrtest._main)F)r)N)__name__ __module__ __qualname____doc__r:r=rPrZrbrwrrrrrrrrrrrrrrrrrrTrr8r8r8r9rs4+ '  I ,;7  1  rcKstjfd|i|dS)zRun the Python suite.rN)rr)rrrr8r8r9rsr)N),rUrrrorrrrJrrr+rZtest.libregrtest.cmdlinerZtest.libregrtest.runtestrrrrrrr r r r r rrrrZtest.libregrtest.setuprZtest.libregrtest.pgorZtest.libregrtest.utilsrrrrrrrrrr8r8r8r9s2 D   A