rl.cpp 134 KB

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