cmCTest.cxx 91 KB

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