rl.cpp 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // rl.cpp
  6. // To build:
  7. // nmake RELEASE=1 rl.exe
  8. //
  9. // Julian Burger
  10. // Microsoft Corporation
  11. // 11/06/98
  12. // Configuration files are XML
  13. //
  14. // rl{asm,exe}dirs.xml have directory lists
  15. // rl{asm,exe}.xml have test lists
  16. //
  17. // General format:
  18. //
  19. // <?xml version="1.0"?>
  20. //
  21. // <regress-asm> // head node, tag unimportant
  22. //
  23. // <test> // test node, tag unimportant
  24. //
  25. // <default> // default test information
  26. //
  27. // test info // see below
  28. //
  29. // </default>
  30. //
  31. // <condition order="1" type="exclude"> // condition node
  32. //
  33. // <target>...</target> // list of targets this condition applies to
  34. //
  35. // </condition>
  36. //
  37. // </test>
  38. //
  39. //
  40. // Test info (valid for all configuration files):
  41. //
  42. // <files>...</files> // list of comma-delimited files
  43. //
  44. // For asm regressions, files may be grouped in a single test node for
  45. // convenience. For exe regressions, all the files comprising a single test
  46. // should be group.
  47. //
  48. // <tags>...</tags> // list of comma-delimited (case-insensitive) tags
  49. //
  50. // Tags are intended as a proper of the test case itself. That is, they
  51. // should be used to indicate features of a test (like C++ EH or x86 asm)
  52. // rather than arbitrary nonsense.
  53. //
  54. // One tag is recognized specifically by RL: "Pogo". This indicates the test
  55. // is a Pogo test and should be run specially. Any other tag is for explicit
  56. // inclusion/exclusion of tests. E.g.
  57. //
  58. // <tags>SEH</tags>
  59. //
  60. // This marks a test with the SEH tag. If -tags:SEH is specified on the command
  61. // line, only tests marked as such would be included. Similarly, -nottags:SEH
  62. // would exclude tests so tagged.
  63. //
  64. // Test info (valid for asm and exe test configuration files):
  65. //
  66. // <compile-flags>...</compile-flags> // compilation flags for this test
  67. // <rl>...</rl> // RL directives (case-insensitive)
  68. //
  69. // Test info (valid for exe test configuration files)
  70. //
  71. // <baseline>...</baseline> // baseline, expected test output
  72. // <link-flags>...</link-flags> // link flags for this test
  73. // <env> // extra env vars for this test
  74. // <envvar1>value1</envvar1> // any number of child nodes with arbitrary data
  75. // ... // <build>release</build>
  76. // // will result in "set build=release" for the test task env
  77. // </env>
  78. //
  79. // <condition> nodes have an explicit order of evaluation and type (action to
  80. // take if the condition applies) which can be either "include" or "exclude".
  81. //
  82. // asm and exe test conditions may contain <override> nodes that allow default
  83. // info to be overridden. E.g.
  84. //
  85. // <condition order="1" type="include">
  86. //
  87. // <target>ia64</target>
  88. //
  89. // <override>
  90. //
  91. // <baseline>ia64-result.out</baseline>
  92. //
  93. // </override>
  94. //
  95. // </condition>
  96. //
  97. // The above would override the default baseline with "ia64-result.out" when
  98. // the target is ia64.
  99. //
  100. //
  101. // Currently, condition nodes may have only a single condition (target or
  102. // compile-flags) and non-target conditions must appear after target
  103. // conditions.
  104. // Tags processing
  105. //
  106. // Tags specified in the same command line argument are treated as OR clauses.
  107. // Multiple -tags (and -nottags) switches are permitted and are processed in
  108. // command line order as AND clauses. E.g.
  109. //
  110. // -tags:Pogo -nottags:SEH,CPPEH -tags:asm
  111. //
  112. // The -tags declarations says: match all tests with "Pogo" tags. From that
  113. // set, exclude those that have "SEH" or "CPPEH". The next -tags arg further
  114. // restricts the set to those with "asm". (This is a contrived example.)
  115. //
  116. // Note that -tags/-nottags are only applied to files. Directories may not
  117. // have tags because they are too error prone.
  118. // Directives
  119. //
  120. // The following directives are recognized in the <rl>...</rl> section of a
  121. // test's default info:
  122. //
  123. // PassFo
  124. // NoAsm
  125. // NoGPF
  126. // Log file format
  127. //
  128. // There are three output files generated by default
  129. // 1. rl.log contains the summary of tests passed and failed in each dir
  130. // 2. rl.results.log contains the passed/failed result of each test variation
  131. // 3. rl.full.log contains all the output from all the tests,
  132. // delimited by +++ <test variation> +++
  133. // Notes:
  134. // 1. The test output in these files is not synchronized on MP,
  135. // without the -sync option.
  136. // 2. rl.results.log can be used as a baseline database to track regressions,
  137. // if -time is not used.
  138. // -genlst mode and lst file format
  139. //
  140. // In -genlst -all mode, rl won't run tests but generate test.lst and env.lst
  141. // containing the same info as in the rlexedirs.xml and rlexe.xml files
  142. // These files are then read by the runall test harness to run the tests.
  143. // Please refer to the runall documentation for the lst file format.
  144. // By default, rl spawns as many threads to execute tests as there are
  145. // processors on the system. Only one thread works per directory because
  146. // running multiple tests in a single directory may cause conflicts in the
  147. // presence of startdir.cmd/enddir.cmd and precompiled header flags (e.g.,
  148. // /YX). The primary thread generates a work queue of directories and files to
  149. // test in each directory. As soon as the tests in a directory are determined,
  150. // the directory becomes available for worker threads.
  151. //
  152. // One complication is that in Windows there is only a single "current
  153. // directory" per process. Thus, we need to synchronize as follows:
  154. //
  155. // 1. Worker threads grab the "directory" critical section immediately before
  156. // spawning a process (e.g., compile, link, etc.),
  157. //
  158. // 2. The process is spawned with the correct current directory, which it
  159. // inherits.
  160. //
  161. // 3. The lock is released and the next worker is free to change the directory.
  162. //
  163. // 4. The primary thread never changes the current directory, to avoid
  164. // synchronization issues.
  165. //
  166. // 5. Any file access (fopen_unsafe, etc.) must use full pathnames. The only place
  167. // relative paths may be used is in commands that are executed via
  168. // ExecuteCommand(), which does a _chdir before creating a new process to
  169. // execute the command.
  170. //
  171. // 6. Global variables used by worker threads must be thread-local or
  172. // properly synchronized. Exceptions are: (a) variables only read, not
  173. // written, by the worker threads, (b) bThreadStop, which is only written
  174. // to TRUE by worker threads, so synchronization is not necessary.
  175. //
  176. // 7. All printf/fprintf output from the worker threads must go through
  177. // the COutputBuffer class, to be properly synchronized. This class buffers
  178. // up output per thread and flushes it at reasonable intervals, normally
  179. // after a test is finished running. This includes any output generated
  180. // by rl as well as any output captured by the pipe output filter on
  181. // spawned processes.
  182. //
  183. // 8. Do not use _putenv() in the worker threads, as it sets process-wide
  184. // state.
  185. #include "rl.h"
  186. #include "strsafe.h"
  187. #pragma warning(disable: 4474) // 'fprintf' : too many arguments passed for format string
  188. // Win64 headers (process.h) has this:
  189. #ifndef _INTPTR_T_DEFINED
  190. #ifdef _WIN64
  191. typedef __int64 intptr_t;
  192. #else
  193. typedef int intptr_t;
  194. #endif
  195. #define _INTPTR_T_DEFINED
  196. #endif
  197. // Target machine information
  198. // Any changes made here should have corresponding name added
  199. // to TARGET_MACHINES in rl.h. NOTE: The TARGET_MACHINES enum is in exactly
  200. // the same order as the TargetInfo array is initialized!
  201. TARGETINFO TargetInfo[] = {
  202. "unknown", TRUE, FALSE, FALSE, NULL, NULL, NULL,
  203. "x86", FALSE, FALSE, TRUE, NULL, NULL, NULL,
  204. "ppcwce", FALSE, FALSE, FALSE, "comcli", NULL, "x86asm",
  205. "wvm", FALSE, FALSE, FALSE, NULL, "vccoree.lib", "x86asm",
  206. "wvmcee", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
  207. "wvmx86", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
  208. "mips", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
  209. "arm", FALSE, FALSE, FALSE, "armsd", "libcnoce.lib", "x86asm",
  210. "thumb", FALSE, FALSE, FALSE, "armsd", "libcnocet.lib", "x86asm",
  211. "arm64", FALSE, FALSE, FALSE, "armsd", "libcnoce.lib", "x86asm",
  212. "sh3", FALSE, FALSE, FALSE, "sh3sim", "libcsim.lib", "x86asm",
  213. "sh4", FALSE, FALSE, FALSE, "sh3sim", "libcsim.lib", "x86asm",
  214. "sh5c", FALSE, FALSE, FALSE, "sh5sim", "libcsim.lib", "x86asm",
  215. "sh5m", FALSE, FALSE, FALSE, "sh5sim", "libcsim.lib", "x86asm",
  216. "ia64", FALSE, TRUE, TRUE, NULL, NULL, "x86asm",
  217. "amd64", FALSE, TRUE, TRUE, NULL, NULL, "x86asm",
  218. "amd64sys", FALSE, FALSE, TRUE, "issuerun", NULL, "x86asm",
  219. "wvm64", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
  220. "am33", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
  221. "m32r", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
  222. "msil", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
  223. NULL
  224. };
  225. // Target OS information
  226. // Any changes made here should have corresponding name added
  227. // to TARGET_OS in rl.h. NOTE: The TARGET_OS enum is in exactly
  228. // the same order as the TargetOSNames array is initialized
  229. const char* const TargetOSNames[] = {
  230. "unknown",
  231. "win7",
  232. "win8",
  233. "winBlue",
  234. "win10",
  235. "wp8",
  236. NULL
  237. };
  238. #define IS_PATH_CHAR(c) ((c == '/') || (c == '\\'))
  239. #define LOG_FULL_SUFFIX ".full"
  240. const char * const ModeNames[] = {
  241. "assembly", "executable", "shouldn't be printed (RM_DIR)"
  242. };
  243. const char * const InternalModeCmd[] = {
  244. "<asm regress>", "<exe regress>"
  245. };
  246. const char * const TestInfoKindName[] =
  247. {
  248. "files",
  249. "baseline",
  250. "compile-flags",
  251. "link-flags",
  252. "tags",
  253. "rl",
  254. "env",
  255. "command",
  256. "timeout",
  257. "sourcepath",
  258. "eol-normalization",
  259. NULL
  260. };
  261. static_assert((sizeof(TestInfoKindName) / sizeof(TestInfoKindName[0])) - 1 == TestInfoKind::_TIK_COUNT, "Fix the buffer size");
  262. const char * const DirectiveNames[] =
  263. {
  264. "PassFo",
  265. "NoAsm",
  266. "NoGPF",
  267. NULL
  268. };
  269. //
  270. // Global variables set before worker threads start, and only accessed
  271. // (not set) by the worker threads.
  272. //
  273. TARGET_MACHINES TargetMachine = DEFAULT_TM;
  274. TARGET_MACHINES RLMachine = DEFAULT_TM;
  275. TARGET_OS TargetOS = DEFAULT_OS;
  276. Tags * TagsList = NULL;
  277. Tags * TagsLast = NULL;
  278. Tags* DirectoryTagsList = NULL;
  279. Tags* DirectoryTagsLast = NULL;
  280. char SavedConsoleTitle[BUFFER_SIZE];
  281. const char *DIFF_DIR;
  282. char *REGRESS = NULL, *MASTER_DIR, *TARGET_MACHINE, *RL_MACHINE, *TARGET_OS_NAME = NULL;
  283. const char *REGR_CL, *REGR_DIFF;
  284. char *REGR_ASM, *REGR_SHOWD;
  285. const char *TARGET_VM;
  286. char *EXTRA_CC_FLAGS, *EXEC_TESTS_FLAGS;
  287. const char *LINKER, *LINKFLAGS;
  288. char *CL, *_CL_;
  289. const char *JCBinary = "jshost.exe";
  290. BOOL FStatus = TRUE;
  291. char *StatusPrefix;
  292. const char *StatusFormat;
  293. BOOL FVerbose;
  294. BOOL FQuiet;
  295. BOOL FNoWarn;
  296. BOOL FTest;
  297. BOOL FLow;
  298. BOOL FNoDelete;
  299. BOOL FCopyOnFail;
  300. BOOL FSummary = TRUE;
  301. BOOL FMoveDiffs;
  302. BOOL FNoMoveDiffsSwitch;
  303. BOOL FRelativeLogPath;
  304. BOOL FNoDirName = TRUE;
  305. BOOL FBaseline;
  306. BOOL FRebase = FALSE;
  307. BOOL FDiff;
  308. BOOL FBaseDiff;
  309. BOOL FSyncEnumDirs;
  310. BOOL FNogpfnt = TRUE;
  311. BOOL FAppend;
  312. BOOL FAppendTestNameToExtraCCFlags = FALSE;
  313. #ifndef NODEBUG
  314. BOOL FDebug;
  315. #endif
  316. // Output synchronization options
  317. BOOL FSyncImmediate = FALSE; // flush output immediately---no buffering
  318. BOOL FSyncVariation = FALSE; // flush after every test variation (default)
  319. BOOL FSyncTest = FALSE; // flush after all variations of a test
  320. BOOL FSyncDir = FALSE; // flush after an entire directory
  321. BOOL FSingleThreadPerDir = FALSE; // Perform all tests within each directory on a single thread.
  322. BOOL FSingleDir = FALSE;
  323. BOOL FNoThreadId = FALSE;
  324. char* ExeCompiler = NULL;
  325. char* BaseCompiler = NULL;
  326. char* DiffCompiler = NULL;
  327. RLMODE Mode = DEFAULT_RLMODE;
  328. char *DCFGfile = NULL;
  329. char const *CFGfile = NULL;
  330. char const *CMDfile = NULL;
  331. int CFGline;
  332. #define MAX_ALLOWED_THREADS 10 // must be <= MAXIMUM_WAIT_OBJECTS (64)
  333. unsigned NumberOfThreads = 0;
  334. TestList DirList, ExcludeDirList;
  335. BOOL FUserSpecifiedFiles = FALSE;
  336. BOOL FUserSpecifiedDirs = TRUE;
  337. BOOL FExcludeDirs = FALSE;
  338. BOOL FGenLst = FALSE;
  339. char *ResumeDir, *MatchDir;
  340. TIME_OPTION Timing = TIME_DIR | TIME_TEST; // Default to report times at test and directory level
  341. static const char *ProgramName;
  342. static const char *LogName;
  343. static const char *FullLogName;
  344. static const char *ResultsLogName;
  345. // NOTE: this might be unused now
  346. static char TempPath[MAX_PATH] = ""; // Path for temporary files
  347. //
  348. // Global variables read and written by the worker threads: these need to
  349. // either be protected by synchronization or use thread-local storage.
  350. //
  351. // Ctrl-C or done? This is written by worker threads or the main thread, but
  352. // only to TRUE. Once written to TRUE, it never changes again. Threads notice
  353. // its new state by polling it periodically, and shutting down gracefully if
  354. // it is TRUE.
  355. BOOL bThreadStop = FALSE;
  356. char TitleStatus[BUFFER_SIZE]; // protected by csTitleBar
  357. CRITICAL_SECTION csTitleBar; // used to serialize title bar
  358. CRITICAL_SECTION csStdio; // printf serialization
  359. CRITICAL_SECTION csCurrentDirectory; // used when changing current directory
  360. CProtectedLong NumVariationsRun[RLS_COUNT];
  361. CProtectedLong NumVariationsTotal[RLS_COUNT]; // run / total is displayed
  362. CProtectedLong NumFailuresTotal[RLS_COUNT];
  363. CProtectedLong NumDiffsTotal[RLS_COUNT];
  364. CProtectedLong MaxThreads;
  365. CProtectedLong CntDeleteFileFailures;
  366. CProtectedLong CntDeleteFileFatals;
  367. // Under -syncdirs, enumerate all directories/files before allowing
  368. // any work to be done. Do this by setting this event when done enumerating.
  369. // This releases the worker threads.
  370. CHandle heventDirsEnumerated;
  371. CDirectoryQueue DirectoryQueue;
  372. CDirectoryQueue DirectoryTestQueue;
  373. CDirectoryAndTestCaseQueue DirectoryAndTestCaseQueue;
  374. CThreadInfo* ThreadInfo = NULL;
  375. // A per-thread id. ThreadId 0 is the primary thread, the directory/file
  376. // enumeration thread. Other threads are numbered 1 to NumberOfThreads
  377. __declspec(thread) int ThreadId = 0;
  378. __declspec(thread) char *TargetVM;
  379. __declspec(thread) COutputBuffer* ThreadOut; // stdout
  380. __declspec(thread) COutputBuffer* ThreadLog; // log file
  381. __declspec(thread) COutputBuffer* ThreadFull; // full log file
  382. __declspec(thread) COutputBuffer* ThreadRes; // results log file
  383. // Per-thread compare buffers, allocated once, deleted on thread destroy
  384. #define CMPBUF_SIZE 65536
  385. __declspec(thread) char *cmpbuf1 = NULL;
  386. __declspec(thread) char *cmpbuf2 = NULL;
  387. // Allow usage of select deprecated CRT APIs without disabling all deprecated CRT API warnings
  388. #pragma warning (push)
  389. #pragma warning (disable:4996)
  390. char * getenv_unsafe(const char * varName)
  391. {
  392. // Use getenv instead of getenv_s or _dupenv_s to simplify calls to the API.
  393. return getenv(varName);
  394. }
  395. FILE * fopen_unsafe(const char * filename, const char * mode)
  396. {
  397. // Using fopen_s leads to EACCES error being returned occasionally, even when contentious
  398. // fopen/fclose pairs are wrapped in a critical section. Unclear why this is happening.
  399. // Use deprecated fopen instead.
  400. _set_errno(0);
  401. return fopen(filename, mode);
  402. }
  403. char* strerror_unsafe(int errnum)
  404. {
  405. return strerror(errnum);
  406. }
  407. #pragma warning (pop)
  408. //////////////////////////////////////////////////////////////////////////////
  409. void
  410. CleanUp(BOOL fKilled)
  411. {
  412. if (FStatus)
  413. SetConsoleTitle(SavedConsoleTitle);
  414. // Try to remove temporary files. The temp files may
  415. // be in use, so we might not be able to.
  416. if (ThreadInfo != NULL) { // if we've gotten through parsing commands
  417. for (unsigned int i = 0; i <= NumberOfThreads; i++) {
  418. ThreadInfo[i].DeleteTmpFileList();
  419. }
  420. }
  421. if (FRLFE)
  422. RLFEDisconnect(fKilled);
  423. }
  424. void __cdecl
  425. NormalCleanUp(void)
  426. {
  427. CleanUp(FALSE);
  428. }
  429. int __stdcall
  430. NT_handling_function(unsigned long /* dummy -- unused */)
  431. {
  432. fprintf(stderr, "Exiting...\n");
  433. fflush(stdout);
  434. fflush(stderr);
  435. CleanUp(TRUE);
  436. // For now, just exit ungracefully. This will probably cause bad
  437. // things to happen with output filtering, since we've
  438. // just killed the pipe.
  439. ExitProcess(1);
  440. #if _MSC_VER<1300
  441. return 1; // avoid C4716 warning caused by no return on ExitProcess
  442. #endif
  443. }
  444. void
  445. assert(
  446. const char *file,
  447. int line
  448. )
  449. {
  450. fprintf(stderr, "Assertion failed on line %d of %s\n",
  451. line, file);
  452. }
  453. //////////////////////////////////////////////////////////////////////////////
  454. //
  455. // Output functions. All worker thread output must be generated using these
  456. // functions, then flushed at appropriate times based on the -sync option.
  457. //
  458. void
  459. __cdecl Fatal(const char *fmt, ...)
  460. {
  461. va_list arg_ptr;
  462. va_start(arg_ptr, fmt);
  463. fprintf(stderr, "Error: ");
  464. vfprintf(stderr, fmt, arg_ptr);
  465. fputc('\n', stderr);
  466. exit(1);
  467. }
  468. void
  469. __cdecl Warning(const char *fmt, ...)
  470. {
  471. va_list arg_ptr;
  472. char buf[50], tempBuf[BUFFER_SIZE];
  473. ASSERT(ThreadOut != NULL);
  474. buf[0] = '\0';
  475. if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
  476. sprintf_s(buf, "%d>", ThreadId);
  477. }
  478. if (!FNoWarn) {
  479. va_start(arg_ptr, fmt);
  480. vsprintf_s(tempBuf, fmt, arg_ptr);
  481. ASSERT(strlen(tempBuf) < BUFFER_SIZE);
  482. ThreadOut->Add("%sWarning: %s\n", buf, tempBuf);
  483. ThreadFull->Add("%sWarning: %s\n", buf, tempBuf);
  484. }
  485. }
  486. void
  487. __cdecl Message(const char *fmt, ...)
  488. {
  489. va_list arg_ptr;
  490. char buf[50], tempBuf[BUFFER_SIZE];
  491. ASSERT(ThreadOut != NULL);
  492. buf[0] = '\0';
  493. if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
  494. sprintf_s(buf, "%d>", ThreadId);
  495. }
  496. va_start(arg_ptr, fmt);
  497. vsprintf_s(tempBuf, fmt, arg_ptr);
  498. ASSERT(strlen(tempBuf) < BUFFER_SIZE);
  499. ThreadOut->Add("%s%s\n", buf, tempBuf);
  500. ThreadFull->Add("%s%s\n", buf, tempBuf);
  501. }
  502. void
  503. __cdecl WriteLog(const char *fmt, ...)
  504. {
  505. va_list arg_ptr;
  506. char buf[50], tempBuf[BUFFER_SIZE];
  507. ASSERT(ThreadLog != NULL);
  508. buf[0] = '\0';
  509. if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
  510. sprintf_s(buf, "%d>", ThreadId);
  511. }
  512. va_start(arg_ptr, fmt);
  513. vsprintf_s(tempBuf, fmt, arg_ptr);
  514. ASSERT(strlen(tempBuf) < BUFFER_SIZE);
  515. ThreadLog->Add("%s%s\n", buf, tempBuf);
  516. }
  517. void
  518. __cdecl LogOut(const char *fmt, ...)
  519. {
  520. va_list arg_ptr;
  521. char buf[50], tempBuf[BUFFER_SIZE];
  522. ASSERT(ThreadOut != NULL);
  523. ASSERT(ThreadLog != NULL);
  524. buf[0] = '\0';
  525. if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
  526. sprintf_s(buf, "%d>", ThreadId);
  527. }
  528. va_start(arg_ptr, fmt);
  529. vsprintf_s(tempBuf, fmt, arg_ptr);
  530. ASSERT(strlen(tempBuf) < BUFFER_SIZE);
  531. ThreadOut->Add("%s%s\n", buf, tempBuf);
  532. ThreadLog->Add("%s%s\n", buf, tempBuf);
  533. ThreadFull->Add("%s%s\n", buf, tempBuf);
  534. }
  535. void
  536. __cdecl LogError(const char *fmt, ...)
  537. {
  538. va_list arg_ptr;
  539. char buf[50], tempBuf[BUFFER_SIZE];
  540. ASSERT(ThreadOut != NULL);
  541. ASSERT(ThreadLog != NULL);
  542. buf[0] = '\0';
  543. if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
  544. sprintf_s(buf, "%d>", ThreadId);
  545. }
  546. va_start(arg_ptr, fmt);
  547. vsprintf_s(tempBuf, fmt, arg_ptr);
  548. ASSERT(strlen(tempBuf) < BUFFER_SIZE);
  549. ThreadOut->Add("%sError: %s\n", buf, tempBuf);
  550. ThreadLog->Add("%sError: %s\n", buf, tempBuf);
  551. ThreadFull->Add("%sError: %s\n", buf, tempBuf);
  552. }
  553. // Helper function to flush all thread output.
  554. __inline void FlushOutput(
  555. void
  556. )
  557. {
  558. ThreadOut->Flush();
  559. ThreadLog->Flush();
  560. ThreadFull->Flush();
  561. ThreadRes->Flush();
  562. }
  563. //////////////////////////////////////////////////////////////////////////////
  564. //
  565. // Various DeleteFile() wrappers. We have had lots of problems where
  566. // DeleteFile() fails with error 5 -- access denied. It's not clear why this
  567. // is: it seems like an OS bug where the handle to a process is not released
  568. // when the process handle becomes signaled. Perhaps there is a process that
  569. // sits around grabbing handles. It seems to be worse with CLR testing and
  570. // issuerun/readrun cross-compiler testing. To deal with this, loop and sleep
  571. // between delete tries for some calls. Keep track of how many failures there
  572. // were. Don't clog the log files with "error 5" unless the
  573. // sleep doesn't fix the problem, or the user specifies verbose.
  574. BOOL
  575. DeleteFileIfFoundInternal(
  576. const char* filename
  577. )
  578. {
  579. BOOL ok;
  580. ASSERT(filename != NULL);
  581. if (FTest)
  582. {
  583. return TRUE;
  584. }
  585. // We could see if it's there and then try to delete it. It's easier to
  586. // just try deleting it and see what happens.
  587. ok = DeleteFile(filename);
  588. if (!ok && (GetLastError() != ERROR_FILE_NOT_FOUND)) {
  589. CntDeleteFileFailures++;
  590. return FALSE;
  591. }
  592. return TRUE;
  593. }
  594. BOOL
  595. DeleteFileIfFound(
  596. const char* filename
  597. )
  598. {
  599. BOOL ok;
  600. ok = DeleteFileIfFoundInternal(filename);
  601. if (!ok) {
  602. LogError("DeleteFileIfFound: Unable to delete file %s - error %d", filename, GetLastError());
  603. return FALSE;
  604. }
  605. return TRUE;
  606. }
  607. // Call Win32's DeleteFile(), and print an error if it fails
  608. void
  609. DeleteFileMsg(
  610. char *filename
  611. )
  612. {
  613. if (FTest)
  614. {
  615. return;
  616. }
  617. BOOL ok;
  618. ok = DeleteFile(filename);
  619. if (!ok) {
  620. CntDeleteFileFailures++;
  621. LogError("DeleteFileMsg: Unable to delete file %s - error %d", filename, GetLastError());
  622. }
  623. }
  624. // Call Win32's DeleteFile(), and print an error if it fails. Retry a few
  625. // times, just to improve robustness. NOTE: This function will fail (after
  626. // retries) if the file does not exist!
  627. #define MAX_DELETE_FILE_TRIES 10
  628. #define DELETE_FILE_INITIAL_INTERVAL_IN_MS 100
  629. #define DELETE_FILE_DELTA_IN_MS 100
  630. void
  631. DeleteFileRetryMsg(
  632. char *filename
  633. )
  634. {
  635. unsigned tries = 1;
  636. BOOL ok;
  637. DWORD dwWait = DELETE_FILE_INITIAL_INTERVAL_IN_MS;
  638. for (;;) {
  639. ok = DeleteFileIfFoundInternal(filename);
  640. if (ok)
  641. break;
  642. if (FVerbose) {
  643. LogError("DeleteFileRetryMsg: Unable to delete file %s - error %d", filename, GetLastError());
  644. }
  645. if (++tries > MAX_DELETE_FILE_TRIES) {
  646. LogError("Giving up trying to delete file %s. Further related errors are likely", filename);
  647. CntDeleteFileFatals++;
  648. break;
  649. }
  650. Sleep(dwWait);
  651. dwWait += DELETE_FILE_DELTA_IN_MS;
  652. }
  653. }
  654. void
  655. DeleteMultipleFiles(
  656. CDirectory* pDir,
  657. const char* pattern
  658. )
  659. {
  660. WIN32_FIND_DATA findData;
  661. HANDLE h;
  662. char full[MAX_PATH];
  663. sprintf_s(full, "%s\\%s", pDir->GetDirectoryPath(), pattern);
  664. // Read filenames...
  665. if ((h = FindFirstFile(full, &findData)) == INVALID_HANDLE_VALUE)
  666. return;
  667. do {
  668. // FindFirstFile/FindNextFile set cFileName to a file name without a
  669. // path. We need to prepend the directory and use a full path to do
  670. // the delete. This is because multithreaded rl might have changed the
  671. // current directory out from underneath us.
  672. sprintf_s(full, "%s\\%s", pDir->GetDirectoryPath(), findData.cFileName);
  673. if (FVerbose)
  674. Message("Deleting %s\n", full);
  675. DeleteFileRetryMsg(full);
  676. } while (FindNextFile(h, &findData));
  677. FindClose(h);
  678. }
  679. char *
  680. GetFilenamePtr(
  681. char *path
  682. )
  683. {
  684. char *s;
  685. s = strrchr(path, '\\');
  686. if (s)
  687. return s + 1;
  688. return path;
  689. }
  690. // Get extension of a filename, or "" if no extension found.
  691. const char* GetFilenameExt(const char *path)
  692. {
  693. const char* ext = strrchr(path, '.');
  694. return ext ? ext : "";
  695. }
  696. char *
  697. mytmpnam(
  698. const char *directory,
  699. const char *prefix,
  700. char *filename
  701. )
  702. {
  703. UINT r;
  704. char threadPrefix[MAX_PATH]; // make the prefix thread-specific
  705. // Note that GetTempFileName only uses the first 3 characters of the
  706. // prefix. This should be okay, because it will still create a unique
  707. // filename.
  708. sprintf_s(threadPrefix, "%s%X", prefix, ThreadId);
  709. // NOTE: GetTempFileName actually creates a file when it succeeds.
  710. r = GetTempFileNameA(directory, threadPrefix, 0, filename);
  711. if (r == 0) {
  712. return NULL;
  713. }
  714. return filename;
  715. }
  716. //
  717. // It is possible antivirus program on dev box locked testout when we want to compare testout with baseline.
  718. // If this happens, delay and try a few more times.
  719. //
  720. HANDLE OpenFileToCompare(char *file)
  721. {
  722. const int MAX_TRY = 1200;
  723. const DWORD NEXT_TRY_SLEEP_MS = 250;
  724. HANDLE h;
  725. int i = 0;
  726. for (;;)
  727. {
  728. // Open the files using exclusive access
  729. h = CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
  730. if (h != INVALID_HANDLE_VALUE)
  731. {
  732. break;
  733. }
  734. DWORD lastError = GetLastError();
  735. if (++i < MAX_TRY && lastError == ERROR_SHARING_VIOLATION)
  736. {
  737. Sleep(NEXT_TRY_SLEEP_MS);
  738. continue;
  739. }
  740. LogError("Unable to open file %s - error %d", file, lastError);
  741. break;
  742. }
  743. return h;
  744. }
  745. struct MyFileWithoutCarriageReturn
  746. {
  747. CHandle* handle;
  748. char* buf = nullptr;
  749. size_t i = 0;
  750. DWORD count = 0;
  751. MyFileWithoutCarriageReturn(CHandle* handle, char* buf) : handle(handle), buf(buf) { Read(); }
  752. bool readingError;
  753. void Read()
  754. {
  755. i = 0;
  756. readingError = !ReadFile(*handle, buf, CMPBUF_SIZE, &count, NULL);
  757. }
  758. bool HasNextChar()
  759. {
  760. if (count == 0)
  761. {
  762. return false;
  763. }
  764. if (i == count)
  765. {
  766. Read();
  767. if (readingError)
  768. {
  769. return false;
  770. }
  771. return HasNextChar();
  772. }
  773. while (buf[i] == '\r')
  774. {
  775. ++i;
  776. if (i == count)
  777. {
  778. Read();
  779. if (readingError)
  780. {
  781. return false;
  782. }
  783. return HasNextChar();
  784. }
  785. }
  786. return true;
  787. }
  788. char GetNextChar()
  789. {
  790. return buf[i++];
  791. }
  792. };
  793. // Do a quick file equality comparison using pure Win32 functions. (Avoid
  794. // using CRT functions; the MT CRT seems to have locking/flushing problems on
  795. // MP boxes.)
  796. int
  797. DoCompare(
  798. char *file1,
  799. char *file2,
  800. BOOL normalizeLineEndings
  801. )
  802. {
  803. CHandle h1, h2; // automatically closes open handles
  804. DWORD count1, count2;
  805. BOOL b1, b2;
  806. DWORD size1, size2;
  807. // Allocate large buffers for doing quick file comparisons.
  808. if (cmpbuf1 == NULL) {
  809. // initialize the buffers
  810. cmpbuf1 = new char[CMPBUF_SIZE];
  811. cmpbuf2 = new char[CMPBUF_SIZE];
  812. if ((cmpbuf1 == NULL) || (cmpbuf2 == NULL))
  813. Fatal("new failed");
  814. }
  815. h1 = OpenFileToCompare(file1);
  816. if (h1 == INVALID_HANDLE_VALUE) {
  817. return -1;
  818. }
  819. h2 = OpenFileToCompare(file2);
  820. if (h2 == INVALID_HANDLE_VALUE) {
  821. return -1;
  822. }
  823. if (normalizeLineEndings)
  824. {
  825. MyFileWithoutCarriageReturn f1(&h1, cmpbuf1);
  826. MyFileWithoutCarriageReturn f2(&h2, cmpbuf2);
  827. if (f1.readingError || f2.readingError)
  828. {
  829. LogError("ReadFile failed doing compare of %s and %s", file1, file2);
  830. return -1;
  831. }
  832. while (f1.HasNextChar() && f2.HasNextChar())
  833. {
  834. if (f1.readingError || f2.readingError)
  835. {
  836. LogError("ReadFile failed doing compare of %s and %s", file1, file2);
  837. return -1;
  838. }
  839. if (f1.GetNextChar() != f2.GetNextChar())
  840. {
  841. #ifndef NODEBUG
  842. if (FDebug)
  843. printf("DoCompare shows %s and %s are NOT equal (contents differ)\n", file1, file2);
  844. #endif
  845. return 1;
  846. }
  847. }
  848. if (f1.HasNextChar() != f2.HasNextChar())
  849. {
  850. #ifndef NODEBUG
  851. if (FDebug)
  852. printf("DoCompare shows %s and %s are NOT equal (contents differ)\n", file1, file2);
  853. #endif
  854. return 1;
  855. }
  856. return 0;
  857. }
  858. size1 = GetFileSize(h1, NULL); // assume < 4GB files
  859. if (size1 == 0xFFFFFFFF) {
  860. LogError("Unable to get file size for %s - error %d", file1, GetLastError());
  861. return -1;
  862. }
  863. size2 = GetFileSize(h2, NULL);
  864. if (size2 == 0xFFFFFFFF) {
  865. LogError("Unable to get file size for %s - error %d", file2, GetLastError());
  866. return -1;
  867. }
  868. if (size1 != size2) { // not equal; don't bother reading the files
  869. #ifndef NODEBUG
  870. if (FDebug)
  871. printf("DoCompare shows %s and %s are NOT equal (different size)\n", file1, file2);
  872. #endif
  873. return 1;
  874. }
  875. do {
  876. b1 = ReadFile(h1, cmpbuf1, CMPBUF_SIZE, &count1, NULL);
  877. b2 = ReadFile(h2, cmpbuf2, CMPBUF_SIZE, &count2, NULL);
  878. if (!b1 || !b2) {
  879. LogError("ReadFile failed doing compare of %s and %s", file1, file2);
  880. return -1;
  881. }
  882. if (count1 != count2 || memcmp(cmpbuf1, cmpbuf2, count1) != 0) {
  883. #ifndef NODEBUG
  884. if (FDebug)
  885. printf("DoCompare shows %s and %s are NOT equal (contents differ)\n", file1, file2);
  886. #endif
  887. return 1;
  888. }
  889. } while (count1 == CMPBUF_SIZE);
  890. #ifndef NODEBUG
  891. if (FDebug)
  892. printf("DoCompare shows %s and %s are equal\n", file1, file2);
  893. #endif
  894. return 0;
  895. }
  896. char *
  897. FormatString(
  898. const char *format
  899. )
  900. {
  901. static char buf[BUFFER_SIZE + 32]; // extra in case a sprintf_s goes over
  902. int i;
  903. i = 0;
  904. while (*format) {
  905. if (*format != '%') {
  906. buf[i++] = *format;
  907. }
  908. else {
  909. switch (*++format) {
  910. case 'd':
  911. i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d", (int32)NumDiffsTotal[RLS_TOTAL]);
  912. break;
  913. case 'f':
  914. i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d", (int32)NumFailuresTotal[RLS_TOTAL]);
  915. break;
  916. case 't':
  917. i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d", (int32)NumVariationsRun[RLS_TOTAL]);
  918. break;
  919. case 'T':
  920. i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d", (int32)NumVariationsTotal[RLS_TOTAL]);
  921. break;
  922. case 'p':
  923. if ((int32)NumVariationsTotal[RLS_TOTAL]) {
  924. i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d",
  925. 100 * (int32)NumVariationsRun[RLS_TOTAL] /
  926. (int32)NumVariationsTotal[RLS_TOTAL]);
  927. }
  928. else {
  929. i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "--");
  930. }
  931. break;
  932. default:
  933. buf[i++] = *format;
  934. }
  935. }
  936. format++;
  937. if (i > BUFFER_SIZE)
  938. break;
  939. }
  940. ASSERTNR(i < BUFFER_SIZE + 32);
  941. buf[i] = '\0';
  942. return buf;
  943. }
  944. void
  945. Usage(
  946. BOOL fExtended
  947. )
  948. {
  949. int i;
  950. BOOL fFirst;
  951. printf(
  952. "Usage: %s [options] [files...] [-args ...]\n"
  953. "Specifying files on the command line overrides the configuration file parsing\n"
  954. "\nOptions:\n"
  955. " -h[x]: short/extended usage info\n"
  956. "\n"
  957. " -base[:backend] update MASTER_DIR assembly regression baselines\n"
  958. " -diff[:backend] assembly regressions (default if no mode option)\n"
  959. " -exe[:backend] run executable tests\n"
  960. "\n"
  961. " -all to run regressions on all directories in directory config file (log files go\n"
  962. " in %%REGRESS%%\\logs directory)\n"
  963. , ProgramName
  964. );
  965. if (fExtended) {
  966. printf(
  967. " -dirs:dir[,dir...] only regress the specified directories\n"
  968. " -nodirs:dir[,dir...] exclude the specified directories\n"
  969. " -resume:dir resume from the specified directory (implies -append)\n"
  970. " -match:dir run regressions on directories with dir as a prefix\n"
  971. "\n"
  972. " -tags:tag[,tag...] only regress tests with any of the specified tags\n"
  973. " -nottags:tag[,tag...] don't regress tests with any of the specified tags\n"
  974. " -dirtags:tag[,tag...] only regress tests within directories with any of the specified tags\n"
  975. " -dirnottags:tag[,tag...] don't regress tests within directories with any of the specified tags\n"
  976. "\n"
  977. " -exeflags:flag[;flag] specify exe flags to use in place of EXEC_TESTS_FLAGS\n"
  978. " -target:arch specify the target architecture, instead of TARGET_MACHINE\n"
  979. " -rltarget:arch specify the target architecture, instead of RL_MACHINE\n"
  980. " -os:name specify the target os, instead of TARGET_OS\n"
  981. " -regress:dir specify the root dir, instead of REGRESS\n"
  982. "\n"
  983. " -log:file specifies log file name (default: " DEFAULT_LOG_FILE ")\n"
  984. " -full:file specifies full log file name (default: " DEFAULT_FULL_LOG_FILE ")\n"
  985. " -results:file specifies runall style results log name (default: " DEFAULT_RESULTS_LOG_FILE ")\n"
  986. " -rellog to allow a relative path log file\n"
  987. "\n"
  988. " -status[:prefix] to track diffs/failures in title\n"
  989. " default prefix is \"{Diffs,Exec} [target] \"\n"
  990. " -statusformat:format to specify display of statistics\n"
  991. " default format is \"(%%d diffs, )%%f failures, %%t/%%T (%%p%%%%)\"\n"
  992. " where %%d = # diffs, %%f = #failures,\n"
  993. " %%t = num tests run, %%T = num tests total,\n"
  994. " %%p = percentage of tests completed\n"
  995. " -rlfe[:options] launch RLFE (graphical front end)\n"
  996. "\n"
  997. " -nosummary disables output of summary diff/failure info (implies -dirname)\n"
  998. " -dirname enables output of '*** dirname ***'\n"
  999. " -nomovediffs to not place assembly diffs in DIFF_DIR\n"
  1000. " -nodelete to not delete objs and exes when doing -exe\n"
  1001. " (only compatible with a single EXEC_TESTS_FLAGS flags)\n"
  1002. " -copyonfail to copy *.exe *.obj to fail.(OPT) subdirectory when rl.mak\n"
  1003. " tests fail\n"
  1004. " -allowpopup to allow popup screen when tests fail to run correctly\n"
  1005. " (do not link with nogpfnt.obj)\n"
  1006. " -append to append to the log files without deleting them first\n"
  1007. "\n"
  1008. " -quiet eliminates console display of progress\n"
  1009. " -verbose displays info about regressions\n"
  1010. " -nowarn turns off warnings\n"
  1011. " -low sets RL process to a lower priority\n"
  1012. " -test just displays regression commands, doesn't execute them\n"
  1013. "\n"
  1014. " -time:variation times each variation\n"
  1015. " -time:test times each test\n"
  1016. " -time:dir times each directory\n"
  1017. " -time:all enables all timing options\n"
  1018. "\n"
  1019. " -rebase:create rebase file if testout is different to baseline\n"
  1020. " -threads:# specifies # of worker threads to use (default==processor count)\n"
  1021. " -nothreadid to omit the thread id from multithreaded output\n"
  1022. " -sync:immediate to flush output immediately---no buffering\n"
  1023. " -sync:variation (default) to flush output after a test variation\n"
  1024. " -sync:test to flush output after all variations of a test\n"
  1025. " -sync:dir to flush output after an entire directory\n"
  1026. "\n"
  1027. " -dcfg:filename override directory config file\n"
  1028. " ASM default:" DEFAULT_ASM_DCFG " EXE default:" DEFAULT_EXE_DCFG "\n"
  1029. " -cfg:filename override file config file\n"
  1030. " ASM default:" DEFAULT_ASM_CFG " EXE default:" DEFAULT_EXE_CFG "\n"
  1031. "\n"
  1032. " -genlst to generate the runall test.lst and env.lst files, and don't run rl tests\n"
  1033. "\n"
  1034. );
  1035. #ifndef NODEBUG
  1036. printf(
  1037. "DEBUG ONLY:\n"
  1038. " -debug to show debug info (implies -verbose)\n"
  1039. " -syncdirs to enumerate all dirs/files before running tests\n"
  1040. "\n"
  1041. );
  1042. #endif
  1043. printf(
  1044. "Perform %s regressions by default.\n"
  1045. , ModeNames[DEFAULT_RLMODE]
  1046. );
  1047. printf(
  1048. "Current directory assumed if -all/-dirs/-resume/-match not specified\n"
  1049. "-status is the default; use -status:- to disable\n"
  1050. "Target machine defaults to %s (option -target or environment var\n"
  1051. " TARGET_MACHINE overrides)\n"
  1052. , TargetInfo[DEFAULT_TM].name
  1053. );
  1054. printf(
  1055. " (Valid targets:");
  1056. fFirst = TRUE;
  1057. for (i = 1; TargetInfo[i].name; i++) {
  1058. if (!TargetInfo[i].fRL_MACHINEonly) {
  1059. if (!fFirst)
  1060. putchar(',');
  1061. else
  1062. fFirst = FALSE;
  1063. printf(" %s", TargetInfo[i].name);
  1064. }
  1065. }
  1066. printf(")\n");
  1067. printf(
  1068. "Option -rltarget or environment var RL_MACHINE overrides TARGET_MACHINE for\n"
  1069. " configuration checking\n"
  1070. " (Additional configurations:");
  1071. fFirst = TRUE;
  1072. for (i = 1; TargetInfo[i].name; i++) {
  1073. if (TargetInfo[i].fRL_MACHINEonly) {
  1074. if (!fFirst)
  1075. putchar(',');
  1076. else
  1077. fFirst = FALSE;
  1078. printf(" %s", TargetInfo[i].name);
  1079. }
  1080. }
  1081. printf(")\n");
  1082. printf(
  1083. "Target os defaults to %s (option -os or environment var TARGET_OS overrides)\n"
  1084. " (Valid os:"
  1085. , TargetOSNames[DEFAULT_OS]);
  1086. fFirst = TRUE;
  1087. for (i = 1; TargetOSNames[i]; i++) {
  1088. if (!fFirst)
  1089. putchar(',');
  1090. else
  1091. fFirst = FALSE;
  1092. printf(" %s", TargetOSNames[i]);
  1093. }
  1094. printf(")\n");
  1095. printf(
  1096. "MASTER_DIR env var defaults to master.<target machine>\n"
  1097. "DIFF_DIR defaults to diffs.<target machine>\n"
  1098. "\n"
  1099. "The following environment variables are recognized:\n"
  1100. "REGR_CL use the specified command instead of " DEFAULT_REGR_CL "\n"
  1101. "REGR_ASM generate assembly listings and use the specified command to\n"
  1102. " assemble them\n"
  1103. "REGR_DIFF use the specified command instead of " DEFAULT_REGR_DIFF " (asm only)\n"
  1104. "REGR_SHOWD use the specified executable instead of %s\\bin\\showd.cmd (asm only)\n"
  1105. "EXTRA_CC_FLAGS specifies additional flags to pass to REGR_CL\n"
  1106. " if EXTRA_CC_FLAGS is not specified, it is constructed from\n"
  1107. " RL_{ASM,EXE}_CFLAGS and RL_B2, if present\n"
  1108. "RL_ASM_CFLAGS specify ASM only flags (used to construct EXTRA_CC_FLAGS)\n"
  1109. "RL_EXE_CFLAGS specify EXE only flags (used to construct EXTRA_CC_FLAGS)\n"
  1110. "RL_B2 specify backend to use (appended to above to create EXTRA_CC_FLAGS)\n"
  1111. "EXEC_TESTS_FLAGS semicolon delimited list of testing options (exe only)\n"
  1112. " (overridden by -exeflags switch) (defaults to %s)\n"
  1113. , getenv_unsafe("REGRESS"), DEFAULT_EXEC_TESTS_FLAGS
  1114. );
  1115. printf(
  1116. "REGR_NOMASTERCMP specifies that the generated ASM files should not be compared\n"
  1117. "to the masters (useful if you don't care about diffs and want to save time.)\n"
  1118. "TARGET_VM specifies the program used to execute a test (exe only)\n"
  1119. );
  1120. fFirst = TRUE;
  1121. for (i = 1; TargetInfo[i].name; i++) {
  1122. if (TargetInfo[i].TARGET_VM) {
  1123. if (fFirst) {
  1124. printf(" (");
  1125. fFirst = FALSE;
  1126. }
  1127. else {
  1128. printf(", ");
  1129. }
  1130. printf("%s: %s", TargetInfo[i].name, TargetInfo[i].TARGET_VM);
  1131. }
  1132. }
  1133. if (!fFirst)
  1134. printf(")\n");
  1135. printf(
  1136. "LINKER use the specified command instead of " DEFAULT_LINKER " (exe only)\n"
  1137. "LINKFLAGS specifies additional flags to pass to LINKER (exe only)\n"
  1138. );
  1139. fFirst = TRUE;
  1140. for (i = 1; TargetInfo[i].name; i++) {
  1141. if (TargetInfo[i].LINKFLAGS) {
  1142. if (fFirst) {
  1143. printf(" (");
  1144. fFirst = FALSE;
  1145. }
  1146. else {
  1147. printf(", ");
  1148. }
  1149. printf("%s: %s", TargetInfo[i].name, TargetInfo[i].LINKFLAGS);
  1150. }
  1151. }
  1152. if (!fFirst)
  1153. printf(")\n");
  1154. }
  1155. }
  1156. TARGET_MACHINES
  1157. ParseMachine(
  1158. char *s
  1159. )
  1160. {
  1161. int i;
  1162. for (i = 1; TargetInfo[i].name; i++) {
  1163. if (!_stricmp(TargetInfo[i].name, s))
  1164. return (TARGET_MACHINES)i;
  1165. }
  1166. return TM_UNKNOWN;
  1167. }
  1168. TARGET_OS
  1169. ParseOS(
  1170. char *s
  1171. )
  1172. {
  1173. int i;
  1174. for (i = 1; TargetOSNames[i]; i++) {
  1175. if (!_stricmp(TargetOSNames[i], s))
  1176. return (TARGET_OS)i;
  1177. }
  1178. return TO_UNKNOWN;
  1179. }
  1180. // Does the config file specified target match with our regression target?
  1181. // TRUE if they are equal or regrTarget is a superset of fileTarget.
  1182. BOOL
  1183. MatchMachine(
  1184. TARGET_MACHINES fileTarget,
  1185. TARGET_MACHINES regrTarget
  1186. )
  1187. {
  1188. if (fileTarget == regrTarget)
  1189. return TRUE;
  1190. if (fileTarget == TM_WVM) {
  1191. if (regrTarget == TM_WVMCEE || regrTarget == TM_WVMX86 || regrTarget == TM_WVM64)
  1192. return TRUE;
  1193. }
  1194. return FALSE;
  1195. }
  1196. BOOL
  1197. MatchOS(
  1198. TARGET_OS fileTarget,
  1199. TARGET_OS regrTarget
  1200. )
  1201. {
  1202. if (fileTarget == regrTarget)
  1203. {
  1204. return TRUE;
  1205. }
  1206. // Apply win8 override for wp8
  1207. if (fileTarget == TO_WIN8 && regrTarget == TO_WP8)
  1208. {
  1209. return TRUE;
  1210. }
  1211. return FALSE;
  1212. }
  1213. BOOL
  1214. HasInfoList
  1215. (
  1216. const char * szInfoList1,
  1217. const char * delim1,
  1218. const char * szInfoList2,
  1219. const char * delim2,
  1220. bool allMustMatch
  1221. )
  1222. {
  1223. if (szInfoList1 == NULL)
  1224. {
  1225. return FALSE;
  1226. }
  1227. if (szInfoList2 == NULL)
  1228. {
  1229. return FALSE;
  1230. }
  1231. const char * s = szInfoList2;
  1232. BOOL fHasInfo = TRUE; // start with TRUE on each entry
  1233. for (;;)
  1234. {
  1235. // Parse an item from szInfoList2.
  1236. char * e;
  1237. for (e = const_cast<char *>(s);
  1238. (strchr(delim2, *e) == NULL) && (*e != '\0');
  1239. e++)
  1240. {
  1241. }
  1242. char c = *e;
  1243. *e = '\0';
  1244. if (allMustMatch)
  1245. {
  1246. if (delim2 && (*delim2 == ','))
  1247. fHasInfo = TRUE; // new condition after ','
  1248. const char *save;
  1249. save = strchr(s, *delim1);
  1250. while(save != NULL) {
  1251. fHasInfo = fHasInfo && HasInfoList(szInfoList1, delim1,
  1252. s, delim1, allMustMatch);
  1253. s = save + 1;
  1254. save = strchr(s, *delim1);
  1255. }
  1256. fHasInfo = fHasInfo && HasInfo(szInfoList1, delim1, s);
  1257. }
  1258. else
  1259. {
  1260. fHasInfo = HasInfo(szInfoList1, delim1, s);
  1261. }
  1262. *e = c;
  1263. if (fHasInfo)
  1264. {
  1265. return TRUE;
  1266. }
  1267. if (c == '\0')
  1268. {
  1269. break;
  1270. }
  1271. s = e + 1;
  1272. }
  1273. return FALSE;
  1274. }
  1275. const char *
  1276. stristr
  1277. (
  1278. const char * str,
  1279. const char * sub
  1280. )
  1281. {
  1282. size_t len = strlen(sub);
  1283. size_t i;
  1284. while (*str)
  1285. {
  1286. for (i = 0; i < len; i++)
  1287. {
  1288. if (tolower(str[i]) != tolower(sub[i]))
  1289. {
  1290. if ((str[i] != '/' && str[i] != '-') || (sub[i] != '-' && sub[i] != '/')) {
  1291. // if the mismatch is not between '/' and '-'
  1292. break;
  1293. }
  1294. }
  1295. }
  1296. if (i == len)
  1297. {
  1298. return str;
  1299. }
  1300. str++;
  1301. }
  1302. return NULL;
  1303. }
  1304. BOOL
  1305. HasInfo
  1306. (
  1307. const char * szInfoList,
  1308. const char * delim1,
  1309. const char * szInfo
  1310. )
  1311. {
  1312. size_t len = strlen(szInfo);
  1313. const char * s = szInfoList;
  1314. if (s != NULL)
  1315. {
  1316. for (;;)
  1317. {
  1318. s = stristr(s, szInfo);
  1319. if (s == NULL)
  1320. {
  1321. return FALSE;
  1322. }
  1323. if (((s == szInfoList) || (strchr(delim1, s[-1]) != NULL))
  1324. && ((s[len] == '\0') || (strchr(delim1, s[len]) != NULL)))
  1325. {
  1326. return TRUE;
  1327. }
  1328. while (*s != '\0')
  1329. {
  1330. if (strchr(delim1, *s) != NULL)
  1331. {
  1332. break;
  1333. }
  1334. s++;
  1335. }
  1336. if (*s == '\0')
  1337. {
  1338. break;
  1339. }
  1340. s++;
  1341. }
  1342. }
  1343. return FALSE;
  1344. }
  1345. template<typename ListType,typename String>
  1346. ListNode<ListType> *
  1347. AddToStringList
  1348. (
  1349. ListNode<ListType> * list,
  1350. String string
  1351. )
  1352. {
  1353. ListNode<ListType> * p = new ListNode<ListType>;
  1354. p->string = string; // NOTE: we store the pointer; we don't copy the string
  1355. p->next = NULL;
  1356. if (list == NULL)
  1357. {
  1358. return p;
  1359. }
  1360. ListNode<ListType> * last = list;
  1361. while (last->next != NULL)
  1362. {
  1363. last = last->next;
  1364. }
  1365. last->next = p;
  1366. return list;
  1367. }
  1368. template<typename T>
  1369. void
  1370. FreeStringList
  1371. (
  1372. ListNode<T> * list
  1373. )
  1374. {
  1375. while (list)
  1376. {
  1377. ListNode<T> * pFree = list;
  1378. list = list->next;
  1379. delete pFree;
  1380. }
  1381. }
  1382. void
  1383. FreeVariants
  1384. (
  1385. TestVariant * list
  1386. )
  1387. {
  1388. while (list)
  1389. {
  1390. TestVariant * pFree = list;
  1391. list = list->next;
  1392. delete pFree;
  1393. }
  1394. }
  1395. StringList *
  1396. ParseStringList(const char* cp, const char* delim)
  1397. {
  1398. StringList * list = NULL;
  1399. if (cp == NULL)
  1400. {
  1401. return list;
  1402. }
  1403. char *p = _strdup(cp); // don't trash passed-in memory
  1404. p = mystrtok(p, delim, delim);
  1405. while (p != NULL)
  1406. {
  1407. list = AddToStringList(list, p);
  1408. p = mystrtok(NULL, delim, delim);
  1409. }
  1410. return list;
  1411. }
  1412. StringList *
  1413. AppendStringList
  1414. (
  1415. StringList * list,
  1416. StringList * listToAppend
  1417. )
  1418. {
  1419. StringList * p;
  1420. if (list == NULL) {
  1421. return listToAppend;
  1422. }
  1423. for (p = list; p->next != NULL; p = p->next) {
  1424. // nothing
  1425. }
  1426. p->next = listToAppend;
  1427. return list;
  1428. }
  1429. BOOL
  1430. CompareStringList
  1431. (
  1432. StringList * list1,
  1433. StringList * list2
  1434. )
  1435. {
  1436. while ((list1 != NULL) && (list2 != NULL))
  1437. {
  1438. if (_stricmp(list1->string, list2->string))
  1439. {
  1440. return FALSE;
  1441. }
  1442. list1 = list1->next;
  1443. list2 = list2->next;
  1444. }
  1445. if (list1 == list2)
  1446. {
  1447. ASSERTNR(list1 == NULL);
  1448. return TRUE;
  1449. }
  1450. return FALSE;
  1451. }
  1452. // Set three environment variables for use in suppressing GPF pop-ups:
  1453. // NOGPF -- for console-mode programs
  1454. // NOGPFWINEXE -- for Windows EXEs
  1455. // NOGPFWINDLL -- for Windows DLLs
  1456. // These are useful for either dotest.cmd tests, or rl.mak tests that don't
  1457. // use the default console-mode nogpfnt.obj.
  1458. void
  1459. SetNOGPF()
  1460. {
  1461. char tempBuf[BUFFER_SIZE];
  1462. if (FNogpfnt && TargetInfo[TargetMachine].fUseNoGPF) {
  1463. sprintf_s(tempBuf,
  1464. "NOGPF=%s\\bin\\%s\\nogpfnt.obj /entry:nogpfntStartup",
  1465. REGRESS, TargetInfo[TargetMachine].name);
  1466. if (_putenv(tempBuf))
  1467. Fatal("Couldn't set NOGPF");
  1468. sprintf_s(tempBuf,
  1469. "NOGPFWINEXE=%s\\bin\\%s\\nogpfntWinMain.obj /entry:nogpfntWinMainStartup",
  1470. REGRESS, TargetInfo[TargetMachine].name);
  1471. if (_putenv(tempBuf))
  1472. Fatal("Couldn't set NOGPFWINEXE");
  1473. sprintf_s(tempBuf,
  1474. "NOGPFWINDLL=%s\\bin\\%s\\nogpfntDllMain.obj /entry:nogpfntDllMainStartup",
  1475. REGRESS, TargetInfo[TargetMachine].name);
  1476. if (_putenv(tempBuf))
  1477. Fatal("Couldn't set NOGPFWINDLL");
  1478. } else {
  1479. if (_putenv("NOGPF="))
  1480. Fatal("Couldn't set NOGPF");
  1481. if (_putenv("NOGPFWINEXE="))
  1482. Fatal("Couldn't set NOGPFWINEXE");
  1483. if (_putenv("NOGPFWINDLL="))
  1484. Fatal("Couldn't set NOGPFWINDLL");
  1485. }
  1486. }
  1487. // Get the LINKFLAGS variable. If necessary, massage it and put it back into
  1488. // the environment for use by the regr386 scripts and makefiles. The
  1489. // manipulation includes:
  1490. // 1. add a "no access violation" object to avoid pop-ups
  1491. // 2. to make LTCG testing easier, if EXTRA_CC_FLAGS contains /B2c2.dll, we
  1492. // copy that to LINKFLAGS as -B2:c2.dll. We check that there doesn't already
  1493. // exist a -B2: on the LINKFLAGS, or that they don't conflict. If we don't
  1494. // do this manipulation, it is too easy to forget to add -B2: to LINKFLAGS
  1495. // on your own, and hence test some compiler besides the one you intend to,
  1496. // namely whatever c2.dll is on your path.
  1497. void
  1498. GetLINKFLAGS()
  1499. {
  1500. char* readLINKFLAGS;
  1501. char* s;
  1502. char* b2;
  1503. char tmpLINKFLAGS[BUFFER_SIZE];
  1504. char tmpstrtok[BUFFER_SIZE];
  1505. char* tmpstrtoknext = NULL;
  1506. char tempBuf[BUFFER_SIZE];
  1507. bool fPropagateB2;
  1508. if ((readLINKFLAGS = getenv_unsafe("LINKFLAGS")) == NULL) {
  1509. if (NULL == TargetInfo[TargetMachine].LINKFLAGS) {
  1510. tmpLINKFLAGS[0] = '\0';
  1511. } else {
  1512. strcpy_s(tmpLINKFLAGS, TargetInfo[TargetMachine].LINKFLAGS);
  1513. }
  1514. } else {
  1515. strcpy_s(tmpLINKFLAGS, readLINKFLAGS);
  1516. }
  1517. // Look for -B2 or /B2 in EXTRA_CC_FLAGS
  1518. fPropagateB2 = false;
  1519. b2 = NULL;
  1520. strcpy_s(tmpstrtok, EXTRA_CC_FLAGS);
  1521. s = strtok_s(tmpstrtok, " \t", &tmpstrtoknext);
  1522. while (s) {
  1523. #ifndef NODEBUG
  1524. if (FDebug)
  1525. printf("\tParsed '%s'\n", s);
  1526. #endif
  1527. if ((0 == _strnicmp(s, "/B2", 3)) || (0 == _strnicmp(s, "-B2", 3))) {
  1528. if (b2 == NULL) {
  1529. b2 = s + 3;
  1530. if (*b2 == '\0')
  1531. b2++;
  1532. while (isspace(*b2))
  1533. b2++;
  1534. b2 = _strdup(b2);
  1535. fPropagateB2 = true;
  1536. } else {
  1537. Warning("Two /B2 flags in EXTRA_CC_FLAGS (%s)", EXTRA_CC_FLAGS);
  1538. }
  1539. }
  1540. s = strtok_s(NULL, " \t", &tmpstrtoknext);
  1541. }
  1542. // Now look for -B2: or /B2: in LINKFLAGS to check for consistency.
  1543. strcpy_s(tmpstrtok, tmpLINKFLAGS);
  1544. tmpstrtoknext = NULL;
  1545. s = strtok_s(tmpstrtok, " \t", &tmpstrtoknext);
  1546. while (s) {
  1547. #ifndef NODEBUG
  1548. if (FDebug)
  1549. printf("\tParsed '%s'\n", s);
  1550. #endif
  1551. if ((0 == _strnicmp(s, "/B2:", 4)) || (0 == _strnicmp(s, "-B2:", 4))) {
  1552. fPropagateB2 = false;
  1553. if (b2 == NULL) {
  1554. Warning("/B2: in LINKFLAGS (%s) but not in EXTRA_CC_FLAGS (%s)", readLINKFLAGS, EXTRA_CC_FLAGS);
  1555. } else {
  1556. // Make sure they are the same
  1557. if (0 != _stricmp(s + 4, b2)) {
  1558. Warning("/B2 flags in EXTRA_CC_FLAGS (%s) conflict with -B2: in LINKFLAGS(%s)", EXTRA_CC_FLAGS, readLINKFLAGS);
  1559. }
  1560. }
  1561. }
  1562. s = strtok_s(NULL, " \t", &tmpstrtoknext);
  1563. }
  1564. if (fPropagateB2) {
  1565. // We found -B2 in EXTRA_CC_FLAGS but not in LINKFLAGS, so propagate
  1566. // it to LINKFLAGS.
  1567. sprintf_s(tempBuf, " -B2:\"%s\"", b2);
  1568. free(b2); // came from _strdup()
  1569. strcat_s(tmpLINKFLAGS, tempBuf);
  1570. }
  1571. // Now, put it back into the environment with all our changes
  1572. sprintf_s(tempBuf, "LINKFLAGS=%s", tmpLINKFLAGS);
  1573. if (_putenv(tempBuf))
  1574. Fatal("Couldn't set LINKFLAGS");
  1575. LINKFLAGS = _strdup(tmpLINKFLAGS);
  1576. }
  1577. // WARNING: we are liberally using _putenv. As a result, it is dangerous to
  1578. // hold onto a pointer returned from getenv(), so always make a copy
  1579. void
  1580. GetEnvironment(
  1581. void
  1582. )
  1583. {
  1584. char *env;
  1585. FILE *showd_fp;
  1586. char tempBuf[BUFFER_SIZE];
  1587. // Get the TARGET_MACHINE environment variable. It may have already been
  1588. // specified on the command-line by the "-target" option, in which case
  1589. // we don't get the environment variable, but we do validate what the
  1590. // user passed.
  1591. if ((TARGET_MACHINE != NULL)
  1592. || ((TARGET_MACHINE = getenv_unsafe("TARGET_MACHINE")) != NULL))
  1593. {
  1594. TargetMachine = RLMachine = ParseMachine(TARGET_MACHINE);
  1595. if (TargetMachine == TM_UNKNOWN) {
  1596. Fatal("Unknown machine type specified by TARGET_MACHINE: %s",
  1597. TARGET_MACHINE);
  1598. }
  1599. if (TargetInfo[TargetMachine].fRL_MACHINEonly) {
  1600. Fatal("TARGET_MACHINE specified is only valid for RL_MACHINE: %s",
  1601. TARGET_MACHINE);
  1602. }
  1603. }
  1604. else {
  1605. // Set environment var in case regr scripts reference.
  1606. sprintf_s(tempBuf, "TARGET_MACHINE=%s", TargetInfo[TargetMachine].name);
  1607. if (_putenv(tempBuf))
  1608. Fatal("Couldn't set TARGET_MACHINE");
  1609. }
  1610. // Get the RL_MACHINE environment variable or option.
  1611. if ((RL_MACHINE != NULL)
  1612. || ((RL_MACHINE = getenv_unsafe("RL_MACHINE")) != NULL))
  1613. {
  1614. RLMachine = ParseMachine(RL_MACHINE);
  1615. if (RLMachine == TM_UNKNOWN) {
  1616. Fatal("Unknown machine type specified by RL_MACHINE: %s", RL_MACHINE);
  1617. }
  1618. }
  1619. else {
  1620. // Set environment var in case regr scripts reference.
  1621. sprintf_s(tempBuf, "RL_MACHINE=%s", TargetInfo[RLMachine].name);
  1622. if (_putenv(tempBuf))
  1623. Fatal("Couldn't set RL_MACHINE");
  1624. }
  1625. // Get the TARGET_OS environment variable or option.
  1626. if (TARGET_OS_NAME != NULL
  1627. || (TARGET_OS_NAME = getenv_unsafe("TARGET_OS")) != NULL)
  1628. {
  1629. TargetOS = ParseOS(TARGET_OS_NAME);
  1630. if (TargetOS == TO_UNKNOWN) {
  1631. Fatal("Unknown os type specified by TargetOS: %s", TARGET_OS_NAME);
  1632. }
  1633. }
  1634. // Get the EXTRA_CC_FLAGS environment variable.
  1635. if ((EXTRA_CC_FLAGS = getenv_unsafe("EXTRA_CC_FLAGS")) == NULL) {
  1636. char *cflags, *b2;
  1637. // It doesn't exist, see if we can construct from RL_{ASM,EXE}_CFLAGS.
  1638. if (Mode == RM_ASM)
  1639. cflags = getenv_unsafe("RL_ASM_CFLAGS");
  1640. else
  1641. cflags = getenv_unsafe("RL_EXE_CFLAGS");
  1642. b2 = getenv_unsafe("RL_B2");
  1643. if (BaseCompiler || DiffCompiler || ExeCompiler) {
  1644. if (FVerbose && b2)
  1645. puts("Command line specified compiler overrides RL_B2 environment variable");
  1646. if (ExeCompiler)
  1647. b2 = ExeCompiler;
  1648. else
  1649. b2 = NULL;
  1650. }
  1651. sprintf_s(tempBuf, "%s%s%s",
  1652. cflags ? cflags : "",
  1653. b2 ? " -B2 " : "",
  1654. b2 ? b2 : "");
  1655. EXTRA_CC_FLAGS = _strdup(tempBuf);
  1656. sprintf_s(tempBuf, "EXTRA_CC_FLAGS=%s", EXTRA_CC_FLAGS);
  1657. if (_putenv(tempBuf))
  1658. Fatal("Couldn't set EXTRA_CC_FLAGS");
  1659. if (FVerbose)
  1660. puts("Constructed EXTRA_CC_FLAGS from RL_{ASM,EXE}_CFLAGS and RL_B2");
  1661. } else {
  1662. EXTRA_CC_FLAGS = _strdup(EXTRA_CC_FLAGS);
  1663. }
  1664. // Get REGR_* overrides.
  1665. if ((REGR_CL = getenv_unsafe("REGR_CL")) == NULL) {
  1666. REGR_CL = DEFAULT_REGR_CL;
  1667. } else {
  1668. REGR_CL = _strdup(REGR_CL);
  1669. }
  1670. if ((REGR_DIFF = getenv_unsafe("REGR_DIFF")) == NULL) {
  1671. REGR_DIFF = DEFAULT_REGR_DIFF;
  1672. } else {
  1673. REGR_DIFF = _strdup(REGR_DIFF);
  1674. }
  1675. REGR_ASM = getenv_unsafe("REGR_ASM");
  1676. if (REGR_ASM != NULL) {
  1677. REGR_ASM = _strdup(REGR_ASM);
  1678. }
  1679. // Get/generate {MASTER,DIFF}_DIR if doing assembly tests.
  1680. if (Mode == RM_ASM) {
  1681. // Get/generate the MASTER directory.
  1682. if ((MASTER_DIR = getenv_unsafe("MASTER_DIR")) == NULL) {
  1683. if (FVerbose) {
  1684. // This should be the default, so don't warn
  1685. Warning("Generating MASTER_DIR environment variable");
  1686. }
  1687. sprintf_s(tempBuf, "master.%s", TargetInfo[RLMachine].name);
  1688. MASTER_DIR = _strdup(tempBuf);
  1689. // Set environment var in case user overrides internal regr
  1690. // with -cmd.
  1691. sprintf_s(tempBuf, "MASTER_DIR=%s", MASTER_DIR);
  1692. if (_putenv(tempBuf))
  1693. Fatal("Couldn't set MASTER_DIR");
  1694. } else {
  1695. MASTER_DIR = _strdup(MASTER_DIR);
  1696. }
  1697. // Get/generate the DIFF directory.
  1698. if (FMoveDiffs) {
  1699. if ((DIFF_DIR = getenv_unsafe("DIFF_DIR")) == NULL) {
  1700. if (FVerbose) {
  1701. // This should be the default, so don't warn
  1702. Warning("Generating DIFF_DIR environment variable");
  1703. }
  1704. sprintf_s(tempBuf, "diffs.%s", TargetInfo[RLMachine].name);
  1705. DIFF_DIR = _strdup(tempBuf);
  1706. // Set environment var in case user overrides internal regr
  1707. // with -cmd.
  1708. sprintf_s(tempBuf, "DIFF_DIR=%s", DIFF_DIR);
  1709. if (_putenv(tempBuf))
  1710. Fatal("Couldn't set DIFF_DIR");
  1711. } else {
  1712. DIFF_DIR = _strdup(DIFF_DIR);
  1713. }
  1714. }
  1715. else {
  1716. DIFF_DIR = ".";
  1717. if (_putenv("DIFF_DIR="))
  1718. Fatal("Couldn't clear DIFF_DIR");
  1719. }
  1720. // Get the REGR_SHOWD directory.
  1721. REGR_SHOWD = getenv_unsafe("REGR_SHOWD");
  1722. if (REGR_SHOWD == NULL) {
  1723. sprintf_s(tempBuf, "%s\\bin\\showd.cmd", REGRESS);
  1724. REGR_SHOWD = _strdup(tempBuf);
  1725. } else {
  1726. REGR_SHOWD = _strdup(REGR_SHOWD);
  1727. }
  1728. showd_fp = fopen_unsafe(REGR_SHOWD, "rt");
  1729. if (showd_fp == NULL) {
  1730. if (!FGenLst)
  1731. Fatal("couldn't open diff processing command file (%s) with error '%s'", REGR_SHOWD, strerror_unsafe(errno));
  1732. } else
  1733. fclose(showd_fp);
  1734. }
  1735. // Get executable test options.
  1736. else {
  1737. if (EXEC_TESTS_FLAGS == NULL) {
  1738. if ((EXEC_TESTS_FLAGS = getenv_unsafe("EXEC_TESTS_FLAGS")) == NULL)
  1739. {
  1740. EXEC_TESTS_FLAGS = _strdup(DEFAULT_EXEC_TESTS_FLAGS);
  1741. } else {
  1742. // We edit EXEC_TESTS_FLAGS, so create a copy.
  1743. EXEC_TESTS_FLAGS = _strdup(EXEC_TESTS_FLAGS);
  1744. }
  1745. }
  1746. if ((TARGET_VM = getenv_unsafe("TARGET_VM")) == NULL) {
  1747. TARGET_VM = TargetInfo[TargetMachine].TARGET_VM;
  1748. // Support automatic cross-compilation
  1749. if ((TARGET_VM == NULL) && TargetInfo[TargetMachine].fAutoCrossCompilation) {
  1750. // If the host processor is not the same as the architecture to
  1751. // test, and we support automatic cross-compilation for this
  1752. // architecture, then create the default TARGET_VM.
  1753. char* PROCESSOR_ARCHITECTURE;
  1754. PROCESSOR_ARCHITECTURE = getenv_unsafe("PROCESSOR_ARCHITECTURE");
  1755. if (PROCESSOR_ARCHITECTURE == NULL) {
  1756. Fatal("PROCESSOR_ARCHITECTURE environment variable not set (this should be set by the OS!)");
  1757. }
  1758. if (0 != _stricmp(TargetInfo[TargetMachine].name, PROCESSOR_ARCHITECTURE)) {
  1759. TARGET_VM = DEFAULT_CROSS_TARGET_VM;
  1760. }
  1761. }
  1762. }
  1763. if (TARGET_VM != NULL) {
  1764. TARGET_VM = _strdup(TARGET_VM);
  1765. }
  1766. if ((LINKER = getenv_unsafe("LINKER")) == NULL) {
  1767. LINKER = DEFAULT_LINKER;
  1768. } else {
  1769. LINKER = _strdup(LINKER);
  1770. }
  1771. GetLINKFLAGS();
  1772. SetNOGPF();
  1773. }
  1774. // Grab CL and _CL_.
  1775. CL = getenv_unsafe("CL");
  1776. if (CL != NULL)
  1777. {
  1778. CL = _strdup(CL);
  1779. }
  1780. _CL_ = getenv_unsafe("_CL_");
  1781. if (_CL_ != NULL)
  1782. {
  1783. _CL_ = _strdup(_CL_);
  1784. }
  1785. // Display all the settings.
  1786. if (FVerbose) {
  1787. if ((env = getenv_unsafe(RL_PRE_ENV_VAR)) != NULL)
  1788. printf(RL_PRE_ENV_VAR"=%s\n", env);
  1789. if ((env = getenv_unsafe(RL_POST_ENV_VAR)) != NULL)
  1790. printf(RL_POST_ENV_VAR"=%s\n", env);
  1791. printf("Target machine = %s", TargetInfo[RLMachine].name);
  1792. printf(", Target os = %s", TargetOSNames[TargetOS]);
  1793. if (Mode == RM_ASM) {
  1794. printf(", MASTER_DIR = %s", MASTER_DIR);
  1795. if (FMoveDiffs)
  1796. printf(", DIFF_DIR = %s", DIFF_DIR);
  1797. if (FBaseline)
  1798. printf(", creating baselines");
  1799. if (FDiff)
  1800. printf(", checking diffs");
  1801. }
  1802. else {
  1803. printf(", TARGET_VM = %s", TARGET_VM);
  1804. printf(", EXEC_TESTS_FLAGS = %s", EXEC_TESTS_FLAGS);
  1805. }
  1806. printf("\nEXTRA_CC_FLAGS = %s\n", EXTRA_CC_FLAGS);
  1807. printf("REGR_CL = %s, REGR_ASM = %s", REGR_CL, REGR_ASM);
  1808. if (Mode == RM_ASM) {
  1809. printf(", REGR_DIFF = %s", REGR_DIFF);
  1810. }
  1811. else {
  1812. printf("\nLINKER = %s, LINKFLAGS = %s", LINKER, LINKFLAGS);
  1813. }
  1814. putchar('\n');
  1815. if (FLow)
  1816. puts("** Running with a low process priority");
  1817. printf("CL = %s, _CL_ = %s\n", CL, _CL_);
  1818. PrintTagsList(TagsList);
  1819. PrintTagsList(DirectoryTagsList);
  1820. }
  1821. if (FStatus && (GetConsoleTitle(SavedConsoleTitle, BUFFER_SIZE) == 0))
  1822. Warning("Couldn't get console title; won't be correctly restored");
  1823. }
  1824. void
  1825. PrintTagsList(
  1826. Tags* pTagsList
  1827. )
  1828. {
  1829. if (pTagsList != NULL)
  1830. {
  1831. for (Tags * tags = pTagsList; tags != NULL; tags = tags->next)
  1832. {
  1833. printf(" %s '%s'\n", tags->fInclude ? "include" : "exclude", tags->str);
  1834. }
  1835. }
  1836. else
  1837. {
  1838. printf(" None\n");
  1839. }
  1840. }
  1841. // Initialize a file list.
  1842. void
  1843. InitTestList(
  1844. TestList * pTestList
  1845. )
  1846. {
  1847. pTestList->first = pTestList->last = NULL;
  1848. }
  1849. // Free a file list.
  1850. void
  1851. FreeTestList(
  1852. TestList * pTestList
  1853. )
  1854. {
  1855. Test * pFilename, * pFree;
  1856. pFilename = pTestList->first;
  1857. while (pFilename) {
  1858. pFree = pFilename;
  1859. pFilename = pFilename->next;
  1860. FreeStringList(pFree->files);
  1861. FreeVariants(pFree->variants);
  1862. free(pFree);
  1863. }
  1864. InitTestList(pTestList);
  1865. }
  1866. // Add one file to a file list.
  1867. Test *
  1868. AddToTestList(
  1869. TestList * pTestList,
  1870. StringList * fileList
  1871. )
  1872. {
  1873. Test * pFilename;
  1874. ASSERTNR(pTestList);
  1875. pFilename = (Test *)malloc(sizeof(Test));
  1876. memset(pFilename, 0, sizeof(Test));
  1877. pFilename->files = fileList;
  1878. if (pTestList->last) {
  1879. ASSERTNR(pTestList->first);
  1880. pTestList->last->next = pFilename;
  1881. }
  1882. else {
  1883. ASSERTNR(pTestList->first == NULL);
  1884. pTestList->first = pFilename;
  1885. }
  1886. pTestList->last = pFilename;
  1887. #ifndef NODEBUG
  1888. if (FDebug)
  1889. printf("Added %s\n", pFilename->name);
  1890. #endif
  1891. return pFilename;
  1892. }
  1893. // Add one file to a file list.
  1894. Test *
  1895. AddToTestList(
  1896. TestList * pTestList,
  1897. char * name
  1898. )
  1899. {
  1900. Test * pTest = AddToTestList(pTestList, (StringList *)NULL);
  1901. pTest->name = name;
  1902. return pTest;
  1903. }
  1904. // Add one dir to the dir list.
  1905. Test *
  1906. AddDir(
  1907. TestList * pTestList,
  1908. char *name
  1909. )
  1910. {
  1911. return AddToTestList(pTestList, name);
  1912. }
  1913. // Add the current directory to the directory list.
  1914. void
  1915. AddCurrentDir(
  1916. void
  1917. )
  1918. {
  1919. char *dir;
  1920. char tempBuf[BUFFER_SIZE];
  1921. if (!GetCurrentDirectory(BUFFER_SIZE, tempBuf))
  1922. Fatal("GetCurrentDirectory couldn't live up to its name");
  1923. // If REGRESS is not a prefix, emit a warning.
  1924. if (_strnicmp(tempBuf, REGRESS, strlen(REGRESS))) {
  1925. Warning("Current directory '%s' is not in the '%s' tree",
  1926. tempBuf, REGRESS);
  1927. AddDir(&DirList, _strdup(tempBuf));
  1928. }
  1929. else {
  1930. dir = tempBuf + strlen(REGRESS);
  1931. if (!IS_PATH_CHAR(*dir)) {
  1932. Fatal("Current directory '%s' is not a subdirectory of '%s'",
  1933. tempBuf, REGRESS);
  1934. }
  1935. else {
  1936. AddDir(&DirList, _strdup(dir + 1));
  1937. }
  1938. }
  1939. }
  1940. // Add a list of user-specified directories.
  1941. void
  1942. AddUserDirs(
  1943. TestList * pTestList,
  1944. char *s
  1945. )
  1946. {
  1947. char *context = NULL;
  1948. s = strtok_s(s, XML_DELIM, &context);
  1949. while (s) {
  1950. AddDir(pTestList, s);
  1951. s = strtok_s(NULL, XML_DELIM, &context);
  1952. }
  1953. }
  1954. #ifndef NODEBUG
  1955. void
  1956. PrintStringList
  1957. (
  1958. StringList *pList
  1959. )
  1960. {
  1961. for (StringList *cur = pList; cur != NULL; cur = cur->next) {
  1962. printf("\t%s\n", cur->string);
  1963. }
  1964. }
  1965. void
  1966. PrintTestInfo
  1967. (
  1968. TestInfo *pTestInfo
  1969. )
  1970. {
  1971. ConstStringList * GetNameDataPairs(Xml::Node * node);
  1972. for(int i=0;i < _TIK_COUNT; i++) {
  1973. if ((i == TIK_ENV) && pTestInfo->data[TIK_ENV]) {
  1974. auto pStringList = GetNameDataPairs((Xml::Node*)pTestInfo->data[TIK_ENV]);
  1975. if (pStringList) {
  1976. for(; pStringList != NULL; pStringList = pStringList->next->next) {
  1977. ASSERT(pStringList->next);
  1978. if (pStringList->next->string[0]=='%') {
  1979. char tmpBuf[BUFFER_SIZE];
  1980. strncpy_s(tmpBuf, pStringList->next->string+1, strlen(pStringList->next->string)-2);
  1981. tmpBuf[strlen(pStringList->next->string)-2]=0;
  1982. if (getenv_unsafe(tmpBuf)==NULL) {
  1983. char msgBuf[BUFFER_SIZE];
  1984. sprintf_s(msgBuf, "%s environment variable used is not set\n", tmpBuf);
  1985. Fatal(msgBuf);
  1986. } else {
  1987. printf("\t%s=%s\n",pStringList->string, getenv_unsafe(tmpBuf));
  1988. }
  1989. } else {
  1990. printf("\t%s=%s\n",pStringList->string, pStringList->next->string);
  1991. }
  1992. }
  1993. }
  1994. }else if (pTestInfo->data[i]) {
  1995. printf("\t%s\n", pTestInfo->data[i]);
  1996. }
  1997. }
  1998. }
  1999. // Display the file list.
  2000. void
  2001. DumpTestList
  2002. (
  2003. TestList * pTestList
  2004. )
  2005. {
  2006. for (Test * pTest = pTestList->first; pTest != NULL; pTest = pTest->next)
  2007. {
  2008. printf("Files:\n");
  2009. PrintStringList(pTest->files);
  2010. printf("\n");
  2011. if (pTest->fullPath)
  2012. printf("fullpath (%s):\n", pTest->fullPath);
  2013. for(ConditionNodeList * conditionNodeList = pTest->conditionNodeList;
  2014. conditionNodeList != NULL; conditionNodeList=conditionNodeList->next)
  2015. {
  2016. printf("Condition nodes\n");
  2017. conditionNodeList->node->Dump();
  2018. }
  2019. printf("Default testinfo\n");
  2020. PrintTestInfo(&pTest->defaultTestInfo);
  2021. int i=0;
  2022. for(TestVariant * variants=pTest->variants; variants!=nullptr; variants=variants->next) {
  2023. printf("variant %d\n", i++);
  2024. PrintTestInfo(&variants->testInfo);
  2025. printf("opt flag %s\n", variants->optFlags);
  2026. }
  2027. printf("\n\n");
  2028. }
  2029. }
  2030. #endif
  2031. void
  2032. PadSpecialChars
  2033. (
  2034. char * strOut,
  2035. const char * strIn
  2036. )
  2037. {
  2038. int i = 0;
  2039. while (*strIn) {
  2040. strOut[i++] = *strIn++;
  2041. if (strOut[i-1] == '\\')
  2042. strOut[i++] = '\\';
  2043. }
  2044. strOut[i] = '\0';
  2045. }
  2046. // given an xml node, returns the name-data StringList pairs for all children
  2047. ConstStringList * GetNameDataPairs
  2048. (
  2049. Xml::Node * node
  2050. )
  2051. {
  2052. ASSERT(node->ChildList != NULL);
  2053. ConstStringList *pStringList = NULL;
  2054. for (Xml::Node *ChildNode = node->ChildList; ChildNode != NULL; ChildNode = ChildNode->Next) {
  2055. pStringList = AddToStringList(pStringList, ChildNode->Name);
  2056. pStringList = AddToStringList(pStringList, ChildNode->Data);
  2057. }
  2058. return pStringList;
  2059. }
  2060. // create the file env.lst
  2061. void
  2062. WriteEnvLst
  2063. (
  2064. Test * pDir, TestList * pTestList
  2065. )
  2066. {
  2067. char comments[BUFFER_SIZE];
  2068. char envlst[BUFFER_SIZE];
  2069. char noSpecialCharsBuf[BUFFER_SIZE];
  2070. ASSERT(pDir->fullPath);
  2071. sprintf_s(envlst, "%s%s", pDir->fullPath, "\\" DEFAULT_ENVLST_CFG);
  2072. DeleteFileIfFound(envlst);
  2073. COutputBuffer *LstFilesOut = new COutputBuffer(envlst, FSyncImmediate ? false : true);
  2074. ASSERT(LstFilesOut);
  2075. for (Test * pTest = pTestList->first; pTest != NULL; pTest = pTest->next)
  2076. {
  2077. for(TestVariant * variants=pTest->variants; variants!=NULL; variants=variants->next) {
  2078. // print the tags first
  2079. if (variants->testInfo.data[TIK_TAGS]) {
  2080. LstFilesOut->Add("%s\t", variants->testInfo.data[TIK_TAGS]);
  2081. } else if (pTest->defaultTestInfo.data[TIK_TAGS]){
  2082. LstFilesOut->Add("%s\t", pTest->defaultTestInfo.data[TIK_TAGS]);
  2083. } else {
  2084. LstFilesOut->Add("\t");
  2085. }
  2086. LstFilesOut->Add("TESTNAME=%s", pTest->name);
  2087. strcpy_s(comments, pTest->name);
  2088. PadSpecialChars(noSpecialCharsBuf, EXTRA_CC_FLAGS);
  2089. if (noSpecialCharsBuf[0] != '\0') {
  2090. LstFilesOut->Add(" EXTRA_CC_FLAGS=\"%s\"", noSpecialCharsBuf);
  2091. }
  2092. LstFilesOut->Add(" REGR_CL=%s", REGR_CL);
  2093. LstFilesOut->Add(" LINKER=%s", LINKER);
  2094. PadSpecialChars(noSpecialCharsBuf, LINKFLAGS);
  2095. if (noSpecialCharsBuf[0] != '\0') {
  2096. LstFilesOut->Add(" LINKFLAGS=\"%s\"", noSpecialCharsBuf);
  2097. }
  2098. if (pTest->files) {
  2099. LstFilesOut->Add(" FILES=\"");
  2100. StringList* pStringList = pTest->files;
  2101. for(;pStringList != NULL;pStringList=pStringList->next) {
  2102. LstFilesOut->Add("%s ", pStringList->string);
  2103. }
  2104. LstFilesOut->Add("\"");
  2105. }
  2106. // how we translate testinfo into env.lst specific stuffs
  2107. const char * const TestInfoEnvLstFmt[] =
  2108. {
  2109. " TESTFILE=\"%s\"",
  2110. " BASELINE=\"%s\"",
  2111. " CFLAGS=\"%s\"",
  2112. " LFLAGS=\"%s\"",
  2113. NULL,
  2114. NULL,
  2115. NULL,
  2116. NULL,
  2117. NULL,
  2118. NULL,
  2119. NULL
  2120. };
  2121. static_assert((sizeof(TestInfoEnvLstFmt) / sizeof(TestInfoEnvLstFmt[0])) == TestInfoKind::_TIK_COUNT, "Fix the buffer size");
  2122. // print the other TIK_*
  2123. for(int i=0;i < _TIK_COUNT; i++) {
  2124. if (variants->testInfo.data[i] && TestInfoEnvLstFmt[i]) {
  2125. LstFilesOut->Add(TestInfoEnvLstFmt[i], variants->testInfo.data[i]);
  2126. } else if (pTest->defaultTestInfo.data[TIK_RL_DIRECTIVES]) {
  2127. // we only handle NoGPF directive, passFo and NoAsm not used
  2128. if (SuppressNoGPF(pTest)) {
  2129. LstFilesOut->Add(" NOGPF=1");
  2130. }
  2131. }
  2132. }
  2133. LstFilesOut->Add(" optFlags=\"%s\"", variants->optFlags);
  2134. strcat_s(comments, " "); strcat_s(comments, variants->optFlags);
  2135. // print the env settings
  2136. if (variants->testInfo.data[TIK_ENV]) {
  2137. auto pStringList = GetNameDataPairs((Xml::Node*)variants->testInfo.data[TIK_ENV]);
  2138. if (pStringList) {
  2139. // assuming even number of elements
  2140. for(; pStringList != NULL; pStringList = pStringList->next->next) {
  2141. ASSERT(pStringList->next);
  2142. if (pStringList->next->string[0]=='%') {
  2143. // grab the env variable specified in the pStringList->next->string
  2144. char tmpBuf[BUFFER_SIZE];
  2145. strncpy_s(tmpBuf, pStringList->next->string+1, strlen(pStringList->next->string)-2);
  2146. tmpBuf[strlen(pStringList->next->string)-2]=0;
  2147. if (getenv_unsafe(tmpBuf)==NULL) {
  2148. char msgBuf[BUFFER_SIZE];
  2149. sprintf_s(msgBuf, "%s environment variable used in %s not set\n", tmpBuf, envlst);
  2150. Fatal(msgBuf);
  2151. } else {
  2152. LstFilesOut->Add(" %s=%s",pStringList->string, getenv_unsafe(tmpBuf));
  2153. sprintf_s(comments, "%s %s=%s", comments, pStringList->string, getenv_unsafe(tmpBuf));
  2154. }
  2155. } else {
  2156. LstFilesOut->Add(" %s=%s",pStringList->string, pStringList->next->string);
  2157. sprintf_s(comments, "%s %s=%s", comments, pStringList->string, pStringList->next->string);
  2158. }
  2159. }
  2160. FreeStringList(pStringList);
  2161. }
  2162. }
  2163. LstFilesOut->Add(" # %s\n", comments);
  2164. }
  2165. }
  2166. LstFilesOut->Flush();
  2167. delete LstFilesOut;
  2168. printf(" %s\n", envlst);
  2169. }
  2170. BOOL
  2171. IsRelativePath(
  2172. const char *path
  2173. )
  2174. {
  2175. char drive[MAX_PATH], dir[MAX_PATH];
  2176. _splitpath_s(path, drive, ARRAYLEN(drive), dir, ARRAYLEN(dir), NULL, 0, NULL, 0);
  2177. // Path is relative if neither drive nor absolute directory are specified.
  2178. if (!*drive && !IS_PATH_CHAR(dir[0]))
  2179. return TRUE;
  2180. return FALSE;
  2181. }
  2182. char*
  2183. MakeFullPath(const char* absFilePath, const char* relPath)
  2184. {
  2185. char drive[MAX_PATH], dir[MAX_PATH];
  2186. _splitpath_s(absFilePath, drive, ARRAYLEN(drive), dir, ARRAYLEN(dir), NULL, 0, NULL, 0);
  2187. char makepath[MAX_PATH + 1];
  2188. makepath[MAX_PATH] = '\0';
  2189. _makepath_s(makepath, drive, dir, relPath, NULL);
  2190. char fullpath[MAX_PATH + 1];
  2191. fullpath[MAX_PATH] = '\0';
  2192. if (_fullpath(fullpath, makepath, MAX_PATH) == NULL)
  2193. {
  2194. return NULL;
  2195. }
  2196. char* fullPathBuf = (char*)malloc(sizeof(fullpath));
  2197. sprintf_s(fullPathBuf, sizeof(fullpath), "%s", fullpath);
  2198. return fullPathBuf;
  2199. }
  2200. BOOL
  2201. VerifyOrCreateDir(
  2202. char *name,
  2203. BOOL fCreate
  2204. )
  2205. {
  2206. if (FTest)
  2207. {
  2208. return TRUE;
  2209. }
  2210. DWORD attrib;
  2211. attrib = GetFileAttributes(name);
  2212. // Already exists?
  2213. if (attrib != INVALID_FILE_ATTRIBUTES) {
  2214. // Make sure it's a directory.
  2215. if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) {
  2216. LogError("%s exists but is not a subdirectory", name);
  2217. return FALSE;
  2218. }
  2219. }
  2220. // Are we allowed to create.
  2221. else if (!fCreate) {
  2222. LogError("%s doesn't exist", name);
  2223. return FALSE;
  2224. }
  2225. // Try to create it.
  2226. else if (!CreateDirectory(name, NULL)) {
  2227. LogError("Unable to create %s", name);
  2228. return FALSE;
  2229. }
  2230. else {
  2231. Warning("Created '%s' directory", name);
  2232. }
  2233. return TRUE;
  2234. }
  2235. // Create MASTER_DIR and DIFF_DIR if non-existent.
  2236. BOOL
  2237. CreateAsmDirs(
  2238. char* root,
  2239. BOOL fBaseline
  2240. )
  2241. {
  2242. char path[_MAX_PATH];
  2243. ASSERTNR(!IsRelativePath(root));
  2244. sprintf_s(path, "%s\\%s", root, MASTER_DIR);
  2245. if (!VerifyOrCreateDir(path, fBaseline))
  2246. return FALSE;
  2247. if (FMoveDiffs && FDiff) {
  2248. sprintf_s(path, "%s\\%s", root, DIFF_DIR);
  2249. if (!VerifyOrCreateDir(path, TRUE))
  2250. return FALSE;
  2251. }
  2252. return TRUE;
  2253. }
  2254. void
  2255. PrintDirs(
  2256. void
  2257. )
  2258. {
  2259. Test * pDir;
  2260. printf("Regression directories:");
  2261. for (pDir = DirList.first; pDir; pDir = pDir->next) {
  2262. printf(" %s", pDir->name);
  2263. }
  2264. printf("\n\n");
  2265. if (ExcludeDirList.first != NULL) {
  2266. printf("Regression exclude directories:");
  2267. for (pDir = ExcludeDirList.first; pDir; pDir = pDir->next) {
  2268. printf(" %s", pDir->name);
  2269. }
  2270. printf("\n\n");
  2271. }
  2272. }
  2273. char *
  2274. GetNonEmptyArg(
  2275. char *arg
  2276. )
  2277. {
  2278. if (arg && (*arg == '\0'))
  2279. return NULL;
  2280. return arg;
  2281. }
  2282. char *
  2283. ComplainIfNoArg(
  2284. char *opt,
  2285. char *arg
  2286. )
  2287. {
  2288. if ((arg == NULL) || (*arg == '\0'))
  2289. Fatal("%s requires an argument", opt);
  2290. return arg;
  2291. }
  2292. // Parse a single command line argument. Returns 1 if -args processed.
  2293. // Returns -1 if a non-switch was processed and pTestList is NULL.
  2294. int
  2295. ParseArg(
  2296. char *arg,
  2297. TestList * pTestList
  2298. )
  2299. {
  2300. char tempBuf[BUFFER_SIZE];
  2301. char *s;
  2302. switch (arg[0]) {
  2303. case '-':
  2304. case '/':
  2305. s = strchr(arg, ':');
  2306. if (s)
  2307. *s++ = '\0';
  2308. if (!_stricmp(&arg[1], "exe")) {
  2309. Mode = RM_EXE;
  2310. ExeCompiler = GetNonEmptyArg(s);
  2311. break;
  2312. }
  2313. if (!_stricmp(&arg[1], "asm")) {
  2314. Mode = RM_ASM;
  2315. ExeCompiler = GetNonEmptyArg(s);
  2316. break;
  2317. }
  2318. if (!_stricmp(&arg[1], "log")) {
  2319. LogName = ComplainIfNoArg(arg, s);
  2320. break;
  2321. }
  2322. if (!_stricmp(&arg[1], "full")) {
  2323. FullLogName = ComplainIfNoArg(arg, s);
  2324. break;
  2325. }
  2326. if (!_stricmp(&arg[1], "results")) {
  2327. ResultsLogName = ComplainIfNoArg(arg, s);
  2328. break;
  2329. }
  2330. // For backward-compatibility, support -tee
  2331. if (!_stricmp(&arg[1], "tee")) {
  2332. Warning("-tee is deprecated; use -full instead");
  2333. FullLogName = ComplainIfNoArg(arg, s);
  2334. break;
  2335. }
  2336. if (!_stricmp(&arg[1], "all")) {
  2337. FUserSpecifiedDirs = FALSE;
  2338. break;
  2339. }
  2340. if (!_stricmp(&arg[1], "dcfg")) {
  2341. DCFGfile = ComplainIfNoArg(arg, s);
  2342. break;
  2343. }
  2344. if (!_stricmp(&arg[1], "cfg")) {
  2345. CFGfile = ComplainIfNoArg(arg, s);
  2346. break;
  2347. }
  2348. if (!_stricmp(&arg[1], "genlst")) {
  2349. FGenLst = TRUE;
  2350. Mode = RM_EXE;
  2351. break;
  2352. }
  2353. // Note: we support "-dir:" for backwards-compatibility
  2354. if (!_stricmp(&arg[1], "dir") || !_stricmp(&arg[1], "dirs")) {
  2355. AddUserDirs(&DirList, ComplainIfNoArg(arg, s));
  2356. break;
  2357. }
  2358. if (!_stricmp(&arg[1], "nodirs")) {
  2359. FExcludeDirs = TRUE;
  2360. AddUserDirs(&ExcludeDirList, ComplainIfNoArg(arg, s));
  2361. break;
  2362. }
  2363. if (!_stricmp(&arg[1], "resume")) {
  2364. ResumeDir = ComplainIfNoArg(arg, s);
  2365. FUserSpecifiedDirs = FALSE;
  2366. FAppend = TRUE;
  2367. break;
  2368. }
  2369. if (!_stricmp(&arg[1], "match")) {
  2370. MatchDir = ComplainIfNoArg(arg, s);
  2371. FUserSpecifiedDirs = FALSE;
  2372. break;
  2373. }
  2374. if (!_stricmp(&arg[1], "status")) {
  2375. // -status:- disables.
  2376. if (s && !strcmp(s, "-")) {
  2377. FStatus = FALSE;
  2378. }
  2379. else {
  2380. FStatus = TRUE;
  2381. StatusPrefix = s;
  2382. }
  2383. break;
  2384. }
  2385. if (!_stricmp(&arg[1], "statusformat")) {
  2386. s = ComplainIfNoArg(arg, s);
  2387. StatusFormat = _strdup(s);
  2388. break;
  2389. }
  2390. if (!_stricmp(&arg[1], "rlfe")) {
  2391. FRLFE = TRUE;
  2392. if (s)
  2393. RLFEOpts = s;
  2394. break;
  2395. }
  2396. if (!_stricmp(&arg[1], "verbose")) {
  2397. FVerbose = TRUE;
  2398. break;
  2399. }
  2400. if (!_stricmp(&arg[1], "quiet")) {
  2401. FQuiet = TRUE;
  2402. break;
  2403. }
  2404. if (!_stricmp(&arg[1], "summary") ||
  2405. !_stricmp(&arg[1], "nodirname") ||
  2406. !_stricmp(&arg[1], "movediffs"))
  2407. {
  2408. Warning("%s is deprecated; it is now the default\n", arg);
  2409. break;
  2410. }
  2411. if (!_stricmp(&arg[1], "nosummary")) {
  2412. FSummary = FNoDirName = FALSE;
  2413. break;
  2414. }
  2415. if (!_stricmp(&arg[1], "allowpopup")) {
  2416. FNogpfnt = FALSE;
  2417. break;
  2418. }
  2419. if (!_stricmp(&arg[1], "append")) {
  2420. FAppend = TRUE;
  2421. break;
  2422. }
  2423. if (!_stricmp(&arg[1], "appendtestnametoextraccflags")) {
  2424. FAppendTestNameToExtraCCFlags = TRUE;
  2425. break;
  2426. }
  2427. if (!_stricmp(&arg[1], "singlethreadperdir")) {
  2428. FSingleThreadPerDir = TRUE;
  2429. break;
  2430. }
  2431. if (!_stricmp(&arg[1], "dirname")) {
  2432. FNoDirName = FALSE;
  2433. break;
  2434. }
  2435. if (!_stricmp(&arg[1], "nomovediffs")) {
  2436. FNoMoveDiffsSwitch = TRUE;
  2437. break;
  2438. }
  2439. if (!_stricmp(&arg[1], "nowarn")) {
  2440. FNoWarn = TRUE;
  2441. break;
  2442. }
  2443. if (!_stricmp(&arg[1], "low")) {
  2444. FLow = TRUE;
  2445. break;
  2446. }
  2447. if (!_stricmp(&arg[1], "test")) {
  2448. FTest = TRUE;
  2449. break;
  2450. }
  2451. if (!_stricmp(&arg[1], "exeflags")) {
  2452. EXEC_TESTS_FLAGS = ComplainIfNoArg(arg, s);
  2453. break;
  2454. }
  2455. if (!_stricmp(&arg[1], "target")) {
  2456. TARGET_MACHINE = ComplainIfNoArg(arg, s);
  2457. // Some test scripts use TARGET_MACHINE, so put it into the
  2458. // environment.
  2459. sprintf_s(tempBuf, "TARGET_MACHINE=%s", TARGET_MACHINE);
  2460. if (_putenv(tempBuf))
  2461. Fatal("Couldn't set TARGET_MACHINE");
  2462. break;
  2463. }
  2464. if (!_stricmp(&arg[1], "os")) {
  2465. TARGET_OS_NAME = ComplainIfNoArg(arg, s);
  2466. break;
  2467. }
  2468. if (!_stricmp(&arg[1], "rltarget")) {
  2469. RL_MACHINE = ComplainIfNoArg(arg, s);
  2470. break;
  2471. }
  2472. if (!_stricmp(&arg[1], "threads")) {
  2473. char* temp;
  2474. temp = ComplainIfNoArg(arg, s);
  2475. NumberOfThreads = atoi(temp);
  2476. if (NumberOfThreads == 0 || NumberOfThreads > MAX_ALLOWED_THREADS) {
  2477. Fatal("Illegal # of threads; must be between 1 and %d", MAX_ALLOWED_THREADS);
  2478. }
  2479. break;
  2480. }
  2481. if (!_stricmp(&arg[1], "regress")) {
  2482. REGRESS = ComplainIfNoArg(arg, s);
  2483. // Some test scripts use REGRESS, so put it into the
  2484. // environment.
  2485. sprintf_s(tempBuf, "REGRESS=%s", REGRESS);
  2486. if (_putenv(tempBuf))
  2487. Fatal("Couldn't set REGRESS");
  2488. break;
  2489. }
  2490. if (!_stricmp(&arg[1], "sync")) {
  2491. s = ComplainIfNoArg(arg, s);
  2492. if (!_stricmp(s, "immediate"))
  2493. FSyncImmediate = TRUE;
  2494. else if (!_stricmp(s, "variation"))
  2495. FSyncVariation = TRUE;
  2496. else if (!_stricmp(s, "test"))
  2497. FSyncTest = TRUE;
  2498. else if (!_stricmp(s, "dir"))
  2499. FSyncDir = TRUE;
  2500. else
  2501. Fatal("Unknown -sync option");
  2502. break;
  2503. }
  2504. if (!_stricmp(&arg[1], "binary")) {
  2505. s = ComplainIfNoArg(arg, s);
  2506. JCBinary = _strdup(s);
  2507. break;
  2508. }
  2509. if (!_stricmp(&arg[1], "nothreadid")) {
  2510. FNoThreadId = TRUE;
  2511. break;
  2512. }
  2513. // We support "-baseline", but we only document "-base". Maybe we
  2514. // should deprecate it and emit a warning message...
  2515. if (!_stricmp(&arg[1], "baseline") || !_stricmp(&arg[1], "base")) {
  2516. FBaseline = TRUE;
  2517. BaseCompiler = GetNonEmptyArg(s);
  2518. break;
  2519. }
  2520. if (!_stricmp(&arg[1], "rebase")) {
  2521. FRebase = TRUE;
  2522. break;
  2523. }
  2524. if (!_stricmp(&arg[1], "diff")) {
  2525. DiffCompiler = GetNonEmptyArg(s);
  2526. FDiff = TRUE;
  2527. break;
  2528. }
  2529. if (!_stricmp(&arg[1], "rellog")) {
  2530. FRelativeLogPath = TRUE;
  2531. break;
  2532. }
  2533. if (!_stricmp(&arg[1], "nodelete")) {
  2534. FNoDelete = TRUE;
  2535. break;
  2536. }
  2537. if (!_stricmp(&arg[1], "copyonfail")) {
  2538. FCopyOnFail = TRUE;
  2539. break;
  2540. }
  2541. if (!_stricmp(&arg[1], "time")) {
  2542. s = ComplainIfNoArg(arg, s);
  2543. if (!_stricmp(s, "variation"))
  2544. Timing |= TIME_VARIATION;
  2545. else if (!_stricmp(s, "test"))
  2546. Timing |= TIME_TEST;
  2547. else if (!_stricmp(s, "dir"))
  2548. Timing |= TIME_DIR;
  2549. else if (!_stricmp(s, "all"))
  2550. Timing |= TIME_ALL;
  2551. else
  2552. Fatal("Unknown -time option");
  2553. break;
  2554. }
  2555. if ((!_stricmp(&arg[1], "nottags")) || (!_stricmp(&arg[1], "tags"))) {
  2556. s = ComplainIfNoArg(arg, s);
  2557. AddTagToTagsList(&TagsList, &TagsLast, s, strcmp(&arg[1], "tags") == 0);
  2558. break;
  2559. }
  2560. if ((!_stricmp(&arg[1], "dirnottags")) || (!_stricmp(&arg[1], "dirtags"))) {
  2561. s = ComplainIfNoArg(arg, s);
  2562. AddTagToTagsList(&DirectoryTagsList, &DirectoryTagsLast, s, strcmp(&arg[1], "dirtags") == 0);
  2563. break;
  2564. }
  2565. #ifndef NODEBUG
  2566. if (!_stricmp(&arg[1], "debug")) {
  2567. FDebug = FVerbose = TRUE;
  2568. break;
  2569. }
  2570. if (!_stricmp(&arg[1], "syncdirs")) {
  2571. FSyncEnumDirs = TRUE;
  2572. break;
  2573. }
  2574. #endif
  2575. switch (arg[1]) {
  2576. case '?':
  2577. case 'h':
  2578. case 'H':
  2579. switch (arg[2]) {
  2580. case '\0':
  2581. Usage(FALSE);
  2582. exit(0);
  2583. case 'x':
  2584. Usage(TRUE);
  2585. exit(0);
  2586. }
  2587. // FALL-THROUGH
  2588. default:
  2589. Fatal("Unrecognized option: %s", arg);
  2590. }
  2591. default:
  2592. if (pTestList == NULL)
  2593. return -1;
  2594. FUserSpecifiedFiles = TRUE;
  2595. AddToTestList(pTestList, arg);
  2596. }
  2597. return 0;
  2598. }
  2599. void
  2600. AddTagToTagsList(
  2601. Tags** pTagsList,
  2602. Tags** pTagsLast,
  2603. const char* str,
  2604. BOOL fInclude
  2605. )
  2606. {
  2607. if (pTagsList == NULL || pTagsLast == NULL)
  2608. {
  2609. return;
  2610. }
  2611. Tags* tags = new Tags;
  2612. tags->str = str;
  2613. tags->fInclude = fInclude;
  2614. tags->next = NULL;
  2615. if (*pTagsLast)
  2616. {
  2617. (*pTagsLast)->next = tags;
  2618. }
  2619. else
  2620. {
  2621. (*pTagsList) = tags;
  2622. }
  2623. (*pTagsLast) = tags;
  2624. }
  2625. // Determines by tags if we should include a given test.
  2626. //
  2627. // Priority:
  2628. // 1. -nottags. Check the full tags list. If we have any exclude tag, reject the test.
  2629. // 2. -tags. If #1 didn't reject the test, we only accept the test if
  2630. // a. There is no include tag,
  2631. // b. Or we matched an include tag, or "mustMatchIncludeTag" is false.
  2632. //
  2633. bool
  2634. ShouldIncludeTest(
  2635. Tags* pTagsList,
  2636. TestInfo* testInfo,
  2637. bool mustMatchIncludeTag = true // false when matching "-tags" on a folder. (The folder may contain tests matching the tags, although itself doesn't.)
  2638. )
  2639. {
  2640. // Automatically append tag "html" to any html tests
  2641. bool isHtmlTest = false;
  2642. if (testInfo->data[TIK_FILES])
  2643. {
  2644. const char* ext = GetFilenameExt(testInfo->data[TIK_FILES]);
  2645. isHtmlTest = _stricmp(ext, ".html") == 0 || _stricmp(ext, ".htm") == 0;
  2646. }
  2647. bool hasIncludeTag = false; // if we have "-tags:" filter
  2648. bool matchedIncludeTag = !mustMatchIncludeTag; // if the test has matched an include tag
  2649. for (Tags* tags = pTagsList; tags != NULL; tags = tags->next)
  2650. {
  2651. if (matchedIncludeTag && tags->fInclude)
  2652. {
  2653. continue; // Already matched one include tag, skip further include tags. Continue to check if we have any exclude tag.
  2654. }
  2655. bool hasTag = HasInfoList(testInfo->data[TIK_TAGS], XML_DELIM, tags->str, XML_DELIM, false)
  2656. || (isHtmlTest && HasInfo(tags->str, XML_DELIM, "html"));
  2657. if (hasTag && !tags->fInclude)
  2658. {
  2659. return false; // #1: Reject, we have an exclude tag.
  2660. }
  2661. if (tags->fInclude)
  2662. {
  2663. hasIncludeTag = true;
  2664. matchedIncludeTag |= hasTag;
  2665. }
  2666. }
  2667. return !hasIncludeTag || matchedIncludeTag;
  2668. }
  2669. void
  2670. ParseEnvVar(
  2671. const char *envVar
  2672. )
  2673. {
  2674. char * s;
  2675. char * context;
  2676. s = getenv_unsafe(envVar);
  2677. if (s == NULL)
  2678. return;
  2679. s = _strdup(s);
  2680. s = strtok_s(s, " \"", &context);
  2681. while (s) {
  2682. switch (ParseArg(s, NULL)) {
  2683. case 1:
  2684. Fatal("-args may not appear in %s environment variable",
  2685. envVar);
  2686. case -1:
  2687. Fatal("Only switches may appear in %s environment variable",
  2688. envVar);
  2689. }
  2690. s = strtok_s(NULL, " \"", &context);
  2691. }
  2692. }
  2693. // Parse the command line and environment variable.
  2694. void
  2695. ParseCommandLine(
  2696. int argc,
  2697. char *argv[],
  2698. TestList * pTestList
  2699. )
  2700. {
  2701. char *s;
  2702. int i;
  2703. char tempBuf[BUFFER_SIZE];
  2704. ProgramName = argv[0];
  2705. ParseEnvVar(RL_PRE_ENV_VAR);
  2706. for (i = 1; i < argc; i++) {
  2707. ParseArg(argv[i], pTestList);
  2708. }
  2709. ParseEnvVar(RL_POST_ENV_VAR);
  2710. // Get the REGRESS environment variable.
  2711. if (REGRESS == NULL)
  2712. REGRESS = getenv_unsafe("REGRESS");
  2713. if (REGRESS == NULL)
  2714. Fatal("REGRESS environment variable not set");
  2715. // Use "rl.log" as the default log file, and rl.full.log as the default
  2716. // full log file. We make sure the log file is a full path. If the user
  2717. // specified "-all", then the logs go in %REGRESS%\logs. Otherwise, they
  2718. // go in the current directory.
  2719. if (LogName == NULL) {
  2720. // The user didn't specify a log filename, so create one.
  2721. if (!FUserSpecifiedDirs || (DirList.first != NULL)) {
  2722. strcpy_s(tempBuf, REGRESS);
  2723. strcat_s(tempBuf, "\\logs\\");
  2724. strcat_s(tempBuf, DEFAULT_LOG_FILE);
  2725. LogName = _strdup(tempBuf);
  2726. } else {
  2727. LogName = DEFAULT_LOG_FILE;
  2728. }
  2729. }
  2730. if (FullLogName == NULL) {
  2731. // The user didn't specify a full log filename, so create one.
  2732. if (!FUserSpecifiedDirs || (DirList.first != NULL)) {
  2733. strcpy_s(tempBuf, REGRESS);
  2734. strcat_s(tempBuf, "\\logs\\");
  2735. strcat_s(tempBuf, DEFAULT_FULL_LOG_FILE);
  2736. FullLogName = _strdup(tempBuf);
  2737. } else {
  2738. FullLogName = DEFAULT_FULL_LOG_FILE;
  2739. }
  2740. }
  2741. if (ResultsLogName == NULL) {
  2742. // The user didn't specify a results log filename, so create one.
  2743. if (!FUserSpecifiedDirs || (DirList.first != NULL)) {
  2744. strcpy_s(tempBuf, REGRESS);
  2745. strcat_s(tempBuf, "\\logs\\");
  2746. strcat_s(tempBuf, DEFAULT_RESULTS_LOG_FILE);
  2747. ResultsLogName = _strdup(tempBuf);
  2748. } else {
  2749. ResultsLogName = DEFAULT_RESULTS_LOG_FILE;
  2750. }
  2751. }
  2752. // If the files already exist, then delete them. Otherwise, we'll simply
  2753. // keep appending to them, which is not usually desired.
  2754. if (!FAppend) {
  2755. DeleteFileIfFound(LogName);
  2756. DeleteFileIfFound(FullLogName);
  2757. DeleteFileIfFound(ResultsLogName);
  2758. }
  2759. // Now we should have a log name, so regenerate the log output objects
  2760. delete ThreadOut; // flush what we've got...
  2761. ThreadOut = new COutputBuffer(FQuiet ? (FILE*)NULL : stdout, FSyncImmediate ? false : true);
  2762. ThreadLog = new COutputBuffer(LogName, FSyncImmediate ? false : true);
  2763. ThreadFull = new COutputBuffer(FullLogName, FSyncImmediate ? false : true);
  2764. ThreadRes = new COutputBuffer(ResultsLogName, FSyncImmediate ? false : true);
  2765. // Check for missing/conflicting items.
  2766. if (!FRelativeLogPath
  2767. && IsRelativePath(LogName)
  2768. && (!FUserSpecifiedDirs || (DirList.first != NULL)))
  2769. {
  2770. Fatal("Log file '%s' specifies a relative path name\n"
  2771. "If this was intended, add -rellog to the command line",
  2772. LogName);
  2773. }
  2774. if (!FRelativeLogPath
  2775. && IsRelativePath(FullLogName)
  2776. && (!FUserSpecifiedDirs || (DirList.first != NULL)))
  2777. {
  2778. Fatal("Log file '%s' specifies a relative path name\n"
  2779. "If this was intended, add -rellog to the command line",
  2780. FullLogName);
  2781. }
  2782. if (!FUserSpecifiedDirs && (DirList.first != NULL))
  2783. Fatal("Specify all directories or explicit directories, not both");
  2784. if (FUserSpecifiedFiles && (DirList.first != NULL))
  2785. Fatal("Specify either a directory or files, not both");
  2786. if (ResumeDir && (DirList.first != NULL))
  2787. Fatal("Specify explicit directories or a resume point, not both");
  2788. if (MatchDir && (DirList.first != NULL))
  2789. Fatal("Specify explicit directories or a matching dir, not both");
  2790. if ((ResumeDir != NULL) && (MatchDir != NULL))
  2791. Fatal("Specify resume point or a matching dir, not both");
  2792. if (FBaseline) {
  2793. if (Mode != RM_ASM)
  2794. Fatal("-base only supported for asm tests");
  2795. if (FDiff) {
  2796. if ((BaseCompiler == NULL) || (DiffCompiler == NULL))
  2797. Fatal("Must specify compilers for both -base and -diff");
  2798. }
  2799. }
  2800. else if (FDiff) {
  2801. if (Mode != RM_ASM)
  2802. Fatal("-diff only supported for asm tests");
  2803. }
  2804. else if (Mode == RM_ASM) {
  2805. FDiff = TRUE;
  2806. }
  2807. if (FNoMoveDiffsSwitch && (Mode == RM_EXE))
  2808. Fatal("-nomovediffs and -exe are incompatible options");
  2809. if (FNoMoveDiffsSwitch && !FDiff)
  2810. Fatal("-nomovediffs requires -diff");
  2811. FBaseDiff = FBaseline && FDiff;
  2812. FMoveDiffs = !FNoMoveDiffsSwitch;
  2813. ASSERTNR((Mode != RM_ASM) || FBaseline || FDiff);
  2814. ASSERTNR(FBaseline || !BaseCompiler);
  2815. ASSERTNR(FDiff || !DiffCompiler);
  2816. ASSERTNR(!FBaseDiff || BaseCompiler);
  2817. ASSERTNR(!FBaseDiff || DiffCompiler);
  2818. // Now that we have parsed a valid command line, get the environment
  2819. // settings.
  2820. GetEnvironment();
  2821. // Prepend target-specific nottags, if any.
  2822. if (TargetInfo[TargetMachine].NotTags != NULL)
  2823. {
  2824. AddTagToTagsList(&TagsList, &TagsLast, _strdup(TargetInfo[TargetMachine].NotTags), false);
  2825. }
  2826. // -nodelete can only be used with EXE when one set of test options is
  2827. // specified.
  2828. if (FNoDelete) {
  2829. if (Mode != RM_EXE)
  2830. Fatal("-nodelete may only be used with -exe");
  2831. if (Mode == RM_EXE)
  2832. {
  2833. int numTestOptions = 0;
  2834. const char * env = EXEC_TESTS_FLAGS;
  2835. while (env) {
  2836. env = strchr(env, ';');
  2837. if (env)
  2838. ++env;
  2839. numTestOptions++;
  2840. }
  2841. if (numTestOptions != 1)
  2842. Fatal("-nodelete only allows one option in EXEC_TESTS_FLAGS");
  2843. }
  2844. }
  2845. // Generate unspecified options.
  2846. if (StatusPrefix == NULL) {
  2847. s = tempBuf + sprintf_s(tempBuf, "%s [%s",
  2848. Mode == RM_ASM
  2849. ? FBaseDiff
  2850. ? "Base/Diff"
  2851. : FBaseline
  2852. ? "Baselines"
  2853. : "Diffs"
  2854. : "Exec",
  2855. TargetInfo[TargetMachine].name);
  2856. if (RLMachine != TargetMachine)
  2857. s += sprintf_s(s, REMAININGARRAYLEN(tempBuf, s), ":%s", TargetInfo[RLMachine].name);
  2858. sprintf_s(s, REMAININGARRAYLEN(tempBuf, s), "]");
  2859. }
  2860. else {
  2861. strcpy_s(tempBuf, StatusPrefix);
  2862. }
  2863. StatusPrefix = _strdup(tempBuf);
  2864. if (StatusFormat == NULL) {
  2865. if (FDiff)
  2866. StatusFormat = "%d diffs, %f failures, %t/%T (%p%%)";
  2867. else
  2868. StatusFormat = "%f failures, %t/%T (%p%%)";
  2869. }
  2870. s = tempBuf + strlen(tempBuf);
  2871. *s++ = ' ';
  2872. strcpy_s(s, REMAININGARRAYLEN(tempBuf, s), StatusFormat);
  2873. StatusFormat = _strdup(tempBuf);
  2874. if (DCFGfile == NULL) {
  2875. sprintf_s(tempBuf, "%s\\%s", REGRESS,
  2876. Mode == RM_ASM ? DEFAULT_ASM_DCFG : DEFAULT_EXE_DCFG);
  2877. DCFGfile = _strdup(tempBuf);
  2878. }
  2879. if (CFGfile == NULL) {
  2880. CFGfile = Mode == RM_ASM
  2881. ? DEFAULT_ASM_CFG
  2882. : DEFAULT_EXE_CFG;
  2883. }
  2884. if (CMDfile == NULL) {
  2885. CMDfile = (Mode == RM_ASM)
  2886. ? DEFAULT_ASM_CMD
  2887. : DEFAULT_EXE_CMD;
  2888. }
  2889. // Warn if doing multiple dirs and not outputting directory name or
  2890. // summary info.
  2891. if (FNoDirName && !FSummary &&
  2892. (!FUserSpecifiedDirs || (DirList.first != DirList.last))) {
  2893. Warning("-nodirname without -summary will make for a hard to read log file");
  2894. }
  2895. if (FVerbose) {
  2896. printf("Perform %s regression, appending output to %s\n",
  2897. ModeNames[Mode], LogName);
  2898. }
  2899. // If no directories specified, use current directory.
  2900. if (FUserSpecifiedDirs && (DirList.first == NULL))
  2901. AddCurrentDir();
  2902. // Set process priority to LOW if requested.
  2903. if (FLow) {
  2904. SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
  2905. }
  2906. // Initialize parallel data
  2907. if (NumberOfThreads == 0) {
  2908. SYSTEM_INFO SystemInfo;
  2909. GetSystemInfo(&SystemInfo);
  2910. NumberOfThreads = SystemInfo.dwNumberOfProcessors;
  2911. }
  2912. if (FVerbose) {
  2913. printf("Using %d threads\n", NumberOfThreads);
  2914. }
  2915. // Test synchronization switches. Only one -sync variant can be specified.
  2916. // If none is specified, we use the default: FSyncVariation for
  2917. // multi-threaded operation, and FSyncImmediate for single-threaded.
  2918. if (FSyncImmediate + FSyncVariation + FSyncTest + FSyncDir == 0) {
  2919. if (NumberOfThreads == 1)
  2920. FSyncImmediate = TRUE;
  2921. else
  2922. FSyncVariation = TRUE;
  2923. }
  2924. if (FSyncImmediate + FSyncVariation + FSyncTest + FSyncDir != TRUE)
  2925. Fatal("-sync options are mutually exclusive");
  2926. if (FRLFE) {
  2927. FSyncEnumDirs = TRUE;
  2928. if (!FSyncVariation) {
  2929. printf("-rlfe requires -sync:variation (overriding your command line)\n");
  2930. FSyncImmediate = FSyncTest = FSyncDir = FALSE;
  2931. FSyncVariation = TRUE;
  2932. }
  2933. }
  2934. }
  2935. // Find a file in the file list with compileFlags corresponding to the passed
  2936. // in ones.
  2937. Test *
  2938. FindTest(
  2939. TestList * pTestList,
  2940. const char * testName,
  2941. BOOL fUserSpecified,
  2942. TestInfo * testInfo
  2943. )
  2944. {
  2945. Test * pTest;
  2946. Test * pMatch;
  2947. pTest = pTestList->first;
  2948. pMatch = NULL;
  2949. while (pTest)
  2950. {
  2951. if (_stricmp(pTest->name, testName) == 0)
  2952. {
  2953. pMatch = pTest;
  2954. // If we have a new user test, or a match on the compileFlags and
  2955. // tags, break.
  2956. if ((fUserSpecified && (pTest->files == NULL)) ||
  2957. (!mystrcmp(pTest->defaultTestInfo.data[TIK_COMPILE_FLAGS],
  2958. testInfo->data[TIK_COMPILE_FLAGS]) &&
  2959. !mystrcmp(pTest->defaultTestInfo.data[TIK_BASELINE],
  2960. testInfo->data[TIK_BASELINE]) &&
  2961. !mystrcmp(pTest->defaultTestInfo.data[TIK_TAGS],
  2962. testInfo->data[TIK_TAGS])))
  2963. {
  2964. break;
  2965. }
  2966. }
  2967. pTest = pTest->next;
  2968. }
  2969. // If we saw a match but didn't accept it and the user is specifying which
  2970. // tests to run and this is a Pogo test, explicitly add it.
  2971. if (fUserSpecified
  2972. && (Mode == RM_EXE)
  2973. && (pTest == NULL)
  2974. && (pMatch != NULL)
  2975. && HasInfo(testInfo->data[TIK_TAGS], XML_DELIM, "Pogo"))
  2976. {
  2977. StringList * dupList = NULL;
  2978. StringList * p;
  2979. for (p = pMatch->files; p != NULL; p = p->next)
  2980. {
  2981. dupList = AddToStringList(dupList, p->string);
  2982. }
  2983. pTest = AddToTestList(pTestList, dupList);
  2984. }
  2985. return pTest;
  2986. }
  2987. BOOL
  2988. IsTimeoutStringValid(const char *strTimeout) {
  2989. char *end;
  2990. _set_errno(0);
  2991. uint32 secTimeout = strtoul(strTimeout, &end, 10);
  2992. if (errno != 0 || *end != 0) {
  2993. return FALSE;
  2994. }
  2995. // Check to see if the value is too large and would cause overflow
  2996. // Do the multiplication using 64-bit unsigned math.
  2997. unsigned __int64 millisecTimeout = 1000ui64 * static_cast<unsigned __int64>(secTimeout);
  2998. // Does the result fit in 32-bits?
  2999. if (millisecTimeout >= (1ui64 << 32)) {
  3000. return FALSE;
  3001. }
  3002. return TRUE;
  3003. }
  3004. BOOL
  3005. GetTestInfoFromNode
  3006. (
  3007. const char * fileName,
  3008. Xml::Node * node,
  3009. TestInfo * testInfo
  3010. )
  3011. {
  3012. if (node == NULL)
  3013. {
  3014. return TRUE;
  3015. }
  3016. for (int i = 0; i < _TIK_COUNT; i++)
  3017. {
  3018. Xml::Node * childNode = node->GetChild(TestInfoKindName[i]);
  3019. if (childNode != NULL)
  3020. {
  3021. testInfo->hasData[i] = TRUE;
  3022. if (i == TIK_ENV)
  3023. {
  3024. ASSERT(childNode->ChildList != NULL);
  3025. testInfo->data[i] = (char*)childNode;
  3026. }
  3027. else
  3028. {
  3029. if (childNode->ChildList != NULL)
  3030. {
  3031. CFG_ERROR_EX(fileName, node->LineNumber,
  3032. "Expected data, not child list\n", NULL);
  3033. childNode->Dump();
  3034. return FALSE;
  3035. }
  3036. if (childNode->Data != NULL && childNode->Data[0] != '\0')
  3037. {
  3038. char * data = childNode->Data;
  3039. if (i == TIK_SOURCE_PATH && IsRelativePath(childNode->Data))
  3040. {
  3041. // Make sure sourcepath is not relative, if relative make it full path
  3042. data = MakeFullPath(fileName, data);
  3043. ASSERT(data != NULL);
  3044. }
  3045. testInfo->data[i] = data;
  3046. }
  3047. else
  3048. {
  3049. testInfo->data[i] = NULL;
  3050. }
  3051. if (i == TIK_TIMEOUT)
  3052. {
  3053. // Validate the timeout string now to fail early so we don't run any tests when there is an error.
  3054. if (!IsTimeoutStringValid(testInfo->data[i])) {
  3055. CFG_ERROR_EX(fileName, node->LineNumber,
  3056. "Invalid timeout specified. Cannot parse or too large.\n", NULL);
  3057. childNode->Dump();
  3058. return FALSE;
  3059. }
  3060. }
  3061. }
  3062. }
  3063. }
  3064. return TRUE;
  3065. }
  3066. BOOL
  3067. AddAsmVariants
  3068. (
  3069. Test * pTest,
  3070. TestInfo * defaultInfo,
  3071. ConditionNodeList * cnl
  3072. )
  3073. {
  3074. // Asm configurations are simple; we simply apply all the conditions to
  3075. // the variant info.
  3076. // Create a variant and inherit the default info.
  3077. TestInfo variantInfo;
  3078. memcpy(&variantInfo, defaultInfo, sizeof(TestInfo));
  3079. while (cnl != NULL)
  3080. {
  3081. ConditionNodeList * next = cnl->next;
  3082. if (!GetTestInfoFromNode(CFGfile, cnl->node, &variantInfo))
  3083. {
  3084. return FALSE;
  3085. }
  3086. delete cnl;
  3087. cnl = next;
  3088. }
  3089. ASSERTNR(pTest->variants == NULL);
  3090. TestVariant * pTestVariant = new TestVariant;
  3091. memcpy(&pTestVariant->testInfo, &variantInfo, sizeof(TestInfo));
  3092. pTest->variants = pTestVariant;
  3093. return TRUE;
  3094. }
  3095. BOOL
  3096. AddExeVariants
  3097. (
  3098. Test * pTest,
  3099. TestInfo * defaultInfo,
  3100. ConditionNodeList * cnl
  3101. )
  3102. {
  3103. // Exe configurations require more work since we have a list of optimization
  3104. // flags to deal with.
  3105. TestVariant ** ppLastVariant = &pTest->variants;
  3106. while (*ppLastVariant != NULL)
  3107. {
  3108. ppLastVariant = &(*ppLastVariant)->next;
  3109. }
  3110. const char ** optFlagsArray;
  3111. // Decide which list to use depending on the tag.
  3112. optFlagsArray = IsPogoTest(pTest)
  3113. ? PogoOptFlags
  3114. : OptFlags
  3115. ;
  3116. // For each optimization flag set, see if the conditional applies.
  3117. for (int i = 0; optFlagsArray[i] != NULL; i++)
  3118. {
  3119. // Create a variant and inherit the default info.
  3120. TestInfo variantInfo;
  3121. memcpy(&variantInfo, defaultInfo, sizeof(TestInfo));
  3122. // Check the conditions.
  3123. ConditionNodeList * cn = cnl;
  3124. while (cn != NULL)
  3125. {
  3126. Xml::Node * cflagsNode = cn->node->GetChild("compile-flags");
  3127. ASSERTNR(cflagsNode != NULL);
  3128. // Check the optimization flags, EXTRA_CC_FLAGS, CL and _CL_
  3129. // for matches.
  3130. if (HasInfoList(optFlagsArray[i], OPT_DELIM, cflagsNode->Data, XML_DELIM, true)
  3131. || HasInfoList(EXTRA_CC_FLAGS, OPT_DELIM, cflagsNode->Data, XML_DELIM, true)
  3132. || HasInfoList(CL, OPT_DELIM, cflagsNode->Data, XML_DELIM, true)
  3133. || HasInfoList(_CL_, OPT_DELIM, cflagsNode->Data, XML_DELIM, true))
  3134. {
  3135. const char * type = cn->node->GetAttributeValue("type");
  3136. if (strcmp(type, "exclude") == 0)
  3137. {
  3138. break;
  3139. }
  3140. Xml::Node * overrideNode = cn->node->GetChild("override");
  3141. if (!GetTestInfoFromNode(CFGfile, overrideNode, &variantInfo))
  3142. {
  3143. return FALSE;
  3144. }
  3145. }
  3146. cn = cn->next;
  3147. }
  3148. // If we terminated early, exclude.
  3149. if (cn != NULL)
  3150. {
  3151. continue;
  3152. }
  3153. TestVariant * pTestVariant = new TestVariant;
  3154. memcpy(&pTestVariant->testInfo, &variantInfo, sizeof(TestInfo));
  3155. pTestVariant->optFlags = optFlagsArray[i];
  3156. *ppLastVariant = pTestVariant;
  3157. ppLastVariant = &(*ppLastVariant)->next;
  3158. }
  3159. return TRUE;
  3160. }
  3161. // Parse one or more files from the file list.
  3162. BOOL
  3163. ParseFiles
  3164. (
  3165. TestList * pTestList,
  3166. const char * testName,
  3167. RLMODE cfg,
  3168. TestInfo * defaultInfo,
  3169. ConditionNodeList * cnl
  3170. )
  3171. {
  3172. Test * pTest;
  3173. // Break into list of strings.
  3174. StringList * fileList =
  3175. ParseStringList(defaultInfo->data[TIK_FILES], XML_DELIM);
  3176. defaultInfo->data[TIK_FILES] = NULL;
  3177. if (fileList == NULL)
  3178. {
  3179. if (cnl != NULL)
  3180. {
  3181. CFG_ERROR_EX(CFGfile, cnl->node->LineNumber,
  3182. "No files specified\n", NULL);
  3183. cnl->node->Dump();
  3184. }
  3185. return FALSE;
  3186. }
  3187. if (cfg == RM_DIR)
  3188. {
  3189. if (fileList->next != NULL)
  3190. {
  3191. CFG_ERROR_EX(CFGfile, cnl->node->LineNumber,
  3192. "Specify exactly one file (dir) for directory nodes\n", NULL);
  3193. cnl->node->Dump();
  3194. return FALSE;
  3195. }
  3196. }
  3197. BOOL fUserSpecified = FALSE;
  3198. if (((cfg == RM_DIR) && FUserSpecifiedDirs)
  3199. || ((cfg == RM_ASM) && FUserSpecifiedFiles)
  3200. || ((cfg == RM_EXE) && FUserSpecifiedFiles))
  3201. {
  3202. fUserSpecified = TRUE;
  3203. }
  3204. // For asm and dir, we loop over the entire file list processing each file
  3205. // individually. (Recall that dir has a single file.) For exe, we
  3206. // process all files at once.
  3207. StringList * next = fileList;
  3208. while (next != NULL)
  3209. {
  3210. fileList = next;
  3211. if (cfg == RM_EXE)
  3212. {
  3213. next = NULL;
  3214. }
  3215. else
  3216. {
  3217. next = fileList->next;
  3218. fileList->next = NULL;
  3219. testName = fileList->string;
  3220. }
  3221. if (cfg == RM_DIR)
  3222. {
  3223. pTest = FindTest(pTestList, testName, fUserSpecified, defaultInfo);
  3224. }
  3225. else
  3226. {
  3227. // Test names are unique for files, so there's no need to do a lookup.
  3228. // If this uniqueness constraint changes, be aware that the RL setup
  3229. // time would be quite long when there are lots of files given that
  3230. // "FindTest" does a linear search.
  3231. pTest = AddToTestList(pTestList, fileList);
  3232. }
  3233. // If the filename doesn't exist yet, we may want to create it.
  3234. if (pTest == NULL)
  3235. {
  3236. // If the user has specified the files to use, skip this one.
  3237. if (fUserSpecified)
  3238. {
  3239. continue;
  3240. }
  3241. pTest = AddToTestList(pTestList, fileList);
  3242. }
  3243. else
  3244. {
  3245. if (pTest->files == NULL)
  3246. {
  3247. ASSERTNR(fUserSpecified);
  3248. pTest->files = fileList;
  3249. }
  3250. }
  3251. // While this may happen multiple times for the same test, it is safe
  3252. // to do so.
  3253. memcpy(&pTest->defaultTestInfo, defaultInfo, sizeof(TestInfo));
  3254. pTest->name = testName;
  3255. if (cfg == RM_DIR)
  3256. {
  3257. if (cnl != NULL)
  3258. {
  3259. CFG_ERROR_EX(CFGfile, cnl->node->LineNumber,
  3260. "Directory node can only be conditional on target\n", NULL);
  3261. cnl->node->Dump();
  3262. return FALSE;
  3263. }
  3264. }
  3265. else if (cfg == RM_ASM)
  3266. {
  3267. if (!AddAsmVariants(pTest, defaultInfo, cnl))
  3268. {
  3269. return FALSE;
  3270. }
  3271. }
  3272. else
  3273. {
  3274. if (!AddExeVariants(pTest, defaultInfo, cnl))
  3275. {
  3276. return FALSE;
  3277. }
  3278. }
  3279. }
  3280. return TRUE;
  3281. }
  3282. // mystrcmp is a frontend to strcmp that doesn't have a problem with NULL
  3283. // parameters.
  3284. int
  3285. mystrcmp(
  3286. const char *a,
  3287. const char *b
  3288. )
  3289. {
  3290. if (a == b)
  3291. return 0;
  3292. if (a == NULL)
  3293. return -1;
  3294. if (b == NULL)
  3295. return 1;
  3296. return strcmp(a,b);
  3297. }
  3298. // mystrtok is similar to strtok_s, but takes two delimiter parameters: one for
  3299. // skipping entirely and one for skipping and terminating.
  3300. char *
  3301. mystrtok(
  3302. char *s,
  3303. const char *delim,
  3304. const char *term
  3305. )
  3306. {
  3307. static char *str = NULL;
  3308. char *ret, *lastNonDelim;
  3309. if (s)
  3310. str = s;
  3311. if (str == NULL)
  3312. return NULL;
  3313. // Skip leading delimiter (and term for first call).
  3314. while (*str &&
  3315. (strchr(delim, *str) ||
  3316. (s && strchr(term, *str)))) {
  3317. ++str;
  3318. }
  3319. // Parse non-delimiter/non-term.
  3320. ret = lastNonDelim = str;
  3321. while (*str && !strchr(term, *str)) {
  3322. if (!strchr(delim, *str))
  3323. lastNonDelim = str;
  3324. ++str;
  3325. }
  3326. // EOS?
  3327. if (!*str) {
  3328. // If we reached EOS because there are no more tokens, return NULL now.
  3329. if (ret == str)
  3330. return nullptr;
  3331. // Otherwise, set up for NULL return on next call.
  3332. str = nullptr;
  3333. }
  3334. // Skip terminator.
  3335. else {
  3336. str++;
  3337. }
  3338. // Trim trailing space.
  3339. if (!strchr(term, *lastNonDelim))
  3340. ++lastNonDelim;
  3341. *lastNonDelim = '\0';
  3342. return ret;
  3343. }
  3344. BOOL
  3345. AppliesToTarget
  3346. (
  3347. const char * fileName,
  3348. int lineNumber,
  3349. char * targetList
  3350. )
  3351. {
  3352. // Special case for target list of "*"
  3353. if (strcmp(targetList, "*") == 0)
  3354. {
  3355. return TRUE;
  3356. }
  3357. TARGET_MACHINES fileMach;
  3358. // Parse the target list looking for our target machine.
  3359. // Using mystrtok here because strtok_s doesn't appear to initialize
  3360. // its static pointer to NULL.
  3361. targetList = mystrtok(targetList, XML_DELIM, XML_DELIM);
  3362. while (targetList)
  3363. {
  3364. #ifndef NODEBUG
  3365. if (FDebug)
  3366. {
  3367. printf("\t\tparsing %s\n", targetList);
  3368. }
  3369. #endif
  3370. // Does the config specified target match our target machine?
  3371. fileMach = ParseMachine(targetList);
  3372. if (fileMach == TM_UNKNOWN)
  3373. {
  3374. CFG_WARNING_EX(fileName, lineNumber, "Specified machine '%s' is unknown", targetList);
  3375. }
  3376. else if (MatchMachine(fileMach, RLMachine))
  3377. {
  3378. return TRUE;
  3379. }
  3380. targetList = mystrtok(NULL, XML_DELIM, XML_DELIM);
  3381. }
  3382. return FALSE;
  3383. }
  3384. BOOL
  3385. AppliesToTargetOS
  3386. (
  3387. const char * fileName,
  3388. int lineNumber,
  3389. char * osList
  3390. )
  3391. {
  3392. osList = mystrtok(osList, XML_DELIM, XML_DELIM);
  3393. while (osList)
  3394. {
  3395. TARGET_OS os = ParseOS(osList);
  3396. if (os == TO_UNKNOWN)
  3397. {
  3398. CFG_WARNING_EX(fileName, lineNumber, "Specified os '%s' is unknown", osList);
  3399. }
  3400. else if (MatchOS(os, TargetOS))
  3401. {
  3402. return TRUE;
  3403. }
  3404. osList = mystrtok(NULL, XML_DELIM, XML_DELIM);
  3405. }
  3406. return FALSE;
  3407. }
  3408. BOOL
  3409. DirectoryExcluded(
  3410. char *filename
  3411. )
  3412. {
  3413. Test * pDir;
  3414. for (pDir = ExcludeDirList.first; pDir; pDir = pDir->next) {
  3415. if (!_stricmp(pDir->name, filename)) {
  3416. return TRUE;
  3417. }
  3418. }
  3419. return FALSE;
  3420. }
  3421. // Parse the configuration file and modify the file list appropriately.
  3422. PROCESS_CONFIG_STATUS
  3423. ProcessConfig
  3424. (
  3425. TestList * pTestList,
  3426. char *CfgFile,
  3427. RLMODE cfg
  3428. )
  3429. {
  3430. static int unnamedCount = 0;
  3431. const char * szOrder;
  3432. ASSERT(!IsRelativePath(CfgFile)); // must be full path
  3433. Xml::Node * topNode = Xml::ReadFile(CfgFile);
  3434. if (topNode == NULL)
  3435. {
  3436. return PCS_FILE_NOT_FOUND;
  3437. }
  3438. Xml::Node * defaultNode;
  3439. Xml::Node * conditionNode;
  3440. Xml::Node * testNode;
  3441. Xml::Node * applyNode;
  3442. ConditionNodeList * conditionNodeList = NULL;
  3443. ConditionNodeList * conditionNodeLast = NULL;
  3444. // Parser doesn't return the XML declaration node, so topNode is the RL root node.
  3445. ASSERTNR(topNode->Next == NULL);
  3446. for (testNode = topNode->ChildList;
  3447. testNode != NULL;
  3448. testNode = testNode->Next)
  3449. {
  3450. if (_stricmp(testNode->Name, "#comment") == 0)
  3451. {
  3452. continue;
  3453. }
  3454. char *testName = new char[20];
  3455. sprintf_s(testName, 20, "UnnamedTest%d", unnamedCount);
  3456. ++unnamedCount;
  3457. #ifndef NODEBUG
  3458. if (FDebug)
  3459. {
  3460. printf("Processing node '%s'\n", testName);
  3461. }
  3462. #endif
  3463. // If we are processing the directory configuration, check for resume
  3464. // and match points.
  3465. if (cfg == RM_DIR)
  3466. {
  3467. // If we have a resume point, check for matching prefix.
  3468. if (ResumeDir)
  3469. {
  3470. if (_strnicmp(testName, ResumeDir, strlen(ResumeDir)))
  3471. {
  3472. continue;
  3473. }
  3474. printf("Resuming from %s\n", testName);
  3475. ResumeDir = NULL;
  3476. }
  3477. // If we have a matching directory, check for matching prefix.
  3478. if (MatchDir)
  3479. {
  3480. if (_strnicmp(testName, MatchDir, strlen(MatchDir)))
  3481. {
  3482. continue;
  3483. }
  3484. }
  3485. // If the directory has been explicitly excluded, then skip it
  3486. if ((cfg == RM_DIR) && FExcludeDirs) {
  3487. if (DirectoryExcluded(testName)) {
  3488. if (FVerbose)
  3489. Message("Excluding %s\n", testName);
  3490. continue;
  3491. }
  3492. }
  3493. }
  3494. // We should sort the children in condition order since we can't trust
  3495. // that Xml nodes are read in the proper order. Since I know that
  3496. // xmlreader.cpp does the right thing, I'm going to enforce the
  3497. // ordering here rather than correct it.
  3498. if (testNode->ChildList == NULL)
  3499. {
  3500. CFG_ERROR_EX(CfgFile, testNode->LineNumber, "test has no information", NULL);
  3501. testNode->Dump();
  3502. goto Label_Error;
  3503. }
  3504. defaultNode = testNode->ChildList;
  3505. if (strcmp(defaultNode->Name, "default") != 0)
  3506. {
  3507. CFG_ERROR_EX(CfgFile, defaultNode->LineNumber, "first node is not default", NULL);
  3508. testNode->Dump();
  3509. goto Label_Error;
  3510. }
  3511. int lastOrder = 0;
  3512. for (applyNode = testNode->ChildList->Next;
  3513. applyNode != NULL;
  3514. applyNode = applyNode->Next)
  3515. {
  3516. if (strcmp(applyNode->Name, "default") == 0)
  3517. {
  3518. CFG_ERROR_EX(CfgFile, applyNode->LineNumber, "multiple default nodes", NULL);
  3519. testNode->Dump();
  3520. goto Label_Error;
  3521. }
  3522. if (strcmp(applyNode->Name, "condition") != 0)
  3523. {
  3524. CFG_ERROR_EX(CfgFile, applyNode->LineNumber, "unknown node", NULL);
  3525. applyNode->Dump();
  3526. goto Label_Error;
  3527. }
  3528. szOrder = applyNode->GetAttributeValue("order");
  3529. if (szOrder == NULL)
  3530. {
  3531. CFG_ERROR_EX(CfgFile, applyNode->LineNumber, "condition node has no order", NULL);
  3532. applyNode->Dump();
  3533. goto Label_Error;
  3534. }
  3535. int order = atoi(szOrder);
  3536. if (order < 1)
  3537. {
  3538. CFG_ERROR_EX(CfgFile, applyNode->LineNumber, "illegal order value '%s'", szOrder);
  3539. applyNode->Dump();
  3540. goto Label_Error;
  3541. }
  3542. if (order <= lastOrder)
  3543. {
  3544. CFG_ERROR_EX(CfgFile, applyNode->LineNumber, "condition node is out-of-order", NULL);
  3545. applyNode->Dump();
  3546. goto Label_Error;
  3547. }
  3548. lastOrder = order;
  3549. // Check for valid conditions.
  3550. int numCond = 0;
  3551. BOOL fHasOverride = FALSE;
  3552. BOOL fHasNonTargetCond = FALSE;
  3553. for (Xml::Node * condNode = applyNode->ChildList;
  3554. condNode != NULL;
  3555. condNode = condNode->Next)
  3556. {
  3557. if (strcmp(condNode->Name, "override") == 0)
  3558. {
  3559. if (!fHasOverride)
  3560. {
  3561. fHasOverride = TRUE;
  3562. }
  3563. else
  3564. {
  3565. CFG_ERROR_EX(CfgFile, applyNode->LineNumber,
  3566. "Too many override nodes", NULL);
  3567. }
  3568. }
  3569. else if (strcmp(condNode->Name, "#comment") == 0)
  3570. {
  3571. }
  3572. else if (strcmp(condNode->Name, "target") == 0 || strcmp(condNode->Name, "os") == 0)
  3573. {
  3574. if (fHasNonTargetCond)
  3575. {
  3576. CFG_ERROR_EX(CfgFile, applyNode->LineNumber,
  3577. "Target conditions must come before non-target conditions",
  3578. NULL);
  3579. applyNode->Dump();
  3580. goto Label_Error;
  3581. }
  3582. numCond++;
  3583. }
  3584. else if (strcmp(condNode->Name, "compile-flags") == 0)
  3585. {
  3586. fHasNonTargetCond = TRUE;
  3587. numCond++;
  3588. }
  3589. else
  3590. {
  3591. CFG_ERROR_EX(CfgFile, applyNode->LineNumber,
  3592. "Can't be conditional on %s", condNode->Name);
  3593. applyNode->Dump();
  3594. goto Label_Error;
  3595. }
  3596. }
  3597. if (numCond == 0)
  3598. {
  3599. CFG_ERROR_EX(CfgFile, applyNode->LineNumber,
  3600. "Missing condition", NULL);
  3601. }
  3602. }
  3603. // Get the defaults from the default node.
  3604. TestInfo testInfo;
  3605. memset(&testInfo, 0, sizeof(TestInfo));
  3606. if (!GetTestInfoFromNode(CfgFile, defaultNode, &testInfo))
  3607. {
  3608. goto Label_Error;
  3609. }
  3610. // Process the tags before checking for condition nodes.
  3611. // Check for any directory tags only if we are in directory mode
  3612. if (cfg == RM_DIR)
  3613. {
  3614. if (ShouldIncludeTest(DirectoryTagsList, &testInfo) == false)
  3615. {
  3616. goto Label_Skip;
  3617. }
  3618. }
  3619. if (ShouldIncludeTest(TagsList, &testInfo, /*mustMatchIncludeTag*/cfg != RM_DIR) == false)
  3620. {
  3621. goto Label_Skip;
  3622. }
  3623. // Walk the condition nodes looking for applicability.
  3624. conditionNodeList = NULL;
  3625. conditionNodeLast = NULL;
  3626. conditionNode = NULL;
  3627. for (applyNode = testNode->ChildList->Next;
  3628. applyNode != NULL;
  3629. applyNode = applyNode->Next)
  3630. {
  3631. // Get the type of condition.
  3632. const char * szType = applyNode->GetAttributeValue("type");
  3633. if (strcmp(szType, "include") == 0)
  3634. {
  3635. }
  3636. else if (strcmp(szType, "exclude") == 0)
  3637. {
  3638. }
  3639. else
  3640. {
  3641. CFG_ERROR_EX(CfgFile, applyNode->LineNumber, "unknown condition type", NULL);
  3642. applyNode->Dump();
  3643. goto Label_Error;
  3644. }
  3645. // See if the condition applies to this target.
  3646. Xml::Node * targetNode = applyNode->GetChild("target");
  3647. Xml::Node * osNode = applyNode->GetChild("os");
  3648. if (targetNode != NULL || osNode != NULL)
  3649. {
  3650. if (targetNode != NULL)
  3651. {
  3652. if (targetNode->ChildList != NULL)
  3653. {
  3654. CFG_ERROR_EX(CfgFile, applyNode->LineNumber,
  3655. "expected data, not child node list", NULL);
  3656. targetNode->Dump();
  3657. goto Label_Error;
  3658. }
  3659. char * targetList = targetNode->Data;
  3660. if ((targetList != NULL)
  3661. && !AppliesToTarget(CfgFile, targetNode->LineNumber, targetList))
  3662. {
  3663. continue;
  3664. }
  3665. }
  3666. if (osNode != NULL)
  3667. {
  3668. char * osList = osNode->Data;
  3669. if (osList != NULL
  3670. && !AppliesToTargetOS(CfgFile, osNode->LineNumber, osList))
  3671. {
  3672. continue;
  3673. }
  3674. }
  3675. // Apply any overrides.
  3676. Xml::Node * overrideNode = applyNode->GetChild("override");
  3677. if (!GetTestInfoFromNode(CfgFile, overrideNode, &testInfo))
  3678. {
  3679. goto Label_Error;
  3680. }
  3681. }
  3682. else if (cfg != RM_EXE)
  3683. {
  3684. CFG_ERROR_EX(CfgFile, applyNode->LineNumber,
  3685. "non-target condition node NYI for non-exe", NULL);
  3686. applyNode->Dump();
  3687. goto Label_Error;
  3688. }
  3689. // We have a potentially applicable condition. Add it to the list
  3690. // of condition nodes if it is not a simple target condition.
  3691. if (targetNode == NULL && osNode == NULL)
  3692. {
  3693. ConditionNodeList * cnl = new ConditionNodeList;
  3694. cnl->node = applyNode;
  3695. cnl->next = NULL;
  3696. if (conditionNodeLast != NULL)
  3697. {
  3698. conditionNodeLast->next = cnl;
  3699. }
  3700. else
  3701. {
  3702. conditionNodeList = cnl;
  3703. }
  3704. conditionNodeLast = cnl;
  3705. }
  3706. else
  3707. {
  3708. // Save the last applicable target condition.
  3709. conditionNode = applyNode;
  3710. }
  3711. }
  3712. // If we have an exclude condition node, then skip this node.
  3713. if ((conditionNode != NULL)
  3714. && (strcmp(conditionNode->GetAttributeValue("type"), "exclude") == 0))
  3715. {
  3716. while (conditionNodeList != NULL)
  3717. {
  3718. ConditionNodeList * cnl = conditionNodeList->next;
  3719. delete conditionNodeList;
  3720. conditionNodeList = cnl;
  3721. }
  3722. continue;
  3723. }
  3724. // Stash the test info into the file list.
  3725. if (!ParseFiles(pTestList, testName, cfg, &testInfo, conditionNodeList))
  3726. {
  3727. // TODO: Figure out where it came from (default or condition.)
  3728. CFG_ERROR_EX(CfgFile, defaultNode->LineNumber,
  3729. "bad file list", NULL);
  3730. goto Label_Error;
  3731. }
  3732. Label_Skip:;
  3733. }
  3734. // If the user specified files, check for ones that didn't match.
  3735. if (FUserSpecifiedFiles && (cfg != RM_DIR))
  3736. {
  3737. for (Test * pTest = pTestList->first; pTest != NULL; pTest = pTest->next)
  3738. {
  3739. if ((pTest->variants == NULL)
  3740. && !IsPogoTest(pTest))
  3741. {
  3742. Warning("'%s' not found", pTest->name);
  3743. }
  3744. }
  3745. }
  3746. return PCS_OK;
  3747. Label_Error:
  3748. return PCS_ERROR;
  3749. }
  3750. void
  3751. WriteTestLst
  3752. (
  3753. TestList * pTestList,
  3754. char *cfgFile
  3755. )
  3756. {
  3757. char tempBuf[BUFFER_SIZE], drive[MAX_PATH], dir[MAX_PATH];
  3758. _splitpath_s(cfgFile, drive, ARRAYLEN(drive), dir, ARRAYLEN(dir), NULL, 0, NULL, 0);
  3759. sprintf_s(tempBuf, "%s%s%s", drive, dir, DEFAULT_TESTLST_DCFG);
  3760. DeleteFileIfFound(tempBuf);
  3761. COutputBuffer *LstFilesOut = new COutputBuffer(tempBuf, FSyncImmediate ? false : true);
  3762. ASSERT(LstFilesOut);
  3763. for(Test * pDir = pTestList->first; pDir; pDir=pDir->next) {
  3764. LstFilesOut->Add("%s\t%s\n", pDir->defaultTestInfo.data[TIK_TAGS], pDir->name);
  3765. }
  3766. LstFilesOut->Flush();
  3767. printf("\nCreated: %s\n", tempBuf);
  3768. delete LstFilesOut;
  3769. }
  3770. // Read the directory configuration file.
  3771. void
  3772. BuildDirList(
  3773. void
  3774. )
  3775. {
  3776. Test * pDir;
  3777. PROCESS_CONFIG_STATUS status;
  3778. char tempBuf[BUFFER_SIZE], drive[MAX_PATH], dir[MAX_PATH];
  3779. status = ProcessConfig(&DirList, DCFGfile, RM_DIR);
  3780. switch (status) {
  3781. case PCS_ERROR:
  3782. exit(1);
  3783. case PCS_FILE_NOT_FOUND:
  3784. if (!FUserSpecifiedDirs) {
  3785. Warning("-dcfg file %s not found; "
  3786. "only regressing the current directory",
  3787. DCFGfile);
  3788. AddCurrentDir();
  3789. }
  3790. break;
  3791. }
  3792. if (ResumeDir)
  3793. Fatal("-resume directory '%s' not found", ResumeDir);
  3794. if (MatchDir && (DirList.first == NULL))
  3795. Fatal("-match prefix '%s' did not match any directory", MatchDir);
  3796. // Get the full path for each. Grab the directory of the DCFG file and
  3797. // append to that each subdirectory.
  3798. _splitpath_s(DCFGfile, drive, ARRAYLEN(drive), dir, ARRAYLEN(dir), NULL, 0, NULL, 0);
  3799. for (pDir = DirList.first; pDir; pDir = pDir->next) {
  3800. sprintf_s(tempBuf, "%s%s%s", drive, dir, pDir->name);
  3801. pDir->fullPath = _strdup(tempBuf);
  3802. }
  3803. #ifndef NODEBUG
  3804. if (FDebug) {
  3805. printf("\nDirectories:\n");
  3806. DumpTestList(&DirList);
  3807. }
  3808. #endif
  3809. if (FGenLst)
  3810. WriteTestLst(&DirList, DCFGfile);
  3811. }
  3812. // Update the status in the title.
  3813. void
  3814. UpdateTitleStatus()
  3815. {
  3816. char* s;
  3817. char tempBuf[BUFFER_SIZE];
  3818. unsigned int i;
  3819. // Don't bother if we're not going to display it.
  3820. if (!FStatus)
  3821. return;
  3822. EnterCriticalSection(&csTitleBar);
  3823. s = FormatString(StatusFormat);
  3824. strcpy_s(TitleStatus, s);
  3825. s = strchr(TitleStatus, '\0');
  3826. // start at 1: skip primary thread 0 (unless we decide to let it do real work)
  3827. for (i = 1; i <= NumberOfThreads; i++) {
  3828. ThreadInfo[i].GetCurrentTest(tempBuf);
  3829. s += sprintf_s(s, REMAININGARRAYLEN(TitleStatus, s), "; %s", tempBuf);
  3830. }
  3831. LeaveCriticalSection(&csTitleBar);
  3832. }
  3833. void
  3834. WriteSummary(
  3835. const char *name,
  3836. BOOL fBaseline,
  3837. int tests,
  3838. int diffs,
  3839. int failures
  3840. )
  3841. {
  3842. char tempBuf[BUFFER_SIZE];
  3843. if (FSummary || FVerbose) {
  3844. if (Mode == RM_ASM) {
  3845. if (fBaseline) {
  3846. sprintf_s(tempBuf,
  3847. "Summary: %s (baselines) has %d tests; %d failures",
  3848. name, tests, failures);
  3849. }
  3850. else {
  3851. sprintf_s(tempBuf,
  3852. "Summary: %s (diffs) has %d tests; %d diffs and %d failures",
  3853. name, tests, diffs, failures);
  3854. }
  3855. LogOut("%s", tempBuf);
  3856. }
  3857. else {
  3858. sprintf_s(tempBuf,
  3859. "Summary: %s had %d tests; %d failures",
  3860. name, tests, failures);
  3861. LogOut("%s", tempBuf);
  3862. }
  3863. }
  3864. }
  3865. void
  3866. __cdecl WriteResults(const char *fmt, ...)
  3867. {
  3868. va_list arg_ptr;
  3869. char tempBuf[BUFFER_SIZE];
  3870. ASSERT(ThreadRes != NULL);
  3871. va_start(arg_ptr, fmt);
  3872. vsprintf_s(tempBuf, fmt, arg_ptr);
  3873. ASSERT(strlen(tempBuf) < BUFFER_SIZE);
  3874. ThreadRes->Add("%s\n", tempBuf);
  3875. }
  3876. void
  3877. __cdecl WriteRunpl(const char *fmt, ...)
  3878. {
  3879. va_list arg_ptr;
  3880. char tempBuf[BUFFER_SIZE], buf[50];
  3881. ASSERT(ThreadFull != NULL);
  3882. buf[0] = '\0';
  3883. if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
  3884. sprintf_s(buf, "%d>", ThreadId);
  3885. }
  3886. va_start(arg_ptr, fmt);
  3887. vsprintf_s(tempBuf, fmt, arg_ptr);
  3888. ASSERT(strlen(tempBuf) < BUFFER_SIZE);
  3889. ThreadFull->Add("%s%s\n", buf, tempBuf);
  3890. }
  3891. // Execute a single regression test.
  3892. void
  3893. PerformSingleRegression(
  3894. CDirectory* pDir,
  3895. Test * pTest
  3896. )
  3897. {
  3898. char testNameBuf[BUFFER_SIZE];
  3899. char tempBuf[BUFFER_SIZE];
  3900. const char* ccFlags;
  3901. time_t start_test, elapsed_test;
  3902. RLFE_STATUS rlfeStatus;
  3903. // Before executing, make sure directory is started.
  3904. pDir->TryBeginDirectory();
  3905. for (TestVariant * pTestVariant = pTest->variants; pTestVariant != NULL; pTestVariant = pTestVariant->next)
  3906. {
  3907. ThreadInfo[ThreadId].SetCurrentTest(pDir->GetDirectoryName(), pTest->name, pDir->IsBaseline());
  3908. pTestVariant->testInfo.data[TIK_FILES] = pTest->name;
  3909. if (FStatus)
  3910. UpdateTitleStatus();
  3911. if (strcmp(pTest->files->string, "dotest.cmd") == 0) {
  3912. sprintf_s(tempBuf, "(%s (", pTest->name);
  3913. } else
  3914. sprintf_s(tempBuf, "(%s (", pTest->files->string);
  3915. if (pTestVariant->optFlags != NULL)
  3916. strcat_s(tempBuf, pTestVariant->optFlags);
  3917. ccFlags = pTestVariant->testInfo.data[TIK_COMPILE_FLAGS];
  3918. if(ccFlags != NULL) {
  3919. if(pTestVariant->optFlags != NULL)
  3920. strcat_s(tempBuf, " ");
  3921. strcat_s(tempBuf, ccFlags);
  3922. }
  3923. if(!pTestVariant->optFlags && !ccFlags)
  3924. tempBuf[0] = '\0';
  3925. else
  3926. strcat_s(tempBuf,") ");
  3927. strcat_s(tempBuf, Mode == RM_ASM ? "asm" : "exe");
  3928. strcat_s(tempBuf, (Mode == RM_ASM) ? (pDir->IsBaseline() ? " base)" : " diffs)") : ")");
  3929. sprintf_s(testNameBuf, "%s %s", pDir->GetDirectoryName(), tempBuf);
  3930. WriteRunpl("+++ %s +++", testNameBuf);
  3931. start_test = time(NULL);
  3932. // Are we doing regressions internally?
  3933. rlfeStatus = RLFES_PASSED;
  3934. int result;
  3935. // Assembly regressions?
  3936. if (Mode == RM_ASM)
  3937. {
  3938. result = RegrFile(pDir, pTest, pTestVariant);
  3939. }
  3940. else
  3941. {
  3942. result = ExecTest(pDir, pTest, pTestVariant);
  3943. }
  3944. switch (result)
  3945. {
  3946. case -1:
  3947. pDir->IncFailures();
  3948. if (Timing & TIME_TEST)
  3949. WriteResults("%s -- failed : exec time=%I64d", testNameBuf, time(NULL) - start_test);
  3950. else
  3951. WriteResults("%s -- failed", testNameBuf);
  3952. rlfeStatus = RLFES_FAILED;
  3953. break;
  3954. case 1:
  3955. pDir->IncDiffs();
  3956. if (Timing & TIME_TEST)
  3957. WriteResults("%s -- diffs : exec time=%I64d", testNameBuf, time(NULL) - start_test);
  3958. else
  3959. WriteResults("%s -- diffs", testNameBuf);
  3960. rlfeStatus = RLFES_DIFFED;
  3961. break;
  3962. case 0:
  3963. if (Timing & TIME_TEST)
  3964. WriteResults("%s -- passed : exec time=%I64d", testNameBuf, time(NULL) - start_test);
  3965. else
  3966. WriteResults("%s -- passed", testNameBuf);
  3967. break;
  3968. default:
  3969. ASSERTNR(UNREACHED);
  3970. }
  3971. pDir->IncRun();
  3972. if (FRLFE)
  3973. RLFETestStatus(pDir);
  3974. elapsed_test = (int)(time(NULL) - start_test);
  3975. if (Timing & TIME_TEST) {
  3976. Message("RL: Test elapsed time (%s, %s): %02d:%02d", pDir->GetDirectoryName(), pTest->name, elapsed_test / 60, elapsed_test % 60);
  3977. }
  3978. if (FSyncTest || (Mode == RM_ASM && FSyncVariation)) {
  3979. if (FRLFE && rlfeStatus)
  3980. RLFEAddLog(pDir, rlfeStatus, pTest->name, NULL, ThreadOut->GetText());
  3981. FlushOutput();
  3982. }
  3983. }
  3984. // Test finished, notify directory in case we are done with it.
  3985. pDir->UpdateState();
  3986. }
  3987. // Execute the regressions on a single directory.
  3988. void
  3989. RegressDirectory(
  3990. CDirectory* pDir
  3991. )
  3992. {
  3993. TestList * pTestList;
  3994. Test * pTest;
  3995. char* path;
  3996. const char* dir;
  3997. #ifndef NODEBUG
  3998. if (FDebug)
  3999. pDir->Dump();
  4000. #endif
  4001. path = pDir->GetDirectoryPath();
  4002. dir = pDir->GetDirectoryName();
  4003. pTestList = pDir->GetTestList();
  4004. // If we are doing baselines and diffs simultaneously and we are now
  4005. // performing the diffs, reinitialize the directory stats.
  4006. if (FBaseDiff && !pDir->IsBaseline())
  4007. pDir->InitStats(0);
  4008. ASSERTNR((int32)pDir->NumVariationsRun == 0);
  4009. ASSERTNR((int32)pDir->NumDiffs == 0);
  4010. ASSERTNR((int32)pDir->NumFailures == 0);
  4011. if (!FNoDirName)
  4012. WriteLog("*** %s ***", dir);
  4013. if ((Mode == RM_ASM) && !CreateAsmDirs(path, pDir->IsBaseline())) {
  4014. pDir->IncFailures(pDir->NumVariations);
  4015. if (FRLFE)
  4016. RLFETestStatus(pDir);
  4017. return;
  4018. }
  4019. if (FRLFE) {
  4020. RLFETestStatus(pDir);
  4021. RLFEThreadDir(pDir, BYTE(ThreadId));
  4022. }
  4023. if (FSyncTest || FSyncVariation)
  4024. FlushOutput();
  4025. // Start a new directory.
  4026. if (((Mode == RM_ASM) && !RegrStartDir(path)) ||
  4027. ((Mode == RM_EXE) && !RunStartDir(path))) {
  4028. pDir->IncRun(pDir->NumVariations);
  4029. pDir->IncFailures(pDir->NumVariations);
  4030. if (FRLFE) {
  4031. RLFETestStatus(pDir);
  4032. RLFEAddLog(pDir, RLFES_FAILED, "Start",
  4033. NULL, "Start dir command failed");
  4034. }
  4035. return;
  4036. }
  4037. // Loop over the test list, invoking the regression command once per test
  4038. // variation. We do not need to write any directory summary here, the CDirectory
  4039. // object itself will take care of that when status is updated during regression
  4040. // execution.
  4041. for (pTest = pTestList->first; pTest; pTest = pTest->next)
  4042. {
  4043. PerformSingleRegression(pDir, pTest);
  4044. }
  4045. // End the directory.
  4046. if (Mode == RM_ASM) {
  4047. if (!RegrEndDir(path))
  4048. return;
  4049. }
  4050. if (FSyncDir)
  4051. FlushOutput();
  4052. }
  4053. DWORD __stdcall
  4054. StatusWorker( void *arg )
  4055. {
  4056. char oldTitleStatus[BUFFER_SIZE];
  4057. ASSERT(FStatus);
  4058. oldTitleStatus[0] = '\0';
  4059. while (!bThreadStop) {
  4060. EnterCriticalSection(&csTitleBar);
  4061. if (0 != strcmp(oldTitleStatus, TitleStatus)) {
  4062. // only if it changed do we set it...
  4063. SetConsoleTitle(TitleStatus);
  4064. strcpy_s(oldTitleStatus, TitleStatus);
  4065. }
  4066. LeaveCriticalSection(&csTitleBar);
  4067. Sleep(500); // don't change it too often
  4068. }
  4069. arg = arg;
  4070. return 0;
  4071. }
  4072. DWORD __stdcall
  4073. ThreadWorker( void *arg )
  4074. {
  4075. ThreadId = (int)(intptr_t)(arg); // thread-local global variable for thread id
  4076. MaxThreads++;
  4077. ThreadOut = new COutputBuffer(FQuiet ? (FILE*)NULL : stdout, FSyncImmediate ? false : true);
  4078. ThreadLog = new COutputBuffer(LogName, FSyncImmediate ? false : true);
  4079. ThreadFull = new COutputBuffer(FullLogName, FSyncImmediate ? false : true);
  4080. ThreadRes = new COutputBuffer(ResultsLogName, FSyncImmediate ? false : true);
  4081. CDirectory* pDir = NULL;
  4082. CDirectoryAndTestCase* pDirAndTest = NULL;
  4083. if (FSyncEnumDirs)
  4084. WaitForSingleObject(heventDirsEnumerated, INFINITE);
  4085. // Create thread-specific target VM command.
  4086. if (TARGET_VM) {
  4087. size_t bufSize = strlen(TARGET_VM) + 1;
  4088. TargetVM = (char *)malloc(bufSize);
  4089. sprintf_s(TargetVM, bufSize, TARGET_VM, ThreadId);
  4090. }
  4091. else {
  4092. TargetVM = NULL;
  4093. }
  4094. while(TRUE) {
  4095. if(bThreadStop)
  4096. break;
  4097. // Poll for new stuff. If the thread is set to stop, then go away.
  4098. // Use DirectoryQueue and schedule each directory on a single thread.
  4099. pDir = DirectoryTestQueue.GetNextItem_NoBlock(1000);
  4100. if(pDir == NULL)
  4101. break;
  4102. while(TRUE) {
  4103. RegressDirectory(pDir);
  4104. // We're done with this directory. If we are doing both
  4105. // baselines and diffs, and it was a baseline directory,
  4106. // changed to diffs and run again.
  4107. if(FBaseDiff && pDir->IsBaseline())
  4108. pDir->SetDiffFlag();
  4109. else
  4110. break;
  4111. }
  4112. delete pDir;
  4113. pDir = NULL;
  4114. }
  4115. while(TRUE) {
  4116. if(bThreadStop)
  4117. break;
  4118. // Poll for new stuff. If the thread is set to stop, then go away.
  4119. // Use DirectoryAndTestCaseQueue and schedule each test on it's own thread.
  4120. pDirAndTest = DirectoryAndTestCaseQueue.GetNextItem_NoBlock(1000);
  4121. if(pDirAndTest == NULL)
  4122. break;
  4123. PerformSingleRegression(pDirAndTest->_pDir, pDirAndTest->_pTest);
  4124. delete pDirAndTest;
  4125. pDirAndTest = NULL;
  4126. }
  4127. // Make sure we've flushed all the output, especially if we're stopping
  4128. // early because of a ctrl-c.
  4129. FlushOutput();
  4130. delete ThreadOut;
  4131. delete ThreadLog;
  4132. delete ThreadFull;
  4133. delete ThreadRes;
  4134. ThreadOut = NULL;
  4135. ThreadLog = NULL;
  4136. ThreadFull = NULL;
  4137. ThreadRes = NULL;
  4138. // Do a little per-thread cleanup
  4139. delete[] cmpbuf1;
  4140. delete[] cmpbuf2;
  4141. // Mark us as done so the title bar shows that.
  4142. ThreadInfo[ThreadId].Done();
  4143. MaxThreads--;
  4144. return 0;
  4145. }
  4146. int __cdecl
  4147. main(int argc, char *argv[])
  4148. {
  4149. Test * pDir, * pTest;
  4150. CDirectory *pDirectory;
  4151. TestList TestList;
  4152. PROCESS_CONFIG_STATUS status;
  4153. DWORD dwThreadId;
  4154. HANDLE newThread;
  4155. HANDLE* workerThreads; // for waiting to finish
  4156. unsigned int i;
  4157. int num, dirNum;
  4158. char fullCfg[_MAX_PATH];
  4159. DWORD err;
  4160. time_t start_total;
  4161. UINT elapsed_total;
  4162. char flagBuff[64];
  4163. start_total = time(NULL);
  4164. SetConsoleCtrlHandler(NT_handling_function, TRUE);
  4165. InitializeCriticalSection(&csTitleBar);
  4166. InitializeCriticalSection(&csStdio);
  4167. InitializeCriticalSection(&csCurrentDirectory);
  4168. // Set up output for primary thread.
  4169. ThreadOut = new COutputBuffer(stdout, true);
  4170. // WARNING: while parsing flags, these are aliased to ThreadOut
  4171. ThreadLog = ThreadOut; // no LogName yet
  4172. ThreadFull = ThreadOut;
  4173. ThreadRes = ThreadOut;
  4174. InitTestList(&TestList);
  4175. ASSERTNR(TestList.first == NULL);
  4176. ASSERTNR(DirList.first == NULL);
  4177. // Get the path for temporary files
  4178. err = GetTempPathA(MAX_PATH, TempPath);
  4179. if (err == 0) {
  4180. strcpy_s(TempPath, "\\");
  4181. } else {
  4182. err = GetFileAttributesA(TempPath);
  4183. if (err == 0xffffffff || !(err & FILE_ATTRIBUTE_DIRECTORY)) {
  4184. strcpy_s(TempPath, "\\");
  4185. }
  4186. }
  4187. ParseCommandLine(argc, argv, &TestList);
  4188. if (FSyncEnumDirs) {
  4189. // The event is manual reset, so once triggered all threads
  4190. // will wake up. It is unsignaled by default; we signal it
  4191. // after all dirs/files have been enumerated.
  4192. heventDirsEnumerated = CreateEvent(NULL, TRUE, FALSE, NULL);
  4193. }
  4194. // If we're using internal code for regressions, initialize.
  4195. Mode == RM_ASM ? RegrInit() : RunInit();
  4196. if (FRLFE) {
  4197. if (!RLFEConnect(StatusPrefix))
  4198. Fatal("Couldn't connect to RLFE");
  4199. }
  4200. atexit(NormalCleanUp);
  4201. BuildDirList();
  4202. if (FVerbose)
  4203. PrintDirs();
  4204. if (DirList.first == nullptr)
  4205. {
  4206. Message("No directories specified for regression - exiting.\n");
  4207. FlushOutput();
  4208. return 0;
  4209. }
  4210. NumDiffsTotal[RLS_TOTAL] = NumFailuresTotal[RLS_TOTAL] = 0;
  4211. if (FRLFE) {
  4212. dirNum = 0;
  4213. for (pDir = DirList.first; pDir; pDir = pDir->next)
  4214. dirNum++;
  4215. RLFEInit((BYTE)NumberOfThreads, dirNum);
  4216. if (Mode == RM_ASM) {
  4217. if (FBaseline)
  4218. RLFEAddRoot(RLS_BASELINES, 0);
  4219. if (FDiff)
  4220. RLFEAddRoot(RLS_DIFFS, 0);
  4221. }
  4222. else {
  4223. RLFEAddRoot(RLS_EXE, 0);
  4224. }
  4225. }
  4226. /*
  4227. * Create an array of info about each thread, accessed by the status
  4228. * update thread.
  4229. */
  4230. ThreadInfo = new CThreadInfo[NumberOfThreads + 1];
  4231. /*
  4232. * Create the thread pool to do the tests
  4233. */
  4234. workerThreads = new HANDLE[NumberOfThreads]; // don't store primary thread
  4235. for( i=1; i <= NumberOfThreads; i++ ) {
  4236. workerThreads[i-1] = newThread = CreateThread( (LPSECURITY_ATTRIBUTES)NULL, 0,
  4237. ThreadWorker, (LPVOID *)i, 0, &dwThreadId );
  4238. if (newThread == INVALID_HANDLE_VALUE)
  4239. Fatal("Couldn't create thread %d", i);
  4240. }
  4241. /*
  4242. * Create the 'update status' thread only for FStatus
  4243. */
  4244. if (FStatus) {
  4245. newThread = CreateThread( (LPSECURITY_ATTRIBUTES)NULL, 0,
  4246. StatusWorker,(LPVOID *)0,0,&dwThreadId );
  4247. if (newThread == INVALID_HANDLE_VALUE)
  4248. Fatal("Couldn't create status thread");
  4249. CloseHandle(newThread);
  4250. }
  4251. // flush all output for the primary thread
  4252. FlushOutput();
  4253. dirNum = 0;
  4254. for (pDir = DirList.first; pDir; pDir = pDir->next) {
  4255. // Number the directories.
  4256. pDir->num = ++dirNum;
  4257. // Build a file list.
  4258. sprintf_s(fullCfg, "%s\\%s", pDir->fullPath, CFGfile);
  4259. status = ProcessConfig(&TestList, fullCfg, Mode);
  4260. if (status != PCS_ERROR)
  4261. {
  4262. #ifndef NODEBUG
  4263. if (FDebug) {
  4264. printf("\nAfter processing config:\n");
  4265. DumpTestList(&TestList);
  4266. }
  4267. #endif
  4268. num = 0;
  4269. for (pTest = TestList.first; pTest; pTest = pTest->next)
  4270. {
  4271. for (TestVariant * variant = pTest->variants;
  4272. variant != NULL;
  4273. variant = variant->next)
  4274. {
  4275. num++;
  4276. }
  4277. if (!FNoWarn && IsPogoTest(pTest) && (pTest->variants == NULL))
  4278. {
  4279. LogOut("Warning: %s::%s is a Pogo test, "
  4280. "but no Pogo-specific options are set",
  4281. pDir->name, pTest->name);
  4282. }
  4283. }
  4284. if (FGenLst) {
  4285. // if generate runall's env.lst config, print the env lst here for the dir
  4286. WriteEnvLst(pDir, &TestList);
  4287. goto nextdir;
  4288. }
  4289. if (num)
  4290. {
  4291. // Queue the tests
  4292. pDirectory = new CDirectory(pDir, TestList);
  4293. pDirectory->InitStats(num);
  4294. if (!FBaseline)
  4295. pDirectory->SetDiffFlag();
  4296. if (FRLFE) {
  4297. if (Mode == RM_EXE) {
  4298. RLFEAddTest(RLS_EXE, pDirectory);
  4299. }
  4300. else {
  4301. if (FBaseline)
  4302. RLFEAddTest(RLS_BASELINES, pDirectory);
  4303. if (FDiff)
  4304. RLFEAddTest(RLS_DIFFS, pDirectory);
  4305. }
  4306. }
  4307. strcpy_s(flagBuff, "sequential");
  4308. BOOL isSerialDirectory = HasInfoList(pDir->defaultTestInfo.data[TIK_TAGS], XML_DELIM, flagBuff, XML_DELIM, false);
  4309. if(isSerialDirectory)
  4310. {
  4311. DirectoryTestQueue.Append(pDirectory);
  4312. }
  4313. else
  4314. {
  4315. // Always put the directory into the DirectoryQueue.
  4316. // We will use this queue to clean up the CDirectory objects if FSingleThreadPerDir is
  4317. // turned off.
  4318. DirectoryQueue.Append(pDirectory);
  4319. // Keep track of tests as a flat list so we can split tests
  4320. // in the same directory across multiple threads.
  4321. for (pTest = TestList.first; pTest; pTest = pTest->next)
  4322. {
  4323. CDirectoryAndTestCase* pDirAndTest = new CDirectoryAndTestCase(pDirectory, pTest);
  4324. DirectoryAndTestCaseQueue.Append(pDirAndTest);
  4325. }
  4326. }
  4327. }
  4328. }
  4329. nextdir:
  4330. InitTestList(&TestList); // get ready for next directory
  4331. ASSERTNR(TestList.first == NULL);
  4332. }
  4333. if (FGenLst) {
  4334. return 0;
  4335. }
  4336. // We can now set the totals.
  4337. if (FRLFE) {
  4338. if (Mode == RM_EXE) {
  4339. RLFEAddRoot(RLS_EXE, (int32)NumVariationsTotal[RLS_EXE]);
  4340. }
  4341. else {
  4342. if (FBaseline)
  4343. RLFEAddRoot(RLS_BASELINES, (int32)NumVariationsTotal[RLS_BASELINES]);
  4344. if (FDiff)
  4345. RLFEAddRoot(RLS_DIFFS, (int32)NumVariationsTotal[RLS_DIFFS]);
  4346. }
  4347. RLFEAddRoot(RLS_TOTAL, (int32)NumVariationsTotal[RLS_TOTAL]);
  4348. }
  4349. DirectoryQueue.AdjustWaitForThreadCount();
  4350. DirectoryAndTestCaseQueue.AdjustWaitForThreadCount();
  4351. #ifndef NODEBUG
  4352. if (FDebug) {
  4353. DirectoryQueue.Dump();
  4354. }
  4355. #endif
  4356. if (FSyncEnumDirs)
  4357. SetEvent(heventDirsEnumerated);
  4358. // Wait for all the threads to die
  4359. WaitForMultipleObjectsEx(NumberOfThreads, workerThreads, TRUE, INFINITE, false);
  4360. for (i = 0; i < NumberOfThreads; i++)
  4361. CloseHandle(workerThreads[i]);
  4362. bThreadStop = TRUE; // make status thread go away
  4363. if (FBaseDiff) {
  4364. WriteSummary(REGRESS, TRUE,
  4365. NumVariationsTotal[RLS_BASELINES],
  4366. NumDiffsTotal[RLS_BASELINES],
  4367. NumFailuresTotal[RLS_BASELINES]);
  4368. WriteSummary(REGRESS, FALSE,
  4369. NumVariationsTotal[RLS_DIFFS],
  4370. NumDiffsTotal[RLS_DIFFS],
  4371. NumFailuresTotal[RLS_DIFFS]);
  4372. }
  4373. else {
  4374. WriteSummary(REGRESS, FBaseline,
  4375. NumVariationsTotal[RLS_TOTAL],
  4376. NumDiffsTotal[RLS_TOTAL],
  4377. NumFailuresTotal[RLS_TOTAL]);
  4378. }
  4379. elapsed_total = (int)(time(NULL) - start_total);
  4380. if (Timing != TIME_NOTHING) {
  4381. Message("RL: Total elapsed time: %02d:%02d",
  4382. elapsed_total / 60, elapsed_total % 60);
  4383. }
  4384. if (((int)CntDeleteFileFailures > 0) || ((int)CntDeleteFileFatals > 0)) {
  4385. Message("RL: Total DeleteFile failures: %d, DeleteFile abandoned: %d",
  4386. (int)CntDeleteFileFailures,
  4387. (int)CntDeleteFileFatals);
  4388. }
  4389. // flush all output for the primary thread
  4390. FlushOutput();
  4391. // The return code from RL is 0 for complete success, 1 for any failure.
  4392. // Note that diffs don't count as failures.
  4393. return ((int32)NumFailuresTotal[RLS_TOTAL] == 0L) ? 0 : 1;
  4394. }