cmCTest.cxx 134 KB

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