cmCTest.cxx 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cm_curl.h"
  11. #include "cmCTest.h"
  12. #include "cmake.h"
  13. #include "cmMakefile.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include <cmsys/Base64.h>
  17. #include <cmsys/Directory.hxx>
  18. #include <cmsys/SystemInformation.hxx>
  19. #include <cmsys/FStream.hxx>
  20. #include "cmDynamicLoader.h"
  21. #include "cmGeneratedFileStream.h"
  22. #include "cmXMLSafe.h"
  23. #include "cmVersionMacros.h"
  24. #include "cmCTestCommand.h"
  25. #include "cmCTestStartCommand.h"
  26. #include "cmCTestBuildHandler.h"
  27. #include "cmCTestBuildAndTestHandler.h"
  28. #include "cmCTestConfigureHandler.h"
  29. #include "cmCTestCoverageHandler.h"
  30. #include "cmCTestMemCheckHandler.h"
  31. #include "cmCTestScriptHandler.h"
  32. #include "cmCTestSubmitHandler.h"
  33. #include "cmCTestTestHandler.h"
  34. #include "cmCTestUpdateHandler.h"
  35. #include "cmCTestUploadHandler.h"
  36. #include "cmVersion.h"
  37. #include <cmsys/RegularExpression.hxx>
  38. #include <cmsys/Process.h>
  39. #include <cmsys/Glob.hxx>
  40. #include <stdlib.h>
  41. #include <math.h>
  42. #include <float.h>
  43. #include <ctype.h>
  44. #include <cmsys/auto_ptr.hxx>
  45. #include <cm_zlib.h>
  46. #include <cmsys/Base64.h>
  47. #if defined(__BEOS__) || defined(__HAIKU__)
  48. #include <be/kernel/OS.h> /* disable_debugger() API. */
  49. #endif
  50. #define DEBUGOUT std::cout << __LINE__ << " "; std::cout
  51. #define DEBUGERR std::cerr << __LINE__ << " "; std::cerr
  52. //----------------------------------------------------------------------
  53. struct tm* cmCTest::GetNightlyTime(std::string str,
  54. bool tomorrowtag)
  55. {
  56. struct tm* lctime;
  57. time_t tctime = time(0);
  58. lctime = gmtime(&tctime);
  59. char buf[1024];
  60. // add todays year day and month to the time in str because
  61. // curl_getdate no longer assumes the day is today
  62. sprintf(buf, "%d%02d%02d %s",
  63. lctime->tm_year+1900,
  64. lctime->tm_mon +1,
  65. lctime->tm_mday,
  66. str.c_str());
  67. cmCTestLog(this, OUTPUT, "Determine Nightly Start Time" << std::endl
  68. << " Specified time: " << str << std::endl);
  69. //Convert the nightly start time to seconds. Since we are
  70. //providing only a time and a timezone, the current date of
  71. //the local machine is assumed. Consequently, nightlySeconds
  72. //is the time at which the nightly dashboard was opened or
  73. //will be opened on the date of the current client machine.
  74. //As such, this time may be in the past or in the future.
  75. time_t ntime = curl_getdate(buf, &tctime);
  76. cmCTestLog(this, DEBUG, " Get curl time: " << ntime << std::endl);
  77. tctime = time(0);
  78. cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl);
  79. const int dayLength = 24 * 60 * 60;
  80. cmCTestLog(this, DEBUG, "Seconds: " << tctime << std::endl);
  81. while ( ntime > tctime )
  82. {
  83. // If nightlySeconds is in the past, this is the current
  84. // open dashboard, then return nightlySeconds. If
  85. // nightlySeconds is in the future, this is the next
  86. // dashboard to be opened, so subtract 24 hours to get the
  87. // time of the current open dashboard
  88. ntime -= dayLength;
  89. cmCTestLog(this, DEBUG, "Pick yesterday" << std::endl);
  90. cmCTestLog(this, DEBUG, " Future time, subtract day: " << ntime
  91. << std::endl);
  92. }
  93. while ( tctime > (ntime + dayLength) )
  94. {
  95. ntime += dayLength;
  96. cmCTestLog(this, DEBUG, " Past time, add day: " << ntime << std::endl);
  97. }
  98. cmCTestLog(this, DEBUG, "nightlySeconds: " << ntime << std::endl);
  99. cmCTestLog(this, DEBUG, " Current time: " << tctime
  100. << " Nightly time: " << ntime << std::endl);
  101. if ( tomorrowtag )
  102. {
  103. cmCTestLog(this, OUTPUT, " Use future tag, Add a day" << std::endl);
  104. ntime += dayLength;
  105. }
  106. lctime = gmtime(&ntime);
  107. return lctime;
  108. }
  109. //----------------------------------------------------------------------
  110. std::string cmCTest::CleanString(const std::string& str)
  111. {
  112. std::string::size_type spos = str.find_first_not_of(" \n\t\r\f\v");
  113. std::string::size_type epos = str.find_last_not_of(" \n\t\r\f\v");
  114. if ( spos == str.npos )
  115. {
  116. return std::string();
  117. }
  118. if ( epos != str.npos )
  119. {
  120. epos = epos - spos + 1;
  121. }
  122. return str.substr(spos, epos);
  123. }
  124. //----------------------------------------------------------------------
  125. std::string cmCTest::CurrentTime()
  126. {
  127. time_t currenttime = time(0);
  128. struct tm* t = localtime(&currenttime);
  129. //return ::CleanString(ctime(&currenttime));
  130. char current_time[1024];
  131. if ( this->ShortDateFormat )
  132. {
  133. strftime(current_time, 1000, "%b %d %H:%M %Z", t);
  134. }
  135. else
  136. {
  137. strftime(current_time, 1000, "%a %b %d %H:%M:%S %Z %Y", t);
  138. }
  139. cmCTestLog(this, DEBUG, " Current_Time: " << current_time << std::endl);
  140. return cmXMLSafe(cmCTest::CleanString(current_time)).str();
  141. }
  142. //----------------------------------------------------------------------
  143. std::string cmCTest::GetCostDataFile()
  144. {
  145. std::string fname = this->GetCTestConfiguration("CostDataFile");
  146. if(fname == "")
  147. {
  148. fname= this->GetBinaryDir() + "/Testing/Temporary/CTestCostData.txt";
  149. }
  150. return fname;
  151. }
  152. #ifdef CMAKE_BUILD_WITH_CMAKE
  153. //----------------------------------------------------------------------------
  154. static size_t
  155. HTTPResponseCallback(void *ptr, size_t size, size_t nmemb, void *data)
  156. {
  157. int realsize = (int)(size * nmemb);
  158. std::string *response
  159. = static_cast<std::string*>(data);
  160. const char* chPtr = static_cast<char*>(ptr);
  161. *response += chPtr;
  162. return realsize;
  163. }
  164. //----------------------------------------------------------------------------
  165. int cmCTest::HTTPRequest(std::string url, HTTPMethod method,
  166. std::string& response,
  167. std::string fields,
  168. std::string putFile, int timeout)
  169. {
  170. CURL* curl;
  171. FILE* file;
  172. ::curl_global_init(CURL_GLOBAL_ALL);
  173. curl = ::curl_easy_init();
  174. //set request options based on method
  175. switch(method)
  176. {
  177. case cmCTest::HTTP_POST:
  178. ::curl_easy_setopt(curl, CURLOPT_POST, 1);
  179. ::curl_easy_setopt(curl, CURLOPT_POSTFIELDS, fields.c_str());
  180. break;
  181. case cmCTest::HTTP_PUT:
  182. if(!cmSystemTools::FileExists(putFile.c_str()))
  183. {
  184. response = "Error: File ";
  185. response += putFile + " does not exist.\n";
  186. return -1;
  187. }
  188. ::curl_easy_setopt(curl, CURLOPT_PUT, 1);
  189. file = cmsys::SystemTools::Fopen(putFile, "rb");
  190. ::curl_easy_setopt(curl, CURLOPT_INFILE, file);
  191. //fall through to append GET fields
  192. case cmCTest::HTTP_GET:
  193. if(fields.size())
  194. {
  195. url += "?" + fields;
  196. }
  197. break;
  198. }
  199. ::curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
  200. ::curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
  201. ::curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
  202. //set response options
  203. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPResponseCallback);
  204. ::curl_easy_setopt(curl, CURLOPT_FILE, (void *)&response);
  205. ::curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
  206. CURLcode res = ::curl_easy_perform(curl);
  207. ::curl_easy_cleanup(curl);
  208. ::curl_global_cleanup();
  209. return static_cast<int>(res);
  210. }
  211. #endif
  212. //----------------------------------------------------------------------
  213. std::string cmCTest::MakeURLSafe(const std::string& str)
  214. {
  215. std::ostringstream ost;
  216. char buffer[10];
  217. for ( std::string::size_type pos = 0; pos < str.size(); pos ++ )
  218. {
  219. unsigned char ch = str[pos];
  220. if ( ( ch > 126 || ch < 32 ||
  221. ch == '&' ||
  222. ch == '%' ||
  223. ch == '+' ||
  224. ch == '=' ||
  225. ch == '@'
  226. ) && ch != 9 )
  227. {
  228. sprintf(buffer, "%02x;", (unsigned int)ch);
  229. ost << buffer;
  230. }
  231. else
  232. {
  233. ost << ch;
  234. }
  235. }
  236. return ost.str();
  237. }
  238. //----------------------------------------------------------------------------
  239. std::string cmCTest::DecodeURL(const std::string& in)
  240. {
  241. std::string out;
  242. for(const char* c = in.c_str(); *c; ++c)
  243. {
  244. if(*c == '%' && isxdigit(*(c+1)) && isxdigit(*(c+2)))
  245. {
  246. char buf[3] = {*(c+1), *(c+2), 0};
  247. out.append(1, char(strtoul(buf, 0, 16)));
  248. c += 2;
  249. }
  250. else
  251. {
  252. out.append(1, *c);
  253. }
  254. }
  255. return out;
  256. }
  257. //----------------------------------------------------------------------
  258. cmCTest::cmCTest()
  259. {
  260. this->LabelSummary = true;
  261. this->ParallelLevel = 1;
  262. this->ParallelLevelSetInCli = false;
  263. this->SubmitIndex = 0;
  264. this->Failover = false;
  265. this->BatchJobs = false;
  266. this->ForceNewCTestProcess = false;
  267. this->TomorrowTag = false;
  268. this->Verbose = false;
  269. this->Debug = false;
  270. this->ShowLineNumbers = false;
  271. this->Quiet = false;
  272. this->ExtraVerbose = false;
  273. this->ProduceXML = false;
  274. this->ShowOnly = false;
  275. this->RunConfigurationScript = false;
  276. this->UseHTTP10 = false;
  277. this->PrintLabels = false;
  278. this->CompressTestOutput = true;
  279. this->CompressMemCheckOutput = true;
  280. this->TestModel = cmCTest::EXPERIMENTAL;
  281. this->MaxTestNameWidth = 30;
  282. this->InteractiveDebugMode = true;
  283. this->TimeOut = 0;
  284. this->GlobalTimeout = 0;
  285. this->LastStopTimeout = 24 * 60 * 60;
  286. this->CompressXMLFiles = false;
  287. this->CTestConfigFile = "";
  288. this->ScheduleType = "";
  289. this->StopTime = "";
  290. this->NextDayStopTime = false;
  291. this->OutputLogFile = 0;
  292. this->OutputLogFileLastTag = -1;
  293. this->SuppressUpdatingCTestConfiguration = false;
  294. this->DartVersion = 1;
  295. this->DropSiteCDash = false;
  296. this->OutputTestOutputOnTestFailure = false;
  297. this->ComputedCompressTestOutput = false;
  298. this->ComputedCompressMemCheckOutput = false;
  299. if(cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE"))
  300. {
  301. this->OutputTestOutputOnTestFailure = true;
  302. }
  303. this->InitStreams();
  304. this->Parts[PartStart].SetName("Start");
  305. this->Parts[PartUpdate].SetName("Update");
  306. this->Parts[PartConfigure].SetName("Configure");
  307. this->Parts[PartBuild].SetName("Build");
  308. this->Parts[PartTest].SetName("Test");
  309. this->Parts[PartCoverage].SetName("Coverage");
  310. this->Parts[PartMemCheck].SetName("MemCheck");
  311. this->Parts[PartSubmit].SetName("Submit");
  312. this->Parts[PartNotes].SetName("Notes");
  313. this->Parts[PartExtraFiles].SetName("ExtraFiles");
  314. this->Parts[PartUpload].SetName("Upload");
  315. // Fill the part name-to-id map.
  316. for(Part p = PartStart; p != PartCount; p = Part(p+1))
  317. {
  318. this->PartMap[cmSystemTools::LowerCase(this->Parts[p].GetName())] = p;
  319. }
  320. this->ShortDateFormat = true;
  321. this->TestingHandlers["build"] = new cmCTestBuildHandler;
  322. this->TestingHandlers["buildtest"] = new cmCTestBuildAndTestHandler;
  323. this->TestingHandlers["coverage"] = new cmCTestCoverageHandler;
  324. this->TestingHandlers["script"] = new cmCTestScriptHandler;
  325. this->TestingHandlers["test"] = new cmCTestTestHandler;
  326. this->TestingHandlers["update"] = new cmCTestUpdateHandler;
  327. this->TestingHandlers["configure"] = new cmCTestConfigureHandler;
  328. this->TestingHandlers["memcheck"] = new cmCTestMemCheckHandler;
  329. this->TestingHandlers["submit"] = new cmCTestSubmitHandler;
  330. this->TestingHandlers["upload"] = new cmCTestUploadHandler;
  331. cmCTest::t_TestingHandlers::iterator it;
  332. for ( it = this->TestingHandlers.begin();
  333. it != this->TestingHandlers.end(); ++ it )
  334. {
  335. it->second->SetCTestInstance(this);
  336. }
  337. // Make sure we can capture the build tool output.
  338. cmSystemTools::EnableVSConsoleOutput();
  339. }
  340. //----------------------------------------------------------------------
  341. cmCTest::~cmCTest()
  342. {
  343. cmDeleteAll(this->TestingHandlers);
  344. this->SetOutputLogFileName(0);
  345. }
  346. void cmCTest::SetParallelLevel(int level)
  347. {
  348. this->ParallelLevel = level < 1 ? 1 : level;
  349. }
  350. //----------------------------------------------------------------------------
  351. bool cmCTest::ShouldCompressTestOutput()
  352. {
  353. if(!this->ComputedCompressTestOutput)
  354. {
  355. std::string cdashVersion = this->GetCDashVersion();
  356. //version >= 1.6?
  357. bool cdashSupportsGzip = cmSystemTools::VersionCompare(
  358. cmSystemTools::OP_GREATER, cdashVersion.c_str(), "1.6") ||
  359. cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
  360. cdashVersion.c_str(), "1.6");
  361. this->CompressTestOutput &= cdashSupportsGzip;
  362. this->ComputedCompressTestOutput = true;
  363. }
  364. return this->CompressTestOutput;
  365. }
  366. //----------------------------------------------------------------------------
  367. bool cmCTest::ShouldCompressMemCheckOutput()
  368. {
  369. if(!this->ComputedCompressMemCheckOutput)
  370. {
  371. std::string cdashVersion = this->GetCDashVersion();
  372. bool compressionSupported = cmSystemTools::VersionCompare(
  373. cmSystemTools::OP_GREATER, cdashVersion.c_str(), "1.9.0");
  374. this->CompressMemCheckOutput &= compressionSupported;
  375. this->ComputedCompressMemCheckOutput = true;
  376. }
  377. return this->CompressMemCheckOutput;
  378. }
  379. //----------------------------------------------------------------------------
  380. std::string cmCTest::GetCDashVersion()
  381. {
  382. #ifdef CMAKE_BUILD_WITH_CMAKE
  383. //First query the server. If that fails, fall back to the local setting
  384. std::string response;
  385. std::string url = "http://";
  386. url += this->GetCTestConfiguration("DropSite");
  387. std::string cdashUri = this->GetCTestConfiguration("DropLocation");
  388. cdashUri = cdashUri.substr(0, cdashUri.find("/submit.php"));
  389. int res = 1;
  390. if ( ! cdashUri.empty() )
  391. {
  392. url += cdashUri + "/api/getversion.php";
  393. res = cmCTest::HTTPRequest(url, cmCTest::HTTP_GET, response, "", "", 3);
  394. }
  395. return res ? this->GetCTestConfiguration("CDashVersion") : response;
  396. #else
  397. return this->GetCTestConfiguration("CDashVersion");
  398. #endif
  399. }
  400. //----------------------------------------------------------------------------
  401. cmCTest::Part cmCTest::GetPartFromName(const char* name)
  402. {
  403. // Look up by lower-case to make names case-insensitive.
  404. std::string lower_name = cmSystemTools::LowerCase(name);
  405. PartMapType::const_iterator i = this->PartMap.find(lower_name);
  406. if(i != this->PartMap.end())
  407. {
  408. return i->second;
  409. }
  410. // The string does not name a valid part.
  411. return PartCount;
  412. }
  413. //----------------------------------------------------------------------
  414. int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command)
  415. {
  416. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  417. if(!this->InteractiveDebugMode)
  418. {
  419. this->BlockTestErrorDiagnostics();
  420. }
  421. else
  422. {
  423. cmSystemTools::PutEnv("CTEST_INTERACTIVE_DEBUG_MODE=1");
  424. }
  425. this->BinaryDir = binary_dir;
  426. cmSystemTools::ConvertToUnixSlashes(this->BinaryDir);
  427. this->UpdateCTestConfiguration();
  428. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  429. if ( this->ProduceXML )
  430. {
  431. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  432. cmCTestLog(this, OUTPUT,
  433. " Site: " << this->GetCTestConfiguration("Site") << std::endl
  434. << " Build name: "
  435. << cmCTest::SafeBuildIdField(
  436. this->GetCTestConfiguration("BuildName"))
  437. << std::endl);
  438. cmCTestLog(this, DEBUG, "Produce XML is on" << std::endl);
  439. if ( this->TestModel == cmCTest::NIGHTLY &&
  440. this->GetCTestConfiguration("NightlyStartTime").empty() )
  441. {
  442. cmCTestLog(this, WARNING,
  443. "WARNING: No nightly start time found please set in"
  444. " CTestConfig.cmake or DartConfig.cmake" << std::endl);
  445. cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
  446. return 0;
  447. }
  448. }
  449. cmake cm;
  450. cmGlobalGenerator gg;
  451. gg.SetCMakeInstance(&cm);
  452. cmsys::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  453. cmMakefile *mf = lg->GetMakefile();
  454. if ( !this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), mf) )
  455. {
  456. cmCTestLog(this, DEBUG, "Cannot find custom configuration file tree"
  457. << std::endl);
  458. return 0;
  459. }
  460. if ( this->ProduceXML )
  461. {
  462. // Verify "Testing" directory exists:
  463. //
  464. std::string testingDir = this->BinaryDir + "/Testing";
  465. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  466. {
  467. if ( !cmSystemTools::FileIsDirectory(testingDir) )
  468. {
  469. cmCTestLog(this, ERROR_MESSAGE, "File " << testingDir
  470. << " is in the place of the testing directory" << std::endl);
  471. return 0;
  472. }
  473. }
  474. else
  475. {
  476. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  477. {
  478. cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory "
  479. << testingDir << std::endl);
  480. return 0;
  481. }
  482. }
  483. // Create new "TAG" file or read existing one:
  484. //
  485. bool createNewTag = true;
  486. if (command)
  487. {
  488. createNewTag = command->ShouldCreateNewTag();
  489. }
  490. std::string tagfile = testingDir + "/TAG";
  491. cmsys::ifstream tfin(tagfile.c_str());
  492. std::string tag;
  493. if (createNewTag)
  494. {
  495. time_t tctime = time(0);
  496. if ( this->TomorrowTag )
  497. {
  498. tctime += ( 24 * 60 * 60 );
  499. }
  500. struct tm *lctime = gmtime(&tctime);
  501. if ( tfin && cmSystemTools::GetLineFromStream(tfin, tag) )
  502. {
  503. int year = 0;
  504. int mon = 0;
  505. int day = 0;
  506. int hour = 0;
  507. int min = 0;
  508. sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d",
  509. &year, &mon, &day, &hour, &min);
  510. if ( year != lctime->tm_year + 1900 ||
  511. mon != lctime->tm_mon+1 ||
  512. day != lctime->tm_mday )
  513. {
  514. tag = "";
  515. }
  516. std::string tagmode;
  517. if ( cmSystemTools::GetLineFromStream(tfin, tagmode) )
  518. {
  519. if (tagmode.size() > 4 && !this->Parts[PartStart])
  520. {
  521. this->TestModel = cmCTest::GetTestModelFromString(tagmode.c_str());
  522. }
  523. }
  524. tfin.close();
  525. }
  526. if (tag.size() == 0 || (0 != command) || this->Parts[PartStart])
  527. {
  528. cmCTestLog(this, DEBUG, "TestModel: " << this->GetTestModelString()
  529. << std::endl);
  530. cmCTestLog(this, DEBUG, "TestModel: " << this->TestModel << std::endl);
  531. if ( this->TestModel == cmCTest::NIGHTLY )
  532. {
  533. lctime = this->GetNightlyTime(
  534. this->GetCTestConfiguration("NightlyStartTime"),
  535. this->TomorrowTag);
  536. }
  537. char datestring[100];
  538. sprintf(datestring, "%04d%02d%02d-%02d%02d",
  539. lctime->tm_year + 1900,
  540. lctime->tm_mon+1,
  541. lctime->tm_mday,
  542. lctime->tm_hour,
  543. lctime->tm_min);
  544. tag = datestring;
  545. cmsys::ofstream ofs(tagfile.c_str());
  546. if ( ofs )
  547. {
  548. ofs << tag << std::endl;
  549. ofs << this->GetTestModelString() << std::endl;
  550. }
  551. ofs.close();
  552. if ( 0 == command )
  553. {
  554. cmCTestLog(this, OUTPUT, "Create new tag: " << tag << " - "
  555. << this->GetTestModelString() << std::endl);
  556. }
  557. }
  558. }
  559. else
  560. {
  561. if ( tfin )
  562. {
  563. cmSystemTools::GetLineFromStream(tfin, tag);
  564. tfin.close();
  565. }
  566. if ( tag.empty() )
  567. {
  568. cmCTestLog(this, ERROR_MESSAGE,
  569. "Cannot read existing TAG file in " << testingDir
  570. << std::endl);
  571. return 0;
  572. }
  573. cmCTestLog(this, OUTPUT, " Use existing tag: " << tag << " - "
  574. << this->GetTestModelString() << std::endl);
  575. }
  576. this->CurrentTag = tag;
  577. }
  578. return 1;
  579. }
  580. //----------------------------------------------------------------------
  581. bool cmCTest::InitializeFromCommand(cmCTestStartCommand* command)
  582. {
  583. std::string src_dir
  584. = this->GetCTestConfiguration("SourceDirectory");
  585. std::string bld_dir = this->GetCTestConfiguration("BuildDirectory");
  586. this->DartVersion = 1;
  587. this->DropSiteCDash = false;
  588. for(Part p = PartStart; p != PartCount; p = Part(p+1))
  589. {
  590. this->Parts[p].SubmitFiles.clear();
  591. }
  592. cmMakefile* mf = command->GetMakefile();
  593. std::string fname;
  594. std::string src_dir_fname = src_dir;
  595. src_dir_fname += "/CTestConfig.cmake";
  596. cmSystemTools::ConvertToUnixSlashes(src_dir_fname);
  597. std::string bld_dir_fname = bld_dir;
  598. bld_dir_fname += "/CTestConfig.cmake";
  599. cmSystemTools::ConvertToUnixSlashes(bld_dir_fname);
  600. if ( cmSystemTools::FileExists(bld_dir_fname.c_str()) )
  601. {
  602. fname = bld_dir_fname;
  603. }
  604. else if ( cmSystemTools::FileExists(src_dir_fname.c_str()) )
  605. {
  606. fname = src_dir_fname;
  607. }
  608. if ( !fname.empty() )
  609. {
  610. cmCTestLog(this, OUTPUT, " Reading ctest configuration file: "
  611. << fname << std::endl);
  612. bool readit = mf->ReadListFile(mf->GetCurrentListFile(),
  613. fname.c_str() );
  614. if(!readit)
  615. {
  616. std::string m = "Could not find include file: ";
  617. m += fname;
  618. command->SetError(m);
  619. return false;
  620. }
  621. }
  622. else
  623. {
  624. cmCTestLog(this, WARNING,
  625. "Cannot locate CTest configuration: in BuildDirectory: "
  626. << bld_dir_fname << std::endl);
  627. cmCTestLog(this, WARNING,
  628. "Cannot locate CTest configuration: in SourceDirectory: "
  629. << src_dir_fname << std::endl);
  630. }
  631. this->SetCTestConfigurationFromCMakeVariable(mf, "NightlyStartTime",
  632. "CTEST_NIGHTLY_START_TIME");
  633. this->SetCTestConfigurationFromCMakeVariable(mf, "Site", "CTEST_SITE");
  634. this->SetCTestConfigurationFromCMakeVariable(mf, "BuildName",
  635. "CTEST_BUILD_NAME");
  636. const char* dartVersion = mf->GetDefinition("CTEST_DART_SERVER_VERSION");
  637. if ( dartVersion )
  638. {
  639. this->DartVersion = atoi(dartVersion);
  640. if ( this->DartVersion < 0 )
  641. {
  642. cmCTestLog(this, ERROR_MESSAGE, "Invalid Dart server version: "
  643. << dartVersion << ". Please specify the version number."
  644. << std::endl);
  645. return false;
  646. }
  647. }
  648. this->DropSiteCDash = mf->IsOn("CTEST_DROP_SITE_CDASH");
  649. if ( !this->Initialize(bld_dir.c_str(), command) )
  650. {
  651. return false;
  652. }
  653. cmCTestLog(this, OUTPUT, " Use " << this->GetTestModelString()
  654. << " tag: " << this->GetCurrentTag() << std::endl);
  655. return true;
  656. }
  657. //----------------------------------------------------------------------
  658. bool cmCTest::UpdateCTestConfiguration()
  659. {
  660. if ( this->SuppressUpdatingCTestConfiguration )
  661. {
  662. return true;
  663. }
  664. std::string fileName = this->CTestConfigFile;
  665. if ( fileName.empty() )
  666. {
  667. fileName = this->BinaryDir + "/CTestConfiguration.ini";
  668. if ( !cmSystemTools::FileExists(fileName.c_str()) )
  669. {
  670. fileName = this->BinaryDir + "/DartConfiguration.tcl";
  671. }
  672. }
  673. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "UpdateCTestConfiguration from :"
  674. << fileName << "\n");
  675. if ( !cmSystemTools::FileExists(fileName.c_str()) )
  676. {
  677. // No need to exit if we are not producing XML
  678. if ( this->ProduceXML )
  679. {
  680. cmCTestLog(this, ERROR_MESSAGE, "Cannot find file: " << fileName
  681. << std::endl);
  682. return false;
  683. }
  684. }
  685. else
  686. {
  687. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Parse Config file:"
  688. << fileName << "\n");
  689. // parse the dart test file
  690. cmsys::ifstream fin(fileName.c_str());
  691. if(!fin)
  692. {
  693. return false;
  694. }
  695. char buffer[1024];
  696. while ( fin )
  697. {
  698. buffer[0] = 0;
  699. fin.getline(buffer, 1023);
  700. buffer[1023] = 0;
  701. std::string line = cmCTest::CleanString(buffer);
  702. if(line.size() == 0)
  703. {
  704. continue;
  705. }
  706. while ( fin && (line[line.size()-1] == '\\') )
  707. {
  708. line = line.substr(0, line.size()-1);
  709. buffer[0] = 0;
  710. fin.getline(buffer, 1023);
  711. buffer[1023] = 0;
  712. line += cmCTest::CleanString(buffer);
  713. }
  714. if ( line[0] == '#' )
  715. {
  716. continue;
  717. }
  718. std::string::size_type cpos = line.find_first_of(":");
  719. if ( cpos == line.npos )
  720. {
  721. continue;
  722. }
  723. std::string key = line.substr(0, cpos);
  724. std::string value
  725. = cmCTest::CleanString(line.substr(cpos+1, line.npos));
  726. this->CTestConfiguration[key] = value;
  727. }
  728. fin.close();
  729. }
  730. if ( !this->GetCTestConfiguration("BuildDirectory").empty() )
  731. {
  732. this->BinaryDir = this->GetCTestConfiguration("BuildDirectory");
  733. cmSystemTools::ChangeDirectory(this->BinaryDir);
  734. }
  735. this->TimeOut = atoi(this->GetCTestConfiguration("TimeOut").c_str());
  736. if ( this->ProduceXML )
  737. {
  738. this->CompressXMLFiles = cmSystemTools::IsOn(
  739. this->GetCTestConfiguration("CompressSubmission").c_str());
  740. }
  741. return true;
  742. }
  743. //----------------------------------------------------------------------
  744. void cmCTest::BlockTestErrorDiagnostics()
  745. {
  746. cmSystemTools::PutEnv("DART_TEST_FROM_DART=1");
  747. cmSystemTools::PutEnv("DASHBOARD_TEST_FROM_CTEST=" CMake_VERSION);
  748. #if defined(_WIN32)
  749. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
  750. #elif defined(__BEOS__) || defined(__HAIKU__)
  751. disable_debugger(1);
  752. #endif
  753. }
  754. //----------------------------------------------------------------------
  755. void cmCTest::SetTestModel(int mode)
  756. {
  757. this->InteractiveDebugMode = false;
  758. this->TestModel = mode;
  759. }
  760. //----------------------------------------------------------------------
  761. bool cmCTest::SetTest(const char* ttype, bool report)
  762. {
  763. if ( cmSystemTools::LowerCase(ttype) == "all" )
  764. {
  765. for(Part p = PartStart; p != PartCount; p = Part(p+1))
  766. {
  767. this->Parts[p].Enable();
  768. }
  769. return true;
  770. }
  771. Part p = this->GetPartFromName(ttype);
  772. if(p != PartCount)
  773. {
  774. this->Parts[p].Enable();
  775. return true;
  776. }
  777. else
  778. {
  779. if ( report )
  780. {
  781. cmCTestLog(this, ERROR_MESSAGE, "Don't know about test \"" << ttype
  782. << "\" yet..." << std::endl);
  783. }
  784. return false;
  785. }
  786. }
  787. //----------------------------------------------------------------------
  788. void cmCTest::Finalize()
  789. {
  790. }
  791. //----------------------------------------------------------------------
  792. bool cmCTest::OpenOutputFile(const std::string& path,
  793. const std::string& name, cmGeneratedFileStream& stream,
  794. bool compress)
  795. {
  796. std::string testingDir = this->BinaryDir + "/Testing";
  797. if ( path.size() > 0 )
  798. {
  799. testingDir += "/" + path;
  800. }
  801. if ( cmSystemTools::FileExists(testingDir.c_str()) )
  802. {
  803. if ( !cmSystemTools::FileIsDirectory(testingDir) )
  804. {
  805. cmCTestLog(this, ERROR_MESSAGE, "File " << testingDir
  806. << " is in the place of the testing directory"
  807. << std::endl);
  808. return false;
  809. }
  810. }
  811. else
  812. {
  813. if ( !cmSystemTools::MakeDirectory(testingDir.c_str()) )
  814. {
  815. cmCTestLog(this, ERROR_MESSAGE, "Cannot create directory " << testingDir
  816. << std::endl);
  817. return false;
  818. }
  819. }
  820. std::string filename = testingDir + "/" + name;
  821. stream.Open(filename.c_str());
  822. if( !stream )
  823. {
  824. cmCTestLog(this, ERROR_MESSAGE, "Problem opening file: " << filename
  825. << std::endl);
  826. return false;
  827. }
  828. if ( compress )
  829. {
  830. if ( this->CompressXMLFiles )
  831. {
  832. stream.SetCompression(true);
  833. }
  834. }
  835. return true;
  836. }
  837. //----------------------------------------------------------------------
  838. bool cmCTest::AddIfExists(Part part, const char* file)
  839. {
  840. if ( this->CTestFileExists(file) )
  841. {
  842. this->AddSubmitFile(part, file);
  843. }
  844. else
  845. {
  846. std::string name = file;
  847. name += ".gz";
  848. if ( this->CTestFileExists(name) )
  849. {
  850. this->AddSubmitFile(part, file);
  851. }
  852. else
  853. {
  854. return false;
  855. }
  856. }
  857. return true;
  858. }
  859. //----------------------------------------------------------------------
  860. bool cmCTest::CTestFileExists(const std::string& filename)
  861. {
  862. std::string testingDir = this->BinaryDir + "/Testing/" +
  863. this->CurrentTag + "/" + filename;
  864. return cmSystemTools::FileExists(testingDir.c_str());
  865. }
  866. //----------------------------------------------------------------------
  867. cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler)
  868. {
  869. cmCTest::t_TestingHandlers::iterator it =
  870. this->TestingHandlers.find(handler);
  871. if ( it == this->TestingHandlers.end() )
  872. {
  873. return 0;
  874. }
  875. it->second->Initialize();
  876. return it->second;
  877. }
  878. //----------------------------------------------------------------------
  879. cmCTestGenericHandler* cmCTest::GetHandler(const char* handler)
  880. {
  881. cmCTest::t_TestingHandlers::iterator it =
  882. this->TestingHandlers.find(handler);
  883. if ( it == this->TestingHandlers.end() )
  884. {
  885. return 0;
  886. }
  887. return it->second;
  888. }
  889. //----------------------------------------------------------------------
  890. int cmCTest::ExecuteHandler(const char* shandler)
  891. {
  892. cmCTestGenericHandler* handler = this->GetHandler(shandler);
  893. if ( !handler )
  894. {
  895. return -1;
  896. }
  897. handler->Initialize();
  898. return handler->ProcessHandler();
  899. }
  900. //----------------------------------------------------------------------
  901. int cmCTest::ProcessTests()
  902. {
  903. int res = 0;
  904. bool notest = true;
  905. int update_count = 0;
  906. for(Part p = PartStart; notest && p != PartCount; p = Part(p+1))
  907. {
  908. notest = !this->Parts[p];
  909. }
  910. if (this->Parts[PartUpdate] &&
  911. (this->GetRemainingTimeAllowed() - 120 > 0))
  912. {
  913. cmCTestGenericHandler* uphandler = this->GetHandler("update");
  914. uphandler->SetPersistentOption("SourceDirectory",
  915. this->GetCTestConfiguration("SourceDirectory").c_str());
  916. update_count = uphandler->ProcessHandler();
  917. if ( update_count < 0 )
  918. {
  919. res |= cmCTest::UPDATE_ERRORS;
  920. }
  921. }
  922. if ( this->TestModel == cmCTest::CONTINUOUS && !update_count )
  923. {
  924. return 0;
  925. }
  926. if (this->Parts[PartConfigure] &&
  927. (this->GetRemainingTimeAllowed() - 120 > 0))
  928. {
  929. if (this->GetHandler("configure")->ProcessHandler() < 0)
  930. {
  931. res |= cmCTest::CONFIGURE_ERRORS;
  932. }
  933. }
  934. if (this->Parts[PartBuild] &&
  935. (this->GetRemainingTimeAllowed() - 120 > 0))
  936. {
  937. this->UpdateCTestConfiguration();
  938. if (this->GetHandler("build")->ProcessHandler() < 0)
  939. {
  940. res |= cmCTest::BUILD_ERRORS;
  941. }
  942. }
  943. if ((this->Parts[PartTest] || notest) &&
  944. (this->GetRemainingTimeAllowed() - 120 > 0))
  945. {
  946. this->UpdateCTestConfiguration();
  947. if (this->GetHandler("test")->ProcessHandler() < 0)
  948. {
  949. res |= cmCTest::TEST_ERRORS;
  950. }
  951. }
  952. if (this->Parts[PartCoverage] &&
  953. (this->GetRemainingTimeAllowed() - 120 > 0))
  954. {
  955. this->UpdateCTestConfiguration();
  956. if (this->GetHandler("coverage")->ProcessHandler() < 0)
  957. {
  958. res |= cmCTest::COVERAGE_ERRORS;
  959. }
  960. }
  961. if (this->Parts[PartMemCheck] &&
  962. (this->GetRemainingTimeAllowed() - 120 > 0))
  963. {
  964. this->UpdateCTestConfiguration();
  965. if (this->GetHandler("memcheck")->ProcessHandler() < 0)
  966. {
  967. res |= cmCTest::MEMORY_ERRORS;
  968. }
  969. }
  970. if ( !notest )
  971. {
  972. std::string notes_dir = this->BinaryDir + "/Testing/Notes";
  973. if ( cmSystemTools::FileIsDirectory(notes_dir) )
  974. {
  975. cmsys::Directory d;
  976. d.Load(notes_dir);
  977. unsigned long kk;
  978. for ( kk = 0; kk < d.GetNumberOfFiles(); kk ++ )
  979. {
  980. const char* file = d.GetFile(kk);
  981. std::string fullname = notes_dir + "/" + file;
  982. if ( cmSystemTools::FileExists(fullname.c_str()) &&
  983. !cmSystemTools::FileIsDirectory(fullname) )
  984. {
  985. if ( this->NotesFiles.size() > 0 )
  986. {
  987. this->NotesFiles += ";";
  988. }
  989. this->NotesFiles += fullname;
  990. this->Parts[PartNotes].Enable();
  991. }
  992. }
  993. }
  994. }
  995. if (this->Parts[PartNotes])
  996. {
  997. this->UpdateCTestConfiguration();
  998. if ( this->NotesFiles.size() )
  999. {
  1000. this->GenerateNotesFile(this->NotesFiles.c_str());
  1001. }
  1002. }
  1003. if (this->Parts[PartSubmit])
  1004. {
  1005. this->UpdateCTestConfiguration();
  1006. if (this->GetHandler("submit")->ProcessHandler() < 0)
  1007. {
  1008. res |= cmCTest::SUBMIT_ERRORS;
  1009. }
  1010. }
  1011. if ( res != 0 )
  1012. {
  1013. cmCTestLog(this, ERROR_MESSAGE, "Errors while running CTest"
  1014. << std::endl);
  1015. }
  1016. return res;
  1017. }
  1018. //----------------------------------------------------------------------
  1019. std::string cmCTest::GetTestModelString()
  1020. {
  1021. if ( !this->SpecificTrack.empty() )
  1022. {
  1023. return this->SpecificTrack;
  1024. }
  1025. switch ( this->TestModel )
  1026. {
  1027. case cmCTest::NIGHTLY:
  1028. return "Nightly";
  1029. case cmCTest::CONTINUOUS:
  1030. return "Continuous";
  1031. }
  1032. return "Experimental";
  1033. }
  1034. //----------------------------------------------------------------------
  1035. int cmCTest::GetTestModelFromString(const char* str)
  1036. {
  1037. if ( !str )
  1038. {
  1039. return cmCTest::EXPERIMENTAL;
  1040. }
  1041. std::string rstr = cmSystemTools::LowerCase(str);
  1042. if ( cmHasLiteralPrefix(rstr.c_str(), "cont") )
  1043. {
  1044. return cmCTest::CONTINUOUS;
  1045. }
  1046. if ( cmHasLiteralPrefix(rstr.c_str(), "nigh") )
  1047. {
  1048. return cmCTest::NIGHTLY;
  1049. }
  1050. return cmCTest::EXPERIMENTAL;
  1051. }
  1052. //######################################################################
  1053. //######################################################################
  1054. //######################################################################
  1055. //######################################################################
  1056. //----------------------------------------------------------------------
  1057. int cmCTest::RunMakeCommand(const char* command, std::string& output,
  1058. int* retVal, const char* dir, int timeout, std::ostream& ofs)
  1059. {
  1060. // First generate the command and arguments
  1061. std::vector<std::string> args = cmSystemTools::ParseArguments(command);
  1062. if(args.size() < 1)
  1063. {
  1064. return false;
  1065. }
  1066. std::vector<const char*> argv;
  1067. for(std::vector<std::string>::const_iterator a = args.begin();
  1068. a != args.end(); ++a)
  1069. {
  1070. argv.push_back(a->c_str());
  1071. }
  1072. argv.push_back(0);
  1073. output = "";
  1074. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Run command:");
  1075. std::vector<const char*>::iterator ait;
  1076. for ( ait = argv.begin(); ait != argv.end() && *ait; ++ ait )
  1077. {
  1078. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, " \"" << *ait << "\"");
  1079. }
  1080. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, std::endl);
  1081. // Now create process object
  1082. cmsysProcess* cp = cmsysProcess_New();
  1083. cmsysProcess_SetCommand(cp, &*argv.begin());
  1084. cmsysProcess_SetWorkingDirectory(cp, dir);
  1085. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  1086. cmsysProcess_SetTimeout(cp, timeout);
  1087. cmsysProcess_Execute(cp);
  1088. // Initialize tick's
  1089. std::string::size_type tick = 0;
  1090. std::string::size_type tick_len = 1024;
  1091. std::string::size_type tick_line_len = 50;
  1092. char* data;
  1093. int length;
  1094. cmCTestLog(this, HANDLER_OUTPUT,
  1095. " Each . represents " << tick_len << " bytes of output" << std::endl
  1096. << " " << std::flush);
  1097. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  1098. {
  1099. for(int cc =0; cc < length; ++cc)
  1100. {
  1101. if(data[cc] == 0)
  1102. {
  1103. data[cc] = '\n';
  1104. }
  1105. }
  1106. output.append(data, length);
  1107. while ( output.size() > (tick * tick_len) )
  1108. {
  1109. tick ++;
  1110. cmCTestLog(this, HANDLER_OUTPUT, "." << std::flush);
  1111. if ( tick % tick_line_len == 0 && tick > 0 )
  1112. {
  1113. cmCTestLog(this, HANDLER_OUTPUT,
  1114. " Size: "
  1115. << int((double(output.size()) / 1024.0) + 1)
  1116. << "K" << std::endl
  1117. << " " << std::flush);
  1118. }
  1119. }
  1120. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length));
  1121. if ( ofs )
  1122. {
  1123. ofs << cmCTestLogWrite(data, length);
  1124. }
  1125. }
  1126. cmCTestLog(this, OUTPUT, " Size of output: "
  1127. << int(double(output.size()) / 1024.0) << "K" << std::endl);
  1128. cmsysProcess_WaitForExit(cp, 0);
  1129. int result = cmsysProcess_GetState(cp);
  1130. if(result == cmsysProcess_State_Exited)
  1131. {
  1132. *retVal = cmsysProcess_GetExitValue(cp);
  1133. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Command exited with the value: "
  1134. << *retVal << std::endl);
  1135. }
  1136. else if(result == cmsysProcess_State_Exception)
  1137. {
  1138. *retVal = cmsysProcess_GetExitException(cp);
  1139. cmCTestLog(this, WARNING, "There was an exception: " << *retVal
  1140. << std::endl);
  1141. }
  1142. else if(result == cmsysProcess_State_Expired)
  1143. {
  1144. cmCTestLog(this, WARNING, "There was a timeout" << std::endl);
  1145. }
  1146. else if(result == cmsysProcess_State_Error)
  1147. {
  1148. output += "\n*** ERROR executing: ";
  1149. output += cmsysProcess_GetErrorString(cp);
  1150. output += "\n***The build process failed.";
  1151. cmCTestLog(this, ERROR_MESSAGE, "There was an error: "
  1152. << cmsysProcess_GetErrorString(cp) << std::endl);
  1153. }
  1154. cmsysProcess_Delete(cp);
  1155. return result;
  1156. }
  1157. //######################################################################
  1158. //######################################################################
  1159. //######################################################################
  1160. //######################################################################
  1161. //----------------------------------------------------------------------
  1162. int cmCTest::RunTest(std::vector<const char*> argv,
  1163. std::string* output, int *retVal,
  1164. std::ostream* log, double testTimeOut,
  1165. std::vector<std::string>* environment)
  1166. {
  1167. bool modifyEnv = (environment && environment->size()>0);
  1168. // determine how much time we have
  1169. double timeout = this->GetRemainingTimeAllowed() - 120;
  1170. if (this->TimeOut > 0 && this->TimeOut < timeout)
  1171. {
  1172. timeout = this->TimeOut;
  1173. }
  1174. if (testTimeOut > 0
  1175. && testTimeOut < this->GetRemainingTimeAllowed())
  1176. {
  1177. timeout = testTimeOut;
  1178. }
  1179. // always have at least 1 second if we got to here
  1180. if (timeout <= 0)
  1181. {
  1182. timeout = 1;
  1183. }
  1184. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1185. "Test timeout computed to be: " << timeout << "\n");
  1186. if(cmSystemTools::SameFile(
  1187. argv[0], cmSystemTools::GetCTestCommand()) &&
  1188. !this->ForceNewCTestProcess)
  1189. {
  1190. cmCTest inst;
  1191. inst.ConfigType = this->ConfigType;
  1192. inst.TimeOut = timeout;
  1193. // Capture output of the child ctest.
  1194. std::ostringstream oss;
  1195. inst.SetStreams(&oss, &oss);
  1196. std::vector<std::string> args;
  1197. for(unsigned int i =0; i < argv.size(); ++i)
  1198. {
  1199. if(argv[i])
  1200. {
  1201. // make sure we pass the timeout in for any build and test
  1202. // invocations. Since --build-generator is required this is a
  1203. // good place to check for it, and to add the arguments in
  1204. if (strcmp(argv[i],"--build-generator") == 0 && timeout > 0)
  1205. {
  1206. args.push_back("--test-timeout");
  1207. std::ostringstream msg;
  1208. msg << timeout;
  1209. args.push_back(msg.str());
  1210. }
  1211. args.push_back(argv[i]);
  1212. }
  1213. }
  1214. if ( log )
  1215. {
  1216. *log << "* Run internal CTest" << std::endl;
  1217. }
  1218. std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
  1219. cmsys::auto_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
  1220. if (modifyEnv)
  1221. {
  1222. saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
  1223. cmSystemTools::AppendEnv(*environment);
  1224. }
  1225. *retVal = inst.Run(args, output);
  1226. *output += oss.str();
  1227. if ( log )
  1228. {
  1229. *log << *output;
  1230. }
  1231. cmSystemTools::ChangeDirectory(oldpath);
  1232. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  1233. "Internal cmCTest object used to run test." << std::endl
  1234. << *output << std::endl);
  1235. return cmsysProcess_State_Exited;
  1236. }
  1237. std::vector<char> tempOutput;
  1238. if ( output )
  1239. {
  1240. *output = "";
  1241. }
  1242. cmsys::auto_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv;
  1243. if (modifyEnv)
  1244. {
  1245. saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment);
  1246. cmSystemTools::AppendEnv(*environment);
  1247. }
  1248. cmsysProcess* cp = cmsysProcess_New();
  1249. cmsysProcess_SetCommand(cp, &*argv.begin());
  1250. cmCTestLog(this, DEBUG, "Command is: " << argv[0] << std::endl);
  1251. if(cmSystemTools::GetRunCommandHideConsole())
  1252. {
  1253. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  1254. }
  1255. cmsysProcess_SetTimeout(cp, timeout);
  1256. cmsysProcess_Execute(cp);
  1257. char* data;
  1258. int length;
  1259. while(cmsysProcess_WaitForData(cp, &data, &length, 0))
  1260. {
  1261. if ( output )
  1262. {
  1263. tempOutput.insert(tempOutput.end(), data, data+length);
  1264. }
  1265. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, cmCTestLogWrite(data, length));
  1266. if ( log )
  1267. {
  1268. log->write(data, length);
  1269. }
  1270. }
  1271. cmsysProcess_WaitForExit(cp, 0);
  1272. if(output && tempOutput.begin() != tempOutput.end())
  1273. {
  1274. output->append(&*tempOutput.begin(), tempOutput.size());
  1275. }
  1276. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "-- Process completed"
  1277. << std::endl);
  1278. int result = cmsysProcess_GetState(cp);
  1279. if(result == cmsysProcess_State_Exited)
  1280. {
  1281. *retVal = cmsysProcess_GetExitValue(cp);
  1282. if(*retVal != 0 && this->OutputTestOutputOnTestFailure)
  1283. {
  1284. OutputTestErrors(tempOutput);
  1285. }
  1286. }
  1287. else if(result == cmsysProcess_State_Exception)
  1288. {
  1289. if(this->OutputTestOutputOnTestFailure)
  1290. {
  1291. OutputTestErrors(tempOutput);
  1292. }
  1293. *retVal = cmsysProcess_GetExitException(cp);
  1294. std::string outerr = "\n*** Exception executing: ";
  1295. outerr += cmsysProcess_GetExceptionString(cp);
  1296. *output += outerr;
  1297. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl
  1298. << std::flush);
  1299. }
  1300. else if(result == cmsysProcess_State_Error)
  1301. {
  1302. std::string outerr = "\n*** ERROR executing: ";
  1303. outerr += cmsysProcess_GetErrorString(cp);
  1304. *output += outerr;
  1305. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl
  1306. << std::flush);
  1307. }
  1308. cmsysProcess_Delete(cp);
  1309. return result;
  1310. }
  1311. //----------------------------------------------------------------------
  1312. std::string cmCTest::SafeBuildIdField(const std::string& value)
  1313. {
  1314. std::string safevalue(value);
  1315. if (safevalue != "")
  1316. {
  1317. // Disallow non-filename and non-space whitespace characters.
  1318. // If they occur, replace them with ""
  1319. //
  1320. const char *disallowed = "\\:*?\"<>|\n\r\t\f\v";
  1321. if (safevalue.find_first_of(disallowed) != value.npos)
  1322. {
  1323. std::string::size_type i = 0;
  1324. std::string::size_type n = strlen(disallowed);
  1325. char replace[2];
  1326. replace[1] = 0;
  1327. for (i= 0; i<n; ++i)
  1328. {
  1329. replace[0] = disallowed[i];
  1330. cmSystemTools::ReplaceString(safevalue, replace, "");
  1331. }
  1332. }
  1333. safevalue = cmXMLSafe(safevalue).str();
  1334. }
  1335. if (safevalue == "")
  1336. {
  1337. safevalue = "(empty)";
  1338. }
  1339. return safevalue;
  1340. }
  1341. //----------------------------------------------------------------------
  1342. void cmCTest::StartXML(std::ostream& ostr, bool append)
  1343. {
  1344. if(this->CurrentTag.empty())
  1345. {
  1346. cmCTestLog(this, ERROR_MESSAGE,
  1347. "Current Tag empty, this may mean"
  1348. " NightlStartTime was not set correctly." << std::endl);
  1349. cmSystemTools::SetFatalErrorOccured();
  1350. }
  1351. // find out about the system
  1352. cmsys::SystemInformation info;
  1353. info.RunCPUCheck();
  1354. info.RunOSCheck();
  1355. info.RunMemoryCheck();
  1356. std::string buildname = cmCTest::SafeBuildIdField(
  1357. this->GetCTestConfiguration("BuildName"));
  1358. std::string stamp = cmCTest::SafeBuildIdField(
  1359. this->CurrentTag + "-" + this->GetTestModelString());
  1360. std::string site = cmCTest::SafeBuildIdField(
  1361. this->GetCTestConfiguration("Site"));
  1362. ostr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1363. << "<Site BuildName=\"" << buildname << "\"\n"
  1364. << "\tBuildStamp=\"" << stamp << "\"\n"
  1365. << "\tName=\"" << site << "\"\n"
  1366. << "\tGenerator=\"ctest-" << cmVersion::GetCMakeVersion() << "\"\n"
  1367. << (append? "\tAppend=\"true\"\n":"")
  1368. << "\tCompilerName=\"" << this->GetCTestConfiguration("Compiler")
  1369. << "\"\n"
  1370. #ifdef _COMPILER_VERSION
  1371. << "\tCompilerVersion=\"_COMPILER_VERSION\"\n"
  1372. #endif
  1373. << "\tOSName=\"" << info.GetOSName() << "\"\n"
  1374. << "\tHostname=\"" << info.GetHostname() << "\"\n"
  1375. << "\tOSRelease=\"" << info.GetOSRelease() << "\"\n"
  1376. << "\tOSVersion=\"" << info.GetOSVersion() << "\"\n"
  1377. << "\tOSPlatform=\"" << info.GetOSPlatform() << "\"\n"
  1378. << "\tIs64Bits=\"" << info.Is64Bits() << "\"\n"
  1379. << "\tVendorString=\"" << info.GetVendorString() << "\"\n"
  1380. << "\tVendorID=\"" << info.GetVendorID() << "\"\n"
  1381. << "\tFamilyID=\"" << info.GetFamilyID() << "\"\n"
  1382. << "\tModelID=\"" << info.GetModelID() << "\"\n"
  1383. << "\tProcessorCacheSize=\"" << info.GetProcessorCacheSize() << "\"\n"
  1384. << "\tNumberOfLogicalCPU=\"" << info.GetNumberOfLogicalCPU() << "\"\n"
  1385. << "\tNumberOfPhysicalCPU=\""<< info.GetNumberOfPhysicalCPU() << "\"\n"
  1386. << "\tTotalVirtualMemory=\"" << info.GetTotalVirtualMemory() << "\"\n"
  1387. << "\tTotalPhysicalMemory=\""<< info.GetTotalPhysicalMemory() << "\"\n"
  1388. << "\tLogicalProcessorsPerPhysical=\""
  1389. << info.GetLogicalProcessorsPerPhysical() << "\"\n"
  1390. << "\tProcessorClockFrequency=\""
  1391. << info.GetProcessorClockFrequency() << "\"\n"
  1392. << ">" << std::endl;
  1393. this->AddSiteProperties(ostr);
  1394. }
  1395. //----------------------------------------------------------------------
  1396. void cmCTest::AddSiteProperties(std::ostream& ostr)
  1397. {
  1398. cmCTestScriptHandler* ch =
  1399. static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  1400. cmake* cm = ch->GetCMake();
  1401. // if no CMake then this is the old style script and props like
  1402. // this will not work anyway.
  1403. if(!cm)
  1404. {
  1405. return;
  1406. }
  1407. // This code should go when cdash is changed to use labels only
  1408. const char* subproject = cm->GetProperty("SubProject", cmProperty::GLOBAL);
  1409. if(subproject)
  1410. {
  1411. ostr << "<Subproject name=\"" << subproject << "\">\n";
  1412. const char* labels =
  1413. ch->GetCMake()->GetProperty("SubProjectLabels", cmProperty::GLOBAL);
  1414. if(labels)
  1415. {
  1416. ostr << " <Labels>\n";
  1417. std::string l = labels;
  1418. std::vector<std::string> args;
  1419. cmSystemTools::ExpandListArgument(l, args);
  1420. for(std::vector<std::string>::iterator i = args.begin();
  1421. i != args.end(); ++i)
  1422. {
  1423. ostr << " <Label>" << *i << "</Label>\n";
  1424. }
  1425. ostr << " </Labels>\n";
  1426. }
  1427. ostr << "</Subproject>\n";
  1428. }
  1429. // This code should stay when cdash only does label based sub-projects
  1430. const char* label = cm->GetProperty("Label", cmProperty::GLOBAL);
  1431. if(label)
  1432. {
  1433. ostr << "<Labels>\n";
  1434. ostr << " <Label>" << label << "</Label>\n";
  1435. ostr << "</Labels>\n";
  1436. }
  1437. }
  1438. //----------------------------------------------------------------------
  1439. void cmCTest::EndXML(std::ostream& ostr)
  1440. {
  1441. ostr << "</Site>" << std::endl;
  1442. }
  1443. //----------------------------------------------------------------------
  1444. int cmCTest::GenerateCTestNotesOutput(std::ostream& os,
  1445. const cmCTest::VectorOfStrings& files)
  1446. {
  1447. std::string buildname = cmCTest::SafeBuildIdField(
  1448. this->GetCTestConfiguration("BuildName"));
  1449. cmCTest::VectorOfStrings::const_iterator it;
  1450. os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  1451. << "<?xml-stylesheet type=\"text/xsl\" "
  1452. "href=\"Dart/Source/Server/XSL/Build.xsl "
  1453. "<file:///Dart/Source/Server/XSL/Build.xsl> \"?>\n"
  1454. << "<Site BuildName=\"" << buildname
  1455. << "\" BuildStamp=\""
  1456. << this->CurrentTag << "-" << this->GetTestModelString() << "\" Name=\""
  1457. << this->GetCTestConfiguration("Site") << "\" Generator=\"ctest"
  1458. << cmVersion::GetCMakeVersion()
  1459. << "\">\n";
  1460. this->AddSiteProperties(os);
  1461. os << "<Notes>" << std::endl;
  1462. for ( it = files.begin(); it != files.end(); it ++ )
  1463. {
  1464. cmCTestLog(this, OUTPUT, "\tAdd file: " << *it << std::endl);
  1465. std::string note_time = this->CurrentTime();
  1466. os << "<Note Name=\"" << cmXMLSafe(*it) << "\">\n"
  1467. << "<Time>" << cmSystemTools::GetTime() << "</Time>\n"
  1468. << "<DateTime>" << note_time << "</DateTime>\n"
  1469. << "<Text>" << std::endl;
  1470. cmsys::ifstream ifs(it->c_str());
  1471. if ( ifs )
  1472. {
  1473. std::string line;
  1474. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  1475. {
  1476. os << cmXMLSafe(line) << std::endl;
  1477. }
  1478. ifs.close();
  1479. }
  1480. else
  1481. {
  1482. os << "Problem reading file: " << *it << std::endl;
  1483. cmCTestLog(this, ERROR_MESSAGE, "Problem reading file: " << *it
  1484. << " while creating notes" << std::endl);
  1485. }
  1486. os << "</Text>\n"
  1487. << "</Note>" << std::endl;
  1488. }
  1489. os << "</Notes>\n"
  1490. << "</Site>" << std::endl;
  1491. return 1;
  1492. }
  1493. //----------------------------------------------------------------------
  1494. int cmCTest::GenerateNotesFile(const VectorOfStrings &files)
  1495. {
  1496. cmGeneratedFileStream ofs;
  1497. if ( !this->OpenOutputFile(this->CurrentTag, "Notes.xml", ofs) )
  1498. {
  1499. cmCTestLog(this, ERROR_MESSAGE, "Cannot open notes file" << std::endl);
  1500. return 1;
  1501. }
  1502. this->GenerateCTestNotesOutput(ofs, files);
  1503. return 0;
  1504. }
  1505. //----------------------------------------------------------------------
  1506. int cmCTest::GenerateNotesFile(const char* cfiles)
  1507. {
  1508. if ( !cfiles )
  1509. {
  1510. return 1;
  1511. }
  1512. VectorOfStrings files;
  1513. cmCTestLog(this, OUTPUT, "Create notes file" << std::endl);
  1514. files = cmSystemTools::SplitString(cfiles, ';');
  1515. if ( files.size() == 0 )
  1516. {
  1517. return 1;
  1518. }
  1519. return this->GenerateNotesFile(files);
  1520. }
  1521. //----------------------------------------------------------------------
  1522. std::string cmCTest::Base64GzipEncodeFile(std::string file)
  1523. {
  1524. std::string tarFile = file + "_temp.tar.gz";
  1525. std::vector<std::string> files;
  1526. files.push_back(file);
  1527. if(!cmSystemTools::CreateTar(tarFile.c_str(), files,
  1528. cmSystemTools::TarCompressGZip, false))
  1529. {
  1530. cmCTestLog(this, ERROR_MESSAGE, "Error creating tar while "
  1531. "encoding file: " << file << std::endl);
  1532. return "";
  1533. }
  1534. std::string base64 = this->Base64EncodeFile(tarFile);
  1535. cmSystemTools::RemoveFile(tarFile);
  1536. return base64;
  1537. }
  1538. //----------------------------------------------------------------------
  1539. std::string cmCTest::Base64EncodeFile(std::string file)
  1540. {
  1541. size_t const len = cmSystemTools::FileLength(file);
  1542. cmsys::ifstream ifs(file.c_str(), std::ios::in
  1543. #ifdef _WIN32
  1544. | std::ios::binary
  1545. #endif
  1546. );
  1547. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1548. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1549. ifs.close();
  1550. unsigned char *encoded_buffer
  1551. = new unsigned char [ (len * 3) / 2 + 5 ];
  1552. size_t const rlen
  1553. = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1554. std::string base64 = "";
  1555. for(size_t i = 0; i < rlen; i++)
  1556. {
  1557. base64 += encoded_buffer[i];
  1558. }
  1559. delete [] file_buffer;
  1560. delete [] encoded_buffer;
  1561. return base64;
  1562. }
  1563. //----------------------------------------------------------------------
  1564. bool cmCTest::SubmitExtraFiles(const VectorOfStrings &files)
  1565. {
  1566. VectorOfStrings::const_iterator it;
  1567. for ( it = files.begin();
  1568. it != files.end();
  1569. ++ it )
  1570. {
  1571. if ( !cmSystemTools::FileExists(it->c_str()) )
  1572. {
  1573. cmCTestLog(this, ERROR_MESSAGE, "Cannot find extra file: "
  1574. << *it << " to submit."
  1575. << std::endl;);
  1576. return false;
  1577. }
  1578. this->AddSubmitFile(PartExtraFiles, it->c_str());
  1579. }
  1580. return true;
  1581. }
  1582. //----------------------------------------------------------------------
  1583. bool cmCTest::SubmitExtraFiles(const char* cfiles)
  1584. {
  1585. if ( !cfiles )
  1586. {
  1587. return 1;
  1588. }
  1589. VectorOfStrings files;
  1590. cmCTestLog(this, OUTPUT, "Submit extra files" << std::endl);
  1591. files = cmSystemTools::SplitString(cfiles, ';');
  1592. if ( files.size() == 0 )
  1593. {
  1594. return 1;
  1595. }
  1596. return this->SubmitExtraFiles(files);
  1597. }
  1598. //-------------------------------------------------------
  1599. // for a -D argument convert the next argument into
  1600. // the proper list of dashboard steps via SetTest
  1601. bool cmCTest::AddTestsForDashboardType(std::string &targ)
  1602. {
  1603. if ( targ == "Experimental" )
  1604. {
  1605. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1606. this->SetTest("Start");
  1607. this->SetTest("Configure");
  1608. this->SetTest("Build");
  1609. this->SetTest("Test");
  1610. this->SetTest("Coverage");
  1611. this->SetTest("Submit");
  1612. }
  1613. else if ( targ == "ExperimentalStart" )
  1614. {
  1615. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1616. this->SetTest("Start");
  1617. }
  1618. else if ( targ == "ExperimentalUpdate" )
  1619. {
  1620. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1621. this->SetTest("Update");
  1622. }
  1623. else if ( targ == "ExperimentalConfigure" )
  1624. {
  1625. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1626. this->SetTest("Configure");
  1627. }
  1628. else if ( targ == "ExperimentalBuild" )
  1629. {
  1630. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1631. this->SetTest("Build");
  1632. }
  1633. else if ( targ == "ExperimentalTest" )
  1634. {
  1635. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1636. this->SetTest("Test");
  1637. }
  1638. else if ( targ == "ExperimentalMemCheck"
  1639. || targ == "ExperimentalPurify" )
  1640. {
  1641. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1642. this->SetTest("MemCheck");
  1643. }
  1644. else if ( targ == "ExperimentalCoverage" )
  1645. {
  1646. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1647. this->SetTest("Coverage");
  1648. }
  1649. else if ( targ == "ExperimentalSubmit" )
  1650. {
  1651. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1652. this->SetTest("Submit");
  1653. }
  1654. else if ( targ == "Continuous" )
  1655. {
  1656. this->SetTestModel(cmCTest::CONTINUOUS);
  1657. this->SetTest("Start");
  1658. this->SetTest("Update");
  1659. this->SetTest("Configure");
  1660. this->SetTest("Build");
  1661. this->SetTest("Test");
  1662. this->SetTest("Coverage");
  1663. this->SetTest("Submit");
  1664. }
  1665. else if ( targ == "ContinuousStart" )
  1666. {
  1667. this->SetTestModel(cmCTest::CONTINUOUS);
  1668. this->SetTest("Start");
  1669. }
  1670. else if ( targ == "ContinuousUpdate" )
  1671. {
  1672. this->SetTestModel(cmCTest::CONTINUOUS);
  1673. this->SetTest("Update");
  1674. }
  1675. else if ( targ == "ContinuousConfigure" )
  1676. {
  1677. this->SetTestModel(cmCTest::CONTINUOUS);
  1678. this->SetTest("Configure");
  1679. }
  1680. else if ( targ == "ContinuousBuild" )
  1681. {
  1682. this->SetTestModel(cmCTest::CONTINUOUS);
  1683. this->SetTest("Build");
  1684. }
  1685. else if ( targ == "ContinuousTest" )
  1686. {
  1687. this->SetTestModel(cmCTest::CONTINUOUS);
  1688. this->SetTest("Test");
  1689. }
  1690. else if ( targ == "ContinuousMemCheck"
  1691. || targ == "ContinuousPurify" )
  1692. {
  1693. this->SetTestModel(cmCTest::CONTINUOUS);
  1694. this->SetTest("MemCheck");
  1695. }
  1696. else if ( targ == "ContinuousCoverage" )
  1697. {
  1698. this->SetTestModel(cmCTest::CONTINUOUS);
  1699. this->SetTest("Coverage");
  1700. }
  1701. else if ( targ == "ContinuousSubmit" )
  1702. {
  1703. this->SetTestModel(cmCTest::CONTINUOUS);
  1704. this->SetTest("Submit");
  1705. }
  1706. else if ( targ == "Nightly" )
  1707. {
  1708. this->SetTestModel(cmCTest::NIGHTLY);
  1709. this->SetTest("Start");
  1710. this->SetTest("Update");
  1711. this->SetTest("Configure");
  1712. this->SetTest("Build");
  1713. this->SetTest("Test");
  1714. this->SetTest("Coverage");
  1715. this->SetTest("Submit");
  1716. }
  1717. else if ( targ == "NightlyStart" )
  1718. {
  1719. this->SetTestModel(cmCTest::NIGHTLY);
  1720. this->SetTest("Start");
  1721. }
  1722. else if ( targ == "NightlyUpdate" )
  1723. {
  1724. this->SetTestModel(cmCTest::NIGHTLY);
  1725. this->SetTest("Update");
  1726. }
  1727. else if ( targ == "NightlyConfigure" )
  1728. {
  1729. this->SetTestModel(cmCTest::NIGHTLY);
  1730. this->SetTest("Configure");
  1731. }
  1732. else if ( targ == "NightlyBuild" )
  1733. {
  1734. this->SetTestModel(cmCTest::NIGHTLY);
  1735. this->SetTest("Build");
  1736. }
  1737. else if ( targ == "NightlyTest" )
  1738. {
  1739. this->SetTestModel(cmCTest::NIGHTLY);
  1740. this->SetTest("Test");
  1741. }
  1742. else if ( targ == "NightlyMemCheck"
  1743. || targ == "NightlyPurify" )
  1744. {
  1745. this->SetTestModel(cmCTest::NIGHTLY);
  1746. this->SetTest("MemCheck");
  1747. }
  1748. else if ( targ == "NightlyCoverage" )
  1749. {
  1750. this->SetTestModel(cmCTest::NIGHTLY);
  1751. this->SetTest("Coverage");
  1752. }
  1753. else if ( targ == "NightlySubmit" )
  1754. {
  1755. this->SetTestModel(cmCTest::NIGHTLY);
  1756. this->SetTest("Submit");
  1757. }
  1758. else if ( targ == "MemoryCheck" )
  1759. {
  1760. this->SetTestModel(cmCTest::EXPERIMENTAL);
  1761. this->SetTest("Start");
  1762. this->SetTest("Configure");
  1763. this->SetTest("Build");
  1764. this->SetTest("MemCheck");
  1765. this->SetTest("Coverage");
  1766. this->SetTest("Submit");
  1767. }
  1768. else if ( targ == "NightlyMemoryCheck" )
  1769. {
  1770. this->SetTestModel(cmCTest::NIGHTLY);
  1771. this->SetTest("Start");
  1772. this->SetTest("Update");
  1773. this->SetTest("Configure");
  1774. this->SetTest("Build");
  1775. this->SetTest("MemCheck");
  1776. this->SetTest("Coverage");
  1777. this->SetTest("Submit");
  1778. }
  1779. else
  1780. {
  1781. return false;
  1782. }
  1783. return true;
  1784. }
  1785. //----------------------------------------------------------------------
  1786. void cmCTest::ErrorMessageUnknownDashDValue(std::string &val)
  1787. {
  1788. cmCTestLog(this, ERROR_MESSAGE,
  1789. "CTest -D called with incorrect option: " << val << std::endl);
  1790. cmCTestLog(this, ERROR_MESSAGE,
  1791. "Available options are:" << std::endl
  1792. << " ctest -D Continuous" << std::endl
  1793. << " ctest -D Continuous(Start|Update|Configure|Build)" << std::endl
  1794. << " ctest -D Continuous(Test|Coverage|MemCheck|Submit)" << std::endl
  1795. << " ctest -D Experimental" << std::endl
  1796. << " ctest -D Experimental(Start|Update|Configure|Build)" << std::endl
  1797. << " ctest -D Experimental(Test|Coverage|MemCheck|Submit)" << std::endl
  1798. << " ctest -D Nightly" << std::endl
  1799. << " ctest -D Nightly(Start|Update|Configure|Build)" << std::endl
  1800. << " ctest -D Nightly(Test|Coverage|MemCheck|Submit)" << std::endl
  1801. << " ctest -D NightlyMemoryCheck" << std::endl);
  1802. }
  1803. //----------------------------------------------------------------------
  1804. bool cmCTest::CheckArgument(const std::string& arg, const char* varg1,
  1805. const char* varg2)
  1806. {
  1807. return (varg1 && arg == varg1) || (varg2 && arg == varg2);
  1808. }
  1809. //----------------------------------------------------------------------
  1810. // Processes one command line argument (and its arguments if any)
  1811. // for many simple options and then returns
  1812. void cmCTest::HandleCommandLineArguments(size_t &i,
  1813. std::vector<std::string> &args)
  1814. {
  1815. std::string arg = args[i];
  1816. if(this->CheckArgument(arg, "-F"))
  1817. {
  1818. this->Failover = true;
  1819. }
  1820. if(this->CheckArgument(arg, "-j", "--parallel") && i < args.size() - 1)
  1821. {
  1822. i++;
  1823. int plevel = atoi(args[i].c_str());
  1824. this->SetParallelLevel(plevel);
  1825. this->ParallelLevelSetInCli = true;
  1826. }
  1827. else if(arg.find("-j") == 0)
  1828. {
  1829. int plevel = atoi(arg.substr(2).c_str());
  1830. this->SetParallelLevel(plevel);
  1831. this->ParallelLevelSetInCli = true;
  1832. }
  1833. if(this->CheckArgument(arg, "--no-compress-output"))
  1834. {
  1835. this->CompressTestOutput = false;
  1836. this->CompressMemCheckOutput = false;
  1837. }
  1838. if(this->CheckArgument(arg, "--print-labels"))
  1839. {
  1840. this->PrintLabels = true;
  1841. }
  1842. if(this->CheckArgument(arg, "--http1.0"))
  1843. {
  1844. this->UseHTTP10 = true;
  1845. }
  1846. if(this->CheckArgument(arg, "--timeout") && i < args.size() - 1)
  1847. {
  1848. i++;
  1849. double timeout = (double)atof(args[i].c_str());
  1850. this->GlobalTimeout = timeout;
  1851. }
  1852. if(this->CheckArgument(arg, "--stop-time") && i < args.size() - 1)
  1853. {
  1854. i++;
  1855. this->SetStopTime(args[i]);
  1856. }
  1857. if(this->CheckArgument(arg, "-C", "--build-config") &&
  1858. i < args.size() - 1)
  1859. {
  1860. i++;
  1861. this->SetConfigType(args[i].c_str());
  1862. }
  1863. if(this->CheckArgument(arg, "--debug"))
  1864. {
  1865. this->Debug = true;
  1866. this->ShowLineNumbers = true;
  1867. }
  1868. if(this->CheckArgument(arg, "--track") && i < args.size() - 1)
  1869. {
  1870. i++;
  1871. this->SpecificTrack = args[i];
  1872. }
  1873. if(this->CheckArgument(arg, "--show-line-numbers"))
  1874. {
  1875. this->ShowLineNumbers = true;
  1876. }
  1877. if(this->CheckArgument(arg, "--no-label-summary"))
  1878. {
  1879. this->LabelSummary = false;
  1880. }
  1881. if(this->CheckArgument(arg, "-Q", "--quiet"))
  1882. {
  1883. this->Quiet = true;
  1884. }
  1885. if(this->CheckArgument(arg, "-V", "--verbose"))
  1886. {
  1887. this->Verbose = true;
  1888. }
  1889. if(this->CheckArgument(arg, "-B"))
  1890. {
  1891. this->BatchJobs = true;
  1892. }
  1893. if(this->CheckArgument(arg, "-VV", "--extra-verbose"))
  1894. {
  1895. this->ExtraVerbose = true;
  1896. this->Verbose = true;
  1897. }
  1898. if(this->CheckArgument(arg, "--output-on-failure"))
  1899. {
  1900. this->OutputTestOutputOnTestFailure = true;
  1901. }
  1902. if(this->CheckArgument(arg, "-N", "--show-only"))
  1903. {
  1904. this->ShowOnly = true;
  1905. }
  1906. if(this->CheckArgument(arg, "-O", "--output-log") && i < args.size() - 1 )
  1907. {
  1908. i++;
  1909. this->SetOutputLogFileName(args[i].c_str());
  1910. }
  1911. if(this->CheckArgument(arg, "--tomorrow-tag"))
  1912. {
  1913. this->TomorrowTag = true;
  1914. }
  1915. if(this->CheckArgument(arg, "--force-new-ctest-process"))
  1916. {
  1917. this->ForceNewCTestProcess = true;
  1918. }
  1919. if(this->CheckArgument(arg, "-W", "--max-width") && i < args.size() - 1)
  1920. {
  1921. i++;
  1922. this->MaxTestNameWidth = atoi(args[i].c_str());
  1923. }
  1924. if(this->CheckArgument(arg, "--interactive-debug-mode") &&
  1925. i < args.size() - 1 )
  1926. {
  1927. i++;
  1928. this->InteractiveDebugMode = cmSystemTools::IsOn(args[i].c_str());
  1929. }
  1930. if(this->CheckArgument(arg, "--submit-index") && i < args.size() - 1 )
  1931. {
  1932. i++;
  1933. this->SubmitIndex = atoi(args[i].c_str());
  1934. if ( this->SubmitIndex < 0 )
  1935. {
  1936. this->SubmitIndex = 0;
  1937. }
  1938. }
  1939. if(this->CheckArgument(arg, "--overwrite") && i < args.size() - 1)
  1940. {
  1941. i++;
  1942. this->AddCTestConfigurationOverwrite(args[i]);
  1943. }
  1944. if(this->CheckArgument(arg, "-A", "--add-notes") && i < args.size() - 1)
  1945. {
  1946. this->ProduceXML = true;
  1947. this->SetTest("Notes");
  1948. i++;
  1949. this->SetNotesFiles(args[i].c_str());
  1950. }
  1951. // options that control what tests are run
  1952. if(this->CheckArgument(arg, "-I", "--tests-information") &&
  1953. i < args.size() - 1)
  1954. {
  1955. i++;
  1956. this->GetHandler("test")->SetPersistentOption("TestsToRunInformation",
  1957. args[i].c_str());
  1958. this->GetHandler("memcheck")->
  1959. SetPersistentOption("TestsToRunInformation",args[i].c_str());
  1960. }
  1961. if(this->CheckArgument(arg, "-U", "--union"))
  1962. {
  1963. this->GetHandler("test")->SetPersistentOption("UseUnion", "true");
  1964. this->GetHandler("memcheck")->SetPersistentOption("UseUnion", "true");
  1965. }
  1966. if(this->CheckArgument(arg, "-R", "--tests-regex") && i < args.size() - 1)
  1967. {
  1968. i++;
  1969. this->GetHandler("test")->
  1970. SetPersistentOption("IncludeRegularExpression", args[i].c_str());
  1971. this->GetHandler("memcheck")->
  1972. SetPersistentOption("IncludeRegularExpression", args[i].c_str());
  1973. }
  1974. if(this->CheckArgument(arg, "-L", "--label-regex") && i < args.size() - 1)
  1975. {
  1976. i++;
  1977. this->GetHandler("test")->
  1978. SetPersistentOption("LabelRegularExpression", args[i].c_str());
  1979. this->GetHandler("memcheck")->
  1980. SetPersistentOption("LabelRegularExpression", args[i].c_str());
  1981. }
  1982. if(this->CheckArgument(arg, "-LE", "--label-exclude") && i < args.size() - 1)
  1983. {
  1984. i++;
  1985. this->GetHandler("test")->
  1986. SetPersistentOption("ExcludeLabelRegularExpression", args[i].c_str());
  1987. this->GetHandler("memcheck")->
  1988. SetPersistentOption("ExcludeLabelRegularExpression", args[i].c_str());
  1989. }
  1990. if(this->CheckArgument(arg, "-E", "--exclude-regex") &&
  1991. i < args.size() - 1)
  1992. {
  1993. i++;
  1994. this->GetHandler("test")->
  1995. SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
  1996. this->GetHandler("memcheck")->
  1997. SetPersistentOption("ExcludeRegularExpression", args[i].c_str());
  1998. }
  1999. if(this->CheckArgument(arg, "--rerun-failed"))
  2000. {
  2001. this->GetHandler("test")->SetPersistentOption("RerunFailed", "true");
  2002. this->GetHandler("memcheck")->SetPersistentOption("RerunFailed", "true");
  2003. }
  2004. }
  2005. //----------------------------------------------------------------------
  2006. // handle the -S -SR and -SP arguments
  2007. void cmCTest::HandleScriptArguments(size_t &i,
  2008. std::vector<std::string> &args,
  2009. bool &SRArgumentSpecified)
  2010. {
  2011. std::string arg = args[i];
  2012. if(this->CheckArgument(arg, "-SP", "--script-new-process") &&
  2013. i < args.size() - 1 )
  2014. {
  2015. this->RunConfigurationScript = true;
  2016. i++;
  2017. cmCTestScriptHandler* ch
  2018. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  2019. // -SR is an internal argument, -SP should be ignored when it is passed
  2020. if (!SRArgumentSpecified)
  2021. {
  2022. ch->AddConfigurationScript(args[i].c_str(),false);
  2023. }
  2024. }
  2025. if(this->CheckArgument(arg, "-SR", "--script-run") &&
  2026. i < args.size() - 1 )
  2027. {
  2028. SRArgumentSpecified = true;
  2029. this->RunConfigurationScript = true;
  2030. i++;
  2031. cmCTestScriptHandler* ch
  2032. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  2033. ch->AddConfigurationScript(args[i].c_str(),true);
  2034. }
  2035. if(this->CheckArgument(arg, "-S", "--script") && i < args.size() - 1 )
  2036. {
  2037. this->RunConfigurationScript = true;
  2038. i++;
  2039. cmCTestScriptHandler* ch
  2040. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  2041. // -SR is an internal argument, -S should be ignored when it is passed
  2042. if (!SRArgumentSpecified)
  2043. {
  2044. ch->AddConfigurationScript(args[i].c_str(),true);
  2045. }
  2046. }
  2047. }
  2048. //----------------------------------------------------------------------
  2049. bool cmCTest::AddVariableDefinition(const std::string &arg)
  2050. {
  2051. std::string name;
  2052. std::string value;
  2053. cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
  2054. if (cmCacheManager::ParseEntry(arg, name, value, type))
  2055. {
  2056. this->Definitions[name] = value;
  2057. return true;
  2058. }
  2059. return false;
  2060. }
  2061. //----------------------------------------------------------------------
  2062. // the main entry point of ctest, called from main
  2063. int cmCTest::Run(std::vector<std::string> &args, std::string* output)
  2064. {
  2065. const char* ctestExec = "ctest";
  2066. bool cmakeAndTest = false;
  2067. bool executeTests = true;
  2068. bool SRArgumentSpecified = false;
  2069. // copy the command line
  2070. for(size_t i=0; i < args.size(); ++i)
  2071. {
  2072. this->InitialCommandLineArguments.push_back(args[i]);
  2073. }
  2074. // process the command line arguments
  2075. for(size_t i=1; i < args.size(); ++i)
  2076. {
  2077. // handle the simple commandline arguments
  2078. this->HandleCommandLineArguments(i,args);
  2079. // handle the script arguments -S -SR -SP
  2080. this->HandleScriptArguments(i,args,SRArgumentSpecified);
  2081. // handle a request for a dashboard
  2082. std::string arg = args[i];
  2083. if(this->CheckArgument(arg, "-D", "--dashboard") && i < args.size() - 1 )
  2084. {
  2085. this->ProduceXML = true;
  2086. i++;
  2087. std::string targ = args[i];
  2088. // AddTestsForDashboard parses the dashboard type and converts it
  2089. // into the separate stages
  2090. if (!this->AddTestsForDashboardType(targ))
  2091. {
  2092. if (!this->AddVariableDefinition(targ))
  2093. {
  2094. this->ErrorMessageUnknownDashDValue(targ);
  2095. executeTests = false;
  2096. }
  2097. }
  2098. }
  2099. // If it's not exactly -D, but it starts with -D, then try to parse out
  2100. // a variable definition from it, same as CMake does. Unsuccessful
  2101. // attempts are simply ignored since previous ctest versions ignore
  2102. // this too. (As well as many other unknown command line args.)
  2103. //
  2104. if(arg != "-D" && cmSystemTools::StringStartsWith(arg.c_str(), "-D"))
  2105. {
  2106. std::string input = arg.substr(2);
  2107. this->AddVariableDefinition(input);
  2108. }
  2109. if(this->CheckArgument(arg, "-T", "--test-action") &&
  2110. (i < args.size() -1) )
  2111. {
  2112. this->ProduceXML = true;
  2113. i++;
  2114. if ( !this->SetTest(args[i].c_str(), false) )
  2115. {
  2116. executeTests = false;
  2117. cmCTestLog(this, ERROR_MESSAGE,
  2118. "CTest -T called with incorrect option: "
  2119. << args[i] << std::endl);
  2120. cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
  2121. << " " << ctestExec << " -T all" << std::endl
  2122. << " " << ctestExec << " -T start" << std::endl
  2123. << " " << ctestExec << " -T update" << std::endl
  2124. << " " << ctestExec << " -T configure" << std::endl
  2125. << " " << ctestExec << " -T build" << std::endl
  2126. << " " << ctestExec << " -T test" << std::endl
  2127. << " " << ctestExec << " -T coverage" << std::endl
  2128. << " " << ctestExec << " -T memcheck" << std::endl
  2129. << " " << ctestExec << " -T notes" << std::endl
  2130. << " " << ctestExec << " -T submit" << std::endl);
  2131. }
  2132. }
  2133. // what type of test model
  2134. if(this->CheckArgument(arg, "-M", "--test-model") &&
  2135. (i < args.size() -1) )
  2136. {
  2137. i++;
  2138. std::string const& str = args[i];
  2139. if ( cmSystemTools::LowerCase(str) == "nightly" )
  2140. {
  2141. this->SetTestModel(cmCTest::NIGHTLY);
  2142. }
  2143. else if ( cmSystemTools::LowerCase(str) == "continuous" )
  2144. {
  2145. this->SetTestModel(cmCTest::CONTINUOUS);
  2146. }
  2147. else if ( cmSystemTools::LowerCase(str) == "experimental" )
  2148. {
  2149. this->SetTestModel(cmCTest::EXPERIMENTAL);
  2150. }
  2151. else
  2152. {
  2153. executeTests = false;
  2154. cmCTestLog(this, ERROR_MESSAGE,
  2155. "CTest -M called with incorrect option: " << str
  2156. << std::endl);
  2157. cmCTestLog(this, ERROR_MESSAGE, "Available options are:" << std::endl
  2158. << " " << ctestExec << " -M Continuous" << std::endl
  2159. << " " << ctestExec << " -M Experimental" << std::endl
  2160. << " " << ctestExec << " -M Nightly" << std::endl);
  2161. }
  2162. }
  2163. if(this->CheckArgument(arg, "--extra-submit") && i < args.size() - 1)
  2164. {
  2165. this->ProduceXML = true;
  2166. this->SetTest("Submit");
  2167. i++;
  2168. if ( !this->SubmitExtraFiles(args[i].c_str()) )
  2169. {
  2170. return 0;
  2171. }
  2172. }
  2173. // --build-and-test options
  2174. if(this->CheckArgument(arg, "--build-and-test") && i < args.size() - 1)
  2175. {
  2176. cmakeAndTest = true;
  2177. }
  2178. if(this->CheckArgument(arg, "--schedule-random"))
  2179. {
  2180. this->ScheduleType = "Random";
  2181. }
  2182. // pass the argument to all the handlers as well, but i may no longer be
  2183. // set to what it was originally so I'm not sure this is working as
  2184. // intended
  2185. cmCTest::t_TestingHandlers::iterator it;
  2186. for ( it = this->TestingHandlers.begin();
  2187. it != this->TestingHandlers.end();
  2188. ++ it )
  2189. {
  2190. if ( !it->second->ProcessCommandLineArguments(arg, i, args) )
  2191. {
  2192. cmCTestLog(this, ERROR_MESSAGE,
  2193. "Problem parsing command line arguments within a handler");
  2194. return 0;
  2195. }
  2196. }
  2197. } // the close of the for argument loop
  2198. if (!this->ParallelLevelSetInCli)
  2199. {
  2200. if (const char *parallel = cmSystemTools::GetEnv("CTEST_PARALLEL_LEVEL"))
  2201. {
  2202. int plevel = atoi(parallel);
  2203. this->SetParallelLevel(plevel);
  2204. }
  2205. }
  2206. // now what sould cmake do? if --build-and-test was specified then
  2207. // we run the build and test handler and return
  2208. if(cmakeAndTest)
  2209. {
  2210. this->Verbose = true;
  2211. cmCTestBuildAndTestHandler* handler =
  2212. static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest"));
  2213. int retv = handler->ProcessHandler();
  2214. *output = handler->GetOutput();
  2215. #ifdef CMAKE_BUILD_WITH_CMAKE
  2216. cmDynamicLoader::FlushCache();
  2217. #endif
  2218. if(retv != 0)
  2219. {
  2220. cmCTestLog(this, DEBUG, "build and test failing returning: " << retv
  2221. << std::endl);
  2222. }
  2223. return retv;
  2224. }
  2225. if(executeTests)
  2226. {
  2227. int res;
  2228. // call process directory
  2229. if (this->RunConfigurationScript)
  2230. {
  2231. if ( this->ExtraVerbose )
  2232. {
  2233. cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl);
  2234. }
  2235. cmCTest::t_TestingHandlers::iterator it;
  2236. for ( it = this->TestingHandlers.begin();
  2237. it != this->TestingHandlers.end();
  2238. ++ it )
  2239. {
  2240. it->second->SetVerbose(this->ExtraVerbose);
  2241. it->second->SetSubmitIndex(this->SubmitIndex);
  2242. }
  2243. this->GetHandler("script")->SetVerbose(this->Verbose);
  2244. res = this->GetHandler("script")->ProcessHandler();
  2245. if(res != 0)
  2246. {
  2247. cmCTestLog(this, DEBUG, "running script failing returning: " << res
  2248. << std::endl);
  2249. }
  2250. }
  2251. else
  2252. {
  2253. // What is this? -V seems to be the same as -VV,
  2254. // and Verbose is always on in this case
  2255. this->ExtraVerbose = this->Verbose;
  2256. this->Verbose = true;
  2257. cmCTest::t_TestingHandlers::iterator it;
  2258. for ( it = this->TestingHandlers.begin();
  2259. it != this->TestingHandlers.end();
  2260. ++ it )
  2261. {
  2262. it->second->SetVerbose(this->Verbose);
  2263. it->second->SetSubmitIndex(this->SubmitIndex);
  2264. }
  2265. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  2266. if(!this->Initialize(cwd.c_str(), 0))
  2267. {
  2268. res = 12;
  2269. cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard."
  2270. << std::endl);
  2271. }
  2272. else
  2273. {
  2274. res = this->ProcessTests();
  2275. }
  2276. this->Finalize();
  2277. }
  2278. if(res != 0)
  2279. {
  2280. cmCTestLog(this, DEBUG, "Running a test(s) failed returning : " << res
  2281. << std::endl);
  2282. }
  2283. return res;
  2284. }
  2285. return 1;
  2286. }
  2287. //----------------------------------------------------------------------
  2288. void cmCTest::SetNotesFiles(const char* notes)
  2289. {
  2290. if ( !notes )
  2291. {
  2292. return;
  2293. }
  2294. this->NotesFiles = notes;
  2295. }
  2296. //----------------------------------------------------------------------
  2297. void cmCTest::SetStopTime(std::string time)
  2298. {
  2299. this->StopTime = time;
  2300. this->DetermineNextDayStop();
  2301. }
  2302. //----------------------------------------------------------------------
  2303. int cmCTest::ReadCustomConfigurationFileTree(const char* dir, cmMakefile* mf)
  2304. {
  2305. bool found = false;
  2306. VectorOfStrings dirs;
  2307. VectorOfStrings ndirs;
  2308. cmCTestLog(this, DEBUG, "* Read custom CTest configuration directory: "
  2309. << dir << std::endl);
  2310. std::string fname = dir;
  2311. fname += "/CTestCustom.cmake";
  2312. cmCTestLog(this, DEBUG, "* Check for file: "
  2313. << fname << std::endl);
  2314. if ( cmSystemTools::FileExists(fname.c_str()) )
  2315. {
  2316. cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
  2317. << fname << std::endl);
  2318. bool erroroc = cmSystemTools::GetErrorOccuredFlag();
  2319. cmSystemTools::ResetErrorOccuredFlag();
  2320. if ( !mf->ReadListFile(0, fname.c_str()) ||
  2321. cmSystemTools::GetErrorOccuredFlag() )
  2322. {
  2323. cmCTestLog(this, ERROR_MESSAGE,
  2324. "Problem reading custom configuration: "
  2325. << fname << std::endl);
  2326. }
  2327. found = true;
  2328. if ( erroroc )
  2329. {
  2330. cmSystemTools::SetErrorOccured();
  2331. }
  2332. }
  2333. std::string rexpr = dir;
  2334. rexpr += "/CTestCustom.ctest";
  2335. cmCTestLog(this, DEBUG, "* Check for file: "
  2336. << rexpr << std::endl);
  2337. if ( !found && cmSystemTools::FileExists(rexpr.c_str()) )
  2338. {
  2339. cmsys::Glob gl;
  2340. gl.RecurseOn();
  2341. gl.FindFiles(rexpr);
  2342. std::vector<std::string>& files = gl.GetFiles();
  2343. std::vector<std::string>::iterator fileIt;
  2344. for ( fileIt = files.begin(); fileIt != files.end();
  2345. ++ fileIt )
  2346. {
  2347. cmCTestLog(this, DEBUG, "* Read custom CTest configuration file: "
  2348. << *fileIt << std::endl);
  2349. if ( !mf->ReadListFile(0, fileIt->c_str()) ||
  2350. cmSystemTools::GetErrorOccuredFlag() )
  2351. {
  2352. cmCTestLog(this, ERROR_MESSAGE,
  2353. "Problem reading custom configuration: "
  2354. << *fileIt << std::endl);
  2355. }
  2356. }
  2357. found = true;
  2358. }
  2359. if ( found )
  2360. {
  2361. cmCTest::t_TestingHandlers::iterator it;
  2362. for ( it = this->TestingHandlers.begin();
  2363. it != this->TestingHandlers.end(); ++ it )
  2364. {
  2365. cmCTestLog(this, DEBUG,
  2366. "* Read custom CTest configuration vectors for handler: "
  2367. << it->first << " (" << it->second << ")" << std::endl);
  2368. it->second->PopulateCustomVectors(mf);
  2369. }
  2370. }
  2371. return 1;
  2372. }
  2373. //----------------------------------------------------------------------
  2374. void cmCTest::PopulateCustomVector(cmMakefile* mf, const std::string& def,
  2375. std::vector<std::string>& vec)
  2376. {
  2377. const char* dval = mf->GetDefinition(def);
  2378. if ( !dval )
  2379. {
  2380. return;
  2381. }
  2382. cmCTestLog(this, DEBUG, "PopulateCustomVector: " << def << std::endl);
  2383. vec.clear();
  2384. cmSystemTools::ExpandListArgument(dval, vec);
  2385. for (std::vector<std::string>::const_iterator it = vec.begin();
  2386. it != vec.end(); ++it )
  2387. {
  2388. cmCTestLog(this, DEBUG, " -- " << *it << std::endl);
  2389. }
  2390. }
  2391. //----------------------------------------------------------------------
  2392. void cmCTest::PopulateCustomInteger(cmMakefile* mf, const std::string& def,
  2393. int& val)
  2394. {
  2395. const char* dval = mf->GetDefinition(def);
  2396. if ( !dval )
  2397. {
  2398. return;
  2399. }
  2400. val = atoi(dval);
  2401. }
  2402. //----------------------------------------------------------------------
  2403. std::string cmCTest::GetShortPathToFile(const char* cfname)
  2404. {
  2405. const std::string& sourceDir
  2406. = cmSystemTools::CollapseFullPath(
  2407. this->GetCTestConfiguration("SourceDirectory"));
  2408. const std::string& buildDir
  2409. = cmSystemTools::CollapseFullPath(
  2410. this->GetCTestConfiguration("BuildDirectory"));
  2411. std::string fname = cmSystemTools::CollapseFullPath(cfname);
  2412. // Find relative paths to both directories
  2413. std::string srcRelpath
  2414. = cmSystemTools::RelativePath(sourceDir.c_str(), fname.c_str());
  2415. std::string bldRelpath
  2416. = cmSystemTools::RelativePath(buildDir.c_str(), fname.c_str());
  2417. // If any contains "." it is not parent directory
  2418. bool inSrc = srcRelpath.find("..") == srcRelpath.npos;
  2419. bool inBld = bldRelpath.find("..") == bldRelpath.npos;
  2420. // TODO: Handle files with .. in their name
  2421. std::string* res = 0;
  2422. if ( inSrc && inBld )
  2423. {
  2424. // If both have relative path with no dots, pick the shorter one
  2425. if ( srcRelpath.size() < bldRelpath.size() )
  2426. {
  2427. res = &srcRelpath;
  2428. }
  2429. else
  2430. {
  2431. res = &bldRelpath;
  2432. }
  2433. }
  2434. else if ( inSrc )
  2435. {
  2436. res = &srcRelpath;
  2437. }
  2438. else if ( inBld )
  2439. {
  2440. res = &bldRelpath;
  2441. }
  2442. std::string path;
  2443. if ( !res )
  2444. {
  2445. path = fname;
  2446. }
  2447. else
  2448. {
  2449. cmSystemTools::ConvertToUnixSlashes(*res);
  2450. path = "./" + *res;
  2451. if ( path[path.size()-1] == '/' )
  2452. {
  2453. path = path.substr(0, path.size()-1);
  2454. }
  2455. }
  2456. cmsys::SystemTools::ReplaceString(path, ":", "_");
  2457. cmsys::SystemTools::ReplaceString(path, " ", "_");
  2458. return path;
  2459. }
  2460. //----------------------------------------------------------------------
  2461. std::string cmCTest::GetCTestConfiguration(const std::string& name)
  2462. {
  2463. if ( this->CTestConfigurationOverwrites.find(name) !=
  2464. this->CTestConfigurationOverwrites.end() )
  2465. {
  2466. return this->CTestConfigurationOverwrites[name];
  2467. }
  2468. return this->CTestConfiguration[name];
  2469. }
  2470. //----------------------------------------------------------------------
  2471. void cmCTest::EmptyCTestConfiguration()
  2472. {
  2473. this->CTestConfiguration.clear();
  2474. }
  2475. //----------------------------------------------------------------------
  2476. void cmCTest::DetermineNextDayStop()
  2477. {
  2478. struct tm* lctime;
  2479. time_t current_time = time(0);
  2480. lctime = gmtime(&current_time);
  2481. int gm_hour = lctime->tm_hour;
  2482. time_t gm_time = mktime(lctime);
  2483. lctime = localtime(&current_time);
  2484. int local_hour = lctime->tm_hour;
  2485. int tzone_offset = local_hour - gm_hour;
  2486. if(gm_time > current_time && gm_hour < local_hour)
  2487. {
  2488. // this means gm_time is on the next day
  2489. tzone_offset -= 24;
  2490. }
  2491. else if(gm_time < current_time && gm_hour > local_hour)
  2492. {
  2493. // this means gm_time is on the previous day
  2494. tzone_offset += 24;
  2495. }
  2496. tzone_offset *= 100;
  2497. char buf[1024];
  2498. sprintf(buf, "%d%02d%02d %s %+05i",
  2499. lctime->tm_year + 1900,
  2500. lctime->tm_mon + 1,
  2501. lctime->tm_mday,
  2502. this->StopTime.c_str(),
  2503. tzone_offset);
  2504. time_t stop_time = curl_getdate(buf, &current_time);
  2505. if(stop_time < current_time)
  2506. {
  2507. this->NextDayStopTime = true;
  2508. }
  2509. }
  2510. //----------------------------------------------------------------------
  2511. void cmCTest::SetCTestConfiguration(const char *name, const char* value)
  2512. {
  2513. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "SetCTestConfiguration:"
  2514. << name << ":" << (value ? value : "(null)") << "\n");
  2515. if ( !name )
  2516. {
  2517. return;
  2518. }
  2519. if ( !value )
  2520. {
  2521. this->CTestConfiguration.erase(name);
  2522. return;
  2523. }
  2524. this->CTestConfiguration[name] = value;
  2525. }
  2526. //----------------------------------------------------------------------
  2527. std::string cmCTest::GetCurrentTag()
  2528. {
  2529. return this->CurrentTag;
  2530. }
  2531. //----------------------------------------------------------------------
  2532. std::string cmCTest::GetBinaryDir()
  2533. {
  2534. return this->BinaryDir;
  2535. }
  2536. //----------------------------------------------------------------------
  2537. std::string const& cmCTest::GetConfigType()
  2538. {
  2539. return this->ConfigType;
  2540. }
  2541. //----------------------------------------------------------------------
  2542. bool cmCTest::GetShowOnly()
  2543. {
  2544. return this->ShowOnly;
  2545. }
  2546. //----------------------------------------------------------------------
  2547. int cmCTest::GetMaxTestNameWidth() const
  2548. {
  2549. return this->MaxTestNameWidth;
  2550. }
  2551. //----------------------------------------------------------------------
  2552. void cmCTest::SetProduceXML(bool v)
  2553. {
  2554. this->ProduceXML = v;
  2555. }
  2556. //----------------------------------------------------------------------
  2557. bool cmCTest::GetProduceXML()
  2558. {
  2559. return this->ProduceXML;
  2560. }
  2561. //----------------------------------------------------------------------
  2562. const char* cmCTest::GetSpecificTrack()
  2563. {
  2564. if ( this->SpecificTrack.empty() )
  2565. {
  2566. return 0;
  2567. }
  2568. return this->SpecificTrack.c_str();
  2569. }
  2570. //----------------------------------------------------------------------
  2571. void cmCTest::SetSpecificTrack(const char* track)
  2572. {
  2573. if ( !track )
  2574. {
  2575. this->SpecificTrack = "";
  2576. return;
  2577. }
  2578. this->SpecificTrack = track;
  2579. }
  2580. //----------------------------------------------------------------------
  2581. void cmCTest::AddSubmitFile(Part part, const char* name)
  2582. {
  2583. this->Parts[part].SubmitFiles.push_back(name);
  2584. }
  2585. //----------------------------------------------------------------------
  2586. void cmCTest::AddCTestConfigurationOverwrite(const std::string& overStr)
  2587. {
  2588. size_t epos = overStr.find("=");
  2589. if ( epos == overStr.npos )
  2590. {
  2591. cmCTestLog(this, ERROR_MESSAGE,
  2592. "CTest configuration overwrite specified in the wrong format."
  2593. << std::endl
  2594. << "Valid format is: --overwrite key=value" << std::endl
  2595. << "The specified was: --overwrite " << overStr << std::endl);
  2596. return;
  2597. }
  2598. std::string key = overStr.substr(0, epos);
  2599. std::string value = overStr.substr(epos+1, overStr.npos);
  2600. this->CTestConfigurationOverwrites[key] = value;
  2601. }
  2602. //----------------------------------------------------------------------
  2603. void cmCTest::SetConfigType(const char* ct)
  2604. {
  2605. this->ConfigType = ct?ct:"";
  2606. cmSystemTools::ReplaceString(this->ConfigType, ".\\", "");
  2607. std::string confTypeEnv
  2608. = "CMAKE_CONFIG_TYPE=" + this->ConfigType;
  2609. cmSystemTools::PutEnv(confTypeEnv);
  2610. }
  2611. //----------------------------------------------------------------------
  2612. bool cmCTest::SetCTestConfigurationFromCMakeVariable(cmMakefile* mf,
  2613. const char* dconfig, const std::string& cmake_var)
  2614. {
  2615. const char* ctvar;
  2616. ctvar = mf->GetDefinition(cmake_var);
  2617. if ( !ctvar )
  2618. {
  2619. return false;
  2620. }
  2621. cmCTestLog(this, HANDLER_VERBOSE_OUTPUT,
  2622. "SetCTestConfigurationFromCMakeVariable:"
  2623. << dconfig << ":" << cmake_var << std::endl);
  2624. this->SetCTestConfiguration(dconfig, ctvar);
  2625. return true;
  2626. }
  2627. bool cmCTest::RunCommand(
  2628. const char* command,
  2629. std::string* stdOut,
  2630. std::string* stdErr,
  2631. int *retVal,
  2632. const char* dir,
  2633. double timeout)
  2634. {
  2635. std::vector<std::string> args = cmSystemTools::ParseArguments(command);
  2636. if(args.size() < 1)
  2637. {
  2638. return false;
  2639. }
  2640. std::vector<const char*> argv;
  2641. for(std::vector<std::string>::const_iterator a = args.begin();
  2642. a != args.end(); ++a)
  2643. {
  2644. argv.push_back(a->c_str());
  2645. }
  2646. argv.push_back(0);
  2647. *stdOut = "";
  2648. *stdErr = "";
  2649. cmsysProcess* cp = cmsysProcess_New();
  2650. cmsysProcess_SetCommand(cp, &*argv.begin());
  2651. cmsysProcess_SetWorkingDirectory(cp, dir);
  2652. if(cmSystemTools::GetRunCommandHideConsole())
  2653. {
  2654. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  2655. }
  2656. cmsysProcess_SetTimeout(cp, timeout);
  2657. cmsysProcess_Execute(cp);
  2658. std::vector<char> tempOutput;
  2659. std::vector<char> tempError;
  2660. char* data;
  2661. int length;
  2662. int res;
  2663. bool done = false;
  2664. while(!done)
  2665. {
  2666. res = cmsysProcess_WaitForData(cp, &data, &length, 0);
  2667. switch ( res )
  2668. {
  2669. case cmsysProcess_Pipe_STDOUT:
  2670. tempOutput.insert(tempOutput.end(), data, data+length);
  2671. break;
  2672. case cmsysProcess_Pipe_STDERR:
  2673. tempError.insert(tempError.end(), data, data+length);
  2674. break;
  2675. default:
  2676. done = true;
  2677. }
  2678. if ( (res == cmsysProcess_Pipe_STDOUT ||
  2679. res == cmsysProcess_Pipe_STDERR) && this->ExtraVerbose )
  2680. {
  2681. cmSystemTools::Stdout(data, length);
  2682. }
  2683. }
  2684. cmsysProcess_WaitForExit(cp, 0);
  2685. if ( tempOutput.size() > 0 )
  2686. {
  2687. stdOut->append(&*tempOutput.begin(), tempOutput.size());
  2688. }
  2689. if ( tempError.size() > 0 )
  2690. {
  2691. stdErr->append(&*tempError.begin(), tempError.size());
  2692. }
  2693. bool result = true;
  2694. if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
  2695. {
  2696. if ( retVal )
  2697. {
  2698. *retVal = cmsysProcess_GetExitValue(cp);
  2699. }
  2700. else
  2701. {
  2702. if ( cmsysProcess_GetExitValue(cp) != 0 )
  2703. {
  2704. result = false;
  2705. }
  2706. }
  2707. }
  2708. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exception)
  2709. {
  2710. const char* exception_str = cmsysProcess_GetExceptionString(cp);
  2711. cmCTestLog(this, ERROR_MESSAGE, exception_str << std::endl);
  2712. stdErr->append(exception_str, strlen(exception_str));
  2713. result = false;
  2714. }
  2715. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
  2716. {
  2717. const char* error_str = cmsysProcess_GetErrorString(cp);
  2718. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2719. stdErr->append(error_str, strlen(error_str));
  2720. result = false;
  2721. }
  2722. else if(cmsysProcess_GetState(cp) == cmsysProcess_State_Expired)
  2723. {
  2724. const char* error_str = "Process terminated due to timeout\n";
  2725. cmCTestLog(this, ERROR_MESSAGE, error_str << std::endl);
  2726. stdErr->append(error_str, strlen(error_str));
  2727. result = false;
  2728. }
  2729. cmsysProcess_Delete(cp);
  2730. return result;
  2731. }
  2732. //----------------------------------------------------------------------
  2733. void cmCTest::SetOutputLogFileName(const char* name)
  2734. {
  2735. if ( this->OutputLogFile)
  2736. {
  2737. delete this->OutputLogFile;
  2738. this->OutputLogFile= 0;
  2739. }
  2740. if ( name )
  2741. {
  2742. this->OutputLogFile = new cmGeneratedFileStream(name);
  2743. }
  2744. }
  2745. //----------------------------------------------------------------------
  2746. static const char* cmCTestStringLogType[] =
  2747. {
  2748. "DEBUG",
  2749. "OUTPUT",
  2750. "HANDLER_OUTPUT",
  2751. "HANDLER_VERBOSE_OUTPUT",
  2752. "WARNING",
  2753. "ERROR_MESSAGE",
  2754. 0
  2755. };
  2756. //----------------------------------------------------------------------
  2757. #ifdef cerr
  2758. # undef cerr
  2759. #endif
  2760. #ifdef cout
  2761. # undef cout
  2762. #endif
  2763. #define cmCTestLogOutputFileLine(stream) \
  2764. if ( this->ShowLineNumbers ) \
  2765. { \
  2766. (stream) << std::endl << file << ":" << line << " "; \
  2767. }
  2768. void cmCTest::InitStreams()
  2769. {
  2770. // By default we write output to the process output streams.
  2771. this->StreamOut = &std::cout;
  2772. this->StreamErr = &std::cerr;
  2773. }
  2774. void cmCTest::Log(int logType, const char* file, int line, const char* msg)
  2775. {
  2776. if ( !msg || !*msg )
  2777. {
  2778. return;
  2779. }
  2780. if ( this->OutputLogFile )
  2781. {
  2782. bool display = true;
  2783. if ( logType == cmCTest::DEBUG && !this->Debug ) { display = false; }
  2784. if ( logType == cmCTest::HANDLER_VERBOSE_OUTPUT && !this->Debug &&
  2785. !this->ExtraVerbose ) { display = false; }
  2786. if ( display )
  2787. {
  2788. cmCTestLogOutputFileLine(*this->OutputLogFile);
  2789. if ( logType != this->OutputLogFileLastTag )
  2790. {
  2791. *this->OutputLogFile << "[";
  2792. if ( logType >= OTHER || logType < 0 )
  2793. {
  2794. *this->OutputLogFile << "OTHER";
  2795. }
  2796. else
  2797. {
  2798. *this->OutputLogFile << cmCTestStringLogType[logType];
  2799. }
  2800. *this->OutputLogFile << "] " << std::endl << std::flush;
  2801. }
  2802. *this->OutputLogFile << msg << std::flush;
  2803. if ( logType != this->OutputLogFileLastTag )
  2804. {
  2805. *this->OutputLogFile << std::endl << std::flush;
  2806. this->OutputLogFileLastTag = logType;
  2807. }
  2808. }
  2809. }
  2810. if ( !this->Quiet )
  2811. {
  2812. std::ostream& out = *this->StreamOut;
  2813. std::ostream& err = *this->StreamErr;
  2814. switch ( logType )
  2815. {
  2816. case DEBUG:
  2817. if ( this->Debug )
  2818. {
  2819. cmCTestLogOutputFileLine(out);
  2820. out << msg;
  2821. out.flush();
  2822. }
  2823. break;
  2824. case OUTPUT: case HANDLER_OUTPUT:
  2825. if ( this->Debug || this->Verbose )
  2826. {
  2827. cmCTestLogOutputFileLine(out);
  2828. out << msg;
  2829. out.flush();
  2830. }
  2831. break;
  2832. case HANDLER_VERBOSE_OUTPUT:
  2833. if ( this->Debug || this->ExtraVerbose )
  2834. {
  2835. cmCTestLogOutputFileLine(out);
  2836. out << msg;
  2837. out.flush();
  2838. }
  2839. break;
  2840. case WARNING:
  2841. cmCTestLogOutputFileLine(err);
  2842. err << msg;
  2843. err.flush();
  2844. break;
  2845. case ERROR_MESSAGE:
  2846. cmCTestLogOutputFileLine(err);
  2847. err << msg;
  2848. err.flush();
  2849. cmSystemTools::SetErrorOccured();
  2850. break;
  2851. default:
  2852. cmCTestLogOutputFileLine(out);
  2853. out << msg;
  2854. out.flush();
  2855. }
  2856. }
  2857. }
  2858. //-------------------------------------------------------------------------
  2859. double cmCTest::GetRemainingTimeAllowed()
  2860. {
  2861. if (!this->GetHandler("script"))
  2862. {
  2863. return 1.0e7;
  2864. }
  2865. cmCTestScriptHandler* ch
  2866. = static_cast<cmCTestScriptHandler*>(this->GetHandler("script"));
  2867. return ch->GetRemainingTimeAllowed();
  2868. }
  2869. //----------------------------------------------------------------------
  2870. void cmCTest::OutputTestErrors(std::vector<char> const &process_output)
  2871. {
  2872. std::string test_outputs("\n*** Test Failed:\n");
  2873. if(process_output.size())
  2874. {
  2875. test_outputs.append(&*process_output.begin(), process_output.size());
  2876. }
  2877. cmCTestLog(this, HANDLER_OUTPUT, test_outputs << std::endl << std::flush);
  2878. }
  2879. //----------------------------------------------------------------------
  2880. bool cmCTest::CompressString(std::string& str)
  2881. {
  2882. int ret;
  2883. z_stream strm;
  2884. unsigned char* in = reinterpret_cast<unsigned char*>(
  2885. const_cast<char*>(str.c_str()));
  2886. //zlib makes the guarantee that this is the maximum output size
  2887. int outSize = static_cast<int>(
  2888. static_cast<double>(str.size()) * 1.001 + 13.0);
  2889. unsigned char* out = new unsigned char[outSize];
  2890. strm.zalloc = Z_NULL;
  2891. strm.zfree = Z_NULL;
  2892. strm.opaque = Z_NULL;
  2893. ret = deflateInit(&strm, -1); //default compression level
  2894. if (ret != Z_OK)
  2895. {
  2896. delete[] out;
  2897. return false;
  2898. }
  2899. strm.avail_in = static_cast<uInt>(str.size());
  2900. strm.next_in = in;
  2901. strm.avail_out = outSize;
  2902. strm.next_out = out;
  2903. ret = deflate(&strm, Z_FINISH);
  2904. if(ret == Z_STREAM_ERROR || ret != Z_STREAM_END)
  2905. {
  2906. cmCTestLog(this, ERROR_MESSAGE, "Error during gzip compression."
  2907. << std::endl);
  2908. delete[] out;
  2909. return false;
  2910. }
  2911. (void)deflateEnd(&strm);
  2912. // Now base64 encode the resulting binary string
  2913. unsigned char* base64EncodedBuffer
  2914. = new unsigned char[(outSize * 3) / 2];
  2915. size_t rlen
  2916. = cmsysBase64_Encode(out, strm.total_out, base64EncodedBuffer, 1);
  2917. str = "";
  2918. str.append(reinterpret_cast<char*>(base64EncodedBuffer), rlen);
  2919. delete [] base64EncodedBuffer;
  2920. delete [] out;
  2921. return true;
  2922. }