cmCTest.cxx 92 KB

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