cmCTestSubmitHandler.cxx 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCTestSubmitHandler.h"
  4. #include "cm_curl.h"
  5. #include "cm_jsoncpp_reader.h"
  6. #include "cm_jsoncpp_value.h"
  7. #include "cmsys/Process.h"
  8. #include <chrono>
  9. #include <sstream>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "cmCTest.h"
  13. #include "cmCTestCurl.h"
  14. #include "cmCTestScriptHandler.h"
  15. #include "cmCryptoHash.h"
  16. #include "cmCurl.h"
  17. #include "cmGeneratedFileStream.h"
  18. #include "cmProcessOutput.h"
  19. #include "cmState.h"
  20. #include "cmSystemTools.h"
  21. #include "cmThirdParty.h"
  22. #include "cmWorkingDirectory.h"
  23. #include "cmXMLParser.h"
  24. #include "cmake.h"
  25. #if defined(CTEST_USE_XMLRPC)
  26. #include "cmVersion.h"
  27. #include "cm_sys_stat.h"
  28. #include "cm_xmlrpc.h"
  29. #endif
  30. #define SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT 120
  31. typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
  32. class cmCTestSubmitHandler::ResponseParser : public cmXMLParser
  33. {
  34. public:
  35. ResponseParser() { this->Status = STATUS_OK; }
  36. ~ResponseParser() override {}
  37. public:
  38. enum StatusType
  39. {
  40. STATUS_OK,
  41. STATUS_WARNING,
  42. STATUS_ERROR
  43. };
  44. StatusType Status;
  45. std::string Filename;
  46. std::string MD5;
  47. std::string Message;
  48. private:
  49. std::vector<char> CurrentValue;
  50. std::string GetCurrentValue()
  51. {
  52. std::string val;
  53. if (!this->CurrentValue.empty()) {
  54. val.assign(&this->CurrentValue[0], this->CurrentValue.size());
  55. }
  56. return val;
  57. }
  58. void StartElement(const std::string& /*name*/,
  59. const char** /*atts*/) override
  60. {
  61. this->CurrentValue.clear();
  62. }
  63. void CharacterDataHandler(const char* data, int length) override
  64. {
  65. this->CurrentValue.insert(this->CurrentValue.end(), data, data + length);
  66. }
  67. void EndElement(const std::string& name) override
  68. {
  69. if (name == "status") {
  70. std::string status = cmSystemTools::UpperCase(this->GetCurrentValue());
  71. if (status == "OK" || status == "SUCCESS") {
  72. this->Status = STATUS_OK;
  73. } else if (status == "WARNING") {
  74. this->Status = STATUS_WARNING;
  75. } else {
  76. this->Status = STATUS_ERROR;
  77. }
  78. } else if (name == "filename") {
  79. this->Filename = this->GetCurrentValue();
  80. } else if (name == "md5") {
  81. this->MD5 = this->GetCurrentValue();
  82. } else if (name == "message") {
  83. this->Message = this->GetCurrentValue();
  84. }
  85. }
  86. };
  87. static size_t cmCTestSubmitHandlerWriteMemoryCallback(void* ptr, size_t size,
  88. size_t nmemb, void* data)
  89. {
  90. int realsize = static_cast<int>(size * nmemb);
  91. cmCTestSubmitHandlerVectorOfChar* vec =
  92. static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
  93. const char* chPtr = static_cast<char*>(ptr);
  94. vec->insert(vec->end(), chPtr, chPtr + realsize);
  95. return realsize;
  96. }
  97. static size_t cmCTestSubmitHandlerCurlDebugCallback(CURL* /*unused*/,
  98. curl_infotype /*unused*/,
  99. char* chPtr, size_t size,
  100. void* data)
  101. {
  102. cmCTestSubmitHandlerVectorOfChar* vec =
  103. static_cast<cmCTestSubmitHandlerVectorOfChar*>(data);
  104. vec->insert(vec->end(), chPtr, chPtr + size);
  105. return size;
  106. }
  107. cmCTestSubmitHandler::cmCTestSubmitHandler()
  108. : HTTPProxy()
  109. , FTPProxy()
  110. {
  111. this->Initialize();
  112. }
  113. void cmCTestSubmitHandler::Initialize()
  114. {
  115. // We submit all available parts by default.
  116. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  117. p = cmCTest::Part(p + 1)) {
  118. this->SubmitPart[p] = true;
  119. }
  120. this->CDash = false;
  121. this->HasWarnings = false;
  122. this->HasErrors = false;
  123. this->Superclass::Initialize();
  124. this->HTTPProxy.clear();
  125. this->HTTPProxyType = 0;
  126. this->HTTPProxyAuth.clear();
  127. this->FTPProxy.clear();
  128. this->FTPProxyType = 0;
  129. this->LogFile = nullptr;
  130. this->Files.clear();
  131. }
  132. bool cmCTestSubmitHandler::SubmitUsingFTP(const std::string& localprefix,
  133. const std::set<std::string>& files,
  134. const std::string& remoteprefix,
  135. const std::string& url)
  136. {
  137. CURL* curl;
  138. CURLcode res;
  139. FILE* ftpfile;
  140. char error_buffer[1024];
  141. /* In windows, this will init the winsock stuff */
  142. ::curl_global_init(CURL_GLOBAL_ALL);
  143. for (std::string const& file : files) {
  144. /* get a curl handle */
  145. curl = curl_easy_init();
  146. if (curl) {
  147. // Using proxy
  148. if (this->FTPProxyType > 0) {
  149. curl_easy_setopt(curl, CURLOPT_PROXY, this->FTPProxy.c_str());
  150. switch (this->FTPProxyType) {
  151. case 2:
  152. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  153. break;
  154. case 3:
  155. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  156. break;
  157. default:
  158. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  159. }
  160. }
  161. // enable uploading
  162. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  163. // if there is little to no activity for too long stop submitting
  164. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
  165. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
  166. SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  167. ::curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  168. std::string local_file = file;
  169. if (!cmSystemTools::FileExists(local_file.c_str())) {
  170. local_file = localprefix + "/" + file;
  171. }
  172. std::string upload_as =
  173. url + "/" + remoteprefix + cmSystemTools::GetFilenameName(file);
  174. if (!cmSystemTools::FileExists(local_file.c_str())) {
  175. cmCTestLog(this->CTest, ERROR_MESSAGE,
  176. " Cannot find file: " << local_file << std::endl);
  177. ::curl_easy_cleanup(curl);
  178. ::curl_global_cleanup();
  179. return false;
  180. }
  181. unsigned long filelen = cmSystemTools::FileLength(local_file);
  182. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  183. *this->LogFile << "\tUpload file: " << local_file << " to " << upload_as
  184. << std::endl;
  185. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  186. " Upload file: " << local_file << " to "
  187. << upload_as << std::endl,
  188. this->Quiet);
  189. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  190. // specify target
  191. ::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
  192. // now specify which file to upload
  193. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  194. // and give the size of the upload (optional)
  195. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(filelen));
  196. // and give curl the buffer for errors
  197. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  198. // specify handler for output
  199. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  200. cmCTestSubmitHandlerWriteMemoryCallback);
  201. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  202. cmCTestSubmitHandlerCurlDebugCallback);
  203. /* we pass our 'chunk' struct to the callback function */
  204. cmCTestSubmitHandlerVectorOfChar chunk;
  205. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  206. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  207. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  208. // Now run off and do what you've been told!
  209. res = ::curl_easy_perform(curl);
  210. if (!chunk.empty()) {
  211. cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: ["
  212. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  213. << "]" << std::endl,
  214. this->Quiet);
  215. }
  216. if (!chunkDebug.empty()) {
  217. cmCTestOptionalLog(
  218. this->CTest, DEBUG, "CURL debug output: ["
  219. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  220. << std::endl,
  221. this->Quiet);
  222. }
  223. fclose(ftpfile);
  224. if (res) {
  225. cmCTestLog(this->CTest, ERROR_MESSAGE, " Error when uploading file: "
  226. << local_file << std::endl);
  227. cmCTestLog(this->CTest, ERROR_MESSAGE,
  228. " Error message was: " << error_buffer << std::endl);
  229. *this->LogFile << " Error when uploading file: " << local_file
  230. << std::endl
  231. << " Error message was: " << error_buffer << std::endl
  232. << " Curl output was: ";
  233. // avoid dereference of empty vector
  234. if (!chunk.empty()) {
  235. *this->LogFile << cmCTestLogWrite(&*chunk.begin(), chunk.size());
  236. cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
  237. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  238. << std::endl);
  239. }
  240. *this->LogFile << std::endl;
  241. ::curl_easy_cleanup(curl);
  242. ::curl_global_cleanup();
  243. return false;
  244. }
  245. // always cleanup
  246. ::curl_easy_cleanup(curl);
  247. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  248. " Uploaded: " + local_file << std::endl,
  249. this->Quiet);
  250. }
  251. }
  252. ::curl_global_cleanup();
  253. return true;
  254. }
  255. // Uploading files is simpler
  256. bool cmCTestSubmitHandler::SubmitUsingHTTP(const std::string& localprefix,
  257. const std::set<std::string>& files,
  258. const std::string& remoteprefix,
  259. const std::string& url)
  260. {
  261. CURL* curl;
  262. CURLcode res;
  263. FILE* ftpfile;
  264. char error_buffer[1024];
  265. // Set Content-Type to satisfy fussy modsecurity rules.
  266. struct curl_slist* headers =
  267. ::curl_slist_append(nullptr, "Content-Type: text/xml");
  268. // Add any additional headers that the user specified.
  269. for (std::string const& h : this->HttpHeaders) {
  270. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  271. " Add HTTP Header: \"" << h << "\"" << std::endl,
  272. this->Quiet);
  273. headers = ::curl_slist_append(headers, h.c_str());
  274. }
  275. /* In windows, this will init the winsock stuff */
  276. ::curl_global_init(CURL_GLOBAL_ALL);
  277. std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
  278. std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
  279. std::vector<std::string> args;
  280. cmSystemTools::ExpandListArgument(curlopt, args);
  281. bool verifyPeerOff = false;
  282. bool verifyHostOff = false;
  283. for (std::string const& arg : args) {
  284. if (arg == "CURLOPT_SSL_VERIFYPEER_OFF") {
  285. verifyPeerOff = true;
  286. }
  287. if (arg == "CURLOPT_SSL_VERIFYHOST_OFF") {
  288. verifyHostOff = true;
  289. }
  290. }
  291. for (std::string const& file : files) {
  292. /* get a curl handle */
  293. curl = curl_easy_init();
  294. if (curl) {
  295. cmCurlSetCAInfo(curl);
  296. if (verifyPeerOff) {
  297. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  298. " Set CURLOPT_SSL_VERIFYPEER to off\n",
  299. this->Quiet);
  300. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
  301. }
  302. if (verifyHostOff) {
  303. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  304. " Set CURLOPT_SSL_VERIFYHOST to off\n",
  305. this->Quiet);
  306. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
  307. }
  308. // Using proxy
  309. if (this->HTTPProxyType > 0) {
  310. curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
  311. switch (this->HTTPProxyType) {
  312. case 2:
  313. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  314. break;
  315. case 3:
  316. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  317. break;
  318. default:
  319. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  320. if (!this->HTTPProxyAuth.empty()) {
  321. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  322. this->HTTPProxyAuth.c_str());
  323. }
  324. }
  325. }
  326. if (this->CTest->ShouldUseHTTP10()) {
  327. curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  328. }
  329. // enable HTTP ERROR parsing
  330. curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
  331. /* enable uploading */
  332. curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
  333. // if there is little to no activity for too long stop submitting
  334. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
  335. ::curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME,
  336. SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  337. /* HTTP PUT please */
  338. ::curl_easy_setopt(curl, CURLOPT_PUT, 1);
  339. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  340. ::curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  341. std::string local_file = file;
  342. if (!cmSystemTools::FileExists(local_file.c_str())) {
  343. local_file = localprefix + "/" + file;
  344. }
  345. std::string remote_file =
  346. remoteprefix + cmSystemTools::GetFilenameName(file);
  347. *this->LogFile << "\tUpload file: " << local_file << " to "
  348. << remote_file << std::endl;
  349. std::string ofile;
  350. for (char c : remote_file) {
  351. char hexCh[4] = { 0, 0, 0, 0 };
  352. hexCh[0] = c;
  353. switch (c) {
  354. case '+':
  355. case '?':
  356. case '/':
  357. case '\\':
  358. case '&':
  359. case ' ':
  360. case '=':
  361. case '%':
  362. sprintf(hexCh, "%%%02X", static_cast<int>(c));
  363. ofile.append(hexCh);
  364. break;
  365. default:
  366. ofile.append(hexCh);
  367. }
  368. }
  369. std::string upload_as = url +
  370. ((url.find('?') == std::string::npos) ? '?' : '&') + "FileName=" +
  371. ofile;
  372. upload_as += "&MD5=";
  373. if (cmSystemTools::IsOn(this->GetOption("InternalTest"))) {
  374. upload_as += "bad_md5sum";
  375. } else {
  376. upload_as +=
  377. cmSystemTools::ComputeFileHash(local_file, cmCryptoHash::AlgoMD5);
  378. }
  379. if (!cmSystemTools::FileExists(local_file.c_str())) {
  380. cmCTestLog(this->CTest, ERROR_MESSAGE,
  381. " Cannot find file: " << local_file << std::endl);
  382. ::curl_easy_cleanup(curl);
  383. ::curl_slist_free_all(headers);
  384. ::curl_global_cleanup();
  385. return false;
  386. }
  387. unsigned long filelen = cmSystemTools::FileLength(local_file);
  388. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  389. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  390. " Upload file: " << local_file << " to "
  391. << upload_as << " Size: "
  392. << filelen << std::endl,
  393. this->Quiet);
  394. // specify target
  395. ::curl_easy_setopt(curl, CURLOPT_URL, upload_as.c_str());
  396. // now specify which file to upload
  397. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  398. // and give the size of the upload (optional)
  399. ::curl_easy_setopt(curl, CURLOPT_INFILESIZE, static_cast<long>(filelen));
  400. // and give curl the buffer for errors
  401. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  402. // specify handler for output
  403. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  404. cmCTestSubmitHandlerWriteMemoryCallback);
  405. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  406. cmCTestSubmitHandlerCurlDebugCallback);
  407. /* we pass our 'chunk' struct to the callback function */
  408. cmCTestSubmitHandlerVectorOfChar chunk;
  409. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  410. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  411. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  412. // Now run off and do what you've been told!
  413. res = ::curl_easy_perform(curl);
  414. if (!chunk.empty()) {
  415. cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: ["
  416. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  417. << "]" << std::endl,
  418. this->Quiet);
  419. this->ParseResponse(chunk);
  420. }
  421. if (!chunkDebug.empty()) {
  422. cmCTestOptionalLog(
  423. this->CTest, DEBUG, "CURL debug output: ["
  424. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  425. << std::endl,
  426. this->Quiet);
  427. }
  428. // If curl failed for any reason, or checksum fails, wait and retry
  429. //
  430. if (res != CURLE_OK || this->HasErrors) {
  431. std::string retryDelay = this->GetOption("RetryDelay") == nullptr
  432. ? ""
  433. : this->GetOption("RetryDelay");
  434. std::string retryCount = this->GetOption("RetryCount") == nullptr
  435. ? ""
  436. : this->GetOption("RetryCount");
  437. auto delay = std::chrono::duration<double>(
  438. retryDelay.empty()
  439. ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryDelay")
  440. .c_str())
  441. : atoi(retryDelay.c_str()));
  442. int count = retryCount.empty()
  443. ? atoi(this->CTest->GetCTestConfiguration("CTestSubmitRetryCount")
  444. .c_str())
  445. : atoi(retryCount.c_str());
  446. for (int i = 0; i < count; i++) {
  447. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  448. " Submit failed, waiting " << delay.count()
  449. << " seconds...\n",
  450. this->Quiet);
  451. auto stop = std::chrono::steady_clock::now() + delay;
  452. while (std::chrono::steady_clock::now() < stop) {
  453. cmSystemTools::Delay(100);
  454. }
  455. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  456. " Retry submission: Attempt "
  457. << (i + 1) << " of " << count << std::endl,
  458. this->Quiet);
  459. ::fclose(ftpfile);
  460. ftpfile = cmsys::SystemTools::Fopen(local_file, "rb");
  461. ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
  462. chunk.clear();
  463. chunkDebug.clear();
  464. this->HasErrors = false;
  465. res = ::curl_easy_perform(curl);
  466. if (!chunk.empty()) {
  467. cmCTestOptionalLog(
  468. this->CTest, DEBUG, "CURL output: ["
  469. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  470. << std::endl,
  471. this->Quiet);
  472. this->ParseResponse(chunk);
  473. }
  474. if (res == CURLE_OK && !this->HasErrors) {
  475. break;
  476. }
  477. }
  478. }
  479. fclose(ftpfile);
  480. if (res) {
  481. cmCTestLog(this->CTest, ERROR_MESSAGE, " Error when uploading file: "
  482. << local_file << std::endl);
  483. cmCTestLog(this->CTest, ERROR_MESSAGE,
  484. " Error message was: " << error_buffer << std::endl);
  485. *this->LogFile << " Error when uploading file: " << local_file
  486. << std::endl
  487. << " Error message was: " << error_buffer
  488. << std::endl;
  489. // avoid deref of begin for zero size array
  490. if (!chunk.empty()) {
  491. *this->LogFile << " Curl output was: "
  492. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  493. << std::endl;
  494. cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
  495. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  496. << std::endl);
  497. }
  498. ::curl_easy_cleanup(curl);
  499. ::curl_slist_free_all(headers);
  500. ::curl_global_cleanup();
  501. return false;
  502. }
  503. // always cleanup
  504. ::curl_easy_cleanup(curl);
  505. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  506. " Uploaded: " + local_file << std::endl,
  507. this->Quiet);
  508. }
  509. }
  510. ::curl_slist_free_all(headers);
  511. ::curl_global_cleanup();
  512. return true;
  513. }
  514. void cmCTestSubmitHandler::ParseResponse(
  515. cmCTestSubmitHandlerVectorOfChar chunk)
  516. {
  517. std::string output;
  518. output.append(chunk.begin(), chunk.end());
  519. if (output.find("<cdash") != std::string::npos) {
  520. ResponseParser parser;
  521. parser.Parse(output.c_str());
  522. if (parser.Status != ResponseParser::STATUS_OK) {
  523. this->HasErrors = true;
  524. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  525. " Submission failed: " << parser.Message << std::endl);
  526. return;
  527. }
  528. }
  529. output = cmSystemTools::UpperCase(output);
  530. if (output.find("WARNING") != std::string::npos) {
  531. this->HasWarnings = true;
  532. }
  533. if (output.find("ERROR") != std::string::npos) {
  534. this->HasErrors = true;
  535. }
  536. if (this->HasWarnings || this->HasErrors) {
  537. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Server Response:\n"
  538. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
  539. }
  540. }
  541. bool cmCTestSubmitHandler::TriggerUsingHTTP(const std::set<std::string>& files,
  542. const std::string& remoteprefix,
  543. const std::string& url)
  544. {
  545. CURL* curl;
  546. char error_buffer[1024];
  547. /* In windows, this will init the winsock stuff */
  548. ::curl_global_init(CURL_GLOBAL_ALL);
  549. for (std::string const& file : files) {
  550. /* get a curl handle */
  551. curl = curl_easy_init();
  552. if (curl) {
  553. // Using proxy
  554. if (this->HTTPProxyType > 0) {
  555. curl_easy_setopt(curl, CURLOPT_PROXY, this->HTTPProxy.c_str());
  556. switch (this->HTTPProxyType) {
  557. case 2:
  558. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  559. break;
  560. case 3:
  561. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  562. break;
  563. default:
  564. curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  565. if (!this->HTTPProxyAuth.empty()) {
  566. curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD,
  567. this->HTTPProxyAuth.c_str());
  568. }
  569. }
  570. }
  571. ::curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  572. // and give curl the buffer for errors
  573. ::curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, &error_buffer);
  574. // specify handler for output
  575. ::curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
  576. cmCTestSubmitHandlerWriteMemoryCallback);
  577. ::curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
  578. cmCTestSubmitHandlerCurlDebugCallback);
  579. /* we pass our 'chunk' struct to the callback function */
  580. cmCTestSubmitHandlerVectorOfChar chunk;
  581. cmCTestSubmitHandlerVectorOfChar chunkDebug;
  582. ::curl_easy_setopt(curl, CURLOPT_FILE, &chunk);
  583. ::curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &chunkDebug);
  584. std::string rfile = remoteprefix + cmSystemTools::GetFilenameName(file);
  585. std::string ofile;
  586. for (char c : rfile) {
  587. char hexCh[4] = { 0, 0, 0, 0 };
  588. hexCh[0] = c;
  589. switch (c) {
  590. case '+':
  591. case '?':
  592. case '/':
  593. case '\\':
  594. case '&':
  595. case ' ':
  596. case '=':
  597. case '%':
  598. sprintf(hexCh, "%%%02X", static_cast<int>(c));
  599. ofile.append(hexCh);
  600. break;
  601. default:
  602. ofile.append(hexCh);
  603. }
  604. }
  605. std::string turl = url +
  606. ((url.find('?') == std::string::npos) ? '?' : '&') + "xmlfile=" +
  607. ofile;
  608. *this->LogFile << "Trigger url: " << turl << std::endl;
  609. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  610. " Trigger url: " << turl << std::endl, this->Quiet);
  611. curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  612. curl_easy_setopt(curl, CURLOPT_URL, turl.c_str());
  613. if (curl_easy_perform(curl)) {
  614. cmCTestLog(this->CTest, ERROR_MESSAGE,
  615. " Error when triggering: " << turl << std::endl);
  616. cmCTestLog(this->CTest, ERROR_MESSAGE,
  617. " Error message was: " << error_buffer << std::endl);
  618. *this->LogFile << "\tTriggering failed with error: " << error_buffer
  619. << std::endl
  620. << " Error message was: " << error_buffer
  621. << std::endl;
  622. if (!chunk.empty()) {
  623. *this->LogFile << " Curl output was: "
  624. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  625. << std::endl;
  626. cmCTestLog(this->CTest, ERROR_MESSAGE, "CURL output: ["
  627. << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
  628. << std::endl);
  629. }
  630. ::curl_easy_cleanup(curl);
  631. ::curl_global_cleanup();
  632. return false;
  633. }
  634. if (!chunk.empty()) {
  635. cmCTestOptionalLog(this->CTest, DEBUG, "CURL output: ["
  636. << cmCTestLogWrite(&*chunk.begin(), chunk.size())
  637. << "]" << std::endl,
  638. this->Quiet);
  639. }
  640. if (!chunkDebug.empty()) {
  641. cmCTestOptionalLog(
  642. this->CTest, DEBUG, "CURL debug output: ["
  643. << cmCTestLogWrite(&*chunkDebug.begin(), chunkDebug.size()) << "]"
  644. << std::endl,
  645. this->Quiet);
  646. }
  647. // always cleanup
  648. ::curl_easy_cleanup(curl);
  649. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl,
  650. this->Quiet);
  651. }
  652. }
  653. ::curl_global_cleanup();
  654. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  655. " Dart server triggered..." << std::endl, this->Quiet);
  656. return true;
  657. }
  658. bool cmCTestSubmitHandler::SubmitUsingSCP(const std::string& scp_command,
  659. const std::string& localprefix,
  660. const std::set<std::string>& files,
  661. const std::string& remoteprefix,
  662. const std::string& url)
  663. {
  664. if (scp_command.empty() || localprefix.empty() || files.empty() ||
  665. remoteprefix.empty() || url.empty()) {
  666. return false;
  667. }
  668. std::vector<const char*> argv;
  669. argv.push_back(scp_command.c_str()); // Scp command
  670. argv.push_back(scp_command.c_str()); // Dummy string for file
  671. argv.push_back(scp_command.c_str()); // Dummy string for remote url
  672. argv.push_back(nullptr);
  673. cmsysProcess* cp = cmsysProcess_New();
  674. cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
  675. // cmsysProcess_SetTimeout(cp, timeout);
  676. int problems = 0;
  677. for (std::string const& file : files) {
  678. int retVal;
  679. std::string lfname = localprefix;
  680. cmSystemTools::ConvertToUnixSlashes(lfname);
  681. lfname += "/" + file;
  682. lfname = cmSystemTools::ConvertToOutputPath(lfname.c_str());
  683. argv[1] = lfname.c_str();
  684. std::string rfname = url + "/" + remoteprefix + file;
  685. argv[2] = rfname.c_str();
  686. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Execute \""
  687. << argv[0] << "\" \"" << argv[1] << "\" \"" << argv[2]
  688. << "\"" << std::endl,
  689. this->Quiet);
  690. *this->LogFile << "Execute \"" << argv[0] << "\" \"" << argv[1] << "\" \""
  691. << argv[2] << "\"" << std::endl;
  692. cmsysProcess_SetCommand(cp, &*argv.begin());
  693. cmsysProcess_Execute(cp);
  694. char* data;
  695. int length;
  696. cmProcessOutput processOutput;
  697. std::string strdata;
  698. while (cmsysProcess_WaitForData(cp, &data, &length, nullptr)) {
  699. processOutput.DecodeText(data, length, strdata);
  700. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  701. cmCTestLogWrite(strdata.c_str(), strdata.size()),
  702. this->Quiet);
  703. }
  704. processOutput.DecodeText(std::string(), strdata);
  705. if (!strdata.empty()) {
  706. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  707. cmCTestLogWrite(strdata.c_str(), strdata.size()),
  708. this->Quiet);
  709. }
  710. cmsysProcess_WaitForExit(cp, nullptr);
  711. int result = cmsysProcess_GetState(cp);
  712. if (result == cmsysProcess_State_Exited) {
  713. retVal = cmsysProcess_GetExitValue(cp);
  714. if (retVal != 0) {
  715. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  716. "\tSCP returned: " << retVal << std::endl,
  717. this->Quiet);
  718. *this->LogFile << "\tSCP returned: " << retVal << std::endl;
  719. problems++;
  720. }
  721. } else if (result == cmsysProcess_State_Exception) {
  722. retVal = cmsysProcess_GetExitException(cp);
  723. cmCTestLog(this->CTest, ERROR_MESSAGE,
  724. "\tThere was an exception: " << retVal << std::endl);
  725. *this->LogFile << "\tThere was an exception: " << retVal << std::endl;
  726. problems++;
  727. } else if (result == cmsysProcess_State_Expired) {
  728. cmCTestLog(this->CTest, ERROR_MESSAGE, "\tThere was a timeout"
  729. << std::endl);
  730. *this->LogFile << "\tThere was a timeout" << std::endl;
  731. problems++;
  732. } else if (result == cmsysProcess_State_Error) {
  733. cmCTestLog(this->CTest, ERROR_MESSAGE, "\tError executing SCP: "
  734. << cmsysProcess_GetErrorString(cp) << std::endl);
  735. *this->LogFile << "\tError executing SCP: "
  736. << cmsysProcess_GetErrorString(cp) << std::endl;
  737. problems++;
  738. }
  739. }
  740. cmsysProcess_Delete(cp);
  741. return problems == 0;
  742. }
  743. bool cmCTestSubmitHandler::SubmitUsingCP(const std::string& localprefix,
  744. const std::set<std::string>& files,
  745. const std::string& remoteprefix,
  746. const std::string& destination)
  747. {
  748. if (localprefix.empty() || files.empty() || remoteprefix.empty() ||
  749. destination.empty()) {
  750. /* clang-format off */
  751. cmCTestLog(this->CTest, ERROR_MESSAGE,
  752. "Missing arguments for submit via cp:\n"
  753. << "\tlocalprefix: " << localprefix << "\n"
  754. << "\tNumber of files: " << files.size() << "\n"
  755. << "\tremoteprefix: " << remoteprefix << "\n"
  756. << "\tdestination: " << destination << std::endl);
  757. /* clang-format on */
  758. return false;
  759. }
  760. for (std::string const& file : files) {
  761. std::string lfname = localprefix;
  762. cmSystemTools::ConvertToUnixSlashes(lfname);
  763. lfname += "/" + file;
  764. std::string rfname = destination + "/" + remoteprefix + file;
  765. cmSystemTools::CopyFileAlways(lfname, rfname);
  766. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, " Copy file: "
  767. << lfname << " to " << rfname << std::endl,
  768. this->Quiet);
  769. }
  770. std::string tagDoneFile = destination + "/" + remoteprefix + "DONE";
  771. cmSystemTools::Touch(tagDoneFile, true);
  772. return true;
  773. }
  774. #if defined(CTEST_USE_XMLRPC)
  775. bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
  776. const std::string& localprefix, const std::set<std::string>& files,
  777. const std::string& remoteprefix, const std::string& url)
  778. {
  779. xmlrpc_env env;
  780. char ctestString[] = "CTest";
  781. std::string ctestVersionString = cmVersion::GetCMakeVersion();
  782. char* ctestVersion = const_cast<char*>(ctestVersionString.c_str());
  783. std::string realURL = url + "/" + remoteprefix + "/Command/";
  784. /* Start up our XML-RPC client library. */
  785. xmlrpc_client_init(XMLRPC_CLIENT_NO_FLAGS, ctestString, ctestVersion);
  786. /* Initialize our error-handling environment. */
  787. xmlrpc_env_init(&env);
  788. /* Call the famous server at UserLand. */
  789. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, " Submitting to: "
  790. << realURL << " (" << remoteprefix << ")" << std::endl,
  791. this->Quiet);
  792. for (std::string const& file : files) {
  793. xmlrpc_value* result;
  794. std::string local_file = file;
  795. if (!cmSystemTools::FileExists(local_file.c_str())) {
  796. local_file = localprefix + "/" + file;
  797. }
  798. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  799. " Submit file: " << local_file << std::endl,
  800. this->Quiet);
  801. struct stat st;
  802. if (::stat(local_file.c_str(), &st)) {
  803. cmCTestLog(this->CTest, ERROR_MESSAGE,
  804. " Cannot find file: " << local_file << std::endl);
  805. return false;
  806. }
  807. // off_t can be bigger than size_t. fread takes size_t.
  808. // make sure the file is not too big.
  809. if (static_cast<off_t>(static_cast<size_t>(st.st_size)) !=
  810. static_cast<off_t>(st.st_size)) {
  811. cmCTestLog(this->CTest, ERROR_MESSAGE, " File too big: " << local_file
  812. << std::endl);
  813. return false;
  814. }
  815. size_t fileSize = static_cast<size_t>(st.st_size);
  816. FILE* fp = cmsys::SystemTools::Fopen(local_file, "rb");
  817. if (!fp) {
  818. cmCTestLog(this->CTest, ERROR_MESSAGE,
  819. " Cannot open file: " << local_file << std::endl);
  820. return false;
  821. }
  822. unsigned char* fileBuffer = new unsigned char[fileSize];
  823. if (fread(fileBuffer, 1, fileSize, fp) != fileSize) {
  824. delete[] fileBuffer;
  825. fclose(fp);
  826. cmCTestLog(this->CTest, ERROR_MESSAGE,
  827. " Cannot read file: " << local_file << std::endl);
  828. return false;
  829. }
  830. fclose(fp);
  831. char remoteCommand[] = "Submit.put";
  832. char* pRealURL = const_cast<char*>(realURL.c_str());
  833. result =
  834. xmlrpc_client_call(&env, pRealURL, remoteCommand, "(6)", fileBuffer,
  835. static_cast<xmlrpc_int32>(fileSize));
  836. delete[] fileBuffer;
  837. if (env.fault_occurred) {
  838. cmCTestLog(this->CTest, ERROR_MESSAGE, " Submission problem: "
  839. << env.fault_string << " (" << env.fault_code << ")"
  840. << std::endl);
  841. xmlrpc_env_clean(&env);
  842. xmlrpc_client_cleanup();
  843. return false;
  844. }
  845. /* Dispose of our result value. */
  846. xmlrpc_DECREF(result);
  847. }
  848. /* Clean up our error-handling environment. */
  849. xmlrpc_env_clean(&env);
  850. /* Shutdown our XML-RPC client library. */
  851. xmlrpc_client_cleanup();
  852. return true;
  853. }
  854. #else
  855. bool cmCTestSubmitHandler::SubmitUsingXMLRPC(
  856. std::string const& /*unused*/, std::set<std::string> const& /*unused*/,
  857. std::string const& /*unused*/, std::string const& /*unused*/)
  858. {
  859. return false;
  860. }
  861. #endif
  862. void cmCTestSubmitHandler::ConstructCDashURL(std::string& dropMethod,
  863. std::string& url)
  864. {
  865. dropMethod = this->CTest->GetCTestConfiguration("DropMethod");
  866. url = dropMethod;
  867. url += "://";
  868. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  869. url += this->CTest->GetCTestConfiguration("DropSiteUser");
  870. cmCTestOptionalLog(
  871. this->CTest, HANDLER_OUTPUT,
  872. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(), this->Quiet);
  873. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  874. url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
  875. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******", this->Quiet);
  876. }
  877. url += "@";
  878. }
  879. url += this->CTest->GetCTestConfiguration("DropSite") +
  880. this->CTest->GetCTestConfiguration("DropLocation");
  881. }
  882. int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
  883. std::string const& typeString)
  884. {
  885. if (file.empty()) {
  886. cmCTestLog(this->CTest, ERROR_MESSAGE, "Upload file not specified\n");
  887. return -1;
  888. }
  889. if (!cmSystemTools::FileExists(file)) {
  890. cmCTestLog(this->CTest, ERROR_MESSAGE, "Upload file not found: '"
  891. << file << "'\n");
  892. return -1;
  893. }
  894. cmCTestCurl curl(this->CTest);
  895. curl.SetQuiet(this->Quiet);
  896. std::string curlopt(this->CTest->GetCTestConfiguration("CurlOptions"));
  897. std::vector<std::string> args;
  898. cmSystemTools::ExpandListArgument(curlopt, args);
  899. curl.SetCurlOptions(args);
  900. curl.SetTimeOutSeconds(SUBMIT_TIMEOUT_IN_SECONDS_DEFAULT);
  901. curl.SetHttpHeaders(this->HttpHeaders);
  902. std::string dropMethod;
  903. std::string url;
  904. this->ConstructCDashURL(dropMethod, url);
  905. std::string::size_type pos = url.find("submit.php?");
  906. url = url.substr(0, pos + 10);
  907. if (!(dropMethod == "http" || dropMethod == "https")) {
  908. cmCTestLog(this->CTest, ERROR_MESSAGE,
  909. "Only http and https are supported for CDASH_UPLOAD\n");
  910. return -1;
  911. }
  912. bool internalTest = cmSystemTools::IsOn(this->GetOption("InternalTest"));
  913. // Get RETRY_COUNT and RETRY_DELAY values if they were set.
  914. std::string retryDelayString = this->GetOption("RetryDelay") == nullptr
  915. ? ""
  916. : this->GetOption("RetryDelay");
  917. std::string retryCountString = this->GetOption("RetryCount") == nullptr
  918. ? ""
  919. : this->GetOption("RetryCount");
  920. auto retryDelay = std::chrono::seconds(0);
  921. if (!retryDelayString.empty()) {
  922. unsigned long retryDelayValue = 0;
  923. if (!cmSystemTools::StringToULong(retryDelayString.c_str(),
  924. &retryDelayValue)) {
  925. cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
  926. << retryDelayString << std::endl);
  927. } else {
  928. retryDelay = std::chrono::seconds(retryDelayValue);
  929. }
  930. }
  931. unsigned long retryCount = 0;
  932. if (!retryCountString.empty()) {
  933. if (!cmSystemTools::StringToULong(retryCountString.c_str(), &retryCount)) {
  934. cmCTestLog(this->CTest, WARNING, "Invalid value for 'RETRY_DELAY' : "
  935. << retryCountString << std::endl);
  936. }
  937. }
  938. std::string md5sum =
  939. cmSystemTools::ComputeFileHash(file, cmCryptoHash::AlgoMD5);
  940. // 1. request the buildid and check to see if the file
  941. // has already been uploaded
  942. // TODO I added support for subproject. You would need to add
  943. // a "&subproject=subprojectname" to the first POST.
  944. cmCTestScriptHandler* ch =
  945. static_cast<cmCTestScriptHandler*>(this->CTest->GetHandler("script"));
  946. cmake* cm = ch->GetCMake();
  947. const char* subproject = cm->GetState()->GetGlobalProperty("SubProject");
  948. // TODO: Encode values for a URL instead of trusting caller.
  949. std::ostringstream str;
  950. str << "project="
  951. << curl.Escape(this->CTest->GetCTestConfiguration("ProjectName")) << "&";
  952. if (subproject) {
  953. str << "subproject=" << curl.Escape(subproject) << "&";
  954. }
  955. auto timeNow =
  956. std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
  957. str << "stamp=" << curl.Escape(this->CTest->GetCurrentTag()) << "-"
  958. << curl.Escape(this->CTest->GetTestModelString()) << "&"
  959. << "model=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  960. << "build="
  961. << curl.Escape(this->CTest->GetCTestConfiguration("BuildName")) << "&"
  962. << "site=" << curl.Escape(this->CTest->GetCTestConfiguration("Site"))
  963. << "&"
  964. << "track=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  965. << "starttime=" << timeNow << "&"
  966. << "endtime=" << timeNow << "&"
  967. << "datafilesmd5[0]=" << md5sum << "&"
  968. << "type=" << curl.Escape(typeString);
  969. std::string fields = str.str();
  970. cmCTestOptionalLog(this->CTest, DEBUG,
  971. "fields: " << fields << "\nurl:" << url
  972. << "\nfile: " << file << "\n",
  973. this->Quiet);
  974. std::string response;
  975. bool requestSucceeded = curl.HttpRequest(url, fields, response);
  976. if (!internalTest && !requestSucceeded) {
  977. // If request failed, wait and retry.
  978. for (unsigned long i = 0; i < retryCount; i++) {
  979. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  980. " Request failed, waiting " << retryDelay.count()
  981. << " seconds...\n",
  982. this->Quiet);
  983. auto stop = std::chrono::steady_clock::now() + retryDelay;
  984. while (std::chrono::steady_clock::now() < stop) {
  985. cmSystemTools::Delay(100);
  986. }
  987. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  988. " Retry request: Attempt "
  989. << (i + 1) << " of " << retryCount << std::endl,
  990. this->Quiet);
  991. requestSucceeded = curl.HttpRequest(url, fields, response);
  992. if (requestSucceeded) {
  993. break;
  994. }
  995. }
  996. }
  997. if (!internalTest && !requestSucceeded) {
  998. cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in HttpRequest\n"
  999. << response);
  1000. return -1;
  1001. }
  1002. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1003. "Request upload response: [" << response << "]\n",
  1004. this->Quiet);
  1005. Json::Value json;
  1006. Json::Reader reader;
  1007. if (!internalTest && !reader.parse(response, json)) {
  1008. cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string ["
  1009. << response << "]\n"
  1010. << reader.getFormattedErrorMessages() << "\n");
  1011. return -1;
  1012. }
  1013. if (!internalTest && json["status"].asInt() != 0) {
  1014. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1015. "Bad status returned from CDash: " << json["status"].asInt());
  1016. return -1;
  1017. }
  1018. if (!internalTest) {
  1019. if (json["datafilesmd5"].isArray()) {
  1020. int datares = json["datafilesmd5"][0].asInt();
  1021. if (datares == 1) {
  1022. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1023. "File already exists on CDash, skip upload "
  1024. << file << "\n",
  1025. this->Quiet);
  1026. return 0;
  1027. }
  1028. } else {
  1029. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1030. "bad datafilesmd5 value in response " << response << "\n");
  1031. return -1;
  1032. }
  1033. }
  1034. std::string upload_as = cmSystemTools::GetFilenameName(file);
  1035. std::ostringstream fstr;
  1036. fstr << "type=" << curl.Escape(typeString) << "&"
  1037. << "md5=" << md5sum << "&"
  1038. << "filename=" << curl.Escape(upload_as) << "&"
  1039. << "buildid=" << json["buildid"].asString();
  1040. bool uploadSucceeded = false;
  1041. if (!internalTest) {
  1042. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1043. }
  1044. if (!uploadSucceeded) {
  1045. // If upload failed, wait and retry.
  1046. for (unsigned long i = 0; i < retryCount; i++) {
  1047. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1048. " Upload failed, waiting " << retryDelay.count()
  1049. << " seconds...\n",
  1050. this->Quiet);
  1051. auto stop = std::chrono::steady_clock::now() + retryDelay;
  1052. while (std::chrono::steady_clock::now() < stop) {
  1053. cmSystemTools::Delay(100);
  1054. }
  1055. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1056. " Retry upload: Attempt "
  1057. << (i + 1) << " of " << retryCount << std::endl,
  1058. this->Quiet);
  1059. if (!internalTest) {
  1060. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1061. }
  1062. if (uploadSucceeded) {
  1063. break;
  1064. }
  1065. }
  1066. }
  1067. if (!uploadSucceeded) {
  1068. cmCTestLog(this->CTest, ERROR_MESSAGE, "error uploading to CDash. "
  1069. << file << " " << url << " " << fstr.str());
  1070. return -1;
  1071. }
  1072. if (!reader.parse(response, json)) {
  1073. cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string ["
  1074. << response << "]\n"
  1075. << reader.getFormattedErrorMessages() << "\n");
  1076. return -1;
  1077. }
  1078. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1079. "Upload file response: [" << response << "]\n",
  1080. this->Quiet);
  1081. return 0;
  1082. }
  1083. int cmCTestSubmitHandler::ProcessHandler()
  1084. {
  1085. const char* cdashUploadFile = this->GetOption("CDashUploadFile");
  1086. const char* cdashUploadType = this->GetOption("CDashUploadType");
  1087. if (cdashUploadFile && cdashUploadType) {
  1088. return this->HandleCDashUploadFile(cdashUploadFile, cdashUploadType);
  1089. }
  1090. std::string iscdash = this->CTest->GetCTestConfiguration("IsCDash");
  1091. // cdash does not need to trigger so just return true
  1092. if (!iscdash.empty()) {
  1093. this->CDash = true;
  1094. }
  1095. const std::string& buildDirectory =
  1096. this->CTest->GetCTestConfiguration("BuildDirectory");
  1097. if (buildDirectory.empty()) {
  1098. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1099. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  1100. << std::endl);
  1101. return -1;
  1102. }
  1103. if (getenv("HTTP_PROXY")) {
  1104. this->HTTPProxyType = 1;
  1105. this->HTTPProxy = getenv("HTTP_PROXY");
  1106. if (getenv("HTTP_PROXY_PORT")) {
  1107. this->HTTPProxy += ":";
  1108. this->HTTPProxy += getenv("HTTP_PROXY_PORT");
  1109. }
  1110. if (getenv("HTTP_PROXY_TYPE")) {
  1111. std::string type = getenv("HTTP_PROXY_TYPE");
  1112. // HTTP/SOCKS4/SOCKS5
  1113. if (type == "HTTP") {
  1114. this->HTTPProxyType = 1;
  1115. } else if (type == "SOCKS4") {
  1116. this->HTTPProxyType = 2;
  1117. } else if (type == "SOCKS5") {
  1118. this->HTTPProxyType = 3;
  1119. }
  1120. }
  1121. if (getenv("HTTP_PROXY_USER")) {
  1122. this->HTTPProxyAuth = getenv("HTTP_PROXY_USER");
  1123. }
  1124. if (getenv("HTTP_PROXY_PASSWD")) {
  1125. this->HTTPProxyAuth += ":";
  1126. this->HTTPProxyAuth += getenv("HTTP_PROXY_PASSWD");
  1127. }
  1128. }
  1129. if (getenv("FTP_PROXY")) {
  1130. this->FTPProxyType = 1;
  1131. this->FTPProxy = getenv("FTP_PROXY");
  1132. if (getenv("FTP_PROXY_PORT")) {
  1133. this->FTPProxy += ":";
  1134. this->FTPProxy += getenv("FTP_PROXY_PORT");
  1135. }
  1136. if (getenv("FTP_PROXY_TYPE")) {
  1137. std::string type = getenv("FTP_PROXY_TYPE");
  1138. // HTTP/SOCKS4/SOCKS5
  1139. if (type == "HTTP") {
  1140. this->FTPProxyType = 1;
  1141. } else if (type == "SOCKS4") {
  1142. this->FTPProxyType = 2;
  1143. } else if (type == "SOCKS5") {
  1144. this->FTPProxyType = 3;
  1145. }
  1146. }
  1147. }
  1148. if (!this->HTTPProxy.empty()) {
  1149. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1150. " Use HTTP Proxy: " << this->HTTPProxy << std::endl,
  1151. this->Quiet);
  1152. }
  1153. if (!this->FTPProxy.empty()) {
  1154. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1155. " Use FTP Proxy: " << this->FTPProxy << std::endl,
  1156. this->Quiet);
  1157. }
  1158. cmGeneratedFileStream ofs;
  1159. this->StartLogFile("Submit", ofs);
  1160. cmCTest::SetOfStrings files;
  1161. std::string prefix = this->GetSubmitResultsPrefix();
  1162. if (!this->Files.empty()) {
  1163. // Submit the explicitly selected files:
  1164. //
  1165. files.insert(this->Files.begin(), this->Files.end());
  1166. }
  1167. // Add to the list of files to submit from any selected, existing parts:
  1168. //
  1169. // TODO:
  1170. // Check if test is enabled
  1171. this->CTest->AddIfExists(cmCTest::PartUpdate, "Update.xml");
  1172. this->CTest->AddIfExists(cmCTest::PartConfigure, "Configure.xml");
  1173. this->CTest->AddIfExists(cmCTest::PartBuild, "Build.xml");
  1174. this->CTest->AddIfExists(cmCTest::PartTest, "Test.xml");
  1175. if (this->CTest->AddIfExists(cmCTest::PartCoverage, "Coverage.xml")) {
  1176. std::vector<std::string> gfiles;
  1177. std::string gpath =
  1178. buildDirectory + "/Testing/" + this->CTest->GetCurrentTag();
  1179. std::string::size_type glen = gpath.size() + 1;
  1180. gpath = gpath + "/CoverageLog*";
  1181. cmCTestOptionalLog(this->CTest, DEBUG,
  1182. "Globbing for: " << gpath << std::endl, this->Quiet);
  1183. if (cmSystemTools::SimpleGlob(gpath, gfiles, 1)) {
  1184. for (std::string& gfile : gfiles) {
  1185. gfile = gfile.substr(glen);
  1186. cmCTestOptionalLog(this->CTest, DEBUG,
  1187. "Glob file: " << gfile << std::endl, this->Quiet);
  1188. this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfile.c_str());
  1189. }
  1190. } else {
  1191. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing" << std::endl);
  1192. }
  1193. }
  1194. this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml");
  1195. this->CTest->AddIfExists(cmCTest::PartMemCheck, "Purify.xml");
  1196. this->CTest->AddIfExists(cmCTest::PartNotes, "Notes.xml");
  1197. this->CTest->AddIfExists(cmCTest::PartUpload, "Upload.xml");
  1198. // Query parts for files to submit.
  1199. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1200. p = cmCTest::Part(p + 1)) {
  1201. // Skip parts we are not submitting.
  1202. if (!this->SubmitPart[p]) {
  1203. continue;
  1204. }
  1205. // Submit files from this part.
  1206. std::vector<std::string> const& pfiles = this->CTest->GetSubmitFiles(p);
  1207. files.insert(pfiles.begin(), pfiles.end());
  1208. }
  1209. if (ofs) {
  1210. ofs << "Upload files:" << std::endl;
  1211. int cnt = 0;
  1212. for (std::string const& file : files) {
  1213. ofs << cnt << "\t" << file << std::endl;
  1214. cnt++;
  1215. }
  1216. }
  1217. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Submit files (using "
  1218. << this->CTest->GetCTestConfiguration("DropMethod")
  1219. << ")" << std::endl,
  1220. this->Quiet);
  1221. const char* specificTrack = this->CTest->GetSpecificTrack();
  1222. if (specificTrack) {
  1223. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1224. " Send to track: " << specificTrack << std::endl,
  1225. this->Quiet);
  1226. }
  1227. this->SetLogFile(&ofs);
  1228. std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
  1229. if (dropMethod.empty() || dropMethod == "ftp") {
  1230. ofs << "Using drop method: FTP" << std::endl;
  1231. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1232. " Using FTP submit method" << std::endl
  1233. << " Drop site: ftp://",
  1234. this->Quiet);
  1235. std::string url = "ftp://";
  1236. url += cmCTest::MakeURLSafe(
  1237. this->CTest->GetCTestConfiguration("DropSiteUser")) +
  1238. ":" + cmCTest::MakeURLSafe(
  1239. this->CTest->GetCTestConfiguration("DropSitePassword")) +
  1240. "@" + this->CTest->GetCTestConfiguration("DropSite") +
  1241. cmCTest::MakeURLSafe(this->CTest->GetCTestConfiguration("DropLocation"));
  1242. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1243. cmCTestOptionalLog(
  1244. this->CTest, HANDLER_OUTPUT,
  1245. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1246. this->Quiet);
  1247. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1248. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1249. this->Quiet);
  1250. }
  1251. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1252. }
  1253. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1254. this->CTest->GetCTestConfiguration("DropSite")
  1255. << this->CTest->GetCTestConfiguration("DropLocation")
  1256. << std::endl,
  1257. this->Quiet);
  1258. if (!this->SubmitUsingFTP(buildDirectory + "/Testing/" +
  1259. this->CTest->GetCurrentTag(),
  1260. files, prefix, url)) {
  1261. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1262. " Problems when submitting via FTP" << std::endl);
  1263. ofs << " Problems when submitting via FTP" << std::endl;
  1264. return -1;
  1265. }
  1266. if (!this->CDash) {
  1267. cmCTestOptionalLog(
  1268. this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
  1269. << std::endl
  1270. << " Trigger site: "
  1271. << this->CTest->GetCTestConfiguration("TriggerSite") << std::endl,
  1272. this->Quiet);
  1273. if (!this->TriggerUsingHTTP(
  1274. files, prefix,
  1275. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1276. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1277. " Problems when triggering via HTTP" << std::endl);
  1278. ofs << " Problems when triggering via HTTP" << std::endl;
  1279. return -1;
  1280. }
  1281. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1282. " Submission successful" << std::endl, this->Quiet);
  1283. ofs << " Submission successful" << std::endl;
  1284. return 0;
  1285. }
  1286. } else if (dropMethod == "http" || dropMethod == "https") {
  1287. std::string url = dropMethod;
  1288. url += "://";
  1289. ofs << "Using drop method: " << dropMethod << std::endl;
  1290. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1291. " Using HTTP submit method" << std::endl
  1292. << " Drop site:" << url,
  1293. this->Quiet);
  1294. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1295. url += this->CTest->GetCTestConfiguration("DropSiteUser");
  1296. cmCTestOptionalLog(
  1297. this->CTest, HANDLER_OUTPUT,
  1298. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1299. this->Quiet);
  1300. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1301. url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
  1302. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1303. this->Quiet);
  1304. }
  1305. url += "@";
  1306. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1307. }
  1308. url += this->CTest->GetCTestConfiguration("DropSite") +
  1309. this->CTest->GetCTestConfiguration("DropLocation");
  1310. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1311. this->CTest->GetCTestConfiguration("DropSite")
  1312. << this->CTest->GetCTestConfiguration("DropLocation")
  1313. << std::endl,
  1314. this->Quiet);
  1315. if (!this->SubmitUsingHTTP(buildDirectory + "/Testing/" +
  1316. this->CTest->GetCurrentTag(),
  1317. files, prefix, url)) {
  1318. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1319. " Problems when submitting via HTTP" << std::endl);
  1320. ofs << " Problems when submitting via HTTP" << std::endl;
  1321. return -1;
  1322. }
  1323. if (!this->CDash) {
  1324. cmCTestOptionalLog(
  1325. this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
  1326. << std::endl
  1327. << " Trigger site: "
  1328. << this->CTest->GetCTestConfiguration("TriggerSite") << std::endl,
  1329. this->Quiet);
  1330. if (!this->TriggerUsingHTTP(
  1331. files, prefix,
  1332. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1333. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1334. " Problems when triggering via HTTP" << std::endl);
  1335. ofs << " Problems when triggering via HTTP" << std::endl;
  1336. return -1;
  1337. }
  1338. }
  1339. if (this->HasErrors) {
  1340. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Errors occurred during "
  1341. "submission."
  1342. << std::endl);
  1343. ofs << " Errors occurred during submission. " << std::endl;
  1344. } else {
  1345. cmCTestOptionalLog(
  1346. this->CTest, HANDLER_OUTPUT, " Submission successful"
  1347. << (this->HasWarnings ? ", with warnings." : "") << std::endl,
  1348. this->Quiet);
  1349. ofs << " Submission successful"
  1350. << (this->HasWarnings ? ", with warnings." : "") << std::endl;
  1351. }
  1352. return 0;
  1353. } else if (dropMethod == "xmlrpc") {
  1354. #if defined(CTEST_USE_XMLRPC)
  1355. ofs << "Using drop method: XML-RPC" << std::endl;
  1356. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1357. " Using XML-RPC submit method" << std::endl,
  1358. this->Quiet);
  1359. std::string url = this->CTest->GetCTestConfiguration("DropSite");
  1360. prefix = this->CTest->GetCTestConfiguration("DropLocation");
  1361. if (!this->SubmitUsingXMLRPC(buildDirectory + "/Testing/" +
  1362. this->CTest->GetCurrentTag(),
  1363. files, prefix, url)) {
  1364. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1365. " Problems when submitting via XML-RPC" << std::endl);
  1366. ofs << " Problems when submitting via XML-RPC" << std::endl;
  1367. return -1;
  1368. }
  1369. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1370. " Submission successful" << std::endl, this->Quiet);
  1371. ofs << " Submission successful" << std::endl;
  1372. return 0;
  1373. #else
  1374. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1375. " Submission method \"xmlrpc\" not compiled into CTest!"
  1376. << std::endl);
  1377. return -1;
  1378. #endif
  1379. } else if (dropMethod == "scp") {
  1380. std::string url;
  1381. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1382. url += this->CTest->GetCTestConfiguration("DropSiteUser") + "@";
  1383. }
  1384. url += this->CTest->GetCTestConfiguration("DropSite") + ":" +
  1385. this->CTest->GetCTestConfiguration("DropLocation");
  1386. // change to the build directory so that we can uses a relative path
  1387. // on windows since scp doesn't support "c:" a drive in the path
  1388. cmWorkingDirectory workdir(buildDirectory);
  1389. if (!this->SubmitUsingSCP(this->CTest->GetCTestConfiguration("ScpCommand"),
  1390. "Testing/" + this->CTest->GetCurrentTag(), files,
  1391. prefix, url)) {
  1392. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1393. " Problems when submitting via SCP" << std::endl);
  1394. ofs << " Problems when submitting via SCP" << std::endl;
  1395. return -1;
  1396. }
  1397. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1398. " Submission successful" << std::endl, this->Quiet);
  1399. ofs << " Submission successful" << std::endl;
  1400. return 0;
  1401. } else if (dropMethod == "cp") {
  1402. std::string location = this->CTest->GetCTestConfiguration("DropLocation");
  1403. // change to the build directory so that we can uses a relative path
  1404. // on windows since scp doesn't support "c:" a drive in the path
  1405. cmWorkingDirectory workdir(buildDirectory);
  1406. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1407. " Change directory: " << buildDirectory << std::endl,
  1408. this->Quiet);
  1409. if (!this->SubmitUsingCP("Testing/" + this->CTest->GetCurrentTag(), files,
  1410. prefix, location)) {
  1411. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1412. " Problems when submitting via CP" << std::endl);
  1413. ofs << " Problems when submitting via cp" << std::endl;
  1414. return -1;
  1415. }
  1416. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1417. " Submission successful" << std::endl, this->Quiet);
  1418. ofs << " Submission successful" << std::endl;
  1419. return 0;
  1420. }
  1421. cmCTestLog(this->CTest, ERROR_MESSAGE, " Unknown submission method: \""
  1422. << dropMethod << "\"" << std::endl);
  1423. return -1;
  1424. }
  1425. std::string cmCTestSubmitHandler::GetSubmitResultsPrefix()
  1426. {
  1427. std::string buildname =
  1428. cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName"));
  1429. std::string name = this->CTest->GetCTestConfiguration("Site") + "___" +
  1430. buildname + "___" + this->CTest->GetCurrentTag() + "-" +
  1431. this->CTest->GetTestModelString() + "___XML___";
  1432. return name;
  1433. }
  1434. void cmCTestSubmitHandler::SelectParts(std::set<cmCTest::Part> const& parts)
  1435. {
  1436. // Check whether each part is selected.
  1437. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1438. p = cmCTest::Part(p + 1)) {
  1439. this->SubmitPart[p] =
  1440. (std::set<cmCTest::Part>::const_iterator(parts.find(p)) != parts.end());
  1441. }
  1442. }
  1443. void cmCTestSubmitHandler::SelectFiles(cmCTest::SetOfStrings const& files)
  1444. {
  1445. this->Files.insert(files.begin(), files.end());
  1446. }