cmCTestSubmitHandler.cxx 58 KB

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