cmCTest.cxx 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTest.h"
  14. #include "cmake.h"
  15. #include "cmMakefile.h"
  16. #include "cmLocalGenerator.h"
  17. #include "cmGlobalGenerator.h"
  18. #include <cmsys/Directory.hxx>
  19. #include "cmListFileCache.h"
  20. #include "cmGlob.h"
  21. #include "cmCTestSubmit.h"
  22. #include "curl/curl.h"
  23. #include <cmsys/RegularExpression.hxx>
  24. #include <cmsys/Process.h>
  25. #include <cmsys/Base64.h>
  26. #include <stdlib.h>
  27. #include <time.h>
  28. #include <math.h>
  29. #include <float.h>
  30. #include "cmDynamicLoader.h"
  31. #define SAFEDIV(x,y) (((y)!=0)?((x)/(y)):(0))
  32. // provide some more detailed info on the return code for ctest
  33. #define CTEST_UPDATE_ERRORS 0x01
  34. #define CTEST_CONFIGURE_ERRORS 0x02
  35. #define CTEST_BUILD_ERRORS 0x04
  36. #define CTEST_TEST_ERRORS 0x08
  37. #define CTEST_MEMORY_ERRORS 0x10
  38. static struct tm* GetNightlyTime(std::string str)
  39. {
  40. struct tm* lctime;
  41. time_t tctime = time(0);
  42. //Convert the nightly start time to seconds. Since we are
  43. //providing only a time and a timezone, the current date of
  44. //the local machine is assumed. Consequently, nightlySeconds
  45. //is the time at which the nightly dashboard was opened or
  46. //will be opened on the date of the current client machine.
  47. //As such, this time may be in the past or in the future.
  48. time_t ntime = curl_getdate(str.c_str(), &tctime);
  49. tctime = time(0);
  50. //std::cout << "Seconds: " << tctime << std::endl;
  51. if ( ntime > tctime )
  52. {
  53. // If nightlySeconds is in the past, this is the current
  54. // open dashboard, then return nightlySeconds. If
  55. // nightlySeconds is in the future, this is the next
  56. // dashboard to be opened, so subtract 24 hours to get the
  57. // time of the current open dashboard
  58. ntime -= (24 * 60 * 60 );
  59. //std::cout << "Pick yesterday" << std::endl;
  60. }
  61. //std::cout << "nightlySeconds: " << ntime << std::endl;
  62. lctime = gmtime(&ntime);
  63. return lctime;
  64. }
  65. static std::string CleanString(const std::string& str)
  66. {
  67. std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
  68. std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
  69. if ( spos == str.npos )
  70. {
  71. return std::string();
  72. }
  73. if ( epos != str.npos )
  74. {
  75. epos = epos - spos + 1;
  76. }
  77. return str.substr(spos, epos);
  78. }
  79. static std::string CurrentTime()
  80. {
  81. time_t currenttime = time(0);
  82. struct tm* t = localtime(&currenttime);
  83. //return ::CleanString(ctime(&currenttime));
  84. char current_time[1024];
  85. strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
  86. //std::cout << "Current_Time: " << current_time << std::endl;
  87. return ::CleanString(current_time);
  88. }
  89. static const char* cmCTestErrorMatches[] = {
  90. "^[Bb]us [Ee]rror",
  91. "^[Ss]egmentation [Vv]iolation",
  92. "^[Ss]egmentation [Ff]ault",
  93. "([^ :]+):([0-9]+): ([^ \\t])",
  94. "([^:]+): error[ \\t]*[0-9]+[ \\t]*:",
  95. "^Error ([0-9]+):",
  96. "^Fatal",
  97. "^Error: ",
  98. "^Error ",
  99. "[0-9] ERROR: ",
  100. "^\"[^\"]+\", line [0-9]+: [^Ww]",
  101. "^cc[^C]*CC: ERROR File = ([^,]+), Line = ([0-9]+)",
  102. "^ld([^:])*:([ \\t])*ERROR([^:])*:",
  103. "^ild:([ \\t])*\\(undefined symbol\\)",
  104. "([^ :]+) : (error|fatal error|catastrophic error)",
  105. "([^:]+): (Error:|error|undefined reference|multiply defined)",
  106. "([^:]+)\\(([^\\)]+)\\) : (error|fatal error|catastrophic error)",
  107. "^fatal error C[0-9]+:",
  108. ": syntax error ",
  109. "^collect2: ld returned 1 exit status",
  110. "Unsatisfied symbols:",
  111. "Undefined symbols:",
  112. "^Undefined[ \\t]+first referenced",
  113. "^CMake Error:",
  114. ":[ \\t]cannot find",
  115. ":[ \\t]can't find",
  116. ": \\*\\*\\* No rule to make target \\`.*\\'. Stop",
  117. ": Invalid loader fixup for symbol",
  118. ": internal link edit command failed",
  119. ": Unrecognized option \\`.*\\'",
  120. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\([^W]\\)",
  121. "ld: 0706-006 Cannot find or open library file: -l ",
  122. 0
  123. };
  124. static const char* cmCTestErrorExceptions[] = {
  125. "instantiated from ",
  126. "candidates are:",
  127. ": warning",
  128. "makefile:",
  129. "Makefile:",
  130. ":[ \\t]+Where:",
  131. 0
  132. };
  133. static const char* cmCTestWarningMatches[] = {
  134. "([^ :]+):([0-9]+): warning:",
  135. "^cc[^C]*CC: WARNING File = ([^,]+), Line = ([0-9]+)",
  136. "^ld([^:])*:([ \\t])*WARNING([^:])*:",
  137. "([^:]+): warning ([0-9]+):",
  138. "^\"[^\"]+\", line [0-9]+: [Ww]arning",
  139. "([^:]+): warning[ \\t]*[0-9]+[ \\t]*:",
  140. "^Warning ([0-9]+):",
  141. "^Warning ",
  142. "WARNING: ",
  143. "([^ :]+) : warning",
  144. "([^:]+): warning",
  145. "\", line [0-9]+\\.[0-9]+: [0-9]+-[0-9]+ \\(W\\)",
  146. 0
  147. };
  148. static const char* cmCTestWarningExceptions[] = {
  149. "/usr/openwin/include/X11/Xlib\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  150. "/usr/openwin/include/X11/Xutil\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  151. "/usr/openwin/include/X11/XResource\\.h:[0-9]+: warning: ANSI C\\+\\+ forbids declaration",
  152. "WARNING 84 :",
  153. "WARNING 47 :",
  154. "makefile:",
  155. "Makefile:",
  156. "warning: Clock skew detected. Your build may be incomplete.",
  157. "/usr/openwin/include/GL/[^:]+:",
  158. "bind_at_load",
  159. "XrmQGetResource",
  160. "IceFlush",
  161. "warning LNK4089: all references to [^ \\t]+ discarded by .OPT:REF",
  162. "ld32: WARNING 85: definition of dataKey in",
  163. "cc: warning 422: Unknown option \"\\+b",
  164. "_with_warning_C",
  165. 0
  166. };
  167. static const char* cmCTestMemCheckResultStrings[] = {
  168. "ABR",
  169. "ABW",
  170. "ABWL",
  171. "COR",
  172. "EXU",
  173. "FFM",
  174. "FIM",
  175. "FMM",
  176. "FMR",
  177. "FMW",
  178. "FUM",
  179. "IPR",
  180. "IPW",
  181. "MAF",
  182. "MLK",
  183. "MPK",
  184. "NPR",
  185. "ODS",
  186. "PAR",
  187. "PLK",
  188. "UMC",
  189. "UMR",
  190. 0
  191. };
  192. std::string cmCTest::MakeXMLSafe(const std::string& str)
  193. {
  194. cmOStringStream ost;
  195. // By uncommenting the lcnt code, it will put newline every 120 characters
  196. //int lcnt = 0;
  197. for (std::string::size_type pos = 0; pos < str.size(); pos ++ )
  198. {
  199. unsigned char ch = str[pos];
  200. if ( (ch > 126 || ch < 32) && ch != 9 && ch != 10 && ch != 13 )
  201. {
  202. char buffer[33];
  203. sprintf(buffer, "&lt;%d&gt;", (int)ch);
  204. //sprintf(buffer, "&#x%0x;", (unsigned int)ch);
  205. ost << buffer;
  206. //lcnt += 4;
  207. }
  208. else
  209. {
  210. switch ( ch )
  211. {
  212. case '&': ost << "&amp;"; break;
  213. case '<': ost << "&lt;"; break;
  214. case '>': ost << "&gt;"; break;
  215. case '\n': ost << "\n";
  216. //lcnt = 0;
  217. break;
  218. default: ost << ch;
  219. }
  220. //lcnt ++;
  221. }
  222. //if ( lcnt > 120 )
  223. // {
  224. // ost << "\n";
  225. // lcnt = 0;
  226. // }
  227. }
  228. return ost.str();
  229. }
  230. std::string cmCTest::MakeURLSafe(const std::string& str)
  231. {
  232. cmOStringStream ost;
  233. char buffer[10];
  234. for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
  235. {
  236. unsigned char ch = str[pos];
  237. if ( ( ch > 126 || ch < 32 ||
  238. ch == '&' ||
  239. ch == '%' ||
  240. ch == '+' ||
  241. ch == '=' ||
  242. ch == '@'
  243. ) && ch != 9 )
  244. {
  245. sprintf(buffer, "%02x;", (unsigned int)ch);
  246. ost << buffer;
  247. }
  248. else
  249. {
  250. ost << ch;
  251. }
  252. }
  253. return ost.str();
  254. }
  255. bool TryExecutable(const char *dir, const char *file,
  256. std::string *fullPath, const char *subdir)
  257. {
  258. // try current directory
  259. std::string tryPath;
  260. if (dir && strcmp(dir,""))
  261. {
  262. tryPath = dir;
  263. tryPath += "/";
  264. }
  265. if (subdir && strcmp(subdir,""))
  266. {
  267. tryPath += subdir;
  268. tryPath += "/";
  269. }
  270. tryPath += file;
  271. if(cmSystemTools::FileExists(tryPath.c_str()))
  272. {
  273. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  274. return true;
  275. }
  276. tryPath += cmSystemTools::GetExecutableExtension();
  277. if(cmSystemTools::FileExists(tryPath.c_str()))
  278. {
  279. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  280. return true;
  281. }
  282. return false;
  283. }
  284. cmCTest::cmCTest()
  285. {
  286. m_BuildNoCMake = false;
  287. m_BuildNoClean = false;
  288. m_BuildTwoConfig = false;
  289. m_UseIncludeRegExp = false;
  290. m_UseExcludeRegExp = false;
  291. m_UseExcludeRegExpFirst = false;
  292. m_Verbose = false;
  293. m_DartMode = false;
  294. m_ShowOnly = false;
  295. m_RunConfigurationScript = false;
  296. m_TestModel = cmCTest::EXPERIMENTAL;
  297. m_TimeOut = 0;
  298. m_CompatibilityMode = 1;
  299. int cc;
  300. for ( cc=0; cc < cmCTest::LAST_TEST; cc ++ )
  301. {
  302. m_Tests[cc] = 0;
  303. }
  304. }
  305. int cmCTest::Initialize()
  306. {
  307. m_ToplevelPath = cmSystemTools::GetCurrentWorkingDirectory();
  308. cmSystemTools::ConvertToUnixSlashes(m_ToplevelPath);
  309. if ( !this->ReadCustomConfigurationFileTree(m_ToplevelPath.c_str()) )
  310. {
  311. return 0;
  312. }
  313. this->UpdateCTestConfiguration();
  314. if ( m_DartMode )
  315. {
  316. std::string testingDir = m_ToplevelPath + "/Testing";
  317. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  318. {
  319. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  320. {
  321. std::cerr << "File " << testingDir << " is in the place of the testing directory"
  322. << std::endl;
  323. return 0;
  324. }
  325. }
  326. else
  327. {
  328. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  329. {
  330. std::cerr << "Cannot create directory " << testingDir
  331. << std::endl;
  332. return 0;
  333. }
  334. }
  335. std::string tagfile = testingDir + "/TAG";
  336. std::ifstream tfin(tagfile.c_str());
  337. std::string tag;
  338. time_t tctime = time(0);
  339. struct tm *lctime = gmtime(&tctime);
  340. if ( tfin && cmSystemTools::GetLineFromStream(tfin, tag) )
  341. {
  342. int year = 0;
  343. int mon = 0;
  344. int day = 0;
  345. int hour = 0;
  346. int min = 0;
  347. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
  348. &year, &mon, &day, &hour, &min);
  349. if ( year != lctime->tm_year + 1900 ||
  350. mon != lctime->tm_mon+1 ||
  351. day != lctime->tm_mday )
  352. {
  353. tag = "";
  354. }
  355. std::string tagmode;
  356. if ( cmSystemTools::GetLineFromStream(tfin, tagmode) )
  357. {
  358. if ( tagmode.size() > 4 && !( m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST] ))
  359. {
  360. m_TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
  361. }
  362. }
  363. tfin.close();
  364. }
  365. if ( tag.size() == 0 || m_Tests[cmCTest::START_TEST] || m_Tests[ALL_TEST])
  366. {
  367. //std::cout << "TestModel: " << this->GetTestModelString() << std::endl;
  368. //std::cout << "TestModel: " << m_TestModel << std::endl;
  369. if ( m_TestModel == cmCTest::NIGHTLY )
  370. {
  371. lctime = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
  372. }
  373. char datestring[100];
  374. sprintf(datestring, "%04d%02d%02d-%02d%02d",
  375. lctime->tm_year + 1900,
  376. lctime->tm_mon+1,
  377. lctime->tm_mday,
  378. lctime->tm_hour,
  379. lctime->tm_min);
  380. tag = datestring;
  381. std::ofstream ofs(tagfile.c_str());
  382. if ( ofs )
  383. {
  384. ofs << tag << std::endl;
  385. ofs << this->GetTestModelString() << std::endl;
  386. }
  387. ofs.close();
  388. std::cout << "Create new tag: " << tag << " - "
  389. << this->GetTestModelString() << std::endl;
  390. }
  391. m_CurrentTag = tag;
  392. }
  393. return 1;
  394. }
  395. void cmCTest::UpdateCTestConfiguration()
  396. {
  397. // parse the dart test file
  398. std::ifstream fin("DartConfiguration.tcl");
  399. if(!fin)
  400. {
  401. return;
  402. }
  403. char buffer[1024];
  404. while ( fin )
  405. {
  406. buffer[0] = 0;
  407. fin.getline(buffer, 1023);
  408. buffer[1023] = 0;
  409. std::string line = ::CleanString(buffer);
  410. if(line.size() == 0)
  411. {
  412. continue;
  413. }
  414. while ( fin && (line[line.size()-1] == '\\') )
  415. {
  416. line = line.substr(0, line.size()-1);
  417. buffer[0] = 0;
  418. fin.getline(buffer, 1023);
  419. buffer[1023] = 0;
  420. line += ::CleanString(buffer);
  421. }
  422. if ( line[0] == '#' )
  423. {
  424. continue;
  425. }
  426. std::string::size_type cpos = line.find_first_of(":");
  427. if ( cpos == line.npos )
  428. {
  429. continue;
  430. }
  431. std::string key = line.substr(0, cpos);
  432. std::string value = ::CleanString(line.substr(cpos+1, line.npos));
  433. m_DartConfiguration[key] = value;
  434. }
  435. fin.close();
  436. if ( m_DartMode )
  437. {
  438. m_TimeOut = atoi(m_DartConfiguration["TimeOut"].c_str());
  439. }
  440. }
  441. bool cmCTest::SetTest(const char* ttype)
  442. {
  443. if ( cmSystemTools::LowerCase(ttype) == "all" )
  444. {
  445. m_Tests[cmCTest::ALL_TEST] = 1;
  446. }
  447. else if ( cmSystemTools::LowerCase(ttype) == "start" )
  448. {
  449. m_Tests[cmCTest::START_TEST] = 1;
  450. }
  451. else if ( cmSystemTools::LowerCase(ttype) == "update" )
  452. {
  453. m_Tests[cmCTest::UPDATE_TEST] = 1;
  454. }
  455. else if ( cmSystemTools::LowerCase(ttype) == "configure" )
  456. {
  457. m_Tests[cmCTest::CONFIGURE_TEST] = 1;
  458. }
  459. else if ( cmSystemTools::LowerCase(ttype) == "build" )
  460. {
  461. m_Tests[cmCTest::BUILD_TEST] = 1;
  462. }
  463. else if ( cmSystemTools::LowerCase(ttype) == "test" )
  464. {
  465. m_Tests[cmCTest::TEST_TEST] = 1;
  466. }
  467. else if ( cmSystemTools::LowerCase(ttype) == "coverage" )
  468. {
  469. m_Tests[cmCTest::COVERAGE_TEST] = 1;
  470. }
  471. else if ( cmSystemTools::LowerCase(ttype) == "memcheck" )
  472. {
  473. m_Tests[cmCTest::MEMCHECK_TEST] = 1;
  474. }
  475. else if ( cmSystemTools::LowerCase(ttype) == "notes" )
  476. {
  477. m_Tests[cmCTest::NOTES_TEST] = 1;
  478. }
  479. else if ( cmSystemTools::LowerCase(ttype) == "submit" )
  480. {
  481. m_Tests[cmCTest::SUBMIT_TEST] = 1;
  482. }
  483. else
  484. {
  485. std::cerr << "Don't know about test \"" << ttype << "\" yet..." << std::endl;
  486. return false;
  487. }
  488. return true;
  489. }
  490. void cmCTest::Finalize()
  491. {
  492. }
  493. std::string cmCTest::FindTheExecutable(const char *exe)
  494. {
  495. std::string fullPath = "";
  496. std::string dir;
  497. std::string file;
  498. cmSystemTools::SplitProgramPath(exe, dir, file);
  499. if(m_ConfigType != "" &&
  500. ::TryExecutable(dir.c_str(), file.c_str(), &fullPath,
  501. m_ConfigType.c_str()))
  502. {
  503. return fullPath;
  504. }
  505. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
  506. {
  507. return fullPath;
  508. }
  509. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
  510. {
  511. return fullPath;
  512. }
  513. if ( m_ConfigType == "" )
  514. {
  515. // No config type, so try to guess it
  516. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
  517. {
  518. return fullPath;
  519. }
  520. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
  521. {
  522. return fullPath;
  523. }
  524. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
  525. {
  526. return fullPath;
  527. }
  528. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
  529. {
  530. return fullPath;
  531. }
  532. }
  533. // if everything else failed, check the users path
  534. if (dir != "")
  535. {
  536. std::string path = cmSystemTools::FindProgram(file.c_str());
  537. if (path != "")
  538. {
  539. return path;
  540. }
  541. }
  542. if ( m_ConfigType != "" )
  543. {
  544. dir += "/";
  545. dir += m_ConfigType;
  546. dir += "/";
  547. dir += file;
  548. cmSystemTools::Error("config type specified on the command line, but test executable not found.",
  549. dir.c_str());
  550. return "";
  551. }
  552. return fullPath;
  553. }
  554. int cmCTest::UpdateDirectory()
  555. {
  556. int count = 0;
  557. std::string::size_type cc, kk;
  558. std::string cvsCommand = m_DartConfiguration["CVSCommand"];
  559. if ( cvsCommand.size() == 0 )
  560. {
  561. std::cerr << "Cannot find CVSCommand key in the DartConfiguration.tcl" << std::endl;
  562. return -1;
  563. }
  564. std::string cvsOptions = m_DartConfiguration["CVSUpdateOptions"];
  565. if ( cvsOptions.size() == 0 )
  566. {
  567. std::cerr << "Cannot find CVSUpdateOptions key in the DartConfiguration.tcl" << std::endl;
  568. return -1;
  569. }
  570. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  571. if ( sourceDirectory.size() == 0 )
  572. {
  573. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  574. return -1;
  575. }
  576. std::string extra_update_opts;
  577. if ( m_TestModel == cmCTest::NIGHTLY )
  578. {
  579. struct tm* t = ::GetNightlyTime(m_DartConfiguration["NightlyStartTime"]);
  580. char current_time[1024];
  581. sprintf(current_time, "%04d-%02d-%02d %02d:%02d:%02d UTC",
  582. t->tm_year + 1900,
  583. t->tm_mon + 1,
  584. t->tm_mday,
  585. t->tm_hour,
  586. t->tm_min,
  587. t->tm_sec);
  588. std::string today_update_date = current_time;
  589. extra_update_opts += "-D \"" + today_update_date +"\"";
  590. //std::cout << "Update: " << extra_update_opts << std::endl;
  591. }
  592. std::string command = cvsCommand + " -z3 update " + cvsOptions +
  593. " " + extra_update_opts;
  594. std::ofstream os;
  595. if ( !this->OpenOutputFile(m_CurrentTag, "Update.xml", os) )
  596. {
  597. std::cerr << "Cannot open log file" << std::endl;
  598. }
  599. std::string start_time = ::CurrentTime();
  600. std::string goutput;
  601. int retVal = 0;
  602. bool res = true;
  603. std::ofstream ofs;
  604. if ( !m_ShowOnly )
  605. {
  606. res = cmSystemTools::RunSingleCommand(command.c_str(), &goutput,
  607. &retVal, sourceDirectory.c_str(),
  608. m_Verbose, 0 /*m_TimeOut*/);
  609. if ( this->OpenOutputFile("Temporary", "LastUpdate.log", ofs) )
  610. {
  611. ofs << goutput << std::endl;;
  612. }
  613. }
  614. else
  615. {
  616. std::cout << "Update with command: " << command << std::endl;
  617. }
  618. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  619. << "<Update mode=\"Client\" Generator=\"ctest\">\n"
  620. << "\t<Site>" <<m_DartConfiguration["Site"] << "</Site>\n"
  621. << "\t<BuildName>" << m_DartConfiguration["BuildName"]
  622. << "</BuildName>\n"
  623. << "\t<BuildStamp>" << m_CurrentTag << "-"
  624. << this->GetTestModelString() << "</BuildStamp>" << std::endl;
  625. os << "\t<StartDateTime>" << start_time << "</StartDateTime>\n"
  626. << "\t<UpdateCommand>" << command << "</UpdateCommand>\n"
  627. << "\t<UpdateReturnStatus>";
  628. if ( retVal )
  629. {
  630. os << goutput;
  631. }
  632. os << "</UpdateReturnStatus>" << std::endl;
  633. std::vector<cmStdString> lines;
  634. cmSystemTools::Split(goutput.c_str(), lines);
  635. std::cout << "Updated; gathering version information" << std::endl;
  636. cmsys::RegularExpression date_author("^date: +([^;]+); +author: +([^;]+); +state: +[^;]+;");
  637. cmsys::RegularExpression revision("^revision +([^ ]*) *$");
  638. cmsys::RegularExpression end_of_file("^=============================================================================$");
  639. cmsys::RegularExpression end_of_comment("^----------------------------$");
  640. std::string current_path = "";
  641. bool first_file = true;
  642. cmCTest::AuthorsToUpdatesMap authors_files_map;
  643. int num_updated = 0;
  644. int num_modified = 0;
  645. int num_conflicting = 0;
  646. for ( cc= 0 ; cc < lines.size(); cc ++ )
  647. {
  648. const char* line = lines[cc].c_str();
  649. char mod = line[0];
  650. if ( line[1] == ' ' && mod != '?' )
  651. {
  652. count ++;
  653. const char* file = line + 2;
  654. //std::cout << "Line" << cc << ": " << mod << " - " << file << std::endl;
  655. std::string logcommand = cvsCommand + " -z3 log -N " + file;
  656. //std::cout << "Do log: " << logcommand << std::endl;
  657. std::string output;
  658. res = cmSystemTools::RunSingleCommand(logcommand.c_str(), &output,
  659. &retVal, sourceDirectory.c_str(),
  660. m_Verbose, 0 /*m_TimeOut*/);
  661. if ( ofs )
  662. {
  663. ofs << output << std::endl;
  664. }
  665. if ( res && retVal == 0)
  666. {
  667. //std::cout << output << std::endl;
  668. std::vector<cmStdString> ulines;
  669. cmSystemTools::Split(output.c_str(), ulines);
  670. std::string::size_type sline = 0;
  671. std::string srevision1 = "Unknown";
  672. std::string sdate1 = "Unknown";
  673. std::string sauthor1 = "Unknown";
  674. std::string semail1 = "Unknown";
  675. std::string comment1 = "";
  676. std::string srevision2 = "Unknown";
  677. std::string sdate2 = "Unknown";
  678. std::string sauthor2 = "Unknown";
  679. std::string comment2 = "";
  680. std::string semail2 = "Unknown";
  681. bool have_first = false;
  682. bool have_second = false;
  683. for ( kk = 0; kk < ulines.size(); kk ++ )
  684. {
  685. const char* clp = ulines[kk].c_str();
  686. if ( !have_second && !sline && revision.find(clp) )
  687. {
  688. if ( !have_first )
  689. {
  690. srevision1 = revision.match(1);
  691. }
  692. else
  693. {
  694. srevision2 = revision.match(1);
  695. }
  696. }
  697. else if ( !have_second && !sline && date_author.find(clp) )
  698. {
  699. sline = kk + 1;
  700. if ( !have_first )
  701. {
  702. sdate1 = date_author.match(1);
  703. sauthor1 = date_author.match(2);
  704. }
  705. else
  706. {
  707. sdate2 = date_author.match(1);
  708. sauthor2 = date_author.match(2);
  709. }
  710. }
  711. else if ( sline && end_of_comment.find(clp) || end_of_file.find(clp))
  712. {
  713. if ( !have_first )
  714. {
  715. have_first = true;
  716. }
  717. else if ( !have_second )
  718. {
  719. have_second = true;
  720. }
  721. sline = 0;
  722. }
  723. else if ( sline )
  724. {
  725. if ( !have_first )
  726. {
  727. comment1 += clp;
  728. comment1 += "\n";
  729. }
  730. else
  731. {
  732. comment2 += clp;
  733. comment2 += "\n";
  734. }
  735. }
  736. }
  737. if ( mod == 'M' )
  738. {
  739. comment1 = "Locally modified file\n";
  740. }
  741. if ( mod == 'C' )
  742. {
  743. comment1 = "Conflict while updating\n";
  744. }
  745. std::string path = cmSystemTools::GetFilenamePath(file);
  746. std::string fname = cmSystemTools::GetFilenameName(file);
  747. if ( path != current_path )
  748. {
  749. if ( !first_file )
  750. {
  751. os << "\t</Directory>" << std::endl;
  752. }
  753. else
  754. {
  755. first_file = false;
  756. }
  757. os << "\t<Directory>\n"
  758. << "\t\t<Name>" << path << "</Name>" << std::endl;
  759. }
  760. if ( mod == 'C' )
  761. {
  762. num_conflicting ++;
  763. os << "\t<Conflicting>" << std::endl;
  764. }
  765. else if ( mod == 'M' )
  766. {
  767. num_modified ++;
  768. os << "\t<Modified>" << std::endl;
  769. }
  770. else
  771. {
  772. num_updated ++;
  773. os << "\t<Updated>" << std::endl;
  774. }
  775. if ( srevision2 == "Unknown" )
  776. {
  777. srevision2 = srevision1;
  778. }
  779. os << "\t\t<File Directory=\"" << path << "\">" << fname
  780. << "</File>\n"
  781. << "\t\t<Directory>" << path << "</Directory>\n"
  782. << "\t\t<FullName>" << file << "</FullName>\n"
  783. << "\t\t<CheckinDate>" << sdate1 << "</CheckinDate>\n"
  784. << "\t\t<Author>" << sauthor1 << "</Author>\n"
  785. << "\t\t<Email>" << semail1 << "</Email>\n"
  786. << "\t\t<Log>" << this->MakeXMLSafe(comment1) << "</Log>\n"
  787. << "\t\t<Revision>" << srevision1 << "</Revision>\n"
  788. << "\t\t<PriorRevision>" << srevision2 << "</PriorRevision>"
  789. << std::endl;
  790. if ( srevision2 != srevision1 )
  791. {
  792. os
  793. << "\t\t<Revisions>\n"
  794. << "\t\t\t<Revision>" << srevision1 << "</Revision>\n"
  795. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  796. << "\t\t\t<Author>" << sauthor1<< "</Author>\n"
  797. << "\t\t\t<Date>" << sdate1 << "</Date>\n"
  798. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment1) << "</Comment>\n"
  799. << "\t\t\t<Email>" << semail1 << "</Email>\n"
  800. << "\t\t</Revisions>\n"
  801. << "\t\t<Revisions>\n"
  802. << "\t\t\t<Revision>" << srevision2 << "</Revision>\n"
  803. << "\t\t\t<PreviousRevision>" << srevision2 << "</PreviousRevision>\n"
  804. << "\t\t\t<Author>" << sauthor2<< "</Author>\n"
  805. << "\t\t\t<Date>" << sdate2 << "</Date>\n"
  806. << "\t\t\t<Comment>" << this->MakeXMLSafe(comment2) << "</Comment>\n"
  807. << "\t\t\t<Email>" << semail2 << "</Email>\n"
  808. << "\t\t</Revisions>" << std::endl;
  809. }
  810. if ( mod == 'C' )
  811. {
  812. os << "\t</Conflicting>" << std::endl;
  813. }
  814. else if ( mod == 'M' )
  815. {
  816. os << "\t</Modified>" << std::endl;
  817. }
  818. else
  819. {
  820. os << "\t</Updated>" << std::endl;
  821. }
  822. cmCTest::UpdateFiles *u = &authors_files_map[sauthor1];
  823. cmCTest::StringPair p;
  824. p.first = path;
  825. p.second = fname;
  826. u->push_back(p);
  827. current_path = path;
  828. }
  829. }
  830. }
  831. if ( num_updated )
  832. {
  833. std::cout << "Found " << num_updated << " updated files" << std::endl;
  834. }
  835. if ( num_modified )
  836. {
  837. std::cout << "Found " << num_modified << " locally modified files"
  838. << std::endl;
  839. }
  840. if ( num_conflicting )
  841. {
  842. std::cout << "Found " << num_conflicting << " conflicting files"
  843. << std::endl;
  844. }
  845. if ( !first_file )
  846. {
  847. os << "\t</Directory>" << std::endl;
  848. }
  849. cmCTest::AuthorsToUpdatesMap::iterator it;
  850. for ( it = authors_files_map.begin();
  851. it != authors_files_map.end();
  852. it ++ )
  853. {
  854. os << "\t<Author>\n"
  855. << "\t\t<Name>" << it->first << "</Name>" << std::endl;
  856. cmCTest::UpdateFiles *u = &(it->second);
  857. for ( cc = 0; cc < u->size(); cc ++ )
  858. {
  859. os << "\t\t<File Directory=\"" << (*u)[cc].first << "\">"
  860. << (*u)[cc].second << "</File>" << std::endl;
  861. }
  862. os << "\t</Author>" << std::endl;
  863. }
  864. //std::cout << "End" << std::endl;
  865. std::string end_time = ::CurrentTime();
  866. os << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  867. << "</Update>" << std::endl;
  868. if ( ofs )
  869. {
  870. ofs.close();
  871. }
  872. if (! res || retVal )
  873. {
  874. std::cerr << "Error(s) when updating the project" << std::endl;
  875. std::cerr << "Output: " << goutput << std::endl;
  876. return -1;
  877. }
  878. return count;
  879. }
  880. int cmCTest::ConfigureDirectory()
  881. {
  882. std::cout << "Configure project" << std::endl;
  883. std::string cCommand = m_DartConfiguration["ConfigureCommand"];
  884. if ( cCommand.size() == 0 )
  885. {
  886. std::cerr << "Cannot find ConfigureCommand key in the DartConfiguration.tcl"
  887. << std::endl;
  888. return 1;
  889. }
  890. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  891. if ( buildDirectory.size() == 0 )
  892. {
  893. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  894. return 1;
  895. }
  896. std::string output;
  897. int retVal = 0;
  898. int res = 0;
  899. if ( !m_ShowOnly )
  900. {
  901. std::ofstream os;
  902. if ( !this->OpenOutputFile(m_CurrentTag, "Configure.xml", os) )
  903. {
  904. std::cerr << "Cannot open configure file" << std::endl;
  905. return 1;
  906. }
  907. std::string start_time = ::CurrentTime();
  908. std::ofstream ofs;
  909. this->OpenOutputFile("Temporary", "LastConfigure.log", ofs);
  910. res = this->RunMakeCommand(cCommand.c_str(), &output,
  911. &retVal, buildDirectory.c_str(),
  912. m_Verbose, 0, ofs);
  913. if ( ofs )
  914. {
  915. ofs.close();
  916. }
  917. if ( os )
  918. {
  919. this->StartXML(os);
  920. os << "<Configure>\n"
  921. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  922. if ( res == cmsysProcess_State_Exited && retVal )
  923. {
  924. os << retVal;
  925. }
  926. os << "<ConfigureCommand>" << cCommand.c_str() << "</ConfigureCommand>" << std::endl;
  927. //std::cout << "End" << std::endl;
  928. os << "<Log>" << this->MakeXMLSafe(output) << "</Log>" << std::endl;
  929. std::string end_time = ::CurrentTime();
  930. os << "\t<ConfigureStatus>" << retVal << "</ConfigureStatus>\n"
  931. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  932. << "</Configure>" << std::endl;
  933. this->EndXML(os);
  934. }
  935. }
  936. else
  937. {
  938. std::cout << "Configure with command: " << cCommand << std::endl;
  939. }
  940. if (! res || retVal )
  941. {
  942. std::cerr << "Error(s) when updating the project" << std::endl;
  943. return 1;
  944. }
  945. return 0;
  946. }
  947. int cmCTest::BuildDirectory()
  948. {
  949. std::cout << "Build project" << std::endl;
  950. std::string makeCommand = m_DartConfiguration["MakeCommand"];
  951. if ( makeCommand.size() == 0 )
  952. {
  953. std::cerr << "Cannot find MakeCommand key in the DartConfiguration.tcl" << std::endl;
  954. return 1;
  955. }
  956. std::string buildDirectory = m_DartConfiguration["BuildDirectory"];
  957. if ( buildDirectory.size() == 0 )
  958. {
  959. std::cerr << "Cannot find BuildDirectory key in the DartConfiguration.tcl" << std::endl;
  960. return 1;
  961. }
  962. std::ofstream ofs;
  963. if ( !this->OpenOutputFile("Temporary", "LastBuild.log", ofs) )
  964. {
  965. std::cerr << "Cannot create LastBuild.log file" << std::endl;
  966. }
  967. m_StartBuild = ::CurrentTime();
  968. std::string output;
  969. int retVal = 0;
  970. int res = cmsysProcess_State_Exited;
  971. if ( !m_ShowOnly )
  972. {
  973. res = this->RunMakeCommand(makeCommand.c_str(), &output,
  974. &retVal, buildDirectory.c_str(),
  975. m_Verbose, 0, ofs);
  976. }
  977. else
  978. {
  979. std::cout << "Build with command: " << makeCommand << std::endl;
  980. }
  981. m_EndBuild = ::CurrentTime();
  982. if (res != cmsysProcess_State_Exited || retVal )
  983. {
  984. std::cerr << "Error(s) when building project" << std::endl;
  985. }
  986. if ( ofs )
  987. {
  988. ofs.close();
  989. }
  990. tm_VectorOfStrings::size_type cc;
  991. if ( m_DartConfiguration["SourceDirectory"].size() > 20 ||
  992. m_DartConfiguration["BuildDirectory"].size() > 20 )
  993. {
  994. std::string srcdir = m_DartConfiguration["SourceDirectory"] + "/";
  995. std::string bindir = m_DartConfiguration["BuildDirectory"] + "/";
  996. std::string srcdirrep;
  997. std::string bindirrep;
  998. for ( cc = srcdir.size()-2; cc > 0; cc -- )
  999. {
  1000. if ( srcdir[cc] == '/' )
  1001. {
  1002. srcdirrep = srcdir.c_str() + cc;
  1003. srcdirrep = "/..." + srcdirrep;
  1004. srcdir = srcdir.substr(0, cc+1);
  1005. break;
  1006. }
  1007. }
  1008. for ( cc = bindir.size()-2; cc > 0; cc -- )
  1009. {
  1010. if ( bindir[cc] == '/' )
  1011. {
  1012. bindirrep = bindir.c_str() + cc;
  1013. bindirrep = "/..." + bindirrep;
  1014. bindir = bindir.substr(0, cc+1);
  1015. break;
  1016. }
  1017. }
  1018. cmSystemTools::ReplaceString(output, srcdir.c_str(), "/.../"); //srcdirrep.c_str());
  1019. cmSystemTools::ReplaceString(output, bindir.c_str(), "/.../"); //bindirrep.c_str());
  1020. }
  1021. // Parsing of output for errors and warnings.
  1022. std::vector<cmStdString> lines;
  1023. cmSystemTools::Split(output.c_str(), lines);
  1024. // Lines are marked:
  1025. // 0 - nothing
  1026. // 1 - error
  1027. // > 1 - warning
  1028. std::vector<int> markedLines(lines.size(), 0);
  1029. // Errors
  1030. for ( cc = 0; cmCTestErrorMatches[cc]; cc ++ )
  1031. {
  1032. m_CustomErrorMatches.push_back(cmCTestErrorMatches[cc]);
  1033. }
  1034. for ( cc = 0; cmCTestErrorExceptions[cc]; cc ++ )
  1035. {
  1036. m_CustomErrorExceptions.push_back(cmCTestErrorExceptions[cc]);
  1037. }
  1038. for ( cc = 0; cmCTestWarningMatches[cc]; cc ++ )
  1039. {
  1040. m_CustomWarningMatches.push_back(cmCTestWarningMatches[cc]);
  1041. }
  1042. for ( cc = 0; cmCTestWarningExceptions[cc]; cc ++ )
  1043. {
  1044. m_CustomWarningExceptions.push_back(cmCTestWarningExceptions[cc]);
  1045. }
  1046. for ( cc = 0; cc < m_CustomErrorMatches.size(); cc ++ )
  1047. {
  1048. cmsys::RegularExpression re(m_CustomErrorMatches[cc].c_str());
  1049. cmCTest::tm_VectorOfStrings::size_type kk;
  1050. for ( kk = 0; kk < lines.size(); kk ++ )
  1051. {
  1052. if ( re.find(lines[kk]) )
  1053. {
  1054. markedLines[kk] = 1;
  1055. }
  1056. }
  1057. }
  1058. // Warnings
  1059. for ( cc = 0; cc < m_CustomWarningMatches.size(); cc ++ )
  1060. {
  1061. cmsys::RegularExpression re(m_CustomWarningMatches[cc].c_str());
  1062. cmCTest::tm_VectorOfStrings::size_type kk;
  1063. for ( kk = 0; kk < lines.size(); kk ++ )
  1064. {
  1065. if ( re.find(lines[kk]) )
  1066. {
  1067. markedLines[kk] += 2;
  1068. }
  1069. }
  1070. }
  1071. // Errors exceptions
  1072. for ( cc = 0; cc < m_CustomErrorExceptions.size(); cc ++ )
  1073. {
  1074. cmsys::RegularExpression re(m_CustomErrorExceptions[cc].c_str());
  1075. std::vector<int>::size_type kk;
  1076. for ( kk =0; kk < markedLines.size(); kk ++ )
  1077. {
  1078. if ( markedLines[kk] == 1 )
  1079. {
  1080. if ( re.find(lines[kk]) )
  1081. {
  1082. markedLines[kk] = 0;
  1083. }
  1084. }
  1085. }
  1086. }
  1087. // Warning exceptions
  1088. for ( cc = 0; cc < m_CustomWarningExceptions.size(); cc ++ )
  1089. {
  1090. cmsys::RegularExpression re(m_CustomWarningExceptions[cc].c_str());
  1091. std::vector<int>::size_type kk;
  1092. for ( kk =0; kk < markedLines.size(); kk ++ )
  1093. {
  1094. if ( markedLines[kk] > 1 )
  1095. {
  1096. if ( re.find(lines[kk]) )
  1097. {
  1098. markedLines[kk] = 0;
  1099. }
  1100. }
  1101. }
  1102. }
  1103. std::vector<cmCTestBuildErrorWarning> errorsWarnings;
  1104. int errors = 0;
  1105. int warnings = 0;
  1106. std::vector<int>::size_type kk;
  1107. cmCTestBuildErrorWarning errorwarning;
  1108. for ( kk =0; kk < markedLines.size(); kk ++ )
  1109. {
  1110. errorwarning.m_LineNumber = -1;
  1111. bool found = false;
  1112. if ( markedLines[kk] == 1 )
  1113. {
  1114. //std::cout << "Error: " << lines[kk] << std::endl;
  1115. errorwarning.m_Error = true;
  1116. found = true;
  1117. }
  1118. else if ( markedLines[kk] > 1 )
  1119. {
  1120. //std::cout << "Warning: " << lines[kk] << std::endl;
  1121. errorwarning.m_Error = false;
  1122. found = true;
  1123. }
  1124. if ( found )
  1125. {
  1126. errorwarning.m_LogLine = static_cast<int>(kk+1);
  1127. errorwarning.m_Text = lines[kk];
  1128. errorwarning.m_PreContext = "";
  1129. errorwarning.m_PostContext = "";
  1130. std::vector<int>::size_type jj;
  1131. std::vector<int>::size_type ll = 0;
  1132. if ( kk > 6 )
  1133. {
  1134. ll = kk - 6;
  1135. }
  1136. for ( jj = kk-1;
  1137. jj > 0 && jj > ll && markedLines[jj] != markedLines[kk];
  1138. jj -- );
  1139. while ( markedLines[jj] == markedLines[kk] && jj < kk )
  1140. {
  1141. jj ++;
  1142. }
  1143. for (; jj < kk; jj ++ )
  1144. {
  1145. errorwarning.m_PreContext += lines[jj] + "\n";
  1146. }
  1147. for ( jj = kk+1;
  1148. jj < lines.size() && jj < kk + 7 && markedLines[jj] != markedLines[kk];
  1149. jj ++ )
  1150. {
  1151. errorwarning.m_PostContext += lines[jj] + "\n";
  1152. }
  1153. errorsWarnings.push_back(errorwarning);
  1154. if ( errorwarning.m_Error )
  1155. {
  1156. errors ++;
  1157. }
  1158. else
  1159. {
  1160. warnings ++;
  1161. }
  1162. }
  1163. }
  1164. std::cout << " " << errors << " Compiler errors" << std::endl;
  1165. std::cout << " " << warnings << " Compiler warnings" << std::endl;
  1166. if( !this->OpenOutputFile(m_CurrentTag, "Build.xml", ofs) )
  1167. {
  1168. std::cerr << "Cannot create build XML file" << std::endl;
  1169. return 1;
  1170. }
  1171. this->GenerateDartBuildOutput(ofs, errorsWarnings);
  1172. return 0;
  1173. }
  1174. int cmCTest::CoverageDirectory()
  1175. {
  1176. std::cout << "Performing coverage" << std::endl;
  1177. cmCTest::tm_VectorOfStrings files;
  1178. cmCTest::tm_VectorOfStrings cfiles;
  1179. cmCTest::tm_VectorOfStrings cdirs;
  1180. bool done = false;
  1181. std::string::size_type cc;
  1182. std::string glob;
  1183. std::map<std::string, std::string> allsourcefiles;
  1184. std::map<std::string, std::string> allbinaryfiles;
  1185. std::string start_time = ::CurrentTime();
  1186. // Find all source files.
  1187. std::string sourceDirectory = m_DartConfiguration["SourceDirectory"];
  1188. if ( sourceDirectory.size() == 0 )
  1189. {
  1190. std::cerr << "Cannot find SourceDirectory key in the DartConfiguration.tcl" << std::endl;
  1191. return 1;
  1192. }
  1193. std::string coverageCommand = m_DartConfiguration["CoverageCommand"];
  1194. if ( coverageCommand.size() == 0 )
  1195. {
  1196. std::cerr << "Coverage command not defined in DartConfiguration.tcl" << std::endl;
  1197. return 1;
  1198. }
  1199. cdirs.push_back(sourceDirectory);
  1200. while ( !done )
  1201. {
  1202. if ( cdirs.size() <= 0 )
  1203. {
  1204. break;
  1205. }
  1206. glob = cdirs[cdirs.size()-1] + "/*";
  1207. //std::cout << "Glob: " << glob << std::endl;
  1208. cdirs.pop_back();
  1209. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1210. {
  1211. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1212. {
  1213. allsourcefiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1214. }
  1215. }
  1216. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1217. {
  1218. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1219. {
  1220. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1221. {
  1222. cdirs.push_back(cfiles[cc]);
  1223. }
  1224. }
  1225. }
  1226. }
  1227. // find all binary files
  1228. cdirs.push_back(cmSystemTools::GetCurrentWorkingDirectory());
  1229. while ( !done )
  1230. {
  1231. if ( cdirs.size() <= 0 )
  1232. {
  1233. break;
  1234. }
  1235. glob = cdirs[cdirs.size()-1] + "/*";
  1236. //std::cout << "Glob: " << glob << std::endl;
  1237. cdirs.pop_back();
  1238. if ( cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1239. {
  1240. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1241. {
  1242. allbinaryfiles[cmSystemTools::GetFilenameName(cfiles[cc])] = cfiles[cc];
  1243. }
  1244. }
  1245. if ( cmSystemTools::SimpleGlob(glob, cfiles, -1) )
  1246. {
  1247. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1248. {
  1249. if ( cfiles[cc] != "." && cfiles[cc] != ".." )
  1250. {
  1251. cdirs.push_back(cfiles[cc]);
  1252. }
  1253. }
  1254. }
  1255. }
  1256. std::map<std::string, std::string>::iterator sit;
  1257. for ( sit = allbinaryfiles.begin(); sit != allbinaryfiles.end(); sit ++ )
  1258. {
  1259. const std::string& fname = sit->second;
  1260. //std::cout << "File: " << fname << std::endl;
  1261. if ( strcmp(fname.substr(fname.size()-3, 3).c_str(), ".da") == 0 )
  1262. {
  1263. files.push_back(fname);
  1264. }
  1265. }
  1266. if ( files.size() == 0 )
  1267. {
  1268. std::cerr << "Cannot find any coverage information files (.da)" << std::endl;
  1269. return 1;
  1270. }
  1271. std::ofstream log;
  1272. if (!this->OpenOutputFile("Temporary", "Coverage.log", log))
  1273. {
  1274. std::cerr << "Cannot open log file" << std::endl;
  1275. return 1;
  1276. }
  1277. log.close();
  1278. if (!this->OpenOutputFile(m_CurrentTag, "Coverage.xml", log))
  1279. {
  1280. std::cerr << "Cannot open log file" << std::endl;
  1281. return 1;
  1282. }
  1283. std::string opath = m_ToplevelPath + "/Testing/Temporary/Coverage";
  1284. cmSystemTools::MakeDirectory(opath.c_str());
  1285. for ( cc = 0; cc < files.size(); cc ++ )
  1286. {
  1287. std::string command = coverageCommand + " -o \"" +
  1288. cmSystemTools::GetFilenamePath(files[cc]) +
  1289. "\" -l \"" + files[cc] + "\"";
  1290. std::string output;
  1291. int retVal = 0;
  1292. //std::cout << "Run gcov on " << files[cc] << std::flush;
  1293. //std::cout << " --- Run [" << command << "]" << std::endl;
  1294. bool res = true;
  1295. if ( !m_ShowOnly )
  1296. {
  1297. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  1298. &retVal, opath.c_str(),
  1299. m_Verbose, 0 /*m_TimeOut*/);
  1300. }
  1301. if ( res && retVal == 0 )
  1302. {
  1303. //std::cout << " - done" << std::endl;
  1304. }
  1305. else
  1306. {
  1307. std::cerr << "Run gcov on " << files[cc] << std::flush;
  1308. std::cerr << " [" << command << "]" << std::endl;
  1309. std::cerr << " - fail" << std::endl;
  1310. }
  1311. }
  1312. files.clear();
  1313. glob = opath + "/*";
  1314. if ( !cmSystemTools::SimpleGlob(glob, cfiles, 1) )
  1315. {
  1316. std::cerr << "Cannot found any coverage files" << std::endl;
  1317. return 1;
  1318. }
  1319. std::map<std::string, cmCTest::tm_VectorOfStrings > sourcefiles;
  1320. for ( cc = 0; cc < cfiles.size(); cc ++ )
  1321. {
  1322. std::string& fname = cfiles[cc];
  1323. // std::cout << "File: " << fname << std::endl;
  1324. if ( strcmp(fname.substr(fname.size()-5, 5).c_str(), ".gcov") == 0 )
  1325. {
  1326. files.push_back(fname);
  1327. std::string::size_type pos = fname.find(".da.");
  1328. std::string::size_type pos2 = fname.find(".da##");
  1329. if(pos2 != fname.npos)
  1330. {
  1331. pos = pos2+1;
  1332. }
  1333. if ( pos != fname.npos )
  1334. {
  1335. pos += 4;
  1336. std::string::size_type epos = fname.size() - pos - strlen(".gcov");
  1337. std::string nf = fname.substr(pos, epos);
  1338. //std::cout << "Substring: " << nf << std::endl;
  1339. if ( allsourcefiles.find(nf) != allsourcefiles.end() ||
  1340. allbinaryfiles.find(nf) != allbinaryfiles.end() )
  1341. {
  1342. cmCTest::tm_VectorOfStrings &cvec = sourcefiles[nf];
  1343. cvec.push_back(fname);
  1344. }
  1345. }
  1346. }
  1347. }
  1348. // for ( cc = 0; cc < files.size(); cc ++ )
  1349. // {
  1350. // std::cout << "File: " << files[cc] << std::endl;
  1351. // }
  1352. std::map<std::string, cmCTest::tm_VectorOfStrings >::iterator it;
  1353. cmCTest::tm_CoverageMap coverageresults;
  1354. this->StartXML(log);
  1355. log << "<Coverage>\n"
  1356. << "\t<StartDateTime>" << start_time << "</StartDateTime>" << std::endl;
  1357. int total_tested = 0;
  1358. int total_untested = 0;
  1359. for ( it = sourcefiles.begin(); it != sourcefiles.end(); it ++ )
  1360. {
  1361. //std::cerr << "Source file: " << it->first << std::endl;
  1362. cmCTest::tm_VectorOfStrings &gfiles = it->second;
  1363. for ( cc = 0; cc < gfiles.size(); cc ++ )
  1364. {
  1365. //std::cout << "\t" << gfiles[cc] << std::endl;
  1366. std::ifstream ifile(gfiles[cc].c_str());
  1367. if ( !ifile )
  1368. {
  1369. std::cerr << "Cannot open file: " << gfiles[cc].c_str() << std::endl;
  1370. }
  1371. ifile.seekg (0, std::ios::end);
  1372. int length = ifile.tellg();
  1373. ifile.seekg (0, std::ios::beg);
  1374. char *buffer = new char [ length + 1 ];
  1375. ifile.read(buffer, length);
  1376. buffer [length] = 0;
  1377. //std::cout << "Read: " << buffer << std::endl;
  1378. std::vector<cmStdString> lines;
  1379. cmSystemTools::Split(buffer, lines);
  1380. delete [] buffer;
  1381. cmCTest::cmCTestCoverage& cov = coverageresults[it->first];
  1382. std::vector<int>& covlines = cov.m_Lines;
  1383. if ( cov.m_FullPath == "" )
  1384. {
  1385. covlines.insert(covlines.begin(), lines.size(), -1);
  1386. if ( allsourcefiles.find(it->first) != allsourcefiles.end() )
  1387. {
  1388. cov.m_FullPath = allsourcefiles[it->first];
  1389. }
  1390. else if ( allbinaryfiles.find(it->first) != allbinaryfiles.end() )
  1391. {
  1392. cov.m_FullPath = allbinaryfiles[it->first];
  1393. }
  1394. cov.m_AbsolutePath = cov.m_FullPath;
  1395. std::string src_dir = m_DartConfiguration["SourceDirectory"];
  1396. if ( src_dir[src_dir.size()-1] != '/' )
  1397. {
  1398. src_dir = src_dir + "/";
  1399. }
  1400. std::string::size_type spos = cov.m_FullPath.find(src_dir);
  1401. if ( spos == 0 )
  1402. {
  1403. cov.m_FullPath = std::string("./") + cov.m_FullPath.substr(src_dir.size());
  1404. }
  1405. else
  1406. {
  1407. //std::cerr << "Compare -- " << cov.m_FullPath << std::endl;
  1408. //std::cerr << " -- " << src_dir << std::endl;
  1409. cov.m_Show = false;
  1410. continue;
  1411. }
  1412. cov.m_Show = true;
  1413. }
  1414. std::string::size_type kk;
  1415. // std::cerr << "number of lines " << lines.size() << "\n";
  1416. for ( kk = 0; kk < lines.size(); kk ++ )
  1417. {
  1418. std::string& line = lines[kk];
  1419. //std::cerr << line << "\n";
  1420. std::string sub1 = line.substr(0, strlen(" #####"));
  1421. std::string sub2 = line.substr(0, strlen(" ######"));
  1422. int count = atoi(sub2.c_str());
  1423. if ( sub1.compare(" #####") == 0 ||
  1424. sub2.compare(" ######") == 0 )
  1425. {
  1426. if ( covlines[kk] == -1 )
  1427. {
  1428. covlines[kk] = 0;
  1429. }
  1430. cov.m_UnTested ++;
  1431. //std::cout << "Untested - ";
  1432. }
  1433. else if ( count > 0 )
  1434. {
  1435. if ( covlines[kk] == -1 )
  1436. {
  1437. covlines[kk] = 0;
  1438. }
  1439. cov.m_Tested ++;
  1440. covlines[kk] ++;
  1441. //std::cout << "Tested[" << count << "] - ";
  1442. }
  1443. //std::cout << line << std::endl;
  1444. }
  1445. }
  1446. }
  1447. //std::cerr << "Finalizing" << std::endl;
  1448. cmCTest::tm_CoverageMap::iterator cit;
  1449. int ccount = 0;
  1450. std::ofstream cfileoutput;
  1451. int cfileoutputcount = 0;
  1452. char cfileoutputname[100];
  1453. std::string local_start_time = ::CurrentTime();
  1454. std::string local_end_time;
  1455. for ( cit = coverageresults.begin(); cit != coverageresults.end(); cit ++ )
  1456. {
  1457. cmCTest::cmCTestCoverage &cov = cit->second;
  1458. if ( !cov.m_Show )
  1459. {
  1460. continue;
  1461. }
  1462. // Check if we should ignore the directory
  1463. std::string coverage_dir = cmSystemTools::GetFilenamePath(cov.m_AbsolutePath.c_str());
  1464. coverage_dir += "/.NoDartCoverage";
  1465. if ( cmSystemTools::FileExists(coverage_dir.c_str()) )
  1466. {
  1467. if ( m_Verbose )
  1468. {
  1469. std::cout << "Ignore file: " << cov.m_FullPath.c_str() << std::endl;
  1470. }
  1471. continue;
  1472. }
  1473. if ( ccount == 100 )
  1474. {
  1475. local_end_time = ::CurrentTime();
  1476. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1477. << "</CoverageLog>" << std::endl;
  1478. this->EndXML(cfileoutput);
  1479. cfileoutput.close();
  1480. std::cout << "Close file: " << cfileoutputname << std::endl;
  1481. ccount = 0;
  1482. }
  1483. if ( ccount == 0 )
  1484. {
  1485. sprintf(cfileoutputname, "CoverageLog-%d.xml", cfileoutputcount++);
  1486. std::cout << "Open file: " << cfileoutputname << std::endl;
  1487. if (!this->OpenOutputFile(m_CurrentTag, cfileoutputname, cfileoutput))
  1488. {
  1489. std::cerr << "Cannot open log file: " << cfileoutputname << std::endl;
  1490. return 1;
  1491. }
  1492. local_start_time = ::CurrentTime();
  1493. this->StartXML(cfileoutput);
  1494. cfileoutput << "<CoverageLog>\n"
  1495. << "\t<StartDateTime>" << local_start_time << "</StartDateTime>" << std::endl;
  1496. }
  1497. //std::cerr << "Final process of Source file: " << cit->first << std::endl;
  1498. cov.m_UnTested = 0;
  1499. cov.m_Tested = 0;
  1500. for ( cc = 0; cc < cov.m_Lines.size(); cc ++ )
  1501. {
  1502. if ( cov.m_Lines[cc] == 0 )
  1503. {
  1504. cov.m_UnTested ++;
  1505. }
  1506. else if ( cov.m_Lines[cc] > 0 )
  1507. {
  1508. cov.m_Tested ++;
  1509. }
  1510. }
  1511. std::ifstream ifile(cov.m_AbsolutePath.c_str());
  1512. if ( !ifile )
  1513. {
  1514. std::cerr << "Cannot open file: " << cov.m_FullPath.c_str() << std::endl;
  1515. }
  1516. ifile.seekg (0, std::ios::end);
  1517. int length = ifile.tellg();
  1518. ifile.seekg (0, std::ios::beg);
  1519. char *buffer = new char [ length + 1 ];
  1520. ifile.read(buffer, length);
  1521. buffer [length] = 0;
  1522. //std::cout << "Read: " << buffer << std::endl;
  1523. std::vector<cmStdString> lines;
  1524. cmSystemTools::Split(buffer, lines);
  1525. delete [] buffer;
  1526. cfileoutput << "\t<File Name=\"" << cit->first << "\" FullPath=\""
  1527. << cov.m_FullPath << "\">\n"
  1528. << "\t\t<Report>" << std::endl;
  1529. for ( cc = 0; cc < lines.size(); cc ++ )
  1530. {
  1531. cfileoutput << "\t\t<Line Number=\""
  1532. << static_cast<int>(cc) << "\" Count=\""
  1533. << cov.m_Lines[cc] << "\">"
  1534. << cmCTest::MakeXMLSafe(lines[cc]) << "</Line>" << std::endl;
  1535. }
  1536. cfileoutput << "\t\t</Report>\n"
  1537. << "\t</File>" << std::endl;
  1538. total_tested += cov.m_Tested;
  1539. total_untested += cov.m_UnTested;
  1540. float cper = 0;
  1541. float cmet = 0;
  1542. if ( total_tested + total_untested > 0 && (cov.m_Tested + cov.m_UnTested) > 0)
  1543. {
  1544. cper = (100 * SAFEDIV(static_cast<float>(cov.m_Tested),
  1545. static_cast<float>(cov.m_Tested + cov.m_UnTested)));
  1546. cmet = ( SAFEDIV(static_cast<float>(cov.m_Tested + 10),
  1547. static_cast<float>(cov.m_Tested + cov.m_UnTested + 10)));
  1548. }
  1549. log << "\t<File Name=\"" << cit->first << "\" FullPath=\"" << cov.m_FullPath
  1550. << "\" Covered=\"" << (cmet>0?"true":"false") << "\">\n"
  1551. << "\t\t<LOCTested>" << cov.m_Tested << "</LOCTested>\n"
  1552. << "\t\t<LOCUnTested>" << cov.m_UnTested << "</LOCUnTested>\n"
  1553. << "\t\t<PercentCoverage>";
  1554. log.setf(std::ios::fixed, std::ios::floatfield);
  1555. log.precision(2);
  1556. log << (cper) << "</PercentCoverage>\n"
  1557. << "\t\t<CoverageMetric>";
  1558. log.setf(std::ios::fixed, std::ios::floatfield);
  1559. log.precision(2);
  1560. log << (cmet) << "</CoverageMetric>\n"
  1561. << "\t</File>" << std::endl;
  1562. ccount ++;
  1563. }
  1564. if ( ccount > 0 )
  1565. {
  1566. local_end_time = ::CurrentTime();
  1567. cfileoutput << "\t<EndDateTime>" << local_end_time << "</EndDateTime>\n"
  1568. << "</CoverageLog>" << std::endl;
  1569. this->EndXML(cfileoutput);
  1570. cfileoutput.close();
  1571. }
  1572. int total_lines = total_tested + total_untested;
  1573. float percent_coverage = 100 * SAFEDIV(static_cast<float>(total_tested),
  1574. static_cast<float>(total_lines));
  1575. if ( total_lines == 0 )
  1576. {
  1577. percent_coverage = 0;
  1578. }
  1579. std::string end_time = ::CurrentTime();
  1580. log << "\t<LOCTested>" << total_tested << "</LOCTested>\n"
  1581. << "\t<LOCUntested>" << total_untested << "</LOCUntested>\n"
  1582. << "\t<LOC>" << total_lines << "</LOC>\n"
  1583. << "\t<PercentCoverage>";
  1584. log.setf(std::ios::fixed, std::ios::floatfield);
  1585. log.precision(2);
  1586. log << (percent_coverage)<< "</PercentCoverage>\n"
  1587. << "\t<EndDateTime>" << end_time << "</EndDateTime>\n"
  1588. << "</Coverage>" << std::endl;
  1589. this->EndXML(log);
  1590. std::cout << "\tCovered LOC: " << total_tested << std::endl
  1591. << "\tNot covered LOC: " << total_untested << std::endl
  1592. << "\tTotal LOC: " << total_lines << std::endl
  1593. << "\tPercentage Coverage: ";
  1594. std::cout.setf(std::ios::fixed, std::ios::floatfield);
  1595. std::cout.precision(2);
  1596. std::cout << (percent_coverage) << "%" << std::endl;
  1597. return 1;
  1598. }
  1599. bool cmCTest::OpenOutputFile(const std::string& path,
  1600. const std::string& name, std::ofstream& stream)
  1601. {
  1602. std::string testingDir = m_ToplevelPath + "/Testing";
  1603. if ( path.size() > 0 )
  1604. {
  1605. testingDir += "/" + path;
  1606. }
  1607. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  1608. {
  1609. if ( !cmSystemTools::FileIsDirectory(testingDir.c_str()) )
  1610. {
  1611. std::cerr << "File " << testingDir
  1612. << " is in the place of the testing directory"
  1613. << std::endl;
  1614. return false;
  1615. }
  1616. }
  1617. else
  1618. {
  1619. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  1620. {
  1621. std::cerr << "Cannot create directory " << testingDir
  1622. << std::endl;
  1623. return false;
  1624. }
  1625. }
  1626. std::string filename = testingDir + "/" + name;
  1627. stream.open(filename.c_str());
  1628. if( !stream )
  1629. {
  1630. std::cerr << "Problem opening file: " << filename << std::endl;
  1631. return false;
  1632. }
  1633. return true;
  1634. }
  1635. void cmCTest::GenerateDartBuildOutput(std::ostream& os,
  1636. std::vector<cmCTestBuildErrorWarning> ew)
  1637. {
  1638. this->StartXML(os);
  1639. os << "<Build>\n"
  1640. << "\t<StartDateTime>" << m_StartBuild << "</StartDateTime>\n"
  1641. << "<BuildCommand>"
  1642. << this->MakeXMLSafe(m_DartConfiguration["MakeCommand"])
  1643. << "</BuildCommand>" << std::endl;
  1644. std::vector<cmCTestBuildErrorWarning>::iterator it;
  1645. for ( it = ew.begin(); it != ew.end(); it++ )
  1646. {
  1647. cmCTestBuildErrorWarning *cm = &(*it);
  1648. os << "\t<" << (cm->m_Error ? "Error" : "Warning") << ">\n"
  1649. << "\t\t<BuildLogLine>" << cm->m_LogLine << "</BuildLogLine>\n"
  1650. << "\t\t<Text>" << this->MakeXMLSafe(cm->m_Text)
  1651. << "\n</Text>" << std::endl;
  1652. if ( cm->m_SourceFile.size() > 0 )
  1653. {
  1654. os << "\t\t<SourceFile>" << cm->m_SourceFile << "</SourceFile>"
  1655. << std::endl;
  1656. }
  1657. if ( cm->m_SourceFileTail.size() > 0 )
  1658. {
  1659. os << "\t\t<SourceFileTail>" << cm->m_SourceFileTail
  1660. << "</SourceFileTail>" << std::endl;
  1661. }
  1662. if ( cm->m_LineNumber >= 0 )
  1663. {
  1664. os << "\t\t<SourceLineNumber>" << cm->m_LineNumber
  1665. << "</SourceLineNumber>" << std::endl;
  1666. }
  1667. os << "\t\t<PreContext>" << this->MakeXMLSafe(cm->m_PreContext)
  1668. << "</PreContext>\n"
  1669. << "\t\t<PostContext>" << this->MakeXMLSafe(cm->m_PostContext)
  1670. << "</PostContext>\n"
  1671. << "\t\t<RepeatCount>0</RepeatCount>\n"
  1672. << "</" << (cm->m_Error ? "Error" : "Warning") << ">\n\n"
  1673. << std::endl;
  1674. }
  1675. os << "\t<Log Encoding=\"base64\" Compression=\"/bin/gzip\">\n\t</Log>\n"
  1676. << "\t<EndDateTime>" << m_EndBuild << "</EndDateTime>\n"
  1677. << "</Build>" << std::endl;
  1678. this->EndXML(os);
  1679. }
  1680. void cmCTest::ProcessDirectory(cmCTest::tm_VectorOfStrings &passed,
  1681. cmCTest::tm_VectorOfStrings &failed,
  1682. bool memcheck, std::ostream* logfile)
  1683. {
  1684. // does the DartTestfile.txt exist ?
  1685. if(!cmSystemTools::FileExists("DartTestfile.txt"))
  1686. {
  1687. return;
  1688. }
  1689. // parse the file
  1690. std::ifstream fin("DartTestfile.txt");
  1691. if(!fin)
  1692. {
  1693. return;
  1694. }
  1695. int firstTest = 1;
  1696. cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
  1697. cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
  1698. cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  1699. cmListFileCache cache;
  1700. cmListFile* listFile = cache.GetFileCache("DartTestfile.txt", false);
  1701. for(std::vector<cmListFileFunction>::const_iterator f =
  1702. listFile->m_Functions.begin(); f != listFile->m_Functions.end(); ++f)
  1703. {
  1704. const cmListFileFunction& lff = *f;
  1705. const std::string& name = lff.m_Name;
  1706. const std::vector<cmListFileArgument>& args = lff.m_Arguments;
  1707. if (name == "SUBDIRS")
  1708. {
  1709. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1710. for(std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1711. j != args.end(); ++j)
  1712. {
  1713. std::string nwd = cwd + "/";
  1714. nwd += j->Value;
  1715. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  1716. {
  1717. cmSystemTools::ChangeDirectory(nwd.c_str());
  1718. this->ProcessDirectory(passed, failed, memcheck, logfile);
  1719. }
  1720. }
  1721. // return to the original directory
  1722. cmSystemTools::ChangeDirectory(cwd.c_str());
  1723. }
  1724. if (name == "ADD_TEST")
  1725. {
  1726. if (this->m_UseExcludeRegExp &&
  1727. this->m_UseExcludeRegExpFirst &&
  1728. ereg.find(args[0].Value.c_str()))
  1729. {
  1730. continue;
  1731. }
  1732. if ( memcheck )
  1733. {
  1734. tm_VectorOfStrings::iterator it;
  1735. bool found = false;
  1736. for ( it = m_CustomMemCheckIgnore.begin();
  1737. it != m_CustomMemCheckIgnore.end(); ++ it )
  1738. {
  1739. if ( *it == args[0].Value )
  1740. {
  1741. found = true;
  1742. break;
  1743. }
  1744. }
  1745. if ( found )
  1746. {
  1747. if ( m_Verbose )
  1748. {
  1749. std::cout << "Ignore memcheck: " << *it << std::endl;
  1750. }
  1751. continue;
  1752. }
  1753. }
  1754. else
  1755. {
  1756. tm_VectorOfStrings::iterator it;
  1757. bool found = false;
  1758. for ( it = m_CustomTestsIgnore.begin();
  1759. it != m_CustomTestsIgnore.end(); ++ it )
  1760. {
  1761. if ( *it == args[0].Value )
  1762. {
  1763. found = true;
  1764. break;
  1765. }
  1766. }
  1767. if ( found )
  1768. {
  1769. if ( m_Verbose )
  1770. {
  1771. std::cout << "Ignore test: " << *it << std::endl;
  1772. }
  1773. continue;
  1774. }
  1775. }
  1776. if (this->m_UseIncludeRegExp && !ireg.find(args[0].Value.c_str()))
  1777. {
  1778. continue;
  1779. }
  1780. if (this->m_UseExcludeRegExp &&
  1781. !this->m_UseExcludeRegExpFirst &&
  1782. ereg.find(args[0].Value.c_str()))
  1783. {
  1784. continue;
  1785. }
  1786. cmCTestTestResult cres;
  1787. cres.m_Status = cmCTest::NOT_RUN;
  1788. if (firstTest)
  1789. {
  1790. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1791. if ( m_Verbose )
  1792. {
  1793. std::cerr << "Changing directory into " << nwd.c_str() << "\n";
  1794. }
  1795. firstTest = 0;
  1796. }
  1797. cres.m_Name = args[0].Value;
  1798. if ( m_ShowOnly )
  1799. {
  1800. std::cout << args[0].Value << std::endl;
  1801. }
  1802. else
  1803. {
  1804. fprintf(stderr,"Testing %-30s ",args[0].Value.c_str());
  1805. fflush(stderr);
  1806. }
  1807. //std::cerr << "Testing " << args[0] << " ... ";
  1808. // find the test executable
  1809. std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str());
  1810. std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  1811. std::string memcheckcommand = "";
  1812. // continue if we did not find the executable
  1813. if (testCommand == "")
  1814. {
  1815. std::cerr << "Unable to find executable: " <<
  1816. args[1].Value.c_str() << "\n";
  1817. m_TestResults.push_back( cres );
  1818. failed.push_back(args[0].Value);
  1819. continue;
  1820. }
  1821. // add the arguments
  1822. std::vector<cmListFileArgument>::const_iterator j = args.begin();
  1823. ++j;
  1824. ++j;
  1825. std::vector<const char*> arguments;
  1826. if ( memcheck )
  1827. {
  1828. cmCTest::tm_VectorOfStrings::size_type pp;
  1829. arguments.push_back(m_MemoryTester.c_str());
  1830. memcheckcommand = m_MemoryTester;
  1831. for ( pp = 0; pp < m_MemoryTesterOptionsParsed.size(); pp ++ )
  1832. {
  1833. arguments.push_back(m_MemoryTesterOptionsParsed[pp].c_str());
  1834. memcheckcommand += " ";
  1835. memcheckcommand += cmSystemTools::EscapeSpaces(m_MemoryTesterOptionsParsed[pp].c_str());
  1836. }
  1837. }
  1838. arguments.push_back(actualCommand.c_str());
  1839. for(;j != args.end(); ++j)
  1840. {
  1841. testCommand += " ";
  1842. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  1843. arguments.push_back(j->Value.c_str());
  1844. }
  1845. arguments.push_back(0);
  1846. /**
  1847. * Run an executable command and put the stdout in output.
  1848. */
  1849. std::string output;
  1850. int retVal = 0;
  1851. double clock_start, clock_finish;
  1852. clock_start = cmSystemTools::GetTime();
  1853. if ( m_Verbose )
  1854. {
  1855. std::cout << std::endl << (memcheck?"MemCheck":"Test") << " command: " << testCommand << std::endl;
  1856. if ( memcheck )
  1857. {
  1858. std::cout << "Memory check command: " << memcheckcommand << std::endl;
  1859. }
  1860. }
  1861. if ( logfile )
  1862. {
  1863. *logfile << "Command: ";
  1864. tm_VectorOfStrings::size_type ll;
  1865. for ( ll = 0; ll < arguments.size()-1; ll ++ )
  1866. {
  1867. *logfile << "\"" << arguments[ll] << "\" ";
  1868. }
  1869. *logfile
  1870. << std::endl
  1871. << "Directory: " << cmSystemTools::GetCurrentWorkingDirectory() << std::endl
  1872. << "Output:" << std::endl
  1873. << "----------------------------------------------------------"
  1874. << std::endl;
  1875. }
  1876. int res = 0;
  1877. if ( !m_ShowOnly )
  1878. {
  1879. res = this->RunTest(arguments, &output, &retVal, logfile);
  1880. }
  1881. if ( logfile )
  1882. {
  1883. *logfile
  1884. << "----------------------------------------------------------"
  1885. << std::endl << std::endl;
  1886. }
  1887. clock_finish = cmSystemTools::GetTime();
  1888. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  1889. cres.m_FullCommandLine = testCommand;
  1890. if ( !m_ShowOnly )
  1891. {
  1892. if (res == cmsysProcess_State_Exited && retVal == 0)
  1893. {
  1894. fprintf(stderr," Passed\n");
  1895. passed.push_back(args[0].Value);
  1896. cres.m_Status = cmCTest::COMPLETED;
  1897. }
  1898. else
  1899. {
  1900. cres.m_Status = cmCTest::FAILED;
  1901. if ( res == cmsysProcess_State_Expired )
  1902. {
  1903. fprintf(stderr,"***Timeout\n");
  1904. cres.m_Status = cmCTest::TIMEOUT;
  1905. }
  1906. else if ( res == cmsysProcess_State_Exception )
  1907. {
  1908. fprintf(stderr,"***Exception: ");
  1909. switch ( retVal )
  1910. {
  1911. case cmsysProcess_Exception_Fault:
  1912. fprintf(stderr,"SegFault");
  1913. cres.m_Status = cmCTest::SEGFAULT;
  1914. break;
  1915. case cmsysProcess_Exception_Illegal:
  1916. fprintf(stderr,"Illegal");
  1917. cres.m_Status = cmCTest::ILLEGAL;
  1918. break;
  1919. case cmsysProcess_Exception_Interrupt:
  1920. fprintf(stderr,"Interrupt");
  1921. cres.m_Status = cmCTest::INTERRUPT;
  1922. break;
  1923. case cmsysProcess_Exception_Numerical:
  1924. fprintf(stderr,"Numerical");
  1925. cres.m_Status = cmCTest::NUMERICAL;
  1926. break;
  1927. default:
  1928. fprintf(stderr,"Other");
  1929. cres.m_Status = cmCTest::OTHER_FAULT;
  1930. }
  1931. fprintf(stderr,"\n");
  1932. }
  1933. else if ( res == cmsysProcess_State_Error )
  1934. {
  1935. fprintf(stderr,"***Bad command %d\n", res);
  1936. cres.m_Status = cmCTest::BAD_COMMAND;
  1937. }
  1938. else
  1939. {
  1940. fprintf(stderr,"***Failed\n");
  1941. }
  1942. failed.push_back(args[0].Value);
  1943. }
  1944. if (output != "")
  1945. {
  1946. if (dartStuff.find(output.c_str()))
  1947. {
  1948. std::string dartString = dartStuff.match(1);
  1949. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  1950. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  1951. }
  1952. }
  1953. }
  1954. cres.m_Output = output;
  1955. cres.m_ReturnValue = retVal;
  1956. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1957. if ( nwd.size() > m_ToplevelPath.size() )
  1958. {
  1959. nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
  1960. }
  1961. cmSystemTools::ReplaceString(nwd, "\\", "/");
  1962. cres.m_Path = nwd;
  1963. cres.m_CompletionStatus = "Completed";
  1964. m_TestResults.push_back( cres );
  1965. }
  1966. }
  1967. }
  1968. bool cmCTest::InitializeMemoryChecking()
  1969. {
  1970. // Setup the command
  1971. if ( cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckCommand"].c_str()) )
  1972. {
  1973. m_MemoryTester
  1974. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["MemoryCheckCommand"].c_str());
  1975. }
  1976. else if ( cmSystemTools::FileExists(m_DartConfiguration["PurifyCommand"].c_str()) )
  1977. {
  1978. m_MemoryTester
  1979. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["PurifyCommand"].c_str());
  1980. }
  1981. else if ( cmSystemTools::FileExists(m_DartConfiguration["ValgrindCommand"].c_str()) )
  1982. {
  1983. m_MemoryTester
  1984. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["ValgrindCommand"].c_str());
  1985. }
  1986. else
  1987. {
  1988. std::cerr << "Memory checker (MemoryCheckCommand) not set, or cannot find the specified program."
  1989. << std::endl;
  1990. return false;
  1991. }
  1992. if ( m_MemoryTester[0] == '\"' && m_MemoryTester[m_MemoryTester.size()-1] == '\"' )
  1993. {
  1994. m_MemoryTester = m_MemoryTester.substr(1, m_MemoryTester.size()-2);
  1995. }
  1996. // Setup the options
  1997. if ( m_DartConfiguration["MemoryCheckCommandOptions"].size() )
  1998. {
  1999. m_MemoryTesterOptions = m_DartConfiguration["MemoryCheckCommandOptions"];
  2000. }
  2001. else if ( m_DartConfiguration["ValgrindCommandOptions"].size() )
  2002. {
  2003. m_MemoryTesterOptions = m_DartConfiguration["ValgrindCommandOptions"];
  2004. }
  2005. m_MemoryTesterOutputFile = m_ToplevelPath + "/Testing/Temporary/MemoryChecker.log";
  2006. m_MemoryTesterOutputFile = cmSystemTools::EscapeSpaces(m_MemoryTesterOutputFile.c_str());
  2007. if ( m_MemoryTester.find("valgrind") != std::string::npos )
  2008. {
  2009. m_MemoryTesterStyle = cmCTest::VALGRIND;
  2010. if ( !m_MemoryTesterOptions.size() )
  2011. {
  2012. m_MemoryTesterOptions = "-q --skin=memcheck --leak-check=yes --show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=100";
  2013. }
  2014. if ( m_DartConfiguration["MemoryCheckSuppressionFile"].size() )
  2015. {
  2016. if ( !cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) )
  2017. {
  2018. std::cerr << "Cannot find memory checker suppression file: "
  2019. << m_DartConfiguration["MemoryCheckSuppressionFile"].c_str() << std::endl;
  2020. return false;
  2021. }
  2022. m_MemoryTesterOptions += " --suppressions=" + cmSystemTools::EscapeSpaces(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) + "";
  2023. }
  2024. }
  2025. else if ( m_MemoryTester.find("purify") != std::string::npos )
  2026. {
  2027. m_MemoryTesterStyle = cmCTest::PURIFY;
  2028. #ifdef _WIN32
  2029. m_MemoryTesterOptions += " /SAVETEXTDATA=" + m_MemoryTesterOutputFile;
  2030. #else
  2031. m_MemoryTesterOptions += " -log-file=" + m_MemoryTesterOutputFile;
  2032. #endif
  2033. }
  2034. else if ( m_MemoryTester.find("boundschecker") != std::string::npos )
  2035. {
  2036. m_MemoryTesterStyle = cmCTest::BOUNDS_CHECKER;
  2037. std::cerr << "Bounds checker not yet implemented" << std::endl;
  2038. return false;
  2039. }
  2040. else
  2041. {
  2042. std::cerr << "Do not understand memory checker: " << m_MemoryTester.c_str() << std::endl;
  2043. return false;
  2044. }
  2045. m_MemoryTesterOptionsParsed = cmSystemTools::ParseArguments(m_MemoryTesterOptions.c_str());
  2046. cmCTest::tm_VectorOfStrings::size_type cc;
  2047. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  2048. {
  2049. m_MemoryTesterGlobalResults[cc] = 0;
  2050. }
  2051. return true;
  2052. }
  2053. int cmCTest::TestDirectory(bool memcheck)
  2054. {
  2055. std::cout << (memcheck ? "Memory check" : "Test") << " project" << std::endl;
  2056. if ( memcheck )
  2057. {
  2058. if ( !this->InitializeMemoryChecking() )
  2059. {
  2060. return 1;
  2061. }
  2062. }
  2063. if ( memcheck )
  2064. {
  2065. if ( !this->ExecuteCommands(m_CustomPreMemCheck) )
  2066. {
  2067. std::cerr << "Problem executing pre-memcheck command(s)." << std::endl;
  2068. return 1;
  2069. }
  2070. }
  2071. else
  2072. {
  2073. if ( !this->ExecuteCommands(m_CustomPreTest) )
  2074. {
  2075. std::cerr << "Problem executing pre-test command(s)." << std::endl;
  2076. return 1;
  2077. }
  2078. }
  2079. cmCTest::tm_VectorOfStrings passed;
  2080. cmCTest::tm_VectorOfStrings failed;
  2081. int total;
  2082. std::ofstream ofs;
  2083. std::ofstream *olog = 0;
  2084. if ( this->OpenOutputFile("Temporary", (memcheck?"LastMemCheck.xml":"LastTest.log"), ofs) )
  2085. {
  2086. olog = &ofs;
  2087. }
  2088. m_StartTest = ::CurrentTime();
  2089. this->ProcessDirectory(passed, failed, memcheck, olog);
  2090. m_EndTest = ::CurrentTime();
  2091. total = int(passed.size()) + int(failed.size());
  2092. if (total == 0)
  2093. {
  2094. if ( !m_ShowOnly )
  2095. {
  2096. std::cerr << "No tests were found!!!\n";
  2097. }
  2098. }
  2099. else
  2100. {
  2101. if (m_Verbose && passed.size() &&
  2102. (m_UseIncludeRegExp || m_UseExcludeRegExp))
  2103. {
  2104. std::cerr << "\nThe following tests passed:\n";
  2105. for(cmCTest::tm_VectorOfStrings::iterator j = passed.begin();
  2106. j != passed.end(); ++j)
  2107. {
  2108. std::cerr << "\t" << *j << "\n";
  2109. }
  2110. }
  2111. float percent = float(passed.size()) * 100.0f / total;
  2112. if ( failed.size() > 0 && percent > 99)
  2113. {
  2114. percent = 99;
  2115. }
  2116. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  2117. percent, int(failed.size()), total);
  2118. if (failed.size())
  2119. {
  2120. std::cerr << "\nThe following tests FAILED:\n";
  2121. for(cmCTest::tm_VectorOfStrings::iterator j = failed.begin();
  2122. j != failed.end(); ++j)
  2123. {
  2124. std::cerr << "\t" << *j << "\n";
  2125. }
  2126. }
  2127. }
  2128. if ( m_DartMode )
  2129. {
  2130. std::ofstream ofs;
  2131. if( !this->OpenOutputFile(m_CurrentTag,
  2132. (memcheck ? (m_CompatibilityMode?"Purify.xml":"MemCheck.xml") : "Test.xml"), ofs) )
  2133. {
  2134. std::cerr << "Cannot create " << (memcheck ? "memory check" : "testing")
  2135. << " XML file" << std::endl;
  2136. return 1;
  2137. }
  2138. if ( memcheck )
  2139. {
  2140. this->GenerateDartMemCheckOutput(ofs);
  2141. }
  2142. else
  2143. {
  2144. this->GenerateDartTestOutput(ofs);
  2145. }
  2146. }
  2147. if ( memcheck )
  2148. {
  2149. if ( !this->ExecuteCommands(m_CustomPostMemCheck) )
  2150. {
  2151. std::cerr << "Problem executing post-memcheck command(s)." << std::endl;
  2152. return 1;
  2153. }
  2154. }
  2155. else
  2156. {
  2157. if ( !this->ExecuteCommands(m_CustomPostTest) )
  2158. {
  2159. std::cerr << "Problem executing post-test command(s)." << std::endl;
  2160. return 1;
  2161. }
  2162. }
  2163. return int(failed.size());
  2164. }
  2165. int cmCTest::SubmitResults()
  2166. {
  2167. cmCTest::tm_VectorOfStrings files;
  2168. std::string prefix = this->GetSubmitResultsPrefix();
  2169. // TODO:
  2170. // Check if test is enabled
  2171. if ( this->CTestFileExists("Update.xml") )
  2172. {
  2173. files.push_back("Update.xml");
  2174. }
  2175. if ( this->CTestFileExists("Configure.xml") )
  2176. {
  2177. files.push_back("Configure.xml");
  2178. }
  2179. if ( this->CTestFileExists("Build.xml") )
  2180. {
  2181. files.push_back("Build.xml");
  2182. }
  2183. if ( this->CTestFileExists("Test.xml") )
  2184. {
  2185. files.push_back("Test.xml");
  2186. }
  2187. if ( this->CTestFileExists("Coverage.xml") )
  2188. {
  2189. files.push_back("Coverage.xml");
  2190. cmCTest::tm_VectorOfStrings gfiles;
  2191. std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
  2192. std::string::size_type glen = gpath.size() + 1;
  2193. gpath = gpath + "/CoverageLog*";
  2194. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  2195. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  2196. {
  2197. size_t cc;
  2198. for ( cc = 0; cc < gfiles.size(); cc ++ )
  2199. {
  2200. gfiles[cc] = gfiles[cc].substr(glen);
  2201. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  2202. files.push_back(gfiles[cc]);
  2203. }
  2204. }
  2205. else
  2206. {
  2207. std::cerr << "Problem globbing" << std::endl;
  2208. }
  2209. }
  2210. if ( this->CTestFileExists("MemCheck.xml") )
  2211. {
  2212. files.push_back("MemCheck.xml");
  2213. }
  2214. if ( this->CTestFileExists("Purify.xml") )
  2215. {
  2216. files.push_back("Purify.xml");
  2217. }
  2218. if ( this->CTestFileExists("Notes.xml") )
  2219. {
  2220. files.push_back("Notes.xml");
  2221. }
  2222. cmCTestSubmit submit;
  2223. submit.SetVerbose(m_Verbose);
  2224. if ( m_DartConfiguration["DropMethod"] == "" ||
  2225. m_DartConfiguration["DropMethod"] == "ftp" )
  2226. {
  2227. std::cout << " Using FTP submit method" << std::endl;
  2228. std::string url = "ftp://";
  2229. url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
  2230. cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
  2231. m_DartConfiguration["DropSite"] +
  2232. cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
  2233. if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
  2234. files, prefix, url) )
  2235. {
  2236. std::cerr << " Problems when submitting via FTP" << std::endl;
  2237. return 0;
  2238. }
  2239. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  2240. {
  2241. std::cerr << " Problems when triggering via HTTP" << std::endl;
  2242. return 0;
  2243. }
  2244. std::cout << " Submission successfull" << std::endl;
  2245. return 1;
  2246. }
  2247. else if ( m_DartConfiguration["DropMethod"] == "http" )
  2248. {
  2249. std::cout << " Using HTTP submit method" << std::endl;
  2250. std::string url = "http://";
  2251. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  2252. {
  2253. url += m_DartConfiguration["DropSiteUser"];
  2254. if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
  2255. {
  2256. url += ":" + m_DartConfiguration["DropSitePassword"];
  2257. }
  2258. url += "@";
  2259. }
  2260. url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
  2261. if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  2262. {
  2263. std::cerr << " Problems when submitting via HTTP" << std::endl;
  2264. return 0;
  2265. }
  2266. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  2267. {
  2268. std::cerr << " Problems when triggering via HTTP" << std::endl;
  2269. return 0;
  2270. }
  2271. std::cout << " Submission successfull" << std::endl;
  2272. return 1;
  2273. }
  2274. else
  2275. {
  2276. std::cerr << "SCP submit not yet implemented" << std::endl;
  2277. }
  2278. return 0;
  2279. }
  2280. bool cmCTest::CTestFileExists(const std::string& filename)
  2281. {
  2282. std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
  2283. filename;
  2284. return cmSystemTools::FileExists(testingDir.c_str());
  2285. }
  2286. std::string cmCTest::GetSubmitResultsPrefix()
  2287. {
  2288. std::string name = m_DartConfiguration["Site"] +
  2289. "___" + m_DartConfiguration["BuildName"] +
  2290. "___" + m_CurrentTag + "-" +
  2291. this->GetTestModelString() + "___XML___";
  2292. return name;
  2293. }
  2294. void cmCTest::GenerateDartMemCheckOutput(std::ostream& os)
  2295. {
  2296. if ( !m_DartMode )
  2297. {
  2298. return;
  2299. }
  2300. this->StartXML(os);
  2301. if ( m_CompatibilityMode )
  2302. {
  2303. os << "<Purify>" << std::endl;
  2304. }
  2305. else
  2306. {
  2307. os << "<MemCheck>" << std::endl;
  2308. }
  2309. os << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2310. << "\t<TestList>\n";
  2311. tm_TestResultsVector::size_type cc;
  2312. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2313. {
  2314. cmCTestTestResult *result = &m_TestResults[cc];
  2315. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2316. << "/" << this->MakeXMLSafe(result->m_Name)
  2317. << "</Test>" << std::endl;
  2318. }
  2319. os << "\t</TestList>\n";
  2320. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2321. {
  2322. cmCTestTestResult *result = &m_TestResults[cc];
  2323. std::string memcheckstr;
  2324. int memcheckresults[cmCTest::NO_MEMORY_FAULT];
  2325. int kk;
  2326. this->ProcessMemCheckOutput(result->m_Output, memcheckstr, memcheckresults);
  2327. os << "\t<Test Status=\"";
  2328. if ( result->m_Status == cmCTest::COMPLETED )
  2329. {
  2330. os << "passed";
  2331. }
  2332. else if ( result->m_Status == cmCTest::NOT_RUN )
  2333. {
  2334. os << "notrun";
  2335. }
  2336. else
  2337. {
  2338. os << "failed";
  2339. }
  2340. os << "\">\n"
  2341. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2342. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2343. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2344. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2345. << "\t\t<FullCommandLine>"
  2346. << this->MakeXMLSafe(result->m_FullCommandLine)
  2347. << "</FullCommandLine>\n"
  2348. << "\t\t<Results>" << std::endl;
  2349. for ( kk = 0; cmCTestMemCheckResultStrings[kk]; kk ++ )
  2350. {
  2351. os << "\t\t\t<" << cmCTestMemCheckResultStrings[kk] << ">"
  2352. << memcheckresults[kk]
  2353. << "</" << cmCTestMemCheckResultStrings[kk] << ">" << std::endl;
  2354. m_MemoryTesterGlobalResults[kk] += memcheckresults[kk];
  2355. }
  2356. os
  2357. << "\t\t</Results>\n"
  2358. << "\t<Log>\n" << memcheckstr << std::endl
  2359. << "\t</Log>\n"
  2360. << "\t</Test>" << std::endl;
  2361. }
  2362. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>" << std::endl;
  2363. if ( m_CompatibilityMode )
  2364. {
  2365. os << "</Purify>" << std::endl;
  2366. }
  2367. else
  2368. {
  2369. os << "</MemCheck>" << std::endl;
  2370. }
  2371. this->EndXML(os);
  2372. std::cerr << "Memory checking results:" << std::endl;
  2373. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  2374. {
  2375. std::cerr << "\t\t" << cmCTestMemCheckResultStrings[cc] << " - "
  2376. << m_MemoryTesterGlobalResults[cc] << std::endl;
  2377. }
  2378. }
  2379. void cmCTest::GenerateDartTestOutput(std::ostream& os)
  2380. {
  2381. if ( !m_DartMode )
  2382. {
  2383. return;
  2384. }
  2385. this->StartXML(os);
  2386. os << "<Testing>\n"
  2387. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2388. << "\t<TestList>\n";
  2389. tm_TestResultsVector::size_type cc;
  2390. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2391. {
  2392. cmCTestTestResult *result = &m_TestResults[cc];
  2393. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2394. << "/" << this->MakeXMLSafe(result->m_Name)
  2395. << "</Test>" << std::endl;
  2396. }
  2397. os << "\t</TestList>\n";
  2398. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2399. {
  2400. cmCTestTestResult *result = &m_TestResults[cc];
  2401. os << "\t<Test Status=\"";
  2402. if ( result->m_Status == cmCTest::COMPLETED )
  2403. {
  2404. os << "passed";
  2405. }
  2406. else if ( result->m_Status == cmCTest::NOT_RUN )
  2407. {
  2408. os << "notrun";
  2409. }
  2410. else
  2411. {
  2412. os << "failed";
  2413. }
  2414. os << "\">\n"
  2415. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2416. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2417. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2418. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2419. << "\t\t<FullCommandLine>"
  2420. << this->MakeXMLSafe(result->m_FullCommandLine)
  2421. << "</FullCommandLine>\n"
  2422. << "\t\t<Results>" << std::endl;
  2423. if ( result->m_Status != cmCTest::NOT_RUN )
  2424. {
  2425. if ( result->m_Status != cmCTest::COMPLETED || result->m_ReturnValue )
  2426. {
  2427. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  2428. << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
  2429. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  2430. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  2431. }
  2432. os << result->m_RegressionImages;
  2433. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  2434. << "name=\"Execution Time\"><Value>"
  2435. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
  2436. os
  2437. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  2438. << "name=\"Completion Status\"><Value>"
  2439. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
  2440. }
  2441. os
  2442. << "\t\t\t<Measurement>\n"
  2443. << "\t\t\t\t<Value>" << this->MakeXMLSafe(result->m_Output)
  2444. << "</Value>\n"
  2445. << "\t\t\t</Measurement>\n"
  2446. << "\t\t</Results>\n"
  2447. << "\t</Test>" << std::endl;
  2448. }
  2449. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  2450. << "</Testing>" << std::endl;
  2451. this->EndXML(os);
  2452. }
  2453. int cmCTest::ProcessTests()
  2454. {
  2455. int res = 0;
  2456. bool notest = true;
  2457. int cc;
  2458. int update_count = 0;
  2459. for ( cc = 0; cc < LAST_TEST; cc ++ )
  2460. {
  2461. if ( m_Tests[cc] )
  2462. {
  2463. notest = false;
  2464. break;
  2465. }
  2466. }
  2467. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  2468. {
  2469. update_count = this->UpdateDirectory();
  2470. if ( update_count < 0 )
  2471. {
  2472. res |= CTEST_UPDATE_ERRORS;
  2473. }
  2474. }
  2475. if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
  2476. {
  2477. return 0;
  2478. }
  2479. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  2480. {
  2481. if (this->ConfigureDirectory())
  2482. {
  2483. res |= CTEST_CONFIGURE_ERRORS;
  2484. }
  2485. }
  2486. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  2487. {
  2488. this->UpdateCTestConfiguration();
  2489. if (this->BuildDirectory())
  2490. {
  2491. res |= CTEST_BUILD_ERRORS;
  2492. }
  2493. }
  2494. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  2495. {
  2496. this->UpdateCTestConfiguration();
  2497. if (this->TestDirectory(false))
  2498. {
  2499. res |= CTEST_TEST_ERRORS;
  2500. }
  2501. }
  2502. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  2503. {
  2504. this->UpdateCTestConfiguration();
  2505. this->CoverageDirectory();
  2506. }
  2507. if ( m_Tests[MEMCHECK_TEST] || m_Tests[ALL_TEST] )
  2508. {
  2509. this->UpdateCTestConfiguration();
  2510. if (this->TestDirectory(true))
  2511. {
  2512. res |= CTEST_MEMORY_ERRORS;
  2513. }
  2514. }
  2515. if ( m_Tests[NOTES_TEST] || m_Tests[ALL_TEST] )
  2516. {
  2517. this->UpdateCTestConfiguration();
  2518. if ( m_NotesFiles.size() )
  2519. {
  2520. this->GenerateNotesFile(m_NotesFiles.c_str());
  2521. }
  2522. }
  2523. if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
  2524. {
  2525. this->UpdateCTestConfiguration();
  2526. this->SubmitResults();
  2527. }
  2528. return res;
  2529. }
  2530. std::string cmCTest::GetTestModelString()
  2531. {
  2532. switch ( m_TestModel )
  2533. {
  2534. case cmCTest::NIGHTLY:
  2535. return "Nightly";
  2536. case cmCTest::CONTINUOUS:
  2537. return "Continuous";
  2538. }
  2539. return "Experimental";
  2540. }
  2541. int cmCTest::GetTestModelFromString(const char* str)
  2542. {
  2543. if ( !str )
  2544. {
  2545. return cmCTest::EXPERIMENTAL;
  2546. }
  2547. std::string rstr = cmSystemTools::LowerCase(str);
  2548. if ( strncmp(rstr.c_str(), "cont", 4) == 0 )
  2549. {
  2550. return cmCTest::CONTINUOUS;
  2551. }
  2552. if ( strncmp(rstr.c_str(), "nigh", 4) == 0 )
  2553. {
  2554. return cmCTest::NIGHTLY;
  2555. }
  2556. return cmCTest::EXPERIMENTAL;
  2557. }
  2558. #define SPACE_REGEX "[ \t\r\n]"
  2559. std::string cmCTest::GenerateRegressionImages(const std::string& xml)
  2560. {
  2561. cmsys::RegularExpression twoattributes(
  2562. "<DartMeasurement"
  2563. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2564. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2565. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2566. cmsys::RegularExpression threeattributes(
  2567. "<DartMeasurement"
  2568. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2569. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2570. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2571. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2572. cmsys::RegularExpression fourattributes(
  2573. "<DartMeasurement"
  2574. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2575. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2576. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2577. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2578. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2579. cmsys::RegularExpression measurementfile(
  2580. "<DartMeasurementFile"
  2581. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2582. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2583. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  2584. cmOStringStream ostr;
  2585. bool done = false;
  2586. std::string cxml = xml;
  2587. while ( ! done )
  2588. {
  2589. if ( twoattributes.find(cxml) )
  2590. {
  2591. ostr
  2592. << "\t\t\t<NamedMeasurement"
  2593. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  2594. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  2595. << "><Value>" << twoattributes.match(5)
  2596. << "</Value></NamedMeasurement>"
  2597. << std::endl;
  2598. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  2599. }
  2600. else if ( threeattributes.find(cxml) )
  2601. {
  2602. ostr
  2603. << "\t\t\t<NamedMeasurement"
  2604. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  2605. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  2606. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  2607. << "><Value>" << threeattributes.match(7)
  2608. << "</Value></NamedMeasurement>"
  2609. << std::endl;
  2610. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  2611. }
  2612. else if ( fourattributes.find(cxml) )
  2613. {
  2614. ostr
  2615. << "\t\t\t<NamedMeasurement"
  2616. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  2617. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  2618. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  2619. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  2620. << "><Value>" << fourattributes.match(9)
  2621. << "</Value></NamedMeasurement>"
  2622. << std::endl;
  2623. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  2624. }
  2625. else if ( measurementfile.find(cxml) )
  2626. {
  2627. const std::string& filename = ::CleanString(measurementfile.match(5));
  2628. if ( cmSystemTools::FileExists(filename.c_str()) )
  2629. {
  2630. long len = cmSystemTools::FileLength(filename.c_str());
  2631. std::ifstream ifs(filename.c_str(), std::ios::in
  2632. #ifdef _WIN32
  2633. | std::ios::binary
  2634. #endif
  2635. );
  2636. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  2637. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  2638. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 1) ];
  2639. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  2640. unsigned long cc;
  2641. ostr
  2642. << "\t\t\t<NamedMeasurement"
  2643. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  2644. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  2645. << " encoding=\"base64\""
  2646. << ">" << std::endl << "\t\t\t\t<Value>";
  2647. for ( cc = 0; cc < rlen; cc ++ )
  2648. {
  2649. ostr << encoded_buffer[cc];
  2650. if ( cc % 60 == 0 && cc )
  2651. {
  2652. ostr << std::endl;
  2653. }
  2654. }
  2655. ostr
  2656. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  2657. << std::endl;
  2658. delete [] file_buffer;
  2659. delete [] encoded_buffer;
  2660. }
  2661. else
  2662. {
  2663. int idx = 4;
  2664. if ( measurementfile.match(1) == "name" )
  2665. {
  2666. idx = 2;
  2667. }
  2668. ostr
  2669. << "\t\t\t<NamedMeasurement"
  2670. << " name=\"" << measurementfile.match(idx) << "\""
  2671. << " text=\"text/string\""
  2672. << "><Value>File " << filename << " not found</Value></NamedMeasurement>"
  2673. << std::endl;
  2674. std::cout << "File \"" << filename.c_str() << "\" not found." << std::endl;
  2675. }
  2676. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  2677. }
  2678. else
  2679. {
  2680. done = true;
  2681. }
  2682. }
  2683. return ostr.str();
  2684. }
  2685. int cmCTest::RunMakeCommand(const char* command, std::string* output,
  2686. int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
  2687. {
  2688. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  2689. if(args.size() < 1)
  2690. {
  2691. return false;
  2692. }
  2693. std::vector<const char*> argv;
  2694. for(std::vector<cmStdString>::const_iterator a = args.begin();
  2695. a != args.end(); ++a)
  2696. {
  2697. argv.push_back(a->c_str());
  2698. }
  2699. argv.push_back(0);
  2700. if ( output )
  2701. {
  2702. *output = "";
  2703. }
  2704. cmsysProcess* cp = cmsysProcess_New();
  2705. cmsysProcess_SetCommand(cp, &*argv.begin());
  2706. cmsysProcess_SetWorkingDirectory(cp, dir);
  2707. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2708. cmsysProcess_SetTimeout(cp, timeout);
  2709. cmsysProcess_Execute(cp);
  2710. std::string::size_type tick = 0;
  2711. std::string::size_type tick_len = 1024;
  2712. std::string::size_type tick_line_len = 50;
  2713. char* data;
  2714. int length;
  2715. if ( !verbose )
  2716. {
  2717. std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
  2718. std::cout << " " << std::flush;
  2719. }
  2720. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  2721. {
  2722. if ( output )
  2723. {
  2724. for(int cc =0; cc < length; ++cc)
  2725. {
  2726. if(data[cc] == 0)
  2727. {
  2728. data[cc] = '\n';
  2729. }
  2730. }
  2731. output->append(data, length);
  2732. if ( !verbose )
  2733. {
  2734. while ( output->size() > (tick * tick_len) )
  2735. {
  2736. tick ++;
  2737. std::cout << "." << std::flush;
  2738. if ( tick % tick_line_len == 0 && tick > 0 )
  2739. {
  2740. std::cout << " Size: ";
  2741. std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl;
  2742. std::cout << " " << std::flush;
  2743. }
  2744. }
  2745. }
  2746. }
  2747. if(verbose)
  2748. {
  2749. std::cout.write(data, length);
  2750. std::cout.flush();
  2751. }
  2752. if ( ofs )
  2753. {
  2754. ofs.write(data, length);
  2755. ofs.flush();
  2756. }
  2757. }
  2758. std::cout << " Size of output: ";
  2759. std::cout << int(output->size() / 1024.0) << "K" << std::endl;
  2760. cmsysProcess_WaitForExit(cp, 0);
  2761. int result = cmsysProcess_GetState(cp);
  2762. if(result == cmsysProcess_State_Exited)
  2763. {
  2764. *retVal = cmsysProcess_GetExitValue(cp);
  2765. }
  2766. else if(result == cmsysProcess_State_Exception)
  2767. {
  2768. *retVal = cmsysProcess_GetExitException(cp);
  2769. std::cout << "There was an exception: " << *retVal << std::endl;
  2770. }
  2771. else if(result == cmsysProcess_State_Expired)
  2772. {
  2773. std::cout << "There was a timeout" << std::endl;
  2774. }
  2775. else if(result == cmsysProcess_State_Error)
  2776. {
  2777. *output += "\n*** ERROR executing: ";
  2778. *output += cmsysProcess_GetErrorString(cp);
  2779. }
  2780. cmsysProcess_Delete(cp);
  2781. return result;
  2782. }
  2783. int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *retVal,
  2784. std::ostream* log)
  2785. {
  2786. if(cmSystemTools::SameFile(argv[0], m_CTestSelf.c_str()))
  2787. {
  2788. cmCTest inst;
  2789. std::vector<std::string> args;
  2790. for(unsigned int i =0; i < argv.size(); ++i)
  2791. {
  2792. if(argv[i])
  2793. {
  2794. args.push_back(argv[i]);
  2795. }
  2796. }
  2797. if ( *log )
  2798. {
  2799. *log << "* Run internal CTest" << std::endl;
  2800. }
  2801. std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
  2802. *retVal = inst.Run(args, output);
  2803. if ( *log )
  2804. {
  2805. *log << output->c_str();
  2806. }
  2807. cmSystemTools::ChangeDirectory(oldpath.c_str());
  2808. if(m_Verbose)
  2809. {
  2810. std::cout << "Internal cmCTest object used to run test.\n";
  2811. std::cout << *output << "\n";
  2812. }
  2813. return cmsysProcess_State_Exited;
  2814. }
  2815. std::vector<char> tempOutput;
  2816. if ( output )
  2817. {
  2818. *output = "";
  2819. }
  2820. cmsysProcess* cp = cmsysProcess_New();
  2821. cmsysProcess_SetCommand(cp, &*argv.begin());
  2822. // std::cout << "Command is: " << argv[0] << std::endl;
  2823. if(cmSystemTools::GetRunCommandHideConsole())
  2824. {
  2825. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2826. }
  2827. cmsysProcess_SetTimeout(cp, m_TimeOut);
  2828. cmsysProcess_Execute(cp);
  2829. char* data;
  2830. int length;
  2831. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  2832. {
  2833. if ( output )
  2834. {
  2835. tempOutput.insert(tempOutput.end(), data, data+length);
  2836. }
  2837. if ( m_Verbose )
  2838. {
  2839. std::cout.write(data, length);
  2840. std::cout.flush();
  2841. }
  2842. if ( log )
  2843. {
  2844. log->write(data, length);
  2845. log->flush();
  2846. }
  2847. }
  2848. cmsysProcess_WaitForExit(cp, 0);
  2849. if(output)
  2850. {
  2851. output->append(&*tempOutput.begin(), tempOutput.size());
  2852. }
  2853. int result = cmsysProcess_GetState(cp);
  2854. if(result == cmsysProcess_State_Exited)
  2855. {
  2856. *retVal = cmsysProcess_GetExitValue(cp);
  2857. }
  2858. else if(result == cmsysProcess_State_Exception)
  2859. {
  2860. *retVal = cmsysProcess_GetExitException(cp);
  2861. std::string outerr = "\n*** Exception executing: ";
  2862. outerr += cmsysProcess_GetExceptionString(cp);
  2863. *output += outerr;
  2864. if ( m_Verbose )
  2865. {
  2866. std::cout << outerr.c_str() << "\n";
  2867. std::cout.flush();
  2868. }
  2869. }
  2870. else if(result == cmsysProcess_State_Error)
  2871. {
  2872. std::string outerr = "\n*** ERROR executing: ";
  2873. outerr += cmsysProcess_GetErrorString(cp);
  2874. *output += outerr;
  2875. if ( m_Verbose )
  2876. {
  2877. std::cout << outerr.c_str() << "\n";
  2878. std::cout.flush();
  2879. }
  2880. }
  2881. cmsysProcess_Delete(cp);
  2882. return result;
  2883. }
  2884. const char* cmCTest::GetTestStatus(int status)
  2885. {
  2886. static const char statuses[][100] = {
  2887. "Not Run",
  2888. "Timeout",
  2889. "SEGFAULT",
  2890. "ILLEGAL",
  2891. "INTERRUPT",
  2892. "NUMERICAL",
  2893. "OTHER_FAULT",
  2894. "Failed",
  2895. "BAD_COMMAND",
  2896. "Completed"
  2897. };
  2898. if ( status < cmCTest::NOT_RUN || status > cmCTest::COMPLETED )
  2899. {
  2900. return "No Status";
  2901. }
  2902. return statuses[status];
  2903. }
  2904. void cmCTest::RestoreBackupDirectories(bool backup,
  2905. const char *srcDir,
  2906. const char *binDir,
  2907. const char *backupSrcDir,
  2908. const char *backupBinDir)
  2909. {
  2910. // if we backed up the dirs and the build failed, then restore
  2911. // the backed up dirs
  2912. if (backup)
  2913. {
  2914. // if for some reason those directories exist then first delete them
  2915. if (cmSystemTools::FileExists(srcDir))
  2916. {
  2917. cmSystemTools::RemoveADirectory(srcDir);
  2918. }
  2919. if (cmSystemTools::FileExists(binDir))
  2920. {
  2921. cmSystemTools::RemoveADirectory(binDir);
  2922. }
  2923. // rename the src and binary directories
  2924. rename(backupSrcDir, srcDir);
  2925. rename(backupBinDir, binDir);
  2926. }
  2927. }
  2928. int cmCTest::RunConfigurationScript()
  2929. {
  2930. m_ConfigurationScript =
  2931. cmSystemTools::CollapseFullPath(m_ConfigurationScript.c_str());
  2932. // make sure the file exists
  2933. if (!cmSystemTools::FileExists(m_ConfigurationScript.c_str()))
  2934. {
  2935. return 1;
  2936. }
  2937. // create a cmake instance to read the configuration script
  2938. cmake cm;
  2939. cmGlobalGenerator gg;
  2940. gg.SetCMakeInstance(&cm);
  2941. // read in the list file to fill the cache
  2942. cmLocalGenerator *lg = gg.CreateLocalGenerator();
  2943. lg->SetGlobalGenerator(&gg);
  2944. // set a variable with the path to the current script
  2945. lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_DIRECTORY",
  2946. cmSystemTools::GetFilenamePath(
  2947. m_ConfigurationScript).c_str());
  2948. lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_NAME",
  2949. cmSystemTools::GetFilenameName(
  2950. m_ConfigurationScript).c_str());
  2951. if (!lg->GetMakefile()->ReadListFile(0, m_ConfigurationScript.c_str()))
  2952. {
  2953. return 2;
  2954. }
  2955. // no popup widows
  2956. cmSystemTools::SetRunCommandHideConsole(true);
  2957. // get some info that should be set
  2958. cmMakefile *mf = lg->GetMakefile();
  2959. const char *srcDir = mf->GetDefinition("CTEST_SOURCE_DIRECTORY");
  2960. const char *binDir = mf->GetDefinition("CTEST_BINARY_DIRECTORY");
  2961. const char *ctestCmd = mf->GetDefinition("CTEST_COMMAND");
  2962. const char *ctestEnv = mf->GetDefinition("CTEST_ENVIRONMENT");
  2963. const char *ctestRoot = mf->GetDefinition("CTEST_DASHBOARD_ROOT");
  2964. bool backup = mf->IsOn("CTEST_BACKUP_AND_RESTORE");
  2965. // in order to back we also must have the cvs root
  2966. const char *cvsCmd = mf->GetDefinition("CTEST_CVS_COMMAND");
  2967. const char *cvsCheckOut = mf->GetDefinition("CTEST_CVS_CHECKOUT");
  2968. if (backup && !cvsCheckOut)
  2969. {
  2970. cmSystemTools::Error("Backup was requested without a cvs checkout");
  2971. return 3;
  2972. }
  2973. // make sure the required info is here
  2974. if (!srcDir || !binDir || !ctestCmd)
  2975. {
  2976. cmSystemTools::Error("Some required settings in the configuration file were missing");
  2977. return 4;
  2978. }
  2979. // set any environment variables
  2980. if (ctestEnv)
  2981. {
  2982. std::vector<std::string> envArgs;
  2983. cmSystemTools::ExpandListArgument(ctestEnv,envArgs);
  2984. // for each variable/argument do a putenv
  2985. for (unsigned i = 0; i < envArgs.size(); ++i)
  2986. {
  2987. cmSystemTools::PutEnv(envArgs[i].c_str());
  2988. }
  2989. }
  2990. // local variables
  2991. std::string command;
  2992. std::string output;
  2993. int retVal = 0;
  2994. bool res;
  2995. // compute the backup names
  2996. std::string backupSrcDir = srcDir;
  2997. backupSrcDir += "_CMakeBackup";
  2998. std::string backupBinDir = binDir;
  2999. backupBinDir += "_CMakeBackup";
  3000. // backup the binary and src directories if requested
  3001. if (backup)
  3002. {
  3003. // if for some reason those directories exist then first delete them
  3004. if (cmSystemTools::FileExists(backupSrcDir.c_str()))
  3005. {
  3006. cmSystemTools::RemoveADirectory(backupSrcDir.c_str());
  3007. }
  3008. if (cmSystemTools::FileExists(backupBinDir.c_str()))
  3009. {
  3010. cmSystemTools::RemoveADirectory(backupBinDir.c_str());
  3011. }
  3012. // first rename the src and binary directories
  3013. rename(srcDir, backupSrcDir.c_str());
  3014. rename(binDir, backupBinDir.c_str());
  3015. // we must now checkout the src dir
  3016. output = "";
  3017. res = cmSystemTools::RunSingleCommand(cvsCheckOut, &output,
  3018. &retVal, ctestRoot,
  3019. m_Verbose, 0 /*m_TimeOut*/);
  3020. if (!res || retVal != 0)
  3021. {
  3022. cmSystemTools::Error("Unable to perform cvs checkout ");
  3023. this->RestoreBackupDirectories(backup, srcDir, binDir,
  3024. backupSrcDir.c_str(),
  3025. backupBinDir.c_str());
  3026. return 6;
  3027. }
  3028. }
  3029. // clear the binary directory?
  3030. if (mf->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY"))
  3031. {
  3032. // try to avoid deleting directories that we shouldn't
  3033. std::string check = binDir;
  3034. check += "/CMakeCache.txt";
  3035. if (cmSystemTools::FileExists(check.c_str()))
  3036. {
  3037. cmSystemTools::RemoveADirectory(binDir);
  3038. }
  3039. }
  3040. // make sure the binary directory exists
  3041. if (!cmSystemTools::FileExists(binDir))
  3042. {
  3043. if (!cmSystemTools::MakeDirectory(binDir))
  3044. {
  3045. cmSystemTools::Error("Unable to create the binary directory");
  3046. this->RestoreBackupDirectories(backup, srcDir, binDir,
  3047. backupSrcDir.c_str(),
  3048. backupBinDir.c_str());
  3049. return 7;
  3050. }
  3051. }
  3052. // do an initial cvs update as required
  3053. if (cvsCmd)
  3054. {
  3055. command = cvsCmd;
  3056. char updateVar[40];
  3057. int i;
  3058. for (i = 1; i < 10; ++i)
  3059. {
  3060. sprintf(updateVar,"CTEST_EXTRA_UPDATES_%i",i);
  3061. const char *updateVal = mf->GetDefinition(updateVar);
  3062. if (updateVal)
  3063. {
  3064. std::vector<std::string> cvsArgs;
  3065. cmSystemTools::ExpandListArgument(updateVal,cvsArgs);
  3066. if (cvsArgs.size() == 2)
  3067. {
  3068. std::string fullCommand = command;
  3069. fullCommand += " update ";
  3070. fullCommand += cvsArgs[1];
  3071. output = "";
  3072. retVal = 0;
  3073. res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output,
  3074. &retVal, cvsArgs[0].c_str(),
  3075. m_Verbose, 0 /*m_TimeOut*/);
  3076. if (!res || retVal != 0)
  3077. {
  3078. cmSystemTools::Error("Unable to perform extra cvs updates");
  3079. this->RestoreBackupDirectories(backup, srcDir, binDir,
  3080. backupSrcDir.c_str(),
  3081. backupBinDir.c_str());
  3082. return 8;
  3083. }
  3084. }
  3085. }
  3086. }
  3087. }
  3088. // put the initial cache into the bin dir
  3089. if (mf->GetDefinition("CTEST_INITIAL_CACHE"))
  3090. {
  3091. const char *initCache = mf->GetDefinition("CTEST_INITIAL_CACHE");
  3092. std::string cacheFile = binDir;
  3093. cacheFile += "/CMakeCache.txt";
  3094. std::ofstream fout(cacheFile.c_str());
  3095. if(!fout)
  3096. {
  3097. this->RestoreBackupDirectories(backup, srcDir, binDir,
  3098. backupSrcDir.c_str(),
  3099. backupBinDir.c_str());
  3100. return 9;
  3101. }
  3102. fout.write(initCache, strlen(initCache));
  3103. // Make sure the operating system has finished writing the file
  3104. // before closing it. This will ensure the file is finished before
  3105. // the check below.
  3106. fout.flush();
  3107. fout.close();
  3108. }
  3109. // do an initial cmake to setup the DartConfig file
  3110. const char *cmakeCmd = mf->GetDefinition("CTEST_CMAKE_COMMAND");
  3111. int cmakeFailed = 0;
  3112. if (cmakeCmd)
  3113. {
  3114. command = cmakeCmd;
  3115. command += " \"";
  3116. command += srcDir;
  3117. output = "";
  3118. command += "\"";
  3119. retVal = 0;
  3120. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  3121. &retVal, binDir,
  3122. m_Verbose, 0 /*m_TimeOut*/);
  3123. if (!res || retVal != 0)
  3124. {
  3125. // even if this fails continue to the next step
  3126. cmakeFailed = 1;
  3127. }
  3128. }
  3129. // run ctest
  3130. command = ctestCmd;
  3131. output = "";
  3132. retVal = 0;
  3133. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  3134. &retVal, binDir,
  3135. m_Verbose, 0 /*m_TimeOut*/);
  3136. // did something critical fail in ctest
  3137. if (!res || cmakeFailed ||
  3138. retVal & CTEST_BUILD_ERRORS)
  3139. {
  3140. this->RestoreBackupDirectories(backup, srcDir, binDir,
  3141. backupSrcDir.c_str(),
  3142. backupBinDir.c_str());
  3143. if (cmakeFailed)
  3144. {
  3145. cmSystemTools::Error("Unable to run cmake");
  3146. return 10;
  3147. }
  3148. cmSystemTools::Error("Unable to run ctest");
  3149. if (!res)
  3150. {
  3151. return 11;
  3152. }
  3153. return retVal * 100;
  3154. }
  3155. // if all was succesful, delete the backup dirs to free up disk space
  3156. if (backup)
  3157. {
  3158. cmSystemTools::RemoveADirectory(backupSrcDir.c_str());
  3159. cmSystemTools::RemoveADirectory(backupBinDir.c_str());
  3160. }
  3161. return 0;
  3162. }
  3163. void cmCTest::StartXML(std::ostream& ostr)
  3164. {
  3165. ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  3166. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  3167. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  3168. << this->GetTestModelString() << "\" Name=\""
  3169. << m_DartConfiguration["Site"] << "\" Generator=\"ctest\">" << std::endl;
  3170. }
  3171. void cmCTest::EndXML(std::ostream& ostr)
  3172. {
  3173. ostr << "</Site>" << std::endl;
  3174. }
  3175. bool cmCTest::ProcessMemCheckPurifyOutput(const std::string&, std::string& log,
  3176. int* results)
  3177. {
  3178. if ( !cmSystemTools::FileExists(m_MemoryTesterOutputFile.c_str()) )
  3179. {
  3180. log = "Cannot find Purify output file: " + m_MemoryTesterOutputFile;
  3181. std::cerr << log.c_str() << std::endl;
  3182. return false;
  3183. }
  3184. std::ifstream ifs(m_MemoryTesterOutputFile.c_str());
  3185. if ( !ifs )
  3186. {
  3187. log = "Cannot read Purify output file: " + m_MemoryTesterOutputFile;
  3188. std::cerr << log.c_str() << std::endl;
  3189. return false;
  3190. }
  3191. cmOStringStream ostr;
  3192. log = "";
  3193. cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
  3194. std::string line;
  3195. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  3196. {
  3197. int failure = cmCTest::NO_MEMORY_FAULT;
  3198. if ( pfW.find(line) )
  3199. {
  3200. int cc;
  3201. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  3202. {
  3203. if ( pfW.match(1) == cmCTestMemCheckResultStrings[cc] )
  3204. {
  3205. failure = cc;
  3206. break;
  3207. }
  3208. }
  3209. if ( cc == cmCTest::NO_MEMORY_FAULT )
  3210. {
  3211. std::cerr<< "Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  3212. ostr << "*** Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  3213. }
  3214. }
  3215. if ( failure != NO_MEMORY_FAULT )
  3216. {
  3217. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  3218. results[failure] ++;
  3219. }
  3220. ostr << cmCTest::MakeXMLSafe(line) << std::endl;
  3221. }
  3222. log = ostr.str();
  3223. return true;
  3224. }
  3225. bool cmCTest::ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
  3226. int* results)
  3227. {
  3228. std::vector<cmStdString> lines;
  3229. cmSystemTools::Split(str.c_str(), lines);
  3230. std::string::size_type cc;
  3231. cmOStringStream ostr;
  3232. log = "";
  3233. cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
  3234. cmsys::RegularExpression vgFIM(
  3235. "== .*Invalid free\\(\\) / delete / delete\\[\\]");
  3236. cmsys::RegularExpression vgFMM(
  3237. "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
  3238. cmsys::RegularExpression vgMLK(
  3239. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are definitely lost"
  3240. " in loss record [0-9][0-9]* of [0-9]");
  3241. cmsys::RegularExpression vgPAR(
  3242. "== .*Syscall param .* contains unaddressable byte\\(s\\)");
  3243. cmsys::RegularExpression vgMPK1(
  3244. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are possibly lost in"
  3245. " loss record [0-9][0-9]* of [0-9]");
  3246. cmsys::RegularExpression vgMPK2(
  3247. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are still reachable"
  3248. " in loss record [0-9][0-9]* of [0-9]");
  3249. cmsys::RegularExpression vgUMC(
  3250. "== .*Conditional jump or move depends on uninitialised value\\(s\\)");
  3251. cmsys::RegularExpression vgUMR1("== .*Use of uninitialised value of size [0-9][0-9]*");
  3252. cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9][0-9]*");
  3253. cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
  3254. cmsys::RegularExpression vgUMR4(
  3255. "== .*Syscall param .* contains uninitialised or unaddressable byte\\(s\\)");
  3256. cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9]");
  3257. for ( cc = 0; cc < lines.size(); cc ++ )
  3258. {
  3259. if ( valgrindLine.find(lines[cc]) )
  3260. {
  3261. int failure = cmCTest::NO_MEMORY_FAULT;
  3262. if ( vgFIM.find(lines[cc]) ) { failure = cmCTest::FIM; }
  3263. else if ( vgFMM.find(lines[cc]) ) { failure = cmCTest::FMM; }
  3264. else if ( vgMLK.find(lines[cc]) ) { failure = cmCTest::MLK; }
  3265. else if ( vgPAR.find(lines[cc]) ) { failure = cmCTest::PAR; }
  3266. else if ( vgMPK1.find(lines[cc]) ){ failure = cmCTest::MPK; }
  3267. else if ( vgMPK2.find(lines[cc]) ){ failure = cmCTest::MPK; }
  3268. else if ( vgUMC.find(lines[cc]) ) { failure = cmCTest::UMC; }
  3269. else if ( vgUMR1.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3270. else if ( vgUMR2.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3271. else if ( vgUMR3.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3272. else if ( vgUMR4.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3273. else if ( vgIPW.find(lines[cc]) ) { failure = cmCTest::IPW; }
  3274. if ( failure != cmCTest::NO_MEMORY_FAULT )
  3275. {
  3276. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  3277. results[failure] ++;
  3278. }
  3279. ostr << cmCTest::MakeXMLSafe(lines[cc]) << std::endl;
  3280. }
  3281. }
  3282. log = ostr.str();
  3283. return true;
  3284. }
  3285. bool cmCTest::ProcessMemCheckOutput(const std::string& str, std::string& log, int* results)
  3286. {
  3287. std::string::size_type cc;
  3288. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  3289. {
  3290. results[cc] = 0;
  3291. }
  3292. if ( m_MemoryTesterStyle == cmCTest::VALGRIND )
  3293. {
  3294. return ProcessMemCheckValgrindOutput(str, log, results);
  3295. }
  3296. else if ( m_MemoryTesterStyle == cmCTest::PURIFY )
  3297. {
  3298. return ProcessMemCheckPurifyOutput(str, log, results);
  3299. }
  3300. else if ( m_MemoryTesterStyle == cmCTest::BOUNDS_CHECKER )
  3301. {
  3302. log.append("\nMemory checking style used was: ");
  3303. log.append("Bounds Checker");
  3304. }
  3305. else
  3306. {
  3307. log.append("\nMemory checking style used was: ");
  3308. log.append("None that I know");
  3309. log = str;
  3310. }
  3311. return true;
  3312. }
  3313. int cmCTest::GenerateDartNotesOutput(std::ostream& os, const cmCTest::tm_VectorOfStrings& files)
  3314. {
  3315. cmCTest::tm_VectorOfStrings::const_iterator it;
  3316. for ( it = files.begin(); it != files.end(); it ++ )
  3317. {
  3318. if ( !cmSystemTools::FileExists(it->c_str()) )
  3319. {
  3320. std::cerr << "Error creating notes. File " << it->c_str() << " does not exists" << std::endl;
  3321. return 0;
  3322. }
  3323. }
  3324. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  3325. << "<?xml-stylesheet type=\"text/xsl\" href=\"Dart/Source/Server/XSL/Build.xsl <file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
  3326. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"] << "\" BuildStamp=\""
  3327. << m_CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
  3328. << m_DartConfiguration["Site"] << "\" Generator=\"ctest\">\n"
  3329. << "<Notes>" << std::endl;
  3330. for ( it = files.begin(); it != files.end(); it ++ )
  3331. {
  3332. std::cout << "\tAdd file: " << it->c_str() << std::endl;
  3333. std::string note_time = ::CurrentTime();
  3334. os << "<Note>\n"
  3335. << "<DateTime>" << note_time << "</DateTime>\n"
  3336. << "<Text>" << std::endl;
  3337. std::ifstream ifs(it->c_str());
  3338. if ( ifs )
  3339. {
  3340. std::string line;
  3341. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  3342. {
  3343. os << this->MakeXMLSafe(line) << std::endl;
  3344. }
  3345. ifs.close();
  3346. }
  3347. else
  3348. {
  3349. os << "Problem reading file: " << it->c_str() << std::endl;
  3350. std::cerr << "Problem reading file: " << it->c_str() << " while creating notes" << std::endl;
  3351. }
  3352. os << "</Text>\n"
  3353. << "</Note>" << std::endl;
  3354. }
  3355. os << "</Notes>\n"
  3356. << "</Site>" << std::endl;
  3357. return 1;
  3358. }
  3359. int cmCTest::GenerateNotesFile(const char* cfiles)
  3360. {
  3361. if ( !cfiles )
  3362. {
  3363. return 1;
  3364. }
  3365. std::vector<cmStdString> files;
  3366. std::cout << "Create notes file" << std::endl;
  3367. files = cmSystemTools::SplitString(cfiles, ';');
  3368. if ( files.size() == 0 )
  3369. {
  3370. return 1;
  3371. }
  3372. std::ofstream ofs;
  3373. if ( !this->OpenOutputFile(m_CurrentTag, "Notes.xml", ofs) )
  3374. {
  3375. std::cerr << "Cannot open notes file" << std::endl;
  3376. return 1;
  3377. }
  3378. this->GenerateDartNotesOutput(ofs, files);
  3379. return 0;
  3380. }
  3381. int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
  3382. {
  3383. this->FindRunningCMake(args[0].c_str());
  3384. bool cmakeAndTest = false;
  3385. for(unsigned int i=1; i < args.size(); ++i)
  3386. {
  3387. std::string arg = args[i];
  3388. if(arg.find("-C",0) == 0 && i < args.size() - 1)
  3389. {
  3390. i++;
  3391. this->m_ConfigType = args[i];
  3392. }
  3393. if( arg.find("-V",0) == 0 || arg.find("--verbose",0) == 0 )
  3394. {
  3395. this->m_Verbose = true;
  3396. }
  3397. if( arg.find("-N",0) == 0 || arg.find("--show-only",0) == 0 )
  3398. {
  3399. this->m_ShowOnly = true;
  3400. }
  3401. if( arg.find("-S",0) == 0 && i < args.size() - 1 )
  3402. {
  3403. this->m_RunConfigurationScript = true;
  3404. i++;
  3405. this->m_ConfigurationScript = args[i];
  3406. }
  3407. if( arg.find("-D",0) == 0 && i < args.size() - 1 )
  3408. {
  3409. this->m_DartMode = true;
  3410. i++;
  3411. std::string targ = args[i];
  3412. if ( targ == "Experimental" )
  3413. {
  3414. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3415. this->SetTest("Start");
  3416. this->SetTest("Configure");
  3417. this->SetTest("Build");
  3418. this->SetTest("Test");
  3419. this->SetTest("Coverage");
  3420. this->SetTest("Submit");
  3421. }
  3422. else if ( targ == "ExperimentalStart" )
  3423. {
  3424. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3425. this->SetTest("Start");
  3426. }
  3427. else if ( targ == "ExperimentalUpdate" )
  3428. {
  3429. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3430. this->SetTest("Update");
  3431. }
  3432. else if ( targ == "ExperimentalConfigure" )
  3433. {
  3434. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3435. this->SetTest("Configure");
  3436. }
  3437. else if ( targ == "ExperimentalBuild" )
  3438. {
  3439. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3440. this->SetTest("Build");
  3441. }
  3442. else if ( targ == "ExperimentalTest" )
  3443. {
  3444. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3445. this->SetTest("Test");
  3446. }
  3447. else if ( targ == "ExperimentalMemCheck" || targ == "ExperimentalPurify" )
  3448. {
  3449. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3450. this->SetTest("MemCheck");
  3451. }
  3452. else if ( targ == "ExperimentalCoverage" )
  3453. {
  3454. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3455. this->SetTest("Coverage");
  3456. }
  3457. else if ( targ == "ExperimentalSubmit" )
  3458. {
  3459. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3460. this->SetTest("Submit");
  3461. }
  3462. else if ( targ == "Continuous" )
  3463. {
  3464. this->SetTestModel(cmCTest::CONTINUOUS);
  3465. this->SetTest("Start");
  3466. this->SetTest("Update");
  3467. this->SetTest("Configure");
  3468. this->SetTest("Build");
  3469. this->SetTest("Test");
  3470. this->SetTest("Coverage");
  3471. this->SetTest("Submit");
  3472. }
  3473. else if ( targ == "ContinuousStart" )
  3474. {
  3475. this->SetTestModel(cmCTest::CONTINUOUS);
  3476. this->SetTest("Start");
  3477. }
  3478. else if ( targ == "ContinuousUpdate" )
  3479. {
  3480. this->SetTestModel(cmCTest::CONTINUOUS);
  3481. this->SetTest("Update");
  3482. }
  3483. else if ( targ == "ContinuousConfigure" )
  3484. {
  3485. this->SetTestModel(cmCTest::CONTINUOUS);
  3486. this->SetTest("Configure");
  3487. }
  3488. else if ( targ == "ContinuousBuild" )
  3489. {
  3490. this->SetTestModel(cmCTest::CONTINUOUS);
  3491. this->SetTest("Build");
  3492. }
  3493. else if ( targ == "ContinuousTest" )
  3494. {
  3495. this->SetTestModel(cmCTest::CONTINUOUS);
  3496. this->SetTest("Test");
  3497. }
  3498. else if ( targ == "ContinuousMemCheck" || targ == "ContinuousPurify" )
  3499. {
  3500. this->SetTestModel(cmCTest::CONTINUOUS);
  3501. this->SetTest("MemCheck");
  3502. }
  3503. else if ( targ == "ContinuousCoverage" )
  3504. {
  3505. this->SetTestModel(cmCTest::CONTINUOUS);
  3506. this->SetTest("Coverage");
  3507. }
  3508. else if ( targ == "ContinuousSubmit" )
  3509. {
  3510. this->SetTestModel(cmCTest::CONTINUOUS);
  3511. this->SetTest("Submit");
  3512. }
  3513. else if ( targ == "Nightly" )
  3514. {
  3515. this->SetTestModel(cmCTest::NIGHTLY);
  3516. this->SetTest("Start");
  3517. this->SetTest("Update");
  3518. this->SetTest("Configure");
  3519. this->SetTest("Build");
  3520. this->SetTest("Test");
  3521. this->SetTest("Coverage");
  3522. this->SetTest("Submit");
  3523. }
  3524. else if ( targ == "NightlyStart" )
  3525. {
  3526. this->SetTestModel(cmCTest::NIGHTLY);
  3527. this->SetTest("Start");
  3528. }
  3529. else if ( targ == "NightlyUpdate" )
  3530. {
  3531. this->SetTestModel(cmCTest::NIGHTLY);
  3532. this->SetTest("Update");
  3533. }
  3534. else if ( targ == "NightlyConfigure" )
  3535. {
  3536. this->SetTestModel(cmCTest::NIGHTLY);
  3537. this->SetTest("Configure");
  3538. }
  3539. else if ( targ == "NightlyBuild" )
  3540. {
  3541. this->SetTestModel(cmCTest::NIGHTLY);
  3542. this->SetTest("Build");
  3543. }
  3544. else if ( targ == "NightlyTest" )
  3545. {
  3546. this->SetTestModel(cmCTest::NIGHTLY);
  3547. this->SetTest("Test");
  3548. }
  3549. else if ( targ == "NightlyMemCheck" || targ == "NightlyPurify" )
  3550. {
  3551. this->SetTestModel(cmCTest::NIGHTLY);
  3552. this->SetTest("MemCheck");
  3553. }
  3554. else if ( targ == "NightlyCoverage" )
  3555. {
  3556. this->SetTestModel(cmCTest::NIGHTLY);
  3557. this->SetTest("Coverage");
  3558. }
  3559. else if ( targ == "NightlySubmit" )
  3560. {
  3561. this->SetTestModel(cmCTest::NIGHTLY);
  3562. this->SetTest("Submit");
  3563. }
  3564. else if ( targ == "MemoryCheck" )
  3565. {
  3566. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3567. this->SetTest("Start");
  3568. this->SetTest("Configure");
  3569. this->SetTest("Build");
  3570. this->SetTest("MemCheck");
  3571. this->SetTest("Coverage");
  3572. this->SetTest("Submit");
  3573. }
  3574. else if ( targ == "NightlyMemoryCheck" )
  3575. {
  3576. this->SetTestModel(cmCTest::NIGHTLY);
  3577. this->SetTest("Start");
  3578. this->SetTest("Update");
  3579. this->SetTest("Configure");
  3580. this->SetTest("Build");
  3581. this->SetTest("MemCheck");
  3582. this->SetTest("Coverage");
  3583. this->SetTest("Submit");
  3584. }
  3585. }
  3586. if( ( arg.find("-T",0) == 0 ) &&
  3587. (i < args.size() -1) )
  3588. {
  3589. this->m_DartMode = true;
  3590. i++;
  3591. this->SetTest(args[i].c_str());
  3592. }
  3593. if( ( arg.find("-M",0) == 0 || arg.find("--test-model",0) == 0 ) &&
  3594. (i < args.size() -1) )
  3595. {
  3596. i++;
  3597. std::string const& str = args[i];
  3598. if ( str == "NIGHTLY" || str == "nightly" || str == "Nightly" )
  3599. {
  3600. this->SetTestModel(cmCTest::NIGHTLY);
  3601. }
  3602. else if ( str == "CONTINUOUS" || str == "continuous" ||
  3603. str == "Continuous" )
  3604. {
  3605. this->SetTestModel(cmCTest::CONTINUOUS);
  3606. std::cout << "Continuous" << std::endl;
  3607. }
  3608. else
  3609. {
  3610. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3611. }
  3612. }
  3613. if(arg.find("-R",0) == 0 && i < args.size() - 1)
  3614. {
  3615. this->m_UseIncludeRegExp = true;
  3616. i++;
  3617. this->m_IncludeRegExp = args[i];
  3618. }
  3619. if(arg.find("-E",0) == 0 && i < args.size() - 1)
  3620. {
  3621. this->m_UseExcludeRegExp = true;
  3622. i++;
  3623. this->m_ExcludeRegExp = args[i];
  3624. this->m_UseExcludeRegExpFirst = this->m_UseIncludeRegExp ? false : true;
  3625. }
  3626. if(arg.find("-A",0) == 0 && i < args.size() - 1)
  3627. {
  3628. this->m_DartMode = true;
  3629. this->SetTest("Notes");
  3630. i++;
  3631. this->SetNotesFiles(args[i].c_str());
  3632. }
  3633. // --build-and-test options
  3634. if(arg.find("--build-and-test",0) == 0 && i < args.size() - 1)
  3635. {
  3636. cmakeAndTest = true;
  3637. if(i+2 < args.size())
  3638. {
  3639. i++;
  3640. m_SourceDir = args[i];
  3641. i++;
  3642. m_BinaryDir = args[i];
  3643. // dir must exist before CollapseFullPath is called
  3644. cmSystemTools::MakeDirectory(m_BinaryDir.c_str());
  3645. m_BinaryDir = cmSystemTools::CollapseFullPath(m_BinaryDir.c_str());
  3646. m_SourceDir = cmSystemTools::CollapseFullPath(m_SourceDir.c_str());
  3647. }
  3648. else
  3649. {
  3650. std::cerr << "--build-and-test must have source and binary dir\n";
  3651. }
  3652. }
  3653. if(arg.find("--build-target",0) == 0 && i < args.size() - 1)
  3654. {
  3655. i++;
  3656. m_BuildTarget = args[i];
  3657. }
  3658. if(arg.find("--build-nocmake",0) == 0 && i < args.size() - 1)
  3659. {
  3660. m_BuildNoCMake = true;
  3661. }
  3662. if(arg.find("--build-run-dir",0) == 0 && i < args.size() - 1)
  3663. {
  3664. i++;
  3665. m_BuildRunDir = args[i];
  3666. }
  3667. if(arg.find("--build-two-config",0) == 0 && i < args.size() - 1)
  3668. {
  3669. m_BuildTwoConfig = true;
  3670. }
  3671. if(arg.find("--build-exe-dir",0) == 0 && i < args.size() - 1)
  3672. {
  3673. i++;
  3674. m_ExecutableDirectory = args[i];
  3675. }
  3676. if(arg.find("--build-generator",0) == 0 && i < args.size() - 1)
  3677. {
  3678. i++;
  3679. m_BuildGenerator = args[i];
  3680. }
  3681. if(arg.find("--build-project",0) == 0 && i < args.size() - 1)
  3682. {
  3683. i++;
  3684. m_BuildProject = args[i];
  3685. }
  3686. if(arg.find("--build-makeprogram",0) == 0 && i < args.size() - 1)
  3687. {
  3688. i++;
  3689. m_BuildMakeProgram = args[i];
  3690. }
  3691. if(arg.find("--build-noclean",0) == 0 && i < args.size() - 1)
  3692. {
  3693. m_BuildNoClean = true;
  3694. }
  3695. if(arg.find("--build-options",0) == 0 && i < args.size() - 1)
  3696. {
  3697. ++i;
  3698. bool done = false;
  3699. while(i < args.size() && !done)
  3700. {
  3701. m_BuildOptions.push_back(args[i]);
  3702. if(i+1 < args.size()
  3703. && (args[i+1] == "--build-target" || args[i+1] == "--test-command"))
  3704. {
  3705. done = true;
  3706. }
  3707. else
  3708. {
  3709. ++i;
  3710. }
  3711. }
  3712. }
  3713. if(arg.find("--test-command",0) == 0 && i < args.size() - 1)
  3714. {
  3715. ++i;
  3716. m_TestCommand = args[i];
  3717. while(i+1 < args.size())
  3718. {
  3719. ++i;
  3720. m_TestCommandArgs.push_back(args[i]);
  3721. }
  3722. }
  3723. }
  3724. if(cmakeAndTest)
  3725. {
  3726. cmSystemTools::ResetErrorOccuredFlag();
  3727. cmListFileCache::GetInstance()->ClearCache();
  3728. int retv = this->RunCMakeAndTest(output);
  3729. cmSystemTools::ResetErrorOccuredFlag();
  3730. cmListFileCache::GetInstance()->ClearCache();
  3731. #ifdef CMAKE_BUILD_WITH_CMAKE
  3732. cmDynamicLoader::FlushCache();
  3733. #endif
  3734. return retv;
  3735. }
  3736. int res;
  3737. // call process directory
  3738. if (this->m_RunConfigurationScript)
  3739. {
  3740. res = this->RunConfigurationScript();
  3741. }
  3742. else
  3743. {
  3744. if ( !this->Initialize() )
  3745. {
  3746. res = 12;
  3747. }
  3748. else
  3749. {
  3750. res = this->ProcessTests();
  3751. }
  3752. this->Finalize();
  3753. }
  3754. return res;
  3755. }
  3756. void cmCTest::FindRunningCMake(const char* arg0)
  3757. {
  3758. // Find our own executable.
  3759. std::vector<cmStdString> failures;
  3760. m_CTestSelf = arg0;
  3761. cmSystemTools::ConvertToUnixSlashes(m_CTestSelf);
  3762. failures.push_back(m_CTestSelf);
  3763. m_CTestSelf = cmSystemTools::FindProgram(m_CTestSelf.c_str());
  3764. if(!cmSystemTools::FileExists(m_CTestSelf.c_str()))
  3765. {
  3766. failures.push_back(m_CTestSelf);
  3767. m_CTestSelf = "/usr/local/bin/ctest";
  3768. }
  3769. if(!cmSystemTools::FileExists(m_CTestSelf.c_str()))
  3770. {
  3771. failures.push_back(m_CTestSelf);
  3772. cmOStringStream msg;
  3773. msg << "CTEST can not find the command line program cmake.\n";
  3774. msg << " argv[0] = \"" << arg0 << "\"\n";
  3775. msg << " Attempted paths:\n";
  3776. std::vector<cmStdString>::iterator i;
  3777. for(i=failures.begin(); i != failures.end(); ++i)
  3778. {
  3779. msg << " \"" << i->c_str() << "\"\n";
  3780. }
  3781. cmSystemTools::Error(msg.str().c_str());
  3782. }
  3783. std::string dir;
  3784. std::string file;
  3785. if(cmSystemTools::SplitProgramPath(m_CTestSelf.c_str(),
  3786. dir,
  3787. file,
  3788. true))
  3789. {
  3790. m_CMakeSelf = dir += "/cmake";
  3791. m_CMakeSelf += cmSystemTools::GetExecutableExtension();
  3792. if(!cmSystemTools::FileExists(m_CMakeSelf.c_str()))
  3793. {
  3794. cmOStringStream msg;
  3795. failures.push_back(m_CMakeSelf);
  3796. msg << "CTEST can not find the command line program cmake.\n";
  3797. msg << " argv[0] = \"" << arg0 << "\"\n";
  3798. msg << " Attempted path:\n";
  3799. msg << " \"" << m_CMakeSelf.c_str() << "\"\n";
  3800. cmSystemTools::Error(msg.str().c_str());
  3801. }
  3802. }
  3803. }
  3804. void CMakeMessageCallback(const char* m, const char*, bool&, void* s)
  3805. {
  3806. std::string* out = (std::string*)s;
  3807. *out += m;
  3808. *out += "\n";
  3809. }
  3810. void CMakeStdoutCallback(const char* m, int len, void* s)
  3811. {
  3812. std::string* out = (std::string*)s;
  3813. out->append(m, len);
  3814. }
  3815. int cmCTest::RunCMakeAndTest(std::string* outstring)
  3816. {
  3817. unsigned int k;
  3818. std::string cmakeOutString;
  3819. cmSystemTools::SetErrorCallback(CMakeMessageCallback, &cmakeOutString);
  3820. cmSystemTools::SetStdoutCallback(CMakeStdoutCallback, &cmakeOutString);
  3821. cmOStringStream out;
  3822. cmake cm;
  3823. // default to the build type of ctest itself
  3824. if(m_ConfigType.size() == 0)
  3825. {
  3826. #ifdef CMAKE_INTDIR
  3827. m_ConfigType = CMAKE_INTDIR;
  3828. #endif
  3829. }
  3830. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  3831. out << "Internal cmake changing into directory: " << m_BinaryDir << "\n";
  3832. if (!cmSystemTools::FileIsDirectory(m_BinaryDir.c_str()))
  3833. {
  3834. cmSystemTools::MakeDirectory(m_BinaryDir.c_str());
  3835. }
  3836. cmSystemTools::ChangeDirectory(m_BinaryDir.c_str());
  3837. if(!m_BuildNoCMake)
  3838. {
  3839. std::vector<std::string> args;
  3840. args.push_back(m_CMakeSelf);
  3841. args.push_back(m_SourceDir);
  3842. if(m_BuildGenerator.size())
  3843. {
  3844. std::string generator = "-G";
  3845. generator += m_BuildGenerator;
  3846. args.push_back(generator);
  3847. }
  3848. if ( m_ConfigType.size() > 0 )
  3849. {
  3850. std::string btype = "-DBUILD_TYPE:STRING=" + m_ConfigType;
  3851. args.push_back(btype);
  3852. }
  3853. for(k=0; k < m_BuildOptions.size(); ++k)
  3854. {
  3855. args.push_back(m_BuildOptions[k]);
  3856. }
  3857. if (cm.Run(args) != 0)
  3858. {
  3859. out << "Error: cmake execution failed\n";
  3860. out << cmakeOutString << "\n";
  3861. // return to the original directory
  3862. cmSystemTools::ChangeDirectory(cwd.c_str());
  3863. if(outstring)
  3864. {
  3865. *outstring = out.str();
  3866. }
  3867. else
  3868. {
  3869. std::cerr << out << "\n";
  3870. }
  3871. return 1;
  3872. }
  3873. if(m_BuildTwoConfig)
  3874. {
  3875. if (cm.Run(args) != 0)
  3876. {
  3877. out << "Error: cmake execution failed\n";
  3878. out << cmakeOutString << "\n";
  3879. // return to the original directory
  3880. cmSystemTools::ChangeDirectory(cwd.c_str());
  3881. if(outstring)
  3882. {
  3883. *outstring = out.str();
  3884. }
  3885. else
  3886. {
  3887. std::cerr << out << "\n";
  3888. }
  3889. return 1;
  3890. }
  3891. }
  3892. }
  3893. cmSystemTools::SetErrorCallback(0, 0);
  3894. out << cmakeOutString << "\n";
  3895. if(m_BuildMakeProgram.size() == 0)
  3896. {
  3897. out << "Error: cmake does not have a valid MAKEPROGRAM\n";
  3898. out << "Did you specify a --build-makeprogram and a --build-generator?\n";
  3899. if(outstring)
  3900. {
  3901. *outstring = out.str();
  3902. }
  3903. else
  3904. {
  3905. std::cerr << out << "\n";
  3906. }
  3907. return 1;
  3908. }
  3909. int retVal = 0;
  3910. std::string makeCommand = cmSystemTools::ConvertToOutputPath(m_BuildMakeProgram.c_str());
  3911. std::string lowerCaseCommand = cmSystemTools::LowerCase(makeCommand);
  3912. // if msdev is the make program then do the following
  3913. // MSDEV 6.0
  3914. if(lowerCaseCommand.find("msdev") != std::string::npos)
  3915. {
  3916. // if there are spaces in the makeCommand, assume a full path
  3917. // and convert it to a path with no spaces in it as the
  3918. // RunSingleCommand does not like spaces
  3919. #if defined(_WIN32) && !defined(__CYGWIN__)
  3920. if(makeCommand.find(' ') != std::string::npos)
  3921. {
  3922. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  3923. }
  3924. #endif
  3925. makeCommand += " ";
  3926. makeCommand += m_BuildProject;
  3927. makeCommand += ".dsw /MAKE \"ALL_BUILD - ";
  3928. makeCommand += m_ConfigType;
  3929. if(m_BuildNoClean)
  3930. {
  3931. makeCommand += "\" /BUILD";
  3932. }
  3933. else
  3934. {
  3935. makeCommand += "\" /REBUILD";
  3936. }
  3937. }
  3938. // MSDEV 7.0 .NET
  3939. else if (lowerCaseCommand.find("devenv") != std::string::npos)
  3940. {
  3941. #if defined(_WIN32) && !defined(__CYGWIN__)
  3942. if(makeCommand.find(' ') != std::string::npos)
  3943. {
  3944. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  3945. }
  3946. #endif
  3947. makeCommand += " ";
  3948. makeCommand += m_BuildProject;
  3949. makeCommand += ".sln ";
  3950. if(m_BuildNoClean)
  3951. {
  3952. makeCommand += "/build ";
  3953. }
  3954. else
  3955. {
  3956. makeCommand += "/rebuild ";
  3957. }
  3958. makeCommand += m_ConfigType + " /project ALL_BUILD";
  3959. }
  3960. else if (lowerCaseCommand.find("make") != std::string::npos)
  3961. {
  3962. // assume a make sytle program
  3963. // clean first
  3964. if(!m_BuildNoClean)
  3965. {
  3966. std::string cleanCommand = makeCommand;
  3967. cleanCommand += " clean";
  3968. out << "Running make clean command: " << cleanCommand.c_str() << " ...\n";
  3969. retVal = 0;
  3970. std::string output;
  3971. if (!cmSystemTools::RunSingleCommand(cleanCommand.c_str(), &output, &retVal) ||
  3972. retVal)
  3973. {
  3974. out << "Error: " << cleanCommand.c_str() << " execution failed\n";
  3975. out << output.c_str() << "\n";
  3976. // return to the original directory
  3977. cmSystemTools::ChangeDirectory(cwd.c_str());
  3978. out << "Return value: " << retVal << std::endl;
  3979. if(outstring)
  3980. {
  3981. *outstring = out.str();
  3982. }
  3983. else
  3984. {
  3985. std::cerr << out << "\n";
  3986. }
  3987. return 1;
  3988. }
  3989. out << output;
  3990. }
  3991. if(m_BuildTarget.size())
  3992. {
  3993. makeCommand += " ";
  3994. makeCommand += m_BuildTarget;
  3995. }
  3996. }
  3997. // command line make program
  3998. out << "Running make command: " << makeCommand.c_str() << "\n";
  3999. retVal = 0;
  4000. std::string output;
  4001. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), &output, &retVal, 0, false))
  4002. {
  4003. out << "Error: " << makeCommand.c_str() << " execution failed\n";
  4004. out << output.c_str() << "\n";
  4005. // return to the original directory
  4006. cmSystemTools::ChangeDirectory(cwd.c_str());
  4007. out << "Return value: " << retVal << std::endl;
  4008. if(outstring)
  4009. {
  4010. *outstring = out.str();
  4011. }
  4012. else
  4013. {
  4014. std::cerr << out << "\n";
  4015. }
  4016. return 1;
  4017. }
  4018. if ( retVal )
  4019. {
  4020. if(outstring)
  4021. {
  4022. *outstring = out.str();
  4023. *outstring += "Building of project failed\n";
  4024. *outstring += output;
  4025. *outstring += "\n";
  4026. }
  4027. else
  4028. {
  4029. std::cerr << "Building of project failed\n";
  4030. std::cerr << out << output << "\n";
  4031. }
  4032. // return to the original directory
  4033. cmSystemTools::ChangeDirectory(cwd.c_str());
  4034. return 1;
  4035. }
  4036. out << output;
  4037. if(m_TestCommand.size() == 0)
  4038. {
  4039. if(outstring)
  4040. {
  4041. *outstring = out.str();
  4042. }
  4043. else
  4044. {
  4045. std::cout << out << "\n";
  4046. }
  4047. return retVal;
  4048. }
  4049. // now run the compiled test if we can find it
  4050. // See if the executable exists as written.
  4051. std::vector<std::string> failed;
  4052. std::string fullPath;
  4053. if(cmSystemTools::FileExists(m_TestCommand.c_str())
  4054. && !cmSystemTools::FileIsDirectory(m_TestCommand.c_str()))
  4055. {
  4056. fullPath = cmSystemTools::CollapseFullPath(m_TestCommand.c_str());
  4057. }
  4058. else
  4059. {
  4060. failed.push_back(m_TestCommand);
  4061. std::string tryPath = m_TestCommand;
  4062. tryPath += cmSystemTools::GetExecutableExtension();
  4063. if(cmSystemTools::FileExists(tryPath.c_str())
  4064. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4065. {
  4066. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4067. }
  4068. else
  4069. {
  4070. failed.push_back(tryPath);
  4071. // try the Debug extension
  4072. tryPath = m_ConfigType + "/";
  4073. tryPath += cmSystemTools::GetFilenameName(m_TestCommand);
  4074. if(cmSystemTools::FileExists(tryPath.c_str())
  4075. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4076. {
  4077. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4078. }
  4079. else
  4080. {
  4081. failed.push_back(tryPath);
  4082. tryPath += cmSystemTools::GetExecutableExtension();
  4083. if(cmSystemTools::FileExists(tryPath.c_str())
  4084. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4085. {
  4086. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4087. }
  4088. else
  4089. {
  4090. failed.push_back(tryPath);
  4091. tryPath = m_ExecutableDirectory;
  4092. tryPath += "/";
  4093. tryPath += m_TestCommand;
  4094. tryPath += cmSystemTools::GetExecutableExtension();
  4095. if(cmSystemTools::FileExists(tryPath.c_str())
  4096. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4097. {
  4098. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4099. }
  4100. else
  4101. {
  4102. failed.push_back(tryPath);
  4103. tryPath = m_ExecutableDirectory;
  4104. tryPath += "/";
  4105. tryPath += m_ConfigType + "/";
  4106. tryPath += m_TestCommand;
  4107. tryPath += cmSystemTools::GetExecutableExtension();
  4108. if(cmSystemTools::FileExists(tryPath.c_str())
  4109. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4110. {
  4111. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4112. }
  4113. else
  4114. {
  4115. failed.push_back(tryPath);
  4116. std::string filepath = cmSystemTools::GetFilenamePath(m_TestCommand);
  4117. std::string filename = cmSystemTools::GetFilenameName(m_TestCommand);
  4118. tryPath = filepath + "/" + m_ConfigType + "/" + filename;
  4119. if ( cmSystemTools::FileExists(tryPath.c_str()) &&
  4120. !cmSystemTools::FileIsDirectory(tryPath.c_str()) )
  4121. {
  4122. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4123. }
  4124. else
  4125. {
  4126. failed.push_back(tryPath);
  4127. }
  4128. }
  4129. }
  4130. }
  4131. }
  4132. }
  4133. }
  4134. if(!cmSystemTools::FileExists(fullPath.c_str()))
  4135. {
  4136. out << "Could not find path to executable, perhaps it was not built: " <<
  4137. m_TestCommand << "\n";
  4138. out << "tried to find it in these places:\n";
  4139. for(unsigned int i=0; i < failed.size(); ++i)
  4140. {
  4141. out << failed[i] << "\n";
  4142. }
  4143. if(outstring)
  4144. {
  4145. *outstring = out.str();
  4146. }
  4147. else
  4148. {
  4149. std::cerr << out.str();
  4150. }
  4151. // return to the original directory
  4152. cmSystemTools::ChangeDirectory(cwd.c_str());
  4153. return 1;
  4154. }
  4155. std::vector<const char*> testCommand;
  4156. testCommand.push_back(fullPath.c_str());
  4157. for(k=0; k < m_TestCommandArgs.size(); ++k)
  4158. {
  4159. testCommand.push_back(m_TestCommandArgs[k].c_str());
  4160. }
  4161. testCommand.push_back(0);
  4162. std::string outs;
  4163. int retval = 0;
  4164. // run the test from the m_BuildRunDir if set
  4165. if(m_BuildRunDir.size())
  4166. {
  4167. out << "Run test in directory: " << m_BuildRunDir << "\n";
  4168. cmSystemTools::ChangeDirectory(m_BuildRunDir.c_str());
  4169. }
  4170. out << "Running test executable: " << fullPath << " ";
  4171. for(k=0; k < m_TestCommandArgs.size(); ++k)
  4172. {
  4173. out << m_TestCommandArgs[k] << " ";
  4174. }
  4175. out << "\n";
  4176. int runTestRes = this->RunTest(testCommand, &outs, &retval, 0);
  4177. if(runTestRes != cmsysProcess_State_Exited || retval != 0)
  4178. {
  4179. out << "Test failed to run.\n";
  4180. retval = 1;
  4181. }
  4182. out << outs << "\n";
  4183. if(outstring)
  4184. {
  4185. *outstring = out.str();
  4186. }
  4187. else
  4188. {
  4189. std::cout << out.str() << "\n";
  4190. }
  4191. return retval;
  4192. }
  4193. void cmCTest::SetNotesFiles(const char* notes)
  4194. {
  4195. if ( !notes )
  4196. {
  4197. return;
  4198. }
  4199. m_NotesFiles = notes;
  4200. }
  4201. int cmCTest::ReadCustomConfigurationFileTree(const char* dir)
  4202. {
  4203. tm_VectorOfStrings dirs;
  4204. tm_VectorOfStrings ndirs;
  4205. dirs.push_back(dir);
  4206. cmake cm;
  4207. cmGlobalGenerator gg;
  4208. gg.SetCMakeInstance(&cm);
  4209. cmLocalGenerator *lg = gg.CreateLocalGenerator();
  4210. lg->SetGlobalGenerator(&gg);
  4211. cmMakefile *mf = lg->GetMakefile();
  4212. while ( dirs.size() > 0 )
  4213. {
  4214. tm_VectorOfStrings::iterator cdir = dirs.end()-1;
  4215. std::string rexpr = *cdir + "/*";
  4216. std::string fname = *cdir + "/CTestCustom.ctest";
  4217. if ( cmSystemTools::FileExists(fname.c_str()) &&
  4218. (!lg->GetMakefile()->ReadListFile(0, fname.c_str()) ||
  4219. cmSystemTools::GetErrorOccuredFlag() ) )
  4220. {
  4221. std::cerr << "Problem reading custom configuration" << std::endl;
  4222. return 0;
  4223. }
  4224. dirs.erase(dirs.end()-1, dirs.end());
  4225. cmSystemTools::SimpleGlob(rexpr, ndirs, -1);
  4226. dirs.insert(dirs.end(), ndirs.begin(), ndirs.end());
  4227. }
  4228. this->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH", m_CustomErrorMatches);
  4229. this->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION", m_CustomErrorExceptions);
  4230. this->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH", m_CustomWarningMatches);
  4231. this->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION", m_CustomWarningExceptions);
  4232. this->PopulateCustomVector(mf, "CTEST_CUSTOM_TESTS_IGNORE", m_CustomTestsIgnore);
  4233. this->PopulateCustomVector(mf, "CTEST_CUSTOM_MEMCHECK_IGNORE", m_CustomMemCheckIgnore);
  4234. this->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST", m_CustomPreTest);
  4235. this->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST", m_CustomPostTest);
  4236. this->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_MEMCHECK", m_CustomPreMemCheck);
  4237. this->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_MEMCHECK", m_CustomPostMemCheck);
  4238. return 1;
  4239. }
  4240. void cmCTest::PopulateCustomVector(cmMakefile* mf, const char* def, tm_VectorOfStrings& vec)
  4241. {
  4242. if ( !def)
  4243. {
  4244. return;
  4245. }
  4246. const char* dval = mf->GetDefinition(def);
  4247. if ( !dval )
  4248. {
  4249. return;
  4250. }
  4251. std::vector<std::string> slist;
  4252. cmSystemTools::ExpandListArgument(dval, slist);
  4253. std::vector<std::string>::iterator it;
  4254. for ( it = slist.begin(); it != slist.end(); ++it )
  4255. {
  4256. vec.push_back(it->c_str());
  4257. }
  4258. }
  4259. int cmCTest::ExecuteCommands(tm_VectorOfStrings& vec)
  4260. {
  4261. tm_VectorOfStrings::iterator it;
  4262. for ( it = vec.begin(); it != vec.end(); ++it )
  4263. {
  4264. int retVal = 0;
  4265. if ( m_Verbose )
  4266. {
  4267. std::cout << "Run command: " << *it << std::endl;
  4268. }
  4269. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true /*m_Verbose*/) ||
  4270. retVal != 0 )
  4271. {
  4272. std::cerr << "Problem running command: " << *it << std::endl;
  4273. return 0;
  4274. }
  4275. }
  4276. return 1;
  4277. }