cmCTest.cxx 91 KB

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