cmCTest.cxx 135 KB

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