cmCTest.cxx 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509
  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)
  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);
  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. int res = 0;
  1862. if ( !m_ShowOnly )
  1863. {
  1864. res = this->RunTest(arguments, &output, &retVal);
  1865. }
  1866. clock_finish = cmSystemTools::GetTime();
  1867. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  1868. cres.m_FullCommandLine = testCommand;
  1869. if ( !m_ShowOnly )
  1870. {
  1871. if (res == cmsysProcess_State_Exited && retVal == 0)
  1872. {
  1873. fprintf(stderr," Passed\n");
  1874. passed.push_back(args[0].Value);
  1875. cres.m_Status = cmCTest::COMPLETED;
  1876. }
  1877. else
  1878. {
  1879. cres.m_Status = cmCTest::FAILED;
  1880. if ( res == cmsysProcess_State_Expired )
  1881. {
  1882. fprintf(stderr,"***Timeout\n");
  1883. cres.m_Status = cmCTest::TIMEOUT;
  1884. }
  1885. else if ( res == cmsysProcess_State_Exception )
  1886. {
  1887. fprintf(stderr,"***Exception: ");
  1888. switch ( retVal )
  1889. {
  1890. case cmsysProcess_Exception_Fault:
  1891. fprintf(stderr,"SegFault");
  1892. cres.m_Status = cmCTest::SEGFAULT;
  1893. break;
  1894. case cmsysProcess_Exception_Illegal:
  1895. fprintf(stderr,"Illegal");
  1896. cres.m_Status = cmCTest::ILLEGAL;
  1897. break;
  1898. case cmsysProcess_Exception_Interrupt:
  1899. fprintf(stderr,"Interrupt");
  1900. cres.m_Status = cmCTest::INTERRUPT;
  1901. break;
  1902. case cmsysProcess_Exception_Numerical:
  1903. fprintf(stderr,"Numerical");
  1904. cres.m_Status = cmCTest::NUMERICAL;
  1905. break;
  1906. default:
  1907. fprintf(stderr,"Other");
  1908. cres.m_Status = cmCTest::OTHER_FAULT;
  1909. }
  1910. fprintf(stderr,"\n");
  1911. }
  1912. else if ( res == cmsysProcess_State_Error )
  1913. {
  1914. fprintf(stderr,"***Bad command %d\n", res);
  1915. cres.m_Status = cmCTest::BAD_COMMAND;
  1916. }
  1917. else
  1918. {
  1919. fprintf(stderr,"***Failed\n");
  1920. }
  1921. failed.push_back(args[0].Value);
  1922. }
  1923. if (output != "")
  1924. {
  1925. if (dartStuff.find(output.c_str()))
  1926. {
  1927. std::string dartString = dartStuff.match(1);
  1928. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  1929. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  1930. }
  1931. }
  1932. }
  1933. cres.m_Output = output;
  1934. cres.m_ReturnValue = retVal;
  1935. std::string nwd = cmSystemTools::GetCurrentWorkingDirectory();
  1936. if ( nwd.size() > m_ToplevelPath.size() )
  1937. {
  1938. nwd = "." + nwd.substr(m_ToplevelPath.size(), nwd.npos);
  1939. }
  1940. cmSystemTools::ReplaceString(nwd, "\\", "/");
  1941. cres.m_Path = nwd;
  1942. cres.m_CompletionStatus = "Completed";
  1943. m_TestResults.push_back( cres );
  1944. }
  1945. }
  1946. }
  1947. bool cmCTest::InitializeMemoryChecking()
  1948. {
  1949. // Setup the command
  1950. if ( cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckCommand"].c_str()) )
  1951. {
  1952. m_MemoryTester
  1953. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["MemoryCheckCommand"].c_str());
  1954. }
  1955. else if ( cmSystemTools::FileExists(m_DartConfiguration["PurifyCommand"].c_str()) )
  1956. {
  1957. m_MemoryTester
  1958. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["PurifyCommand"].c_str());
  1959. }
  1960. else if ( cmSystemTools::FileExists(m_DartConfiguration["ValgrindCommand"].c_str()) )
  1961. {
  1962. m_MemoryTester
  1963. = cmSystemTools::ConvertToOutputPath(m_DartConfiguration["ValgrindCommand"].c_str());
  1964. }
  1965. else
  1966. {
  1967. std::cerr << "Memory checker (MemoryCheckCommand) not set, or cannot find the specified program."
  1968. << std::endl;
  1969. return false;
  1970. }
  1971. if ( m_MemoryTester[0] == '\"' && m_MemoryTester[m_MemoryTester.size()-1] == '\"' )
  1972. {
  1973. m_MemoryTester = m_MemoryTester.substr(1, m_MemoryTester.size()-2);
  1974. }
  1975. // Setup the options
  1976. if ( m_DartConfiguration["MemoryCheckCommandOptions"].size() )
  1977. {
  1978. m_MemoryTesterOptions = m_DartConfiguration["MemoryCheckCommandOptions"];
  1979. }
  1980. else if ( m_DartConfiguration["ValgrindCommandOptions"].size() )
  1981. {
  1982. m_MemoryTesterOptions = m_DartConfiguration["ValgrindCommandOptions"];
  1983. }
  1984. m_MemoryTesterOutputFile = m_ToplevelPath + "/Testing/Temporary/MemoryChecker.log";
  1985. m_MemoryTesterOutputFile = cmSystemTools::EscapeSpaces(m_MemoryTesterOutputFile.c_str());
  1986. if ( m_MemoryTester.find("valgrind") != std::string::npos )
  1987. {
  1988. m_MemoryTesterStyle = cmCTest::VALGRIND;
  1989. if ( !m_MemoryTesterOptions.size() )
  1990. {
  1991. m_MemoryTesterOptions = "-q --skin=memcheck --leak-check=yes --show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=100";
  1992. }
  1993. if ( m_DartConfiguration["MemoryCheckSuppressionFile"].size() )
  1994. {
  1995. if ( !cmSystemTools::FileExists(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) )
  1996. {
  1997. std::cerr << "Cannot find memory checker suppression file: "
  1998. << m_DartConfiguration["MemoryCheckSuppressionFile"].c_str() << std::endl;
  1999. return false;
  2000. }
  2001. m_MemoryTesterOptions += " --suppressions=" + cmSystemTools::EscapeSpaces(m_DartConfiguration["MemoryCheckSuppressionFile"].c_str()) + "";
  2002. }
  2003. }
  2004. else if ( m_MemoryTester.find("purify") != std::string::npos )
  2005. {
  2006. m_MemoryTesterStyle = cmCTest::PURIFY;
  2007. #ifdef _WIN32
  2008. m_MemoryTesterOptions += " /SAVETEXTDATA=" + m_MemoryTesterOutputFile;
  2009. #else
  2010. m_MemoryTesterOptions += " -log-file=" + m_MemoryTesterOutputFile;
  2011. #endif
  2012. }
  2013. else if ( m_MemoryTester.find("boundschecker") != std::string::npos )
  2014. {
  2015. m_MemoryTesterStyle = cmCTest::BOUNDS_CHECKER;
  2016. std::cerr << "Bounds checker not yet implemented" << std::endl;
  2017. return false;
  2018. }
  2019. else
  2020. {
  2021. std::cerr << "Do not understand memory checker: " << m_MemoryTester.c_str() << std::endl;
  2022. return false;
  2023. }
  2024. m_MemoryTesterOptionsParsed = cmSystemTools::ParseArguments(m_MemoryTesterOptions.c_str());
  2025. cmCTest::tm_VectorOfStrings::size_type cc;
  2026. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  2027. {
  2028. m_MemoryTesterGlobalResults[cc] = 0;
  2029. }
  2030. return true;
  2031. }
  2032. int cmCTest::TestDirectory(bool memcheck)
  2033. {
  2034. std::cout << (memcheck ? "Memory check" : "Test") << " project" << std::endl;
  2035. if ( memcheck )
  2036. {
  2037. if ( !this->InitializeMemoryChecking() )
  2038. {
  2039. return 1;
  2040. }
  2041. }
  2042. if ( memcheck )
  2043. {
  2044. if ( !this->ExecuteCommands(m_CustomPreMemCheck) )
  2045. {
  2046. std::cerr << "Problem executing pre-memcheck command(s)." << std::endl;
  2047. return 1;
  2048. }
  2049. }
  2050. else
  2051. {
  2052. if ( !this->ExecuteCommands(m_CustomPreTest) )
  2053. {
  2054. std::cerr << "Problem executing pre-test command(s)." << std::endl;
  2055. return 1;
  2056. }
  2057. }
  2058. cmCTest::tm_VectorOfStrings passed;
  2059. cmCTest::tm_VectorOfStrings failed;
  2060. int total;
  2061. m_StartTest = ::CurrentTime();
  2062. this->ProcessDirectory(passed, failed, memcheck);
  2063. m_EndTest = ::CurrentTime();
  2064. total = int(passed.size()) + int(failed.size());
  2065. if (total == 0)
  2066. {
  2067. if ( !m_ShowOnly )
  2068. {
  2069. std::cerr << "No tests were found!!!\n";
  2070. }
  2071. }
  2072. else
  2073. {
  2074. if (m_Verbose && passed.size() &&
  2075. (m_UseIncludeRegExp || m_UseExcludeRegExp))
  2076. {
  2077. std::cerr << "\nThe following tests passed:\n";
  2078. for(cmCTest::tm_VectorOfStrings::iterator j = passed.begin();
  2079. j != passed.end(); ++j)
  2080. {
  2081. std::cerr << "\t" << *j << "\n";
  2082. }
  2083. }
  2084. float percent = float(passed.size()) * 100.0f / total;
  2085. if ( failed.size() > 0 && percent > 99)
  2086. {
  2087. percent = 99;
  2088. }
  2089. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  2090. percent, int(failed.size()), total);
  2091. if (failed.size())
  2092. {
  2093. std::cerr << "\nThe following tests FAILED:\n";
  2094. for(cmCTest::tm_VectorOfStrings::iterator j = failed.begin();
  2095. j != failed.end(); ++j)
  2096. {
  2097. std::cerr << "\t" << *j << "\n";
  2098. }
  2099. }
  2100. }
  2101. if ( m_DartMode )
  2102. {
  2103. std::ofstream ofs;
  2104. if( !this->OpenOutputFile(m_CurrentTag,
  2105. (memcheck ? (m_CompatibilityMode?"Purify.xml":"MemCheck.xml") : "Test.xml"), ofs) )
  2106. {
  2107. std::cerr << "Cannot create " << (memcheck ? "memory check" : "testing")
  2108. << " XML file" << std::endl;
  2109. return 1;
  2110. }
  2111. if ( memcheck )
  2112. {
  2113. this->GenerateDartMemCheckOutput(ofs);
  2114. }
  2115. else
  2116. {
  2117. this->GenerateDartTestOutput(ofs);
  2118. }
  2119. }
  2120. if ( memcheck )
  2121. {
  2122. if ( !this->ExecuteCommands(m_CustomPostMemCheck) )
  2123. {
  2124. std::cerr << "Problem executing post-memcheck command(s)." << std::endl;
  2125. return 1;
  2126. }
  2127. }
  2128. else
  2129. {
  2130. if ( !this->ExecuteCommands(m_CustomPostTest) )
  2131. {
  2132. std::cerr << "Problem executing post-test command(s)." << std::endl;
  2133. return 1;
  2134. }
  2135. }
  2136. return int(failed.size());
  2137. }
  2138. int cmCTest::SubmitResults()
  2139. {
  2140. cmCTest::tm_VectorOfStrings files;
  2141. std::string prefix = this->GetSubmitResultsPrefix();
  2142. // TODO:
  2143. // Check if test is enabled
  2144. if ( this->CTestFileExists("Update.xml") )
  2145. {
  2146. files.push_back("Update.xml");
  2147. }
  2148. if ( this->CTestFileExists("Configure.xml") )
  2149. {
  2150. files.push_back("Configure.xml");
  2151. }
  2152. if ( this->CTestFileExists("Build.xml") )
  2153. {
  2154. files.push_back("Build.xml");
  2155. }
  2156. if ( this->CTestFileExists("Test.xml") )
  2157. {
  2158. files.push_back("Test.xml");
  2159. }
  2160. if ( this->CTestFileExists("Coverage.xml") )
  2161. {
  2162. files.push_back("Coverage.xml");
  2163. cmCTest::tm_VectorOfStrings gfiles;
  2164. std::string gpath = m_ToplevelPath + "/Testing/" + m_CurrentTag;
  2165. std::string::size_type glen = gpath.size() + 1;
  2166. gpath = gpath + "/CoverageLog*";
  2167. //std::cout << "Globbing for: " << gpath.c_str() << std::endl;
  2168. if ( cmSystemTools::SimpleGlob(gpath, gfiles, 1) )
  2169. {
  2170. size_t cc;
  2171. for ( cc = 0; cc < gfiles.size(); cc ++ )
  2172. {
  2173. gfiles[cc] = gfiles[cc].substr(glen);
  2174. //std::cout << "Glob file: " << gfiles[cc].c_str() << std::endl;
  2175. files.push_back(gfiles[cc]);
  2176. }
  2177. }
  2178. else
  2179. {
  2180. std::cerr << "Problem globbing" << std::endl;
  2181. }
  2182. }
  2183. if ( this->CTestFileExists("MemCheck.xml") )
  2184. {
  2185. files.push_back("MemCheck.xml");
  2186. }
  2187. if ( this->CTestFileExists("Purify.xml") )
  2188. {
  2189. files.push_back("Purify.xml");
  2190. }
  2191. if ( this->CTestFileExists("Notes.xml") )
  2192. {
  2193. files.push_back("Notes.xml");
  2194. }
  2195. cmCTestSubmit submit;
  2196. submit.SetVerbose(m_Verbose);
  2197. if ( m_DartConfiguration["DropMethod"] == "" ||
  2198. m_DartConfiguration["DropMethod"] == "ftp" )
  2199. {
  2200. std::cout << " Using FTP submit method" << std::endl;
  2201. std::string url = "ftp://";
  2202. url += cmCTest::MakeURLSafe(m_DartConfiguration["DropSiteUser"]) + ":" +
  2203. cmCTest::MakeURLSafe(m_DartConfiguration["DropSitePassword"]) + "@" +
  2204. m_DartConfiguration["DropSite"] +
  2205. cmCTest::MakeURLSafe(m_DartConfiguration["DropLocation"]);
  2206. if ( !submit.SubmitUsingFTP(m_ToplevelPath+"/Testing/"+m_CurrentTag,
  2207. files, prefix, url) )
  2208. {
  2209. std::cerr << " Problems when submitting via FTP" << std::endl;
  2210. return 0;
  2211. }
  2212. if ( !submit.TriggerUsingHTTP(files, prefix, m_DartConfiguration["TriggerSite"]) )
  2213. {
  2214. std::cerr << " Problems when triggering via HTTP" << std::endl;
  2215. return 0;
  2216. }
  2217. std::cout << " Submission successfull" << std::endl;
  2218. return 1;
  2219. }
  2220. else if ( m_DartConfiguration["DropMethod"] == "http" )
  2221. {
  2222. std::cout << " Using HTTP submit method" << std::endl;
  2223. std::string url = "http://";
  2224. if ( m_DartConfiguration["DropSiteUser"].size() > 0 )
  2225. {
  2226. url += m_DartConfiguration["DropSiteUser"];
  2227. if ( m_DartConfiguration["DropSitePassword"].size() > 0 )
  2228. {
  2229. url += ":" + m_DartConfiguration["DropSitePassword"];
  2230. }
  2231. url += "@";
  2232. }
  2233. url += m_DartConfiguration["DropSite"] + m_DartConfiguration["DropLocation"];
  2234. if ( !submit.SubmitUsingHTTP(m_ToplevelPath+"/Testing/"+m_CurrentTag, files, prefix, url) )
  2235. {
  2236. std::cerr << " Problems when submitting via HTTP" << 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
  2248. {
  2249. std::cerr << "SCP submit not yet implemented" << std::endl;
  2250. }
  2251. return 0;
  2252. }
  2253. bool cmCTest::CTestFileExists(const std::string& filename)
  2254. {
  2255. std::string testingDir = m_ToplevelPath + "/Testing/" + m_CurrentTag + "/" +
  2256. filename;
  2257. return cmSystemTools::FileExists(testingDir.c_str());
  2258. }
  2259. std::string cmCTest::GetSubmitResultsPrefix()
  2260. {
  2261. std::string name = m_DartConfiguration["Site"] +
  2262. "___" + m_DartConfiguration["BuildName"] +
  2263. "___" + m_CurrentTag + "-" +
  2264. this->GetTestModelString() + "___XML___";
  2265. return name;
  2266. }
  2267. void cmCTest::GenerateDartMemCheckOutput(std::ostream& os)
  2268. {
  2269. if ( !m_DartMode )
  2270. {
  2271. return;
  2272. }
  2273. this->StartXML(os);
  2274. if ( m_CompatibilityMode )
  2275. {
  2276. os << "<Purify>" << std::endl;
  2277. }
  2278. else
  2279. {
  2280. os << "<MemCheck>" << std::endl;
  2281. }
  2282. os << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2283. << "\t<TestList>\n";
  2284. tm_TestResultsVector::size_type cc;
  2285. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2286. {
  2287. cmCTestTestResult *result = &m_TestResults[cc];
  2288. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2289. << "/" << this->MakeXMLSafe(result->m_Name)
  2290. << "</Test>" << std::endl;
  2291. }
  2292. os << "\t</TestList>\n";
  2293. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2294. {
  2295. cmCTestTestResult *result = &m_TestResults[cc];
  2296. std::string memcheckstr;
  2297. int memcheckresults[cmCTest::NO_MEMORY_FAULT];
  2298. int kk;
  2299. this->ProcessMemCheckOutput(result->m_Output, memcheckstr, memcheckresults);
  2300. os << "\t<Test Status=\"";
  2301. if ( result->m_Status == cmCTest::COMPLETED )
  2302. {
  2303. os << "passed";
  2304. }
  2305. else if ( result->m_Status == cmCTest::NOT_RUN )
  2306. {
  2307. os << "notrun";
  2308. }
  2309. else
  2310. {
  2311. os << "failed";
  2312. }
  2313. os << "\">\n"
  2314. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2315. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2316. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2317. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2318. << "\t\t<FullCommandLine>"
  2319. << this->MakeXMLSafe(result->m_FullCommandLine)
  2320. << "</FullCommandLine>\n"
  2321. << "\t\t<Results>" << std::endl;
  2322. for ( kk = 0; cmCTestMemCheckResultStrings[kk]; kk ++ )
  2323. {
  2324. os << "\t\t\t<" << cmCTestMemCheckResultStrings[kk] << ">"
  2325. << memcheckresults[kk]
  2326. << "</" << cmCTestMemCheckResultStrings[kk] << ">" << std::endl;
  2327. m_MemoryTesterGlobalResults[kk] += memcheckresults[kk];
  2328. }
  2329. os
  2330. << "\t\t</Results>\n"
  2331. << "\t<Log>\n" << memcheckstr << std::endl
  2332. << "\t</Log>\n"
  2333. << "\t</Test>" << std::endl;
  2334. }
  2335. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>" << std::endl;
  2336. if ( m_CompatibilityMode )
  2337. {
  2338. os << "</Purify>" << std::endl;
  2339. }
  2340. else
  2341. {
  2342. os << "</MemCheck>" << std::endl;
  2343. }
  2344. this->EndXML(os);
  2345. std::cerr << "Memory checking results:" << std::endl;
  2346. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  2347. {
  2348. std::cerr << "\t\t" << cmCTestMemCheckResultStrings[cc] << " - "
  2349. << m_MemoryTesterGlobalResults[cc] << std::endl;
  2350. }
  2351. }
  2352. void cmCTest::GenerateDartTestOutput(std::ostream& os)
  2353. {
  2354. if ( !m_DartMode )
  2355. {
  2356. return;
  2357. }
  2358. this->StartXML(os);
  2359. os << "<Testing>\n"
  2360. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  2361. << "\t<TestList>\n";
  2362. tm_TestResultsVector::size_type cc;
  2363. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2364. {
  2365. cmCTestTestResult *result = &m_TestResults[cc];
  2366. os << "\t\t<Test>" << this->MakeXMLSafe(result->m_Path)
  2367. << "/" << this->MakeXMLSafe(result->m_Name)
  2368. << "</Test>" << std::endl;
  2369. }
  2370. os << "\t</TestList>\n";
  2371. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  2372. {
  2373. cmCTestTestResult *result = &m_TestResults[cc];
  2374. os << "\t<Test Status=\"";
  2375. if ( result->m_Status == cmCTest::COMPLETED )
  2376. {
  2377. os << "passed";
  2378. }
  2379. else if ( result->m_Status == cmCTest::NOT_RUN )
  2380. {
  2381. os << "notrun";
  2382. }
  2383. else
  2384. {
  2385. os << "failed";
  2386. }
  2387. os << "\">\n"
  2388. << "\t\t<Name>" << this->MakeXMLSafe(result->m_Name) << "</Name>\n"
  2389. << "\t\t<Path>" << this->MakeXMLSafe(result->m_Path) << "</Path>\n"
  2390. << "\t\t<FullName>" << this->MakeXMLSafe(result->m_Path)
  2391. << "/" << this->MakeXMLSafe(result->m_Name) << "</FullName>\n"
  2392. << "\t\t<FullCommandLine>"
  2393. << this->MakeXMLSafe(result->m_FullCommandLine)
  2394. << "</FullCommandLine>\n"
  2395. << "\t\t<Results>" << std::endl;
  2396. if ( result->m_Status != cmCTest::NOT_RUN )
  2397. {
  2398. if ( result->m_Status != cmCTest::COMPLETED || result->m_ReturnValue )
  2399. {
  2400. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  2401. << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
  2402. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  2403. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  2404. }
  2405. os << result->m_RegressionImages;
  2406. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  2407. << "name=\"Execution Time\"><Value>"
  2408. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
  2409. os
  2410. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  2411. << "name=\"Completion Status\"><Value>"
  2412. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
  2413. }
  2414. os
  2415. << "\t\t\t<Measurement>\n"
  2416. << "\t\t\t\t<Value>" << this->MakeXMLSafe(result->m_Output)
  2417. << "</Value>\n"
  2418. << "\t\t\t</Measurement>\n"
  2419. << "\t\t</Results>\n"
  2420. << "\t</Test>" << std::endl;
  2421. }
  2422. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  2423. << "</Testing>" << std::endl;
  2424. this->EndXML(os);
  2425. }
  2426. int cmCTest::ProcessTests()
  2427. {
  2428. int res = 0;
  2429. bool notest = true;
  2430. int cc;
  2431. int update_count = 0;
  2432. for ( cc = 0; cc < LAST_TEST; cc ++ )
  2433. {
  2434. if ( m_Tests[cc] )
  2435. {
  2436. notest = false;
  2437. break;
  2438. }
  2439. }
  2440. if ( m_Tests[UPDATE_TEST] || m_Tests[ALL_TEST] )
  2441. {
  2442. update_count = this->UpdateDirectory();
  2443. if ( update_count < 0 )
  2444. {
  2445. res |= CTEST_UPDATE_ERRORS;
  2446. }
  2447. }
  2448. if ( m_TestModel == cmCTest::CONTINUOUS && !update_count )
  2449. {
  2450. return 0;
  2451. }
  2452. if ( m_Tests[CONFIGURE_TEST] || m_Tests[ALL_TEST] )
  2453. {
  2454. if (this->ConfigureDirectory())
  2455. {
  2456. res |= CTEST_CONFIGURE_ERRORS;
  2457. }
  2458. }
  2459. if ( m_Tests[BUILD_TEST] || m_Tests[ALL_TEST] )
  2460. {
  2461. this->UpdateCTestConfiguration();
  2462. if (this->BuildDirectory())
  2463. {
  2464. res |= CTEST_BUILD_ERRORS;
  2465. }
  2466. }
  2467. if ( m_Tests[TEST_TEST] || m_Tests[ALL_TEST] || notest )
  2468. {
  2469. this->UpdateCTestConfiguration();
  2470. if (this->TestDirectory(false))
  2471. {
  2472. res |= CTEST_TEST_ERRORS;
  2473. }
  2474. }
  2475. if ( m_Tests[COVERAGE_TEST] || m_Tests[ALL_TEST] )
  2476. {
  2477. this->UpdateCTestConfiguration();
  2478. this->CoverageDirectory();
  2479. }
  2480. if ( m_Tests[MEMCHECK_TEST] || m_Tests[ALL_TEST] )
  2481. {
  2482. this->UpdateCTestConfiguration();
  2483. if (this->TestDirectory(true))
  2484. {
  2485. res |= CTEST_MEMORY_ERRORS;
  2486. }
  2487. }
  2488. if ( m_Tests[NOTES_TEST] || m_Tests[ALL_TEST] )
  2489. {
  2490. this->UpdateCTestConfiguration();
  2491. if ( m_NotesFiles.size() )
  2492. {
  2493. this->GenerateNotesFile(m_NotesFiles.c_str());
  2494. }
  2495. }
  2496. if ( m_Tests[SUBMIT_TEST] || m_Tests[ALL_TEST] )
  2497. {
  2498. this->UpdateCTestConfiguration();
  2499. this->SubmitResults();
  2500. }
  2501. return res;
  2502. }
  2503. std::string cmCTest::GetTestModelString()
  2504. {
  2505. switch ( m_TestModel )
  2506. {
  2507. case cmCTest::NIGHTLY:
  2508. return "Nightly";
  2509. case cmCTest::CONTINUOUS:
  2510. return "Continuous";
  2511. }
  2512. return "Experimental";
  2513. }
  2514. int cmCTest::GetTestModelFromString(const char* str)
  2515. {
  2516. if ( !str )
  2517. {
  2518. return cmCTest::EXPERIMENTAL;
  2519. }
  2520. std::string rstr = cmSystemTools::LowerCase(str);
  2521. if ( strncmp(rstr.c_str(), "cont", 4) == 0 )
  2522. {
  2523. return cmCTest::CONTINUOUS;
  2524. }
  2525. if ( strncmp(rstr.c_str(), "nigh", 4) == 0 )
  2526. {
  2527. return cmCTest::NIGHTLY;
  2528. }
  2529. return cmCTest::EXPERIMENTAL;
  2530. }
  2531. #define SPACE_REGEX "[ \t\r\n]"
  2532. std::string cmCTest::GenerateRegressionImages(const std::string& xml)
  2533. {
  2534. cmsys::RegularExpression twoattributes(
  2535. "<DartMeasurement"
  2536. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2537. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2538. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2539. cmsys::RegularExpression threeattributes(
  2540. "<DartMeasurement"
  2541. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2542. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2543. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2544. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2545. cmsys::RegularExpression fourattributes(
  2546. "<DartMeasurement"
  2547. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2548. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2549. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2550. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2551. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  2552. cmsys::RegularExpression measurementfile(
  2553. "<DartMeasurementFile"
  2554. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2555. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  2556. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  2557. cmOStringStream ostr;
  2558. bool done = false;
  2559. std::string cxml = xml;
  2560. while ( ! done )
  2561. {
  2562. if ( twoattributes.find(cxml) )
  2563. {
  2564. ostr
  2565. << "\t\t\t<NamedMeasurement"
  2566. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  2567. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  2568. << "><Value>" << twoattributes.match(5)
  2569. << "</Value></NamedMeasurement>"
  2570. << std::endl;
  2571. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  2572. }
  2573. else if ( threeattributes.find(cxml) )
  2574. {
  2575. ostr
  2576. << "\t\t\t<NamedMeasurement"
  2577. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  2578. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  2579. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  2580. << "><Value>" << threeattributes.match(7)
  2581. << "</Value></NamedMeasurement>"
  2582. << std::endl;
  2583. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  2584. }
  2585. else if ( fourattributes.find(cxml) )
  2586. {
  2587. ostr
  2588. << "\t\t\t<NamedMeasurement"
  2589. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  2590. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  2591. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  2592. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  2593. << "><Value>" << fourattributes.match(9)
  2594. << "</Value></NamedMeasurement>"
  2595. << std::endl;
  2596. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  2597. }
  2598. else if ( measurementfile.find(cxml) )
  2599. {
  2600. const std::string& filename = ::CleanString(measurementfile.match(5));
  2601. if ( cmSystemTools::FileExists(filename.c_str()) )
  2602. {
  2603. long len = cmSystemTools::FileLength(filename.c_str());
  2604. std::ifstream ifs(filename.c_str(), std::ios::in
  2605. #ifdef _WIN32
  2606. | std::ios::binary
  2607. #endif
  2608. );
  2609. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  2610. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  2611. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 1) ];
  2612. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  2613. unsigned long cc;
  2614. ostr
  2615. << "\t\t\t<NamedMeasurement"
  2616. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  2617. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  2618. << " encoding=\"base64\""
  2619. << ">" << std::endl << "\t\t\t\t<Value>";
  2620. for ( cc = 0; cc < rlen; cc ++ )
  2621. {
  2622. ostr << encoded_buffer[cc];
  2623. if ( cc % 60 == 0 && cc )
  2624. {
  2625. ostr << std::endl;
  2626. }
  2627. }
  2628. ostr
  2629. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  2630. << std::endl;
  2631. delete [] file_buffer;
  2632. delete [] encoded_buffer;
  2633. }
  2634. else
  2635. {
  2636. int idx = 4;
  2637. if ( measurementfile.match(1) == "name" )
  2638. {
  2639. idx = 2;
  2640. }
  2641. ostr
  2642. << "\t\t\t<NamedMeasurement"
  2643. << " name=\"" << measurementfile.match(idx) << "\""
  2644. << " text=\"text/string\""
  2645. << "><Value>File " << filename << " not found</Value></NamedMeasurement>"
  2646. << std::endl;
  2647. std::cout << "File \"" << filename.c_str() << "\" not found." << std::endl;
  2648. }
  2649. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  2650. }
  2651. else
  2652. {
  2653. done = true;
  2654. }
  2655. }
  2656. return ostr.str();
  2657. }
  2658. int cmCTest::RunMakeCommand(const char* command, std::string* output,
  2659. int* retVal, const char* dir, bool verbose, int timeout, std::ofstream& ofs)
  2660. {
  2661. std::vector<cmStdString> args = cmSystemTools::ParseArguments(command);
  2662. if(args.size() < 1)
  2663. {
  2664. return false;
  2665. }
  2666. std::vector<const char*> argv;
  2667. for(std::vector<cmStdString>::const_iterator a = args.begin();
  2668. a != args.end(); ++a)
  2669. {
  2670. argv.push_back(a->c_str());
  2671. }
  2672. argv.push_back(0);
  2673. if ( output )
  2674. {
  2675. *output = "";
  2676. }
  2677. cmsysProcess* cp = cmsysProcess_New();
  2678. cmsysProcess_SetCommand(cp, &*argv.begin());
  2679. cmsysProcess_SetWorkingDirectory(cp, dir);
  2680. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2681. cmsysProcess_SetTimeout(cp, timeout);
  2682. cmsysProcess_Execute(cp);
  2683. std::string::size_type tick = 0;
  2684. std::string::size_type tick_len = 1024;
  2685. std::string::size_type tick_line_len = 50;
  2686. char* data;
  2687. int length;
  2688. if ( !verbose )
  2689. {
  2690. std::cout << " Each . represents " << tick_len << " bytes of output" << std::endl;
  2691. std::cout << " " << std::flush;
  2692. }
  2693. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  2694. {
  2695. if ( output )
  2696. {
  2697. for(int cc =0; cc < length; ++cc)
  2698. {
  2699. if(data[cc] == 0)
  2700. {
  2701. data[cc] = '\n';
  2702. }
  2703. }
  2704. output->append(data, length);
  2705. if ( !verbose )
  2706. {
  2707. while ( output->size() > (tick * tick_len) )
  2708. {
  2709. tick ++;
  2710. std::cout << "." << std::flush;
  2711. if ( tick % tick_line_len == 0 && tick > 0 )
  2712. {
  2713. std::cout << " Size: ";
  2714. std::cout << int((output->size() / 1024.0) + 1) << "K" << std::endl;
  2715. std::cout << " " << std::flush;
  2716. }
  2717. }
  2718. }
  2719. }
  2720. if(verbose)
  2721. {
  2722. std::cout.write(data, length);
  2723. std::cout.flush();
  2724. }
  2725. if ( ofs )
  2726. {
  2727. ofs.write(data, length);
  2728. ofs.flush();
  2729. }
  2730. }
  2731. std::cout << " Size of output: ";
  2732. std::cout << int(output->size() / 1024.0) << "K" << std::endl;
  2733. cmsysProcess_WaitForExit(cp, 0);
  2734. int result = cmsysProcess_GetState(cp);
  2735. if(result == cmsysProcess_State_Exited)
  2736. {
  2737. *retVal = cmsysProcess_GetExitValue(cp);
  2738. }
  2739. else if(result == cmsysProcess_State_Exception)
  2740. {
  2741. *retVal = cmsysProcess_GetExitException(cp);
  2742. std::cout << "There was an exception: " << *retVal << std::endl;
  2743. }
  2744. else if(result == cmsysProcess_State_Expired)
  2745. {
  2746. std::cout << "There was a timeout" << std::endl;
  2747. }
  2748. else if(result == cmsysProcess_State_Error)
  2749. {
  2750. *output += "\n*** ERROR executing: ";
  2751. *output += cmsysProcess_GetErrorString(cp);
  2752. }
  2753. cmsysProcess_Delete(cp);
  2754. return result;
  2755. }
  2756. int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, int *retVal)
  2757. {
  2758. if(cmSystemTools::SameFile(argv[0], m_CTestSelf.c_str()))
  2759. {
  2760. cmCTest inst;
  2761. std::vector<std::string> args;
  2762. for(unsigned int i =0; i < argv.size(); ++i)
  2763. {
  2764. if(argv[i])
  2765. {
  2766. args.push_back(argv[i]);
  2767. }
  2768. }
  2769. std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
  2770. *retVal = inst.Run(args, output);
  2771. cmSystemTools::ChangeDirectory(oldpath.c_str());
  2772. if(m_Verbose)
  2773. {
  2774. std::cout << "Internal cmCTest object used to run test.\n";
  2775. std::cout << *output << "\n";
  2776. }
  2777. return cmsysProcess_State_Exited;
  2778. }
  2779. std::vector<char> tempOutput;
  2780. if ( output )
  2781. {
  2782. *output = "";
  2783. }
  2784. cmsysProcess* cp = cmsysProcess_New();
  2785. cmsysProcess_SetCommand(cp, &*argv.begin());
  2786. // std::cout << "Command is: " << argv[0] << std::endl;
  2787. if(cmSystemTools::GetRunCommandHideConsole())
  2788. {
  2789. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2790. }
  2791. cmsysProcess_SetTimeout(cp, m_TimeOut);
  2792. cmsysProcess_Execute(cp);
  2793. char* data;
  2794. int length;
  2795. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  2796. {
  2797. if ( output )
  2798. {
  2799. tempOutput.insert(tempOutput.end(), data, data+length);
  2800. }
  2801. if ( m_Verbose )
  2802. {
  2803. std::cout.write(data, length);
  2804. std::cout.flush();
  2805. }
  2806. }
  2807. cmsysProcess_WaitForExit(cp, 0);
  2808. if(output)
  2809. {
  2810. output->append(&*tempOutput.begin(), tempOutput.size());
  2811. }
  2812. int result = cmsysProcess_GetState(cp);
  2813. if(result == cmsysProcess_State_Exited)
  2814. {
  2815. *retVal = cmsysProcess_GetExitValue(cp);
  2816. }
  2817. else if(result == cmsysProcess_State_Exception)
  2818. {
  2819. *retVal = cmsysProcess_GetExitException(cp);
  2820. std::string outerr = "\n*** Exception executing: ";
  2821. outerr += cmsysProcess_GetExceptionString(cp);
  2822. *output += outerr;
  2823. if ( m_Verbose )
  2824. {
  2825. std::cout << outerr.c_str() << "\n";
  2826. std::cout.flush();
  2827. }
  2828. }
  2829. else if(result == cmsysProcess_State_Error)
  2830. {
  2831. std::string outerr = "\n*** ERROR executing: ";
  2832. outerr += cmsysProcess_GetErrorString(cp);
  2833. *output += outerr;
  2834. if ( m_Verbose )
  2835. {
  2836. std::cout << outerr.c_str() << "\n";
  2837. std::cout.flush();
  2838. }
  2839. }
  2840. cmsysProcess_Delete(cp);
  2841. return result;
  2842. }
  2843. const char* cmCTest::GetTestStatus(int status)
  2844. {
  2845. static const char statuses[][100] = {
  2846. "Not Run",
  2847. "Timeout",
  2848. "SEGFAULT",
  2849. "ILLEGAL",
  2850. "INTERRUPT",
  2851. "NUMERICAL",
  2852. "OTHER_FAULT",
  2853. "Failed",
  2854. "BAD_COMMAND",
  2855. "Completed"
  2856. };
  2857. if ( status < cmCTest::NOT_RUN || status > cmCTest::COMPLETED )
  2858. {
  2859. return "No Status";
  2860. }
  2861. return statuses[status];
  2862. }
  2863. void cmCTest::RestoreBackupDirectories(bool backup,
  2864. const char *srcDir,
  2865. const char *binDir,
  2866. const char *backupSrcDir,
  2867. const char *backupBinDir)
  2868. {
  2869. // if we backed up the dirs and the build failed, then restore
  2870. // the backed up dirs
  2871. if (backup)
  2872. {
  2873. // if for some reason those directories exist then first delete them
  2874. if (cmSystemTools::FileExists(srcDir))
  2875. {
  2876. cmSystemTools::RemoveADirectory(srcDir);
  2877. }
  2878. if (cmSystemTools::FileExists(binDir))
  2879. {
  2880. cmSystemTools::RemoveADirectory(binDir);
  2881. }
  2882. // rename the src and binary directories
  2883. rename(backupSrcDir, srcDir);
  2884. rename(backupBinDir, binDir);
  2885. }
  2886. }
  2887. int cmCTest::RunConfigurationScript()
  2888. {
  2889. m_ConfigurationScript =
  2890. cmSystemTools::CollapseFullPath(m_ConfigurationScript.c_str());
  2891. // make sure the file exists
  2892. if (!cmSystemTools::FileExists(m_ConfigurationScript.c_str()))
  2893. {
  2894. return 1;
  2895. }
  2896. // create a cmake instance to read the configuration script
  2897. cmake cm;
  2898. cmGlobalGenerator gg;
  2899. gg.SetCMakeInstance(&cm);
  2900. // read in the list file to fill the cache
  2901. cmLocalGenerator *lg = gg.CreateLocalGenerator();
  2902. lg->SetGlobalGenerator(&gg);
  2903. // set a variable with the path to the current script
  2904. lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_DIRECTORY",
  2905. cmSystemTools::GetFilenamePath(
  2906. m_ConfigurationScript).c_str());
  2907. lg->GetMakefile()->AddDefinition("CTEST_SCRIPT_NAME",
  2908. cmSystemTools::GetFilenameName(
  2909. m_ConfigurationScript).c_str());
  2910. if (!lg->GetMakefile()->ReadListFile(0, m_ConfigurationScript.c_str()))
  2911. {
  2912. return 2;
  2913. }
  2914. // no popup widows
  2915. cmSystemTools::SetRunCommandHideConsole(true);
  2916. // get some info that should be set
  2917. cmMakefile *mf = lg->GetMakefile();
  2918. const char *srcDir = mf->GetDefinition("CTEST_SOURCE_DIRECTORY");
  2919. const char *binDir = mf->GetDefinition("CTEST_BINARY_DIRECTORY");
  2920. const char *ctestCmd = mf->GetDefinition("CTEST_COMMAND");
  2921. const char *ctestEnv = mf->GetDefinition("CTEST_ENVIRONMENT");
  2922. const char *ctestRoot = mf->GetDefinition("CTEST_DASHBOARD_ROOT");
  2923. bool backup = mf->IsOn("CTEST_BACKUP_AND_RESTORE");
  2924. // in order to back we also must have the cvs root
  2925. const char *cvsCmd = mf->GetDefinition("CTEST_CVS_COMMAND");
  2926. const char *cvsCheckOut = mf->GetDefinition("CTEST_CVS_CHECKOUT");
  2927. if (backup && !cvsCheckOut)
  2928. {
  2929. cmSystemTools::Error("Backup was requested without a cvs checkout");
  2930. return 3;
  2931. }
  2932. // make sure the required info is here
  2933. if (!srcDir || !binDir || !ctestCmd)
  2934. {
  2935. cmSystemTools::Error("Some required settings in the configuration file were missing");
  2936. return 4;
  2937. }
  2938. // set any environment variables
  2939. if (ctestEnv)
  2940. {
  2941. std::vector<std::string> envArgs;
  2942. cmSystemTools::ExpandListArgument(ctestEnv,envArgs);
  2943. // for each variable/argument do a putenv
  2944. for (unsigned i = 0; i < envArgs.size(); ++i)
  2945. {
  2946. cmSystemTools::PutEnv(envArgs[i].c_str());
  2947. }
  2948. }
  2949. // local variables
  2950. std::string command;
  2951. std::string output;
  2952. int retVal = 0;
  2953. bool res;
  2954. // compute the backup names
  2955. std::string backupSrcDir = srcDir;
  2956. backupSrcDir += "_CMakeBackup";
  2957. std::string backupBinDir = binDir;
  2958. backupBinDir += "_CMakeBackup";
  2959. // backup the binary and src directories if requested
  2960. if (backup)
  2961. {
  2962. // if for some reason those directories exist then first delete them
  2963. if (cmSystemTools::FileExists(backupSrcDir.c_str()))
  2964. {
  2965. cmSystemTools::RemoveADirectory(backupSrcDir.c_str());
  2966. }
  2967. if (cmSystemTools::FileExists(backupBinDir.c_str()))
  2968. {
  2969. cmSystemTools::RemoveADirectory(backupBinDir.c_str());
  2970. }
  2971. // first rename the src and binary directories
  2972. rename(srcDir, backupSrcDir.c_str());
  2973. rename(binDir, backupBinDir.c_str());
  2974. // we must now checkout the src dir
  2975. output = "";
  2976. res = cmSystemTools::RunSingleCommand(cvsCheckOut, &output,
  2977. &retVal, ctestRoot,
  2978. m_Verbose, 0 /*m_TimeOut*/);
  2979. if (!res || retVal != 0)
  2980. {
  2981. cmSystemTools::Error("Unable to perform cvs checkout ");
  2982. this->RestoreBackupDirectories(backup, srcDir, binDir,
  2983. backupSrcDir.c_str(),
  2984. backupBinDir.c_str());
  2985. return 6;
  2986. }
  2987. }
  2988. // clear the binary directory?
  2989. if (mf->IsOn("CTEST_START_WITH_EMPTY_BINARY_DIRECTORY"))
  2990. {
  2991. // try to avoid deleting directories that we shouldn't
  2992. std::string check = binDir;
  2993. check += "/CMakeCache.txt";
  2994. if (cmSystemTools::FileExists(check.c_str()))
  2995. {
  2996. cmSystemTools::RemoveADirectory(binDir);
  2997. }
  2998. }
  2999. // make sure the binary directory exists
  3000. if (!cmSystemTools::FileExists(binDir))
  3001. {
  3002. if (!cmSystemTools::MakeDirectory(binDir))
  3003. {
  3004. cmSystemTools::Error("Unable to create the binary directory");
  3005. this->RestoreBackupDirectories(backup, srcDir, binDir,
  3006. backupSrcDir.c_str(),
  3007. backupBinDir.c_str());
  3008. return 7;
  3009. }
  3010. }
  3011. // do an initial cvs update as required
  3012. if (cvsCmd)
  3013. {
  3014. command = cvsCmd;
  3015. char updateVar[40];
  3016. int i;
  3017. for (i = 1; i < 10; ++i)
  3018. {
  3019. sprintf(updateVar,"CTEST_EXTRA_UPDATES_%i",i);
  3020. const char *updateVal = mf->GetDefinition(updateVar);
  3021. if (updateVal)
  3022. {
  3023. std::vector<std::string> cvsArgs;
  3024. cmSystemTools::ExpandListArgument(updateVal,cvsArgs);
  3025. if (cvsArgs.size() == 2)
  3026. {
  3027. std::string fullCommand = command;
  3028. fullCommand += " update ";
  3029. fullCommand += cvsArgs[1];
  3030. output = "";
  3031. retVal = 0;
  3032. res = cmSystemTools::RunSingleCommand(fullCommand.c_str(), &output,
  3033. &retVal, cvsArgs[0].c_str(),
  3034. m_Verbose, 0 /*m_TimeOut*/);
  3035. if (!res || retVal != 0)
  3036. {
  3037. cmSystemTools::Error("Unable to perform extra cvs updates");
  3038. this->RestoreBackupDirectories(backup, srcDir, binDir,
  3039. backupSrcDir.c_str(),
  3040. backupBinDir.c_str());
  3041. return 8;
  3042. }
  3043. }
  3044. }
  3045. }
  3046. }
  3047. // put the initial cache into the bin dir
  3048. if (mf->GetDefinition("CTEST_INITIAL_CACHE"))
  3049. {
  3050. const char *initCache = mf->GetDefinition("CTEST_INITIAL_CACHE");
  3051. std::string cacheFile = binDir;
  3052. cacheFile += "/CMakeCache.txt";
  3053. std::ofstream fout(cacheFile.c_str());
  3054. if(!fout)
  3055. {
  3056. this->RestoreBackupDirectories(backup, srcDir, binDir,
  3057. backupSrcDir.c_str(),
  3058. backupBinDir.c_str());
  3059. return 9;
  3060. }
  3061. fout.write(initCache, strlen(initCache));
  3062. // Make sure the operating system has finished writing the file
  3063. // before closing it. This will ensure the file is finished before
  3064. // the check below.
  3065. fout.flush();
  3066. fout.close();
  3067. }
  3068. // do an initial cmake to setup the DartConfig file
  3069. const char *cmakeCmd = mf->GetDefinition("CTEST_CMAKE_COMMAND");
  3070. int cmakeFailed = 0;
  3071. if (cmakeCmd)
  3072. {
  3073. command = cmakeCmd;
  3074. command += " \"";
  3075. command += srcDir;
  3076. output = "";
  3077. command += "\"";
  3078. retVal = 0;
  3079. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  3080. &retVal, binDir,
  3081. m_Verbose, 0 /*m_TimeOut*/);
  3082. if (!res || retVal != 0)
  3083. {
  3084. // even if this fails continue to the next step
  3085. cmakeFailed = 1;
  3086. }
  3087. }
  3088. // run ctest
  3089. command = ctestCmd;
  3090. output = "";
  3091. retVal = 0;
  3092. res = cmSystemTools::RunSingleCommand(command.c_str(), &output,
  3093. &retVal, binDir,
  3094. m_Verbose, 0 /*m_TimeOut*/);
  3095. // did something critical fail in ctest
  3096. if (!res || cmakeFailed ||
  3097. retVal & CTEST_BUILD_ERRORS)
  3098. {
  3099. this->RestoreBackupDirectories(backup, srcDir, binDir,
  3100. backupSrcDir.c_str(),
  3101. backupBinDir.c_str());
  3102. if (cmakeFailed)
  3103. {
  3104. cmSystemTools::Error("Unable to run cmake");
  3105. return 10;
  3106. }
  3107. cmSystemTools::Error("Unable to run ctest");
  3108. if (!res)
  3109. {
  3110. return 11;
  3111. }
  3112. return retVal * 100;
  3113. }
  3114. // if all was succesful, delete the backup dirs to free up disk space
  3115. if (backup)
  3116. {
  3117. cmSystemTools::RemoveADirectory(backupSrcDir.c_str());
  3118. cmSystemTools::RemoveADirectory(backupBinDir.c_str());
  3119. }
  3120. return 0;
  3121. }
  3122. void cmCTest::StartXML(std::ostream& ostr)
  3123. {
  3124. ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  3125. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"]
  3126. << "\" BuildStamp=\"" << m_CurrentTag << "-"
  3127. << this->GetTestModelString() << "\" Name=\""
  3128. << m_DartConfiguration["Site"] << "\" Generator=\"ctest\">" << std::endl;
  3129. }
  3130. void cmCTest::EndXML(std::ostream& ostr)
  3131. {
  3132. ostr << "</Site>" << std::endl;
  3133. }
  3134. bool cmCTest::ProcessMemCheckPurifyOutput(const std::string&, std::string& log,
  3135. int* results)
  3136. {
  3137. if ( !cmSystemTools::FileExists(m_MemoryTesterOutputFile.c_str()) )
  3138. {
  3139. log = "Cannot find Purify output file: " + m_MemoryTesterOutputFile;
  3140. std::cerr << log.c_str() << std::endl;
  3141. return false;
  3142. }
  3143. std::ifstream ifs(m_MemoryTesterOutputFile.c_str());
  3144. if ( !ifs )
  3145. {
  3146. log = "Cannot read Purify output file: " + m_MemoryTesterOutputFile;
  3147. std::cerr << log.c_str() << std::endl;
  3148. return false;
  3149. }
  3150. cmOStringStream ostr;
  3151. log = "";
  3152. cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
  3153. std::string line;
  3154. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  3155. {
  3156. int failure = cmCTest::NO_MEMORY_FAULT;
  3157. if ( pfW.find(line) )
  3158. {
  3159. int cc;
  3160. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  3161. {
  3162. if ( pfW.match(1) == cmCTestMemCheckResultStrings[cc] )
  3163. {
  3164. failure = cc;
  3165. break;
  3166. }
  3167. }
  3168. if ( cc == cmCTest::NO_MEMORY_FAULT )
  3169. {
  3170. std::cerr<< "Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  3171. ostr << "*** Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  3172. }
  3173. }
  3174. if ( failure != NO_MEMORY_FAULT )
  3175. {
  3176. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  3177. results[failure] ++;
  3178. }
  3179. ostr << cmCTest::MakeXMLSafe(line) << std::endl;
  3180. }
  3181. log = ostr.str();
  3182. return true;
  3183. }
  3184. bool cmCTest::ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
  3185. int* results)
  3186. {
  3187. std::vector<cmStdString> lines;
  3188. cmSystemTools::Split(str.c_str(), lines);
  3189. std::string::size_type cc;
  3190. cmOStringStream ostr;
  3191. log = "";
  3192. cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
  3193. cmsys::RegularExpression vgFIM(
  3194. "== .*Invalid free\\(\\) / delete / delete\\[\\]");
  3195. cmsys::RegularExpression vgFMM(
  3196. "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
  3197. cmsys::RegularExpression vgMLK(
  3198. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are definitely lost"
  3199. " in loss record [0-9][0-9]* of [0-9]");
  3200. cmsys::RegularExpression vgPAR(
  3201. "== .*Syscall param .* contains unaddressable byte\\(s\\)");
  3202. cmsys::RegularExpression vgMPK1(
  3203. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are possibly lost in"
  3204. " loss record [0-9][0-9]* of [0-9]");
  3205. cmsys::RegularExpression vgMPK2(
  3206. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are still reachable"
  3207. " in loss record [0-9][0-9]* of [0-9]");
  3208. cmsys::RegularExpression vgUMC(
  3209. "== .*Conditional jump or move depends on uninitialised value\\(s\\)");
  3210. cmsys::RegularExpression vgUMR1("== .*Use of uninitialised value of size [0-9][0-9]*");
  3211. cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9][0-9]*");
  3212. cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
  3213. cmsys::RegularExpression vgUMR4(
  3214. "== .*Syscall param .* contains uninitialised or unaddressable byte\\(s\\)");
  3215. cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9]");
  3216. for ( cc = 0; cc < lines.size(); cc ++ )
  3217. {
  3218. if ( valgrindLine.find(lines[cc]) )
  3219. {
  3220. int failure = cmCTest::NO_MEMORY_FAULT;
  3221. if ( vgFIM.find(lines[cc]) ) { failure = cmCTest::FIM; }
  3222. else if ( vgFMM.find(lines[cc]) ) { failure = cmCTest::FMM; }
  3223. else if ( vgMLK.find(lines[cc]) ) { failure = cmCTest::MLK; }
  3224. else if ( vgPAR.find(lines[cc]) ) { failure = cmCTest::PAR; }
  3225. else if ( vgMPK1.find(lines[cc]) ){ failure = cmCTest::MPK; }
  3226. else if ( vgMPK2.find(lines[cc]) ){ failure = cmCTest::MPK; }
  3227. else if ( vgUMC.find(lines[cc]) ) { failure = cmCTest::UMC; }
  3228. else if ( vgUMR1.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3229. else if ( vgUMR2.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3230. else if ( vgUMR3.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3231. else if ( vgUMR4.find(lines[cc]) ){ failure = cmCTest::UMR; }
  3232. else if ( vgIPW.find(lines[cc]) ) { failure = cmCTest::IPW; }
  3233. if ( failure != cmCTest::NO_MEMORY_FAULT )
  3234. {
  3235. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  3236. results[failure] ++;
  3237. }
  3238. ostr << cmCTest::MakeXMLSafe(lines[cc]) << std::endl;
  3239. }
  3240. }
  3241. log = ostr.str();
  3242. return true;
  3243. }
  3244. bool cmCTest::ProcessMemCheckOutput(const std::string& str, std::string& log, int* results)
  3245. {
  3246. std::string::size_type cc;
  3247. for ( cc = 0; cc < cmCTest::NO_MEMORY_FAULT; cc ++ )
  3248. {
  3249. results[cc] = 0;
  3250. }
  3251. if ( m_MemoryTesterStyle == cmCTest::VALGRIND )
  3252. {
  3253. return ProcessMemCheckValgrindOutput(str, log, results);
  3254. }
  3255. else if ( m_MemoryTesterStyle == cmCTest::PURIFY )
  3256. {
  3257. return ProcessMemCheckPurifyOutput(str, log, results);
  3258. }
  3259. else if ( m_MemoryTesterStyle == cmCTest::BOUNDS_CHECKER )
  3260. {
  3261. log.append("\nMemory checking style used was: ");
  3262. log.append("Bounds Checker");
  3263. }
  3264. else
  3265. {
  3266. log.append("\nMemory checking style used was: ");
  3267. log.append("None that I know");
  3268. log = str;
  3269. }
  3270. return true;
  3271. }
  3272. int cmCTest::GenerateDartNotesOutput(std::ostream& os, const cmCTest::tm_VectorOfStrings& files)
  3273. {
  3274. cmCTest::tm_VectorOfStrings::const_iterator it;
  3275. for ( it = files.begin(); it != files.end(); it ++ )
  3276. {
  3277. if ( !cmSystemTools::FileExists(it->c_str()) )
  3278. {
  3279. std::cerr << "Error creating notes. File " << it->c_str() << " does not exists" << std::endl;
  3280. return 0;
  3281. }
  3282. }
  3283. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  3284. << "<?xml-stylesheet type=\"text/xsl\" href=\"Dart/Source/Server/XSL/Build.xsl <file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
  3285. << "<Site BuildName=\"" << m_DartConfiguration["BuildName"] << "\" BuildStamp=\""
  3286. << m_CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
  3287. << m_DartConfiguration["Site"] << "\" Generator=\"ctest\">\n"
  3288. << "<Notes>" << std::endl;
  3289. for ( it = files.begin(); it != files.end(); it ++ )
  3290. {
  3291. std::cout << "\tAdd file: " << it->c_str() << std::endl;
  3292. std::string note_time = ::CurrentTime();
  3293. os << "<Note>\n"
  3294. << "<DateTime>" << note_time << "</DateTime>\n"
  3295. << "<Text>" << std::endl;
  3296. std::ifstream ifs(it->c_str());
  3297. if ( ifs )
  3298. {
  3299. std::string line;
  3300. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  3301. {
  3302. os << this->MakeXMLSafe(line) << std::endl;
  3303. }
  3304. ifs.close();
  3305. }
  3306. else
  3307. {
  3308. os << "Problem reading file: " << it->c_str() << std::endl;
  3309. std::cerr << "Problem reading file: " << it->c_str() << " while creating notes" << std::endl;
  3310. }
  3311. os << "</Text>\n"
  3312. << "</Note>" << std::endl;
  3313. }
  3314. os << "</Notes>\n"
  3315. << "</Site>" << std::endl;
  3316. return 1;
  3317. }
  3318. int cmCTest::GenerateNotesFile(const char* cfiles)
  3319. {
  3320. if ( !cfiles )
  3321. {
  3322. return 1;
  3323. }
  3324. std::vector<cmStdString> files;
  3325. std::cout << "Create notes file" << std::endl;
  3326. files = cmSystemTools::SplitString(cfiles, ';');
  3327. if ( files.size() == 0 )
  3328. {
  3329. return 1;
  3330. }
  3331. std::ofstream ofs;
  3332. if ( !this->OpenOutputFile(m_CurrentTag, "Notes.xml", ofs) )
  3333. {
  3334. std::cerr << "Cannot open notes file" << std::endl;
  3335. return 1;
  3336. }
  3337. this->GenerateDartNotesOutput(ofs, files);
  3338. return 0;
  3339. }
  3340. int cmCTest::Run(std::vector<std::string>const& args, std::string* output)
  3341. {
  3342. this->FindRunningCMake(args[0].c_str());
  3343. bool cmakeAndTest = false;
  3344. for(unsigned int i=1; i < args.size(); ++i)
  3345. {
  3346. std::string arg = args[i];
  3347. if(arg.find("-C",0) == 0 && i < args.size() - 1)
  3348. {
  3349. i++;
  3350. this->m_ConfigType = args[i];
  3351. }
  3352. if( arg.find("-V",0) == 0 || arg.find("--verbose",0) == 0 )
  3353. {
  3354. this->m_Verbose = true;
  3355. }
  3356. if( arg.find("-N",0) == 0 || arg.find("--show-only",0) == 0 )
  3357. {
  3358. this->m_ShowOnly = true;
  3359. }
  3360. if( arg.find("-S",0) == 0 && i < args.size() - 1 )
  3361. {
  3362. this->m_RunConfigurationScript = true;
  3363. i++;
  3364. this->m_ConfigurationScript = args[i];
  3365. }
  3366. if( arg.find("-D",0) == 0 && i < args.size() - 1 )
  3367. {
  3368. this->m_DartMode = true;
  3369. i++;
  3370. std::string targ = args[i];
  3371. if ( targ == "Experimental" )
  3372. {
  3373. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3374. this->SetTest("Start");
  3375. this->SetTest("Configure");
  3376. this->SetTest("Build");
  3377. this->SetTest("Test");
  3378. this->SetTest("Coverage");
  3379. this->SetTest("Submit");
  3380. }
  3381. else if ( targ == "ExperimentalStart" )
  3382. {
  3383. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3384. this->SetTest("Start");
  3385. }
  3386. else if ( targ == "ExperimentalUpdate" )
  3387. {
  3388. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3389. this->SetTest("Update");
  3390. }
  3391. else if ( targ == "ExperimentalConfigure" )
  3392. {
  3393. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3394. this->SetTest("Configure");
  3395. }
  3396. else if ( targ == "ExperimentalBuild" )
  3397. {
  3398. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3399. this->SetTest("Build");
  3400. }
  3401. else if ( targ == "ExperimentalTest" )
  3402. {
  3403. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3404. this->SetTest("Test");
  3405. }
  3406. else if ( targ == "ExperimentalMemCheck" || targ == "ExperimentalPurify" )
  3407. {
  3408. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3409. this->SetTest("MemCheck");
  3410. }
  3411. else if ( targ == "ExperimentalCoverage" )
  3412. {
  3413. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3414. this->SetTest("Coverage");
  3415. }
  3416. else if ( targ == "ExperimentalSubmit" )
  3417. {
  3418. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3419. this->SetTest("Submit");
  3420. }
  3421. else if ( targ == "Continuous" )
  3422. {
  3423. this->SetTestModel(cmCTest::CONTINUOUS);
  3424. this->SetTest("Start");
  3425. this->SetTest("Update");
  3426. this->SetTest("Configure");
  3427. this->SetTest("Build");
  3428. this->SetTest("Test");
  3429. this->SetTest("Coverage");
  3430. this->SetTest("Submit");
  3431. }
  3432. else if ( targ == "ContinuousStart" )
  3433. {
  3434. this->SetTestModel(cmCTest::CONTINUOUS);
  3435. this->SetTest("Start");
  3436. }
  3437. else if ( targ == "ContinuousUpdate" )
  3438. {
  3439. this->SetTestModel(cmCTest::CONTINUOUS);
  3440. this->SetTest("Update");
  3441. }
  3442. else if ( targ == "ContinuousConfigure" )
  3443. {
  3444. this->SetTestModel(cmCTest::CONTINUOUS);
  3445. this->SetTest("Configure");
  3446. }
  3447. else if ( targ == "ContinuousBuild" )
  3448. {
  3449. this->SetTestModel(cmCTest::CONTINUOUS);
  3450. this->SetTest("Build");
  3451. }
  3452. else if ( targ == "ContinuousTest" )
  3453. {
  3454. this->SetTestModel(cmCTest::CONTINUOUS);
  3455. this->SetTest("Test");
  3456. }
  3457. else if ( targ == "ContinuousMemCheck" || targ == "ContinuousPurify" )
  3458. {
  3459. this->SetTestModel(cmCTest::CONTINUOUS);
  3460. this->SetTest("MemCheck");
  3461. }
  3462. else if ( targ == "ContinuousCoverage" )
  3463. {
  3464. this->SetTestModel(cmCTest::CONTINUOUS);
  3465. this->SetTest("Coverage");
  3466. }
  3467. else if ( targ == "ContinuousSubmit" )
  3468. {
  3469. this->SetTestModel(cmCTest::CONTINUOUS);
  3470. this->SetTest("Submit");
  3471. }
  3472. else if ( targ == "Nightly" )
  3473. {
  3474. this->SetTestModel(cmCTest::NIGHTLY);
  3475. this->SetTest("Start");
  3476. this->SetTest("Update");
  3477. this->SetTest("Configure");
  3478. this->SetTest("Build");
  3479. this->SetTest("Test");
  3480. this->SetTest("Coverage");
  3481. this->SetTest("Submit");
  3482. }
  3483. else if ( targ == "NightlyStart" )
  3484. {
  3485. this->SetTestModel(cmCTest::NIGHTLY);
  3486. this->SetTest("Start");
  3487. }
  3488. else if ( targ == "NightlyUpdate" )
  3489. {
  3490. this->SetTestModel(cmCTest::NIGHTLY);
  3491. this->SetTest("Update");
  3492. }
  3493. else if ( targ == "NightlyConfigure" )
  3494. {
  3495. this->SetTestModel(cmCTest::NIGHTLY);
  3496. this->SetTest("Configure");
  3497. }
  3498. else if ( targ == "NightlyBuild" )
  3499. {
  3500. this->SetTestModel(cmCTest::NIGHTLY);
  3501. this->SetTest("Build");
  3502. }
  3503. else if ( targ == "NightlyTest" )
  3504. {
  3505. this->SetTestModel(cmCTest::NIGHTLY);
  3506. this->SetTest("Test");
  3507. }
  3508. else if ( targ == "NightlyMemCheck" || targ == "NightlyPurify" )
  3509. {
  3510. this->SetTestModel(cmCTest::NIGHTLY);
  3511. this->SetTest("MemCheck");
  3512. }
  3513. else if ( targ == "NightlyCoverage" )
  3514. {
  3515. this->SetTestModel(cmCTest::NIGHTLY);
  3516. this->SetTest("Coverage");
  3517. }
  3518. else if ( targ == "NightlySubmit" )
  3519. {
  3520. this->SetTestModel(cmCTest::NIGHTLY);
  3521. this->SetTest("Submit");
  3522. }
  3523. else if ( targ == "MemoryCheck" )
  3524. {
  3525. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3526. this->SetTest("Start");
  3527. this->SetTest("Configure");
  3528. this->SetTest("Build");
  3529. this->SetTest("MemCheck");
  3530. this->SetTest("Coverage");
  3531. this->SetTest("Submit");
  3532. }
  3533. else if ( targ == "NightlyMemoryCheck" )
  3534. {
  3535. this->SetTestModel(cmCTest::NIGHTLY);
  3536. this->SetTest("Start");
  3537. this->SetTest("Update");
  3538. this->SetTest("Configure");
  3539. this->SetTest("Build");
  3540. this->SetTest("MemCheck");
  3541. this->SetTest("Coverage");
  3542. this->SetTest("Submit");
  3543. }
  3544. }
  3545. if( ( arg.find("-T",0) == 0 ) &&
  3546. (i < args.size() -1) )
  3547. {
  3548. this->m_DartMode = true;
  3549. i++;
  3550. this->SetTest(args[i].c_str());
  3551. }
  3552. if( ( arg.find("-M",0) == 0 || arg.find("--test-model",0) == 0 ) &&
  3553. (i < args.size() -1) )
  3554. {
  3555. i++;
  3556. std::string const& str = args[i];
  3557. if ( str == "NIGHTLY" || str == "nightly" || str == "Nightly" )
  3558. {
  3559. this->SetTestModel(cmCTest::NIGHTLY);
  3560. }
  3561. else if ( str == "CONTINUOUS" || str == "continuous" ||
  3562. str == "Continuous" )
  3563. {
  3564. this->SetTestModel(cmCTest::CONTINUOUS);
  3565. std::cout << "Continuous" << std::endl;
  3566. }
  3567. else
  3568. {
  3569. this->SetTestModel(cmCTest::EXPERIMENTAL);
  3570. }
  3571. }
  3572. if(arg.find("-R",0) == 0 && i < args.size() - 1)
  3573. {
  3574. this->m_UseIncludeRegExp = true;
  3575. i++;
  3576. this->m_IncludeRegExp = args[i];
  3577. }
  3578. if(arg.find("-E",0) == 0 && i < args.size() - 1)
  3579. {
  3580. this->m_UseExcludeRegExp = true;
  3581. i++;
  3582. this->m_ExcludeRegExp = args[i];
  3583. this->m_UseExcludeRegExpFirst = this->m_UseIncludeRegExp ? false : true;
  3584. }
  3585. if(arg.find("-A",0) == 0 && i < args.size() - 1)
  3586. {
  3587. this->m_DartMode = true;
  3588. this->SetTest("Notes");
  3589. i++;
  3590. this->SetNotesFiles(args[i].c_str());
  3591. }
  3592. // --build-and-test options
  3593. if(arg.find("--build-and-test",0) == 0 && i < args.size() - 1)
  3594. {
  3595. cmakeAndTest = true;
  3596. if(i+2 < args.size())
  3597. {
  3598. i++;
  3599. m_SourceDir = args[i];
  3600. i++;
  3601. m_BinaryDir = args[i];
  3602. // dir must exist before CollapseFullPath is called
  3603. cmSystemTools::MakeDirectory(m_BinaryDir.c_str());
  3604. m_BinaryDir = cmSystemTools::CollapseFullPath(m_BinaryDir.c_str());
  3605. m_SourceDir = cmSystemTools::CollapseFullPath(m_SourceDir.c_str());
  3606. }
  3607. else
  3608. {
  3609. std::cerr << "--build-and-test must have source and binary dir\n";
  3610. }
  3611. }
  3612. if(arg.find("--build-target",0) == 0 && i < args.size() - 1)
  3613. {
  3614. i++;
  3615. m_BuildTarget = args[i];
  3616. }
  3617. if(arg.find("--build-nocmake",0) == 0 && i < args.size() - 1)
  3618. {
  3619. m_BuildNoCMake = true;
  3620. }
  3621. if(arg.find("--build-run-dir",0) == 0 && i < args.size() - 1)
  3622. {
  3623. i++;
  3624. m_BuildRunDir = args[i];
  3625. }
  3626. if(arg.find("--build-two-config",0) == 0 && i < args.size() - 1)
  3627. {
  3628. m_BuildTwoConfig = true;
  3629. }
  3630. if(arg.find("--build-exe-dir",0) == 0 && i < args.size() - 1)
  3631. {
  3632. i++;
  3633. m_ExecutableDirectory = args[i];
  3634. }
  3635. if(arg.find("--build-generator",0) == 0 && i < args.size() - 1)
  3636. {
  3637. i++;
  3638. m_BuildGenerator = args[i];
  3639. }
  3640. if(arg.find("--build-project",0) == 0 && i < args.size() - 1)
  3641. {
  3642. i++;
  3643. m_BuildProject = args[i];
  3644. }
  3645. if(arg.find("--build-makeprogram",0) == 0 && i < args.size() - 1)
  3646. {
  3647. i++;
  3648. m_BuildMakeProgram = args[i];
  3649. }
  3650. if(arg.find("--build-noclean",0) == 0 && i < args.size() - 1)
  3651. {
  3652. m_BuildNoClean = true;
  3653. }
  3654. if(arg.find("--build-options",0) == 0 && i < args.size() - 1)
  3655. {
  3656. ++i;
  3657. bool done = false;
  3658. while(i < args.size() && !done)
  3659. {
  3660. m_BuildOptions.push_back(args[i]);
  3661. if(i+1 < args.size()
  3662. && (args[i+1] == "--build-target" || args[i+1] == "--test-command"))
  3663. {
  3664. done = true;
  3665. }
  3666. else
  3667. {
  3668. ++i;
  3669. }
  3670. }
  3671. }
  3672. if(arg.find("--test-command",0) == 0 && i < args.size() - 1)
  3673. {
  3674. ++i;
  3675. m_TestCommand = args[i];
  3676. while(i+1 < args.size())
  3677. {
  3678. ++i;
  3679. m_TestCommandArgs.push_back(args[i]);
  3680. }
  3681. }
  3682. }
  3683. if(cmakeAndTest)
  3684. {
  3685. cmSystemTools::ResetErrorOccuredFlag();
  3686. cmListFileCache::GetInstance()->ClearCache();
  3687. int retv = this->RunCMakeAndTest(output);
  3688. cmSystemTools::ResetErrorOccuredFlag();
  3689. cmListFileCache::GetInstance()->ClearCache();
  3690. #ifdef CMAKE_BUILD_WITH_CMAKE
  3691. cmDynamicLoader::FlushCache();
  3692. #endif
  3693. return retv;
  3694. }
  3695. int res;
  3696. // call process directory
  3697. if (this->m_RunConfigurationScript)
  3698. {
  3699. res = this->RunConfigurationScript();
  3700. }
  3701. else
  3702. {
  3703. if ( !this->Initialize() )
  3704. {
  3705. res = 12;
  3706. }
  3707. else
  3708. {
  3709. res = this->ProcessTests();
  3710. }
  3711. this->Finalize();
  3712. }
  3713. return res;
  3714. }
  3715. void cmCTest::FindRunningCMake(const char* arg0)
  3716. {
  3717. // Find our own executable.
  3718. std::vector<cmStdString> failures;
  3719. m_CTestSelf = arg0;
  3720. cmSystemTools::ConvertToUnixSlashes(m_CTestSelf);
  3721. failures.push_back(m_CTestSelf);
  3722. m_CTestSelf = cmSystemTools::FindProgram(m_CTestSelf.c_str());
  3723. if(!cmSystemTools::FileExists(m_CTestSelf.c_str()))
  3724. {
  3725. failures.push_back(m_CTestSelf);
  3726. m_CTestSelf = "/usr/local/bin/ctest";
  3727. }
  3728. if(!cmSystemTools::FileExists(m_CTestSelf.c_str()))
  3729. {
  3730. failures.push_back(m_CTestSelf);
  3731. cmOStringStream msg;
  3732. msg << "CTEST can not find the command line program cmake.\n";
  3733. msg << " argv[0] = \"" << arg0 << "\"\n";
  3734. msg << " Attempted paths:\n";
  3735. std::vector<cmStdString>::iterator i;
  3736. for(i=failures.begin(); i != failures.end(); ++i)
  3737. {
  3738. msg << " \"" << i->c_str() << "\"\n";
  3739. }
  3740. cmSystemTools::Error(msg.str().c_str());
  3741. }
  3742. std::string dir;
  3743. std::string file;
  3744. if(cmSystemTools::SplitProgramPath(m_CTestSelf.c_str(),
  3745. dir,
  3746. file,
  3747. true))
  3748. {
  3749. m_CMakeSelf = dir += "/cmake";
  3750. m_CMakeSelf += cmSystemTools::GetExecutableExtension();
  3751. if(!cmSystemTools::FileExists(m_CMakeSelf.c_str()))
  3752. {
  3753. cmOStringStream msg;
  3754. failures.push_back(m_CMakeSelf);
  3755. msg << "CTEST can not find the command line program cmake.\n";
  3756. msg << " argv[0] = \"" << arg0 << "\"\n";
  3757. msg << " Attempted path:\n";
  3758. msg << " \"" << m_CMakeSelf.c_str() << "\"\n";
  3759. cmSystemTools::Error(msg.str().c_str());
  3760. }
  3761. }
  3762. }
  3763. void CMakeMessageCallback(const char* m, const char*, bool&, void* s)
  3764. {
  3765. std::string* out = (std::string*)s;
  3766. *out += m;
  3767. *out += "\n";
  3768. }
  3769. void CMakeStdoutCallback(const char* m, int len, void* s)
  3770. {
  3771. std::string* out = (std::string*)s;
  3772. out->append(m, len);
  3773. }
  3774. int cmCTest::RunCMakeAndTest(std::string* outstring)
  3775. {
  3776. unsigned int k;
  3777. std::string cmakeOutString;
  3778. cmSystemTools::SetErrorCallback(CMakeMessageCallback, &cmakeOutString);
  3779. cmSystemTools::SetStdoutCallback(CMakeStdoutCallback, &cmakeOutString);
  3780. cmOStringStream out;
  3781. cmake cm;
  3782. // default to the build type of ctest itself
  3783. if(m_ConfigType.size() == 0)
  3784. {
  3785. #ifdef CMAKE_INTDIR
  3786. m_ConfigType = CMAKE_INTDIR;
  3787. #endif
  3788. }
  3789. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  3790. out << "Internal cmake changing into directory: " << m_BinaryDir << "\n";
  3791. if (!cmSystemTools::FileIsDirectory(m_BinaryDir.c_str()))
  3792. {
  3793. cmSystemTools::MakeDirectory(m_BinaryDir.c_str());
  3794. }
  3795. cmSystemTools::ChangeDirectory(m_BinaryDir.c_str());
  3796. if(!m_BuildNoCMake)
  3797. {
  3798. std::vector<std::string> args;
  3799. args.push_back(m_CMakeSelf);
  3800. args.push_back(m_SourceDir);
  3801. if(m_BuildGenerator.size())
  3802. {
  3803. std::string generator = "-G";
  3804. generator += m_BuildGenerator;
  3805. args.push_back(generator);
  3806. }
  3807. if ( m_ConfigType.size() > 0 )
  3808. {
  3809. std::string btype = "-DBUILD_TYPE:STRING=" + m_ConfigType;
  3810. args.push_back(btype);
  3811. }
  3812. for(k=0; k < m_BuildOptions.size(); ++k)
  3813. {
  3814. args.push_back(m_BuildOptions[k]);
  3815. }
  3816. if (cm.Run(args) != 0)
  3817. {
  3818. out << "Error: cmake execution failed\n";
  3819. out << cmakeOutString << "\n";
  3820. // return to the original directory
  3821. cmSystemTools::ChangeDirectory(cwd.c_str());
  3822. if(outstring)
  3823. {
  3824. *outstring = out.str();
  3825. }
  3826. else
  3827. {
  3828. std::cerr << out << "\n";
  3829. }
  3830. return 1;
  3831. }
  3832. if(m_BuildTwoConfig)
  3833. {
  3834. if (cm.Run(args) != 0)
  3835. {
  3836. out << "Error: cmake execution failed\n";
  3837. out << cmakeOutString << "\n";
  3838. // return to the original directory
  3839. cmSystemTools::ChangeDirectory(cwd.c_str());
  3840. if(outstring)
  3841. {
  3842. *outstring = out.str();
  3843. }
  3844. else
  3845. {
  3846. std::cerr << out << "\n";
  3847. }
  3848. return 1;
  3849. }
  3850. }
  3851. }
  3852. cmSystemTools::SetErrorCallback(0, 0);
  3853. out << cmakeOutString << "\n";
  3854. if(m_BuildMakeProgram.size() == 0)
  3855. {
  3856. out << "Error: cmake does not have a valid MAKEPROGRAM\n";
  3857. out << "Did you specify a --build-makeprogram and a --build-generator?\n";
  3858. if(outstring)
  3859. {
  3860. *outstring = out.str();
  3861. }
  3862. else
  3863. {
  3864. std::cerr << out << "\n";
  3865. }
  3866. return 1;
  3867. }
  3868. int retVal = 0;
  3869. std::string makeCommand = cmSystemTools::ConvertToOutputPath(m_BuildMakeProgram.c_str());
  3870. std::string lowerCaseCommand = cmSystemTools::LowerCase(makeCommand);
  3871. // if msdev is the make program then do the following
  3872. // MSDEV 6.0
  3873. if(lowerCaseCommand.find("msdev") != std::string::npos)
  3874. {
  3875. // if there are spaces in the makeCommand, assume a full path
  3876. // and convert it to a path with no spaces in it as the
  3877. // RunSingleCommand does not like spaces
  3878. #if defined(_WIN32) && !defined(__CYGWIN__)
  3879. if(makeCommand.find(' ') != std::string::npos)
  3880. {
  3881. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  3882. }
  3883. #endif
  3884. makeCommand += " ";
  3885. makeCommand += m_BuildProject;
  3886. makeCommand += ".dsw /MAKE \"ALL_BUILD - ";
  3887. makeCommand += m_ConfigType;
  3888. if(m_BuildNoClean)
  3889. {
  3890. makeCommand += "\" /BUILD";
  3891. }
  3892. else
  3893. {
  3894. makeCommand += "\" /REBUILD";
  3895. }
  3896. }
  3897. // MSDEV 7.0 .NET
  3898. else if (lowerCaseCommand.find("devenv") != std::string::npos)
  3899. {
  3900. #if defined(_WIN32) && !defined(__CYGWIN__)
  3901. if(makeCommand.find(' ') != std::string::npos)
  3902. {
  3903. cmSystemTools::GetShortPath(makeCommand.c_str(), makeCommand);
  3904. }
  3905. #endif
  3906. makeCommand += " ";
  3907. makeCommand += m_BuildProject;
  3908. makeCommand += ".sln ";
  3909. if(m_BuildNoClean)
  3910. {
  3911. makeCommand += "/build ";
  3912. }
  3913. else
  3914. {
  3915. makeCommand += "/rebuild ";
  3916. }
  3917. makeCommand += m_ConfigType + " /project ALL_BUILD";
  3918. }
  3919. else if (lowerCaseCommand.find("make") != std::string::npos)
  3920. {
  3921. // assume a make sytle program
  3922. // clean first
  3923. if(!m_BuildNoClean)
  3924. {
  3925. std::string cleanCommand = makeCommand;
  3926. cleanCommand += " clean";
  3927. out << "Running make clean command: " << cleanCommand.c_str() << " ...\n";
  3928. retVal = 0;
  3929. std::string output;
  3930. if (!cmSystemTools::RunSingleCommand(cleanCommand.c_str(), &output, &retVal) ||
  3931. retVal)
  3932. {
  3933. out << "Error: " << cleanCommand.c_str() << " execution failed\n";
  3934. out << output.c_str() << "\n";
  3935. // return to the original directory
  3936. cmSystemTools::ChangeDirectory(cwd.c_str());
  3937. out << "Return value: " << retVal << std::endl;
  3938. if(outstring)
  3939. {
  3940. *outstring = out.str();
  3941. }
  3942. else
  3943. {
  3944. std::cerr << out << "\n";
  3945. }
  3946. return 1;
  3947. }
  3948. out << output;
  3949. }
  3950. if(m_BuildTarget.size())
  3951. {
  3952. makeCommand += " ";
  3953. makeCommand += m_BuildTarget;
  3954. }
  3955. }
  3956. // command line make program
  3957. out << "Running make command: " << makeCommand.c_str() << "\n";
  3958. retVal = 0;
  3959. std::string output;
  3960. if (!cmSystemTools::RunSingleCommand(makeCommand.c_str(), &output, &retVal, 0, false))
  3961. {
  3962. out << "Error: " << makeCommand.c_str() << " execution failed\n";
  3963. out << output.c_str() << "\n";
  3964. // return to the original directory
  3965. cmSystemTools::ChangeDirectory(cwd.c_str());
  3966. out << "Return value: " << retVal << std::endl;
  3967. if(outstring)
  3968. {
  3969. *outstring = out.str();
  3970. }
  3971. else
  3972. {
  3973. std::cerr << out << "\n";
  3974. }
  3975. return 1;
  3976. }
  3977. if ( retVal )
  3978. {
  3979. if(outstring)
  3980. {
  3981. *outstring = out.str();
  3982. *outstring += "Building of project failed\n";
  3983. *outstring += output;
  3984. *outstring += "\n";
  3985. }
  3986. else
  3987. {
  3988. std::cerr << "Building of project failed\n";
  3989. std::cerr << out << output << "\n";
  3990. }
  3991. // return to the original directory
  3992. cmSystemTools::ChangeDirectory(cwd.c_str());
  3993. return 1;
  3994. }
  3995. out << output;
  3996. if(m_TestCommand.size() == 0)
  3997. {
  3998. if(outstring)
  3999. {
  4000. *outstring = out.str();
  4001. }
  4002. else
  4003. {
  4004. std::cout << out << "\n";
  4005. }
  4006. return retVal;
  4007. }
  4008. // now run the compiled test if we can find it
  4009. // See if the executable exists as written.
  4010. std::vector<std::string> failed;
  4011. std::string fullPath;
  4012. if(cmSystemTools::FileExists(m_TestCommand.c_str())
  4013. && !cmSystemTools::FileIsDirectory(m_TestCommand.c_str()))
  4014. {
  4015. fullPath = cmSystemTools::CollapseFullPath(m_TestCommand.c_str());
  4016. }
  4017. else
  4018. {
  4019. failed.push_back(m_TestCommand);
  4020. std::string tryPath = m_TestCommand;
  4021. tryPath += cmSystemTools::GetExecutableExtension();
  4022. if(cmSystemTools::FileExists(tryPath.c_str())
  4023. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4024. {
  4025. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4026. }
  4027. else
  4028. {
  4029. failed.push_back(tryPath);
  4030. // try the Debug extension
  4031. tryPath = m_ConfigType + "/";
  4032. tryPath += cmSystemTools::GetFilenameName(m_TestCommand);
  4033. if(cmSystemTools::FileExists(tryPath.c_str())
  4034. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4035. {
  4036. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4037. }
  4038. else
  4039. {
  4040. failed.push_back(tryPath);
  4041. tryPath += cmSystemTools::GetExecutableExtension();
  4042. if(cmSystemTools::FileExists(tryPath.c_str())
  4043. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4044. {
  4045. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4046. }
  4047. else
  4048. {
  4049. failed.push_back(tryPath);
  4050. tryPath = m_ExecutableDirectory;
  4051. tryPath += "/";
  4052. tryPath += m_TestCommand;
  4053. tryPath += cmSystemTools::GetExecutableExtension();
  4054. if(cmSystemTools::FileExists(tryPath.c_str())
  4055. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4056. {
  4057. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4058. }
  4059. else
  4060. {
  4061. failed.push_back(tryPath);
  4062. tryPath = m_ExecutableDirectory;
  4063. tryPath += "/";
  4064. tryPath += m_ConfigType + "/";
  4065. tryPath += m_TestCommand;
  4066. tryPath += cmSystemTools::GetExecutableExtension();
  4067. if(cmSystemTools::FileExists(tryPath.c_str())
  4068. && !cmSystemTools::FileIsDirectory(tryPath.c_str()))
  4069. {
  4070. fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  4071. }
  4072. else
  4073. {
  4074. failed.push_back(tryPath);
  4075. }
  4076. }
  4077. }
  4078. }
  4079. }
  4080. }
  4081. if(!cmSystemTools::FileExists(fullPath.c_str()))
  4082. {
  4083. out << "Could not find path to executable, perhaps it was not built: " <<
  4084. m_TestCommand << "\n";
  4085. out << "tried to find it in these places:\n";
  4086. for(unsigned int i=0; i < failed.size(); ++i)
  4087. {
  4088. out << failed[i] << "\n";
  4089. }
  4090. if(outstring)
  4091. {
  4092. *outstring = out.str();
  4093. }
  4094. else
  4095. {
  4096. std::cerr << out.str();
  4097. }
  4098. // return to the original directory
  4099. cmSystemTools::ChangeDirectory(cwd.c_str());
  4100. return 1;
  4101. }
  4102. std::vector<const char*> testCommand;
  4103. testCommand.push_back(fullPath.c_str());
  4104. for(k=0; k < m_TestCommandArgs.size(); ++k)
  4105. {
  4106. testCommand.push_back(m_TestCommandArgs[k].c_str());
  4107. }
  4108. testCommand.push_back(0);
  4109. std::string outs;
  4110. int retval = 0;
  4111. // run the test from the m_BuildRunDir if set
  4112. if(m_BuildRunDir.size())
  4113. {
  4114. out << "Run test in directory: " << m_BuildRunDir << "\n";
  4115. cmSystemTools::ChangeDirectory(m_BuildRunDir.c_str());
  4116. }
  4117. out << "Running test executable: " << fullPath << " ";
  4118. for(k=0; k < m_TestCommandArgs.size(); ++k)
  4119. {
  4120. out << m_TestCommandArgs[k] << " ";
  4121. }
  4122. out << "\n";
  4123. int runTestRes = this->RunTest(testCommand, &outs, &retval);
  4124. if(runTestRes != cmsysProcess_State_Exited || retval != 0)
  4125. {
  4126. out << "Test failed to run.\n";
  4127. retval = 1;
  4128. }
  4129. out << outs << "\n";
  4130. if(outstring)
  4131. {
  4132. *outstring = out.str();
  4133. }
  4134. else
  4135. {
  4136. std::cout << out.str() << "\n";
  4137. }
  4138. return retval;
  4139. }
  4140. void cmCTest::SetNotesFiles(const char* notes)
  4141. {
  4142. if ( !notes )
  4143. {
  4144. return;
  4145. }
  4146. m_NotesFiles = notes;
  4147. }
  4148. int cmCTest::ReadCustomConfigurationFileTree(const char* dir)
  4149. {
  4150. tm_VectorOfStrings dirs;
  4151. tm_VectorOfStrings ndirs;
  4152. dirs.push_back(dir);
  4153. cmake cm;
  4154. cmGlobalGenerator gg;
  4155. gg.SetCMakeInstance(&cm);
  4156. cmLocalGenerator *lg = gg.CreateLocalGenerator();
  4157. lg->SetGlobalGenerator(&gg);
  4158. cmMakefile *mf = lg->GetMakefile();
  4159. while ( dirs.size() > 0 )
  4160. {
  4161. tm_VectorOfStrings::iterator cdir = dirs.end()-1;
  4162. std::string rexpr = *cdir + "/*";
  4163. std::string fname = *cdir + "/CTestCustom.ctest";
  4164. if ( cmSystemTools::FileExists(fname.c_str()) &&
  4165. (!lg->GetMakefile()->ReadListFile(0, fname.c_str()) ||
  4166. cmSystemTools::GetErrorOccuredFlag() ) )
  4167. {
  4168. std::cerr << "Problem reading custom configuration" << std::endl;
  4169. return 0;
  4170. }
  4171. dirs.erase(dirs.end()-1, dirs.end());
  4172. cmSystemTools::SimpleGlob(rexpr, ndirs, -1);
  4173. dirs.insert(dirs.end(), ndirs.begin(), ndirs.end());
  4174. }
  4175. this->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_MATCH", m_CustomErrorMatches);
  4176. this->PopulateCustomVector(mf, "CTEST_CUSTOM_ERROR_EXCEPTION", m_CustomErrorExceptions);
  4177. this->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_MATCH", m_CustomWarningMatches);
  4178. this->PopulateCustomVector(mf, "CTEST_CUSTOM_WARNING_EXCEPTION", m_CustomWarningExceptions);
  4179. this->PopulateCustomVector(mf, "CTEST_CUSTOM_TESTS_IGNORE", m_CustomTestsIgnore);
  4180. this->PopulateCustomVector(mf, "CTEST_CUSTOM_MEMCHECK_IGNORE", m_CustomMemCheckIgnore);
  4181. this->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST", m_CustomPreTest);
  4182. this->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST", m_CustomPostTest);
  4183. this->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_MEMCHECK", m_CustomPreMemCheck);
  4184. this->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_MEMCHECK", m_CustomPostMemCheck);
  4185. return 1;
  4186. }
  4187. void cmCTest::PopulateCustomVector(cmMakefile* mf, const char* def, tm_VectorOfStrings& vec)
  4188. {
  4189. if ( !def)
  4190. {
  4191. return;
  4192. }
  4193. const char* dval = mf->GetDefinition(def);
  4194. if ( !dval )
  4195. {
  4196. return;
  4197. }
  4198. std::vector<std::string> slist;
  4199. cmSystemTools::ExpandListArgument(dval, slist);
  4200. std::vector<std::string>::iterator it;
  4201. for ( it = slist.begin(); it != slist.end(); ++it )
  4202. {
  4203. vec.push_back(it->c_str());
  4204. }
  4205. }
  4206. int cmCTest::ExecuteCommands(tm_VectorOfStrings& vec)
  4207. {
  4208. tm_VectorOfStrings::iterator it;
  4209. for ( it = vec.begin(); it != vec.end(); ++it )
  4210. {
  4211. int retVal = 0;
  4212. if ( m_Verbose )
  4213. {
  4214. std::cout << "Run command: " << *it << std::endl;
  4215. }
  4216. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true /*m_Verbose*/) ||
  4217. retVal != 0 )
  4218. {
  4219. std::cerr << "Problem running command: " << *it << std::endl;
  4220. return 0;
  4221. }
  4222. }
  4223. return 1;
  4224. }