cmCTest.cxx 121 KB

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