cmCTest.cxx 120 KB

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