rl.cpp 135 KB

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