a ZÚß^>`c@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddl m!Z!ddl"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)Ú findtestsÚruntestÚget_abs_moduleÚSTDTESTSÚNOTTESTSÚPASSEDÚFAILEDÚ ENV_CHANGEDÚSKIPPEDÚRESOURCE_DENIEDÚ INTERRUPTEDÚ CHILD_ERRORÚTEST_DID_NOT_RUNÚTIMEOUTÚPROGRESS_MIN_TIMEÚformat_test_resultÚ is_failed)Ú setup_tests)Úsetup_pgo_tests)ÚremovepyÚcountÚformat_durationÚ printlist)Úsupportg^@c@sÚeZdZdd„Zdd„Zd6dd„Zd7d d „Zd d „Zd d„Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd8d0d1„Zd2d3„Zd4d5„Zd/S)9ÚRegrtestcCs’d|_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Ú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©r8ú-/usr/lib64/python3.9/test/libregrtest/main.pyÚ__init__6s. zRegrtest.__init__cCs<t|jƒt|jƒBt|jƒBt|jƒBt|jƒBt|jƒBS©N)Úsetr r!r"r#r$r%r6r8r8r9Ú get_executed`sÿÿþzRegrtest.get_executedFc Cs†|j}|j}|ttfvr.|s.|j |j|f¡|tkrD|j |¡n´|t tfvrb|sø|j  |¡n–|t krx|j  |¡n€|t krŽ|j |¡nj|tkr°|j |¡|j |¡nH|tkrÆ|j |¡n2|tkrÖd|_n"|tkrì|j  |¡n td|ƒ‚|r|t tthvr|j  |¡|j}|r‚ddlmm}|D]D}z|j | |¡¡Wn&|jy|t|tj d‚Yn0q}| dd¡d}|  ¡}| |¡}|dur°|j | ¡¡q°Wdƒn1s0Yt|jƒ|jjr.t|jƒtdd…}t ¡}|jjr‚|jjD]$} | |vrl| | ¡| | ¡qTg|j_|jjr¢t |jjt!ƒt"ƒƒ} nt |jj||ƒ} |jj sÖ|jpÐ|jjpÐ| |_#n|j|_#|jjr0|j#dd…|_#z"|  $|j#d¡} | | d|_%Wnt&y.Yn0|jj'r‚z|j#d|j# $|jj'¡…=Wn*t(y€t)d|jj't*j+dYn0|jj,rÂ|jj-dur¨t. /d ¡|j_-t. 0|jj-¡t. 1|j#¡dS) NZ pynexttestÚrz\btest_[a-zA-Z0-9_]+\bz#rrz1Couldn't find starting test (%s), using all testsr>i€–˜)2rrÚsinglerfrgÚjoinr4r1ÚopenZreadZstripZOSErrorZfromfileÚreZcompilerÚSAVEDCWDÚsplitZsearchrBZgrouprrWrrrZcopyZexcluderarEZaddZtestdirrÚlistr<rZindexr0Z IndexErrorZstartrDrJrKrcÚ randomizeÚ random_seedÚrandomZ randrangeZseedZshuffle) r7rÚfpZ next_testZregexrSZmatchZstdtestsZnottestsZargZalltestsZposr8r8r9Ú find_testsÉsr *    2            ÿÿ  zRegrtest.find_testscCs|jD] }t|ƒqdSr;)rrJ)r7Únamer8r8r9Ú list_testss zRegrtest.list_testscCsX|D]N}t|tjjƒrqt|tjƒr0| |¡qt|tjƒrt |¡rt |  ¡ƒqdSr;) Z isinstanceÚunittestZloaderZ _FailedTestZ TestSuiteÚ _list_casesZTestCaserZ match_testrJZid)r7ÚsuiteÚtestr8r8r9r~s    zRegrtest._list_casesc Cs°dt_t |jj|jj¡|jD]L}t|j|ƒ}ztj   |¡}|  |¡Wq tj yj|j  |¡Yq 0q |j r¬ttjdttt|j ƒdƒdtjdt|j tjddS)NFr>r€úskipped:)rÚverboseZset_match_testsrZ match_testsZ ignore_testsrrr}ZdefaultTestLoaderZloadTestsFromNamer~ZSkipTestr"rBrJrKrcrrVr)r7r@Zabstestrr8r8r9Ú list_cases s    zRegrtest.list_casescCsÄd|j_d|j_d|j_| ¡|_| ¡| d¡|jdd…|_|jD]F}| d|›d¡d|j_t |j|ƒ}|j |dd|j t krJq’qJ|jr¸t tt|jƒdƒdƒt|jƒ| ¡dS) NTFz'Re-running failed tests in verbose modez Re-running z in verbose mode)r&r€z failed again:)rr‚ÚfailfastZverbose3Úget_tests_resultr'rTr!r&rrMrAr rJrrVrÚdisplay_result)r7r@rAr8r8r9Úrerun_failed_tests1s$      zRegrtest.rerun_failed_testscCs |jjr dStƒtd| ¡ƒ|jr0tdƒt|jƒ| ¡}|rhtƒttt |ƒdƒdƒt |ƒ|j r¾|jj s¾tƒ|j s¨|js¨|js¨t |j ƒdkr¨tdddttt |j ƒdƒd ƒ|jjr|jjd d tƒtd ƒ|jdd …D]\}}td|t|ƒfƒqò|j r>tƒttt |j ƒdƒdƒt |j ƒ|jrptƒtd tt |jƒdƒ¡ƒt |jƒ|jr¨|jj s¨tƒttt |jƒdƒdƒt |jƒ|jrØtƒtdtt |jƒdƒƒt |jƒ|jrtƒttt |jƒdƒdƒt |jƒdS)Nz== Tests result: %s ==z(Test suite interrupted by signal SIGINT.r€zomitted:rZAllrN)ZendzOK.T)Zreversez10 slowest tests:i z- %s: %szfailed:z%{} altered the execution environment:rz%s:z re-run testz run no tests:)rrWrJr…r(r<rr=rrVrr rUr!r"Z print_slowr)Zsortrr$Úformatr&r%)r7ZomittedrCr€r8r8r9r†Ksdÿþ ý   ÿ   zRegrtest.display_resultcCsŽ|jjr ddl}|jddd|_tj ¡}d}|jjrJ|dt|jjƒ7}|  |¡d}t |j dƒD]\}}t   ¡}|}|rŠd||f}| ||¡|jrÈd } ttƒƒ} |jj| tƒ| d | d } nt|j|ƒ} | | ¡| jtkrîq|t| ƒ}t   ¡|} | tkrd |t| ƒf}n| jtkr.d}tj ¡D]&} | |vr8|  d ¡r8t | ¡q8|jjrdt| |jƒrdq|qd|rŠt|ƒdS)NrFT)ÚtracerzRun tests sequentiallyz (timeout: %s)rz%s -- %szDresult = runtest(self.ns, test_name); self.accumulate_result(result))ÚglobalsÚlocalsrAz%s in %sztest.) rr‰ZTracer*rKZmodulesZkeysZtimeoutrrTZ enumeraterr+r,rZZdictr‹ZrunctxrŠrrMrAr rrrZ startswithrZunloadr„rrJ)r7r‰Z save_modulesrlZ previous_testrXr@r-rYZcmdrrArCZmoduler8r8r9Úrun_tests_sequential†sJ            zRegrtest.run_tests_sequentialccs6|D]*}|V|jrdS|jjr|jrdSqqdSr;)r!rÚfail_env_changedr$)r7rr@r8r8r9Ú _test_forever½s zRegrtest._test_forevercCsxtdt ¡gtj ¡¢RŽtdtjdddtjƒtdt ¡ƒt  ¡}|rZtd|ƒtdt   d¡t  ¡fƒdS) Nz==T)Zaliasedz %s-endianz== cwd:z == CPU count:z== encodings: locale=%s, FS=%sF) rJÚplatformZpython_implementationrKZversionrtZ byteorderrfZgetcwdÚ cpu_countÚlocaleZgetpreferredencodingZgetfilesystemencoding)r7rr8r8r9Údisplay_headerÆsÿ ÿÿzRegrtest.display_headercCs–g}|jr| d¡n@|jjr0|jr0| d¡n&t|j|j|j|j|jfƒsV| d¡|jrf| d¡|st| d¡d  |¡}|j r’d|j |f}|S)NZFAILUREz ENV CHANGEDz NO TEST RUNr ZSUCCESSz, z %s then %s) r!rBrrr$Zanyr r"r(rpr')r7rAr8r8r9r…Ós"  ÿ    zRegrtest.get_tests_resultcCsþ|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ƒ|_d t|jƒ¡|_t|jƒd|_|jjròd d lm}||ƒn| ¡dS) NézhWARNING: Running tests with --huntrleaks/-R and less than 3 warmup repetitions can give false positives!Tr\zUsing random seedrz/{}rr)Úrun_tests_multiprocess)rZheaderrWrUrorrar’rbrJrKZstdoutrvrwZforeverrŽrurr.r/ZiterrˆrVZuse_mpr`r”rŒ)r7rirjrkrlr”r8r8r9Ú run_testsès<ÿÿÿþþ   zRegrtest.run_testscCsÌ|jrV|jrJt|jdƒ }| |jd¡WdƒqV1s>0Yn t |j¡|jrz|j ¡}|jdd|j j dt ƒt   ¡|j}t dt|ƒƒt d| ¡ƒ|j jrÈt dt ¡¡dS)NZwZ T)Z show_missingZsummaryÚcoverdirzTotal duration: %szTests result: %szleaks %d)r1r0rqÚwriterfÚunlinkr*ZresultsZ write_resultsrr–rJr+r,r-rr…ZrunleaksZsystemÚgetpid)r7ryrnZdurationr8r8r9Úfinalizes 0  ÿzRegrtest.finalizec Cs |jjs|jsdSddlmm}| d¡}ddddœ}|jD]L}| |¡|D]8}z ||t|  |d¡ƒ7<WqRt yˆYqR0qRq@|  ¡D]\}}|  |t |ƒ¡q–tj tj|jj¡}t|dƒ*}| |¡D]} | | ¡qÚWdƒn1sþ0YdS)NrZ testsuites)rZerrorsZfailuresZwb)rr^r2rGrHrIZElementrBrRZgetrDZitemsr<ZstrrfrgrprrsrqZ tostringlistr—) r7rLZrootZtotalsrZkZvr^ZfZsr8r8r9Úsave_xml_results$        zRegrtest.save_xml_resultcCst|jjr|jj|_|js`t ¡rVt d¡|_|jdurBt d¡|_tj |jd¡|_n t   ¡|_tj  |j¡|_dS)NZ abs_builddirZsrcdirZbuild) rrer4Ú sysconfigZis_python_buildZget_config_varrfrgrpÚtempfileZ gettempdirZabspathr6r8r8r9Ú set_temp_dir6s     zRegrtest.set_temp_dircCsLtj|jddt ¡}|jdur.d |¡}n d |¡}tj |j|¡}|S)NT)Zexist_okztest_python_worker_{}ztest_python_{})rfZmakedirsr4r™r5rˆrgrp)r7ZpidÚtest_cwdr8r8r9Úcreate_temp_dirLs   zRegrtest.create_temp_dircCstddl}tj |jd¡}td|jƒ| |¡D]>}tj |¡rXtd|ƒt |¡q0td|ƒt  |¡q0dS)Nrz test_python_*zCleanup %s directoryzRemove directory: %szRemove file: %s) Úglobrfrgrpr4rJZisdirrZrmtreer˜)r7r¡rgr{r8r8r9ÚcleanupZs    zRegrtest.cleanupNc Ks¾| |¡| ¡|jjr,| ¡t d¡| ¡}zFtj|dd$||j_ |  ||¡Wdƒn1sn0YWn>t y¸}z&t j tddt |j¡WYd}~n d}~00dS)NrT)rU)rd)rmržrr¢rKrdr rZtemp_cwdreÚ_mainZ SystemExitÚ faulthandlerZdump_traceback_laterÚ EXIT_TIMEOUTZcode)r7rrhrŸZexcr8r8r9Úmaings  .z Regrtest.maincCs.|jdur|j ¡Sttdƒr*t ¡dSdS)NrPr)r3rPZhasattrrfr6r8r8r9rP…s     zRegrtest.getloadavgc Cs¸|jdur$ddlm}||j|jƒ|jjr4tdƒ|jjt_|jj t_ t |jƒ|  |¡|jj rv|  ¡t d¡|jjr| ¡t d¡tjdkrð|jdurðddlm}z |ƒ|_Wn2tyî}ztd|›ƒWYd}~n d}~00zJ| ¡| ¡|jjr|jr| ¡W|jdurZ|j ¡d|_n|jdurX|j ¡d|_0| ¡| ¡|jr|t d¡|jrŽt d¡|jj rª|j!rªt d ¡t d¡dS) Nr)Úrun_tests_workerzPress any key to continue...Zwin32)ÚWindowsLoadTrackerz%Failed to create WindowsLoadTracker: r]i‚r“)"r5r`r§rZwaitZinputrWrZPGOZ pgo_extendedZ PGO_EXTENDEDrrzr|rKrdrƒrZtest.libregrtest.win_utilsr¨r3ZFileNotFoundErrorrJr•r†Zverbose2r!r‡Zcloseršr›r(rr$)r7rrhr§r¨Zerrorr8r8r9r£ŽsR          $   þ     zRegrtest._main)F)rr;)Z__name__Z __module__Z __qualname__r:r=rMrTrZrmrzr|r~rƒr‡r†rŒrŽr’r…r•ršr›ržr r¢r¦rPr£r8r8r8r9rs2* )  I ;7     rcKstƒjfd|i|¤ŽdS)Nr)rr¦)rrhr8r8r9r¦Ésr¦r;).rQr¤r‘rfrrxrrrKrœrr+r}Ztest.libregrtest.cmdlinerZtest.libregrtest.runtestrrrrrrrr r r r r rrrrrZtest.libregrtest.setuprZtest.libregrtest.pgorZtest.libregrtest.utilsrrrrr€rr¥rr¦r8r8r8r9Zs2 L   /