cmCTest.cxx 132 KB

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