rl.cpp 142 KB

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