cmCTest.cxx 120 KB

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