cmCTestSubmitHandler.cxx 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  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. str << "stamp=" << curl.Escape(this->CTest->GetCurrentTag()) << "-"
  956. << curl.Escape(this->CTest->GetTestModelString()) << "&"
  957. << "model=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  958. << "build="
  959. << curl.Escape(this->CTest->GetCTestConfiguration("BuildName")) << "&"
  960. << "site=" << curl.Escape(this->CTest->GetCTestConfiguration("Site"))
  961. << "&"
  962. << "track=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
  963. << "starttime=" << static_cast<int>(cmSystemTools::GetTime()) << "&"
  964. << "endtime=" << static_cast<int>(cmSystemTools::GetTime()) << "&"
  965. << "datafilesmd5[0]=" << md5sum << "&"
  966. << "type=" << curl.Escape(typeString);
  967. std::string fields = str.str();
  968. cmCTestOptionalLog(this->CTest, DEBUG,
  969. "fields: " << fields << "\nurl:" << url
  970. << "\nfile: " << file << "\n",
  971. this->Quiet);
  972. std::string response;
  973. bool requestSucceeded = curl.HttpRequest(url, fields, response);
  974. if (!internalTest && !requestSucceeded) {
  975. // If request failed, wait and retry.
  976. for (unsigned long i = 0; i < retryCount; i++) {
  977. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  978. " Request failed, waiting " << retryDelay.count()
  979. << " seconds...\n",
  980. this->Quiet);
  981. auto stop = std::chrono::steady_clock::now() + retryDelay;
  982. while (std::chrono::steady_clock::now() < stop) {
  983. cmSystemTools::Delay(100);
  984. }
  985. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  986. " Retry request: Attempt "
  987. << (i + 1) << " of " << retryCount << std::endl,
  988. this->Quiet);
  989. requestSucceeded = curl.HttpRequest(url, fields, response);
  990. if (requestSucceeded) {
  991. break;
  992. }
  993. }
  994. }
  995. if (!internalTest && !requestSucceeded) {
  996. cmCTestLog(this->CTest, ERROR_MESSAGE, "Error in HttpRequest\n"
  997. << response);
  998. return -1;
  999. }
  1000. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1001. "Request upload response: [" << response << "]\n",
  1002. this->Quiet);
  1003. Json::Value json;
  1004. Json::Reader reader;
  1005. if (!internalTest && !reader.parse(response, json)) {
  1006. cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string ["
  1007. << response << "]\n"
  1008. << reader.getFormattedErrorMessages() << "\n");
  1009. return -1;
  1010. }
  1011. if (!internalTest && json["status"].asInt() != 0) {
  1012. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1013. "Bad status returned from CDash: " << json["status"].asInt());
  1014. return -1;
  1015. }
  1016. if (!internalTest) {
  1017. if (json["datafilesmd5"].isArray()) {
  1018. int datares = json["datafilesmd5"][0].asInt();
  1019. if (datares == 1) {
  1020. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1021. "File already exists on CDash, skip upload "
  1022. << file << "\n",
  1023. this->Quiet);
  1024. return 0;
  1025. }
  1026. } else {
  1027. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1028. "bad datafilesmd5 value in response " << response << "\n");
  1029. return -1;
  1030. }
  1031. }
  1032. std::string upload_as = cmSystemTools::GetFilenameName(file);
  1033. std::ostringstream fstr;
  1034. fstr << "type=" << curl.Escape(typeString) << "&"
  1035. << "md5=" << md5sum << "&"
  1036. << "filename=" << curl.Escape(upload_as) << "&"
  1037. << "buildid=" << json["buildid"].asString();
  1038. bool uploadSucceeded = false;
  1039. if (!internalTest) {
  1040. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1041. }
  1042. if (!uploadSucceeded) {
  1043. // If upload failed, wait and retry.
  1044. for (unsigned long i = 0; i < retryCount; i++) {
  1045. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1046. " Upload failed, waiting " << retryDelay.count()
  1047. << " seconds...\n",
  1048. this->Quiet);
  1049. auto stop = std::chrono::steady_clock::now() + retryDelay;
  1050. while (std::chrono::steady_clock::now() < stop) {
  1051. cmSystemTools::Delay(100);
  1052. }
  1053. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1054. " Retry upload: Attempt "
  1055. << (i + 1) << " of " << retryCount << std::endl,
  1056. this->Quiet);
  1057. if (!internalTest) {
  1058. uploadSucceeded = curl.UploadFile(file, url, fstr.str(), response);
  1059. }
  1060. if (uploadSucceeded) {
  1061. break;
  1062. }
  1063. }
  1064. }
  1065. if (!uploadSucceeded) {
  1066. cmCTestLog(this->CTest, ERROR_MESSAGE, "error uploading to CDash. "
  1067. << file << " " << url << " " << fstr.str());
  1068. return -1;
  1069. }
  1070. if (!reader.parse(response, json)) {
  1071. cmCTestLog(this->CTest, ERROR_MESSAGE, "error parsing json string ["
  1072. << response << "]\n"
  1073. << reader.getFormattedErrorMessages() << "\n");
  1074. return -1;
  1075. }
  1076. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1077. "Upload file response: [" << response << "]\n",
  1078. this->Quiet);
  1079. return 0;
  1080. }
  1081. int cmCTestSubmitHandler::ProcessHandler()
  1082. {
  1083. const char* cdashUploadFile = this->GetOption("CDashUploadFile");
  1084. const char* cdashUploadType = this->GetOption("CDashUploadType");
  1085. if (cdashUploadFile && cdashUploadType) {
  1086. return this->HandleCDashUploadFile(cdashUploadFile, cdashUploadType);
  1087. }
  1088. std::string iscdash = this->CTest->GetCTestConfiguration("IsCDash");
  1089. // cdash does not need to trigger so just return true
  1090. if (!iscdash.empty()) {
  1091. this->CDash = true;
  1092. }
  1093. const std::string& buildDirectory =
  1094. this->CTest->GetCTestConfiguration("BuildDirectory");
  1095. if (buildDirectory.empty()) {
  1096. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1097. "Cannot find BuildDirectory key in the DartConfiguration.tcl"
  1098. << std::endl);
  1099. return -1;
  1100. }
  1101. if (getenv("HTTP_PROXY")) {
  1102. this->HTTPProxyType = 1;
  1103. this->HTTPProxy = getenv("HTTP_PROXY");
  1104. if (getenv("HTTP_PROXY_PORT")) {
  1105. this->HTTPProxy += ":";
  1106. this->HTTPProxy += getenv("HTTP_PROXY_PORT");
  1107. }
  1108. if (getenv("HTTP_PROXY_TYPE")) {
  1109. std::string type = getenv("HTTP_PROXY_TYPE");
  1110. // HTTP/SOCKS4/SOCKS5
  1111. if (type == "HTTP") {
  1112. this->HTTPProxyType = 1;
  1113. } else if (type == "SOCKS4") {
  1114. this->HTTPProxyType = 2;
  1115. } else if (type == "SOCKS5") {
  1116. this->HTTPProxyType = 3;
  1117. }
  1118. }
  1119. if (getenv("HTTP_PROXY_USER")) {
  1120. this->HTTPProxyAuth = getenv("HTTP_PROXY_USER");
  1121. }
  1122. if (getenv("HTTP_PROXY_PASSWD")) {
  1123. this->HTTPProxyAuth += ":";
  1124. this->HTTPProxyAuth += getenv("HTTP_PROXY_PASSWD");
  1125. }
  1126. }
  1127. if (getenv("FTP_PROXY")) {
  1128. this->FTPProxyType = 1;
  1129. this->FTPProxy = getenv("FTP_PROXY");
  1130. if (getenv("FTP_PROXY_PORT")) {
  1131. this->FTPProxy += ":";
  1132. this->FTPProxy += getenv("FTP_PROXY_PORT");
  1133. }
  1134. if (getenv("FTP_PROXY_TYPE")) {
  1135. std::string type = getenv("FTP_PROXY_TYPE");
  1136. // HTTP/SOCKS4/SOCKS5
  1137. if (type == "HTTP") {
  1138. this->FTPProxyType = 1;
  1139. } else if (type == "SOCKS4") {
  1140. this->FTPProxyType = 2;
  1141. } else if (type == "SOCKS5") {
  1142. this->FTPProxyType = 3;
  1143. }
  1144. }
  1145. }
  1146. if (!this->HTTPProxy.empty()) {
  1147. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1148. " Use HTTP Proxy: " << this->HTTPProxy << std::endl,
  1149. this->Quiet);
  1150. }
  1151. if (!this->FTPProxy.empty()) {
  1152. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1153. " Use FTP Proxy: " << this->FTPProxy << std::endl,
  1154. this->Quiet);
  1155. }
  1156. cmGeneratedFileStream ofs;
  1157. this->StartLogFile("Submit", ofs);
  1158. cmCTest::SetOfStrings files;
  1159. std::string prefix = this->GetSubmitResultsPrefix();
  1160. if (!this->Files.empty()) {
  1161. // Submit the explicitly selected files:
  1162. //
  1163. files.insert(this->Files.begin(), this->Files.end());
  1164. }
  1165. // Add to the list of files to submit from any selected, existing parts:
  1166. //
  1167. // TODO:
  1168. // Check if test is enabled
  1169. this->CTest->AddIfExists(cmCTest::PartUpdate, "Update.xml");
  1170. this->CTest->AddIfExists(cmCTest::PartConfigure, "Configure.xml");
  1171. this->CTest->AddIfExists(cmCTest::PartBuild, "Build.xml");
  1172. this->CTest->AddIfExists(cmCTest::PartTest, "Test.xml");
  1173. if (this->CTest->AddIfExists(cmCTest::PartCoverage, "Coverage.xml")) {
  1174. std::vector<std::string> gfiles;
  1175. std::string gpath =
  1176. buildDirectory + "/Testing/" + this->CTest->GetCurrentTag();
  1177. std::string::size_type glen = gpath.size() + 1;
  1178. gpath = gpath + "/CoverageLog*";
  1179. cmCTestOptionalLog(this->CTest, DEBUG,
  1180. "Globbing for: " << gpath << std::endl, this->Quiet);
  1181. if (cmSystemTools::SimpleGlob(gpath, gfiles, 1)) {
  1182. for (std::string& gfile : gfiles) {
  1183. gfile = gfile.substr(glen);
  1184. cmCTestOptionalLog(this->CTest, DEBUG,
  1185. "Glob file: " << gfile << std::endl, this->Quiet);
  1186. this->CTest->AddSubmitFile(cmCTest::PartCoverage, gfile.c_str());
  1187. }
  1188. } else {
  1189. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem globbing" << std::endl);
  1190. }
  1191. }
  1192. this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml");
  1193. this->CTest->AddIfExists(cmCTest::PartMemCheck, "Purify.xml");
  1194. this->CTest->AddIfExists(cmCTest::PartNotes, "Notes.xml");
  1195. this->CTest->AddIfExists(cmCTest::PartUpload, "Upload.xml");
  1196. // Query parts for files to submit.
  1197. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1198. p = cmCTest::Part(p + 1)) {
  1199. // Skip parts we are not submitting.
  1200. if (!this->SubmitPart[p]) {
  1201. continue;
  1202. }
  1203. // Submit files from this part.
  1204. std::vector<std::string> const& pfiles = this->CTest->GetSubmitFiles(p);
  1205. files.insert(pfiles.begin(), pfiles.end());
  1206. }
  1207. if (ofs) {
  1208. ofs << "Upload files:" << std::endl;
  1209. int cnt = 0;
  1210. for (std::string const& file : files) {
  1211. ofs << cnt << "\t" << file << std::endl;
  1212. cnt++;
  1213. }
  1214. }
  1215. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Submit files (using "
  1216. << this->CTest->GetCTestConfiguration("DropMethod")
  1217. << ")" << std::endl,
  1218. this->Quiet);
  1219. const char* specificTrack = this->CTest->GetSpecificTrack();
  1220. if (specificTrack) {
  1221. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1222. " Send to track: " << specificTrack << std::endl,
  1223. this->Quiet);
  1224. }
  1225. this->SetLogFile(&ofs);
  1226. std::string dropMethod(this->CTest->GetCTestConfiguration("DropMethod"));
  1227. if (dropMethod.empty() || dropMethod == "ftp") {
  1228. ofs << "Using drop method: FTP" << std::endl;
  1229. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1230. " Using FTP submit method" << std::endl
  1231. << " Drop site: ftp://",
  1232. this->Quiet);
  1233. std::string url = "ftp://";
  1234. url += cmCTest::MakeURLSafe(
  1235. this->CTest->GetCTestConfiguration("DropSiteUser")) +
  1236. ":" + cmCTest::MakeURLSafe(
  1237. this->CTest->GetCTestConfiguration("DropSitePassword")) +
  1238. "@" + this->CTest->GetCTestConfiguration("DropSite") +
  1239. cmCTest::MakeURLSafe(this->CTest->GetCTestConfiguration("DropLocation"));
  1240. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1241. cmCTestOptionalLog(
  1242. this->CTest, HANDLER_OUTPUT,
  1243. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1244. this->Quiet);
  1245. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1246. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1247. this->Quiet);
  1248. }
  1249. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1250. }
  1251. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1252. this->CTest->GetCTestConfiguration("DropSite")
  1253. << this->CTest->GetCTestConfiguration("DropLocation")
  1254. << std::endl,
  1255. this->Quiet);
  1256. if (!this->SubmitUsingFTP(buildDirectory + "/Testing/" +
  1257. this->CTest->GetCurrentTag(),
  1258. files, prefix, url)) {
  1259. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1260. " Problems when submitting via FTP" << std::endl);
  1261. ofs << " Problems when submitting via FTP" << std::endl;
  1262. return -1;
  1263. }
  1264. if (!this->CDash) {
  1265. cmCTestOptionalLog(
  1266. this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
  1267. << std::endl
  1268. << " Trigger site: "
  1269. << this->CTest->GetCTestConfiguration("TriggerSite") << std::endl,
  1270. this->Quiet);
  1271. if (!this->TriggerUsingHTTP(
  1272. files, prefix,
  1273. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1274. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1275. " Problems when triggering via HTTP" << std::endl);
  1276. ofs << " Problems when triggering via HTTP" << std::endl;
  1277. return -1;
  1278. }
  1279. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1280. " Submission successful" << std::endl, this->Quiet);
  1281. ofs << " Submission successful" << std::endl;
  1282. return 0;
  1283. }
  1284. } else if (dropMethod == "http" || dropMethod == "https") {
  1285. std::string url = dropMethod;
  1286. url += "://";
  1287. ofs << "Using drop method: " << dropMethod << std::endl;
  1288. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1289. " Using HTTP submit method" << std::endl
  1290. << " Drop site:" << url,
  1291. this->Quiet);
  1292. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1293. url += this->CTest->GetCTestConfiguration("DropSiteUser");
  1294. cmCTestOptionalLog(
  1295. this->CTest, HANDLER_OUTPUT,
  1296. this->CTest->GetCTestConfiguration("DropSiteUser").c_str(),
  1297. this->Quiet);
  1298. if (!this->CTest->GetCTestConfiguration("DropSitePassword").empty()) {
  1299. url += ":" + this->CTest->GetCTestConfiguration("DropSitePassword");
  1300. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, ":******",
  1301. this->Quiet);
  1302. }
  1303. url += "@";
  1304. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "@", this->Quiet);
  1305. }
  1306. url += this->CTest->GetCTestConfiguration("DropSite") +
  1307. this->CTest->GetCTestConfiguration("DropLocation");
  1308. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1309. this->CTest->GetCTestConfiguration("DropSite")
  1310. << this->CTest->GetCTestConfiguration("DropLocation")
  1311. << std::endl,
  1312. this->Quiet);
  1313. if (!this->SubmitUsingHTTP(buildDirectory + "/Testing/" +
  1314. this->CTest->GetCurrentTag(),
  1315. files, prefix, url)) {
  1316. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1317. " Problems when submitting via HTTP" << std::endl);
  1318. ofs << " Problems when submitting via HTTP" << std::endl;
  1319. return -1;
  1320. }
  1321. if (!this->CDash) {
  1322. cmCTestOptionalLog(
  1323. this->CTest, HANDLER_OUTPUT, " Using HTTP trigger method"
  1324. << std::endl
  1325. << " Trigger site: "
  1326. << this->CTest->GetCTestConfiguration("TriggerSite") << std::endl,
  1327. this->Quiet);
  1328. if (!this->TriggerUsingHTTP(
  1329. files, prefix,
  1330. this->CTest->GetCTestConfiguration("TriggerSite"))) {
  1331. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1332. " Problems when triggering via HTTP" << std::endl);
  1333. ofs << " Problems when triggering via HTTP" << std::endl;
  1334. return -1;
  1335. }
  1336. }
  1337. if (this->HasErrors) {
  1338. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Errors occurred during "
  1339. "submission."
  1340. << std::endl);
  1341. ofs << " Errors occurred during submission. " << std::endl;
  1342. } else {
  1343. cmCTestOptionalLog(
  1344. this->CTest, HANDLER_OUTPUT, " Submission successful"
  1345. << (this->HasWarnings ? ", with warnings." : "") << std::endl,
  1346. this->Quiet);
  1347. ofs << " Submission successful"
  1348. << (this->HasWarnings ? ", with warnings." : "") << std::endl;
  1349. }
  1350. return 0;
  1351. } else if (dropMethod == "xmlrpc") {
  1352. #if defined(CTEST_USE_XMLRPC)
  1353. ofs << "Using drop method: XML-RPC" << std::endl;
  1354. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1355. " Using XML-RPC submit method" << std::endl,
  1356. this->Quiet);
  1357. std::string url = this->CTest->GetCTestConfiguration("DropSite");
  1358. prefix = this->CTest->GetCTestConfiguration("DropLocation");
  1359. if (!this->SubmitUsingXMLRPC(buildDirectory + "/Testing/" +
  1360. this->CTest->GetCurrentTag(),
  1361. files, prefix, url)) {
  1362. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1363. " Problems when submitting via XML-RPC" << std::endl);
  1364. ofs << " Problems when submitting via XML-RPC" << std::endl;
  1365. return -1;
  1366. }
  1367. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1368. " Submission successful" << std::endl, this->Quiet);
  1369. ofs << " Submission successful" << std::endl;
  1370. return 0;
  1371. #else
  1372. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1373. " Submission method \"xmlrpc\" not compiled into CTest!"
  1374. << std::endl);
  1375. return -1;
  1376. #endif
  1377. } else if (dropMethod == "scp") {
  1378. std::string url;
  1379. if (!this->CTest->GetCTestConfiguration("DropSiteUser").empty()) {
  1380. url += this->CTest->GetCTestConfiguration("DropSiteUser") + "@";
  1381. }
  1382. url += this->CTest->GetCTestConfiguration("DropSite") + ":" +
  1383. this->CTest->GetCTestConfiguration("DropLocation");
  1384. // change to the build directory so that we can uses a relative path
  1385. // on windows since scp doesn't support "c:" a drive in the path
  1386. cmWorkingDirectory workdir(buildDirectory);
  1387. if (!this->SubmitUsingSCP(this->CTest->GetCTestConfiguration("ScpCommand"),
  1388. "Testing/" + this->CTest->GetCurrentTag(), files,
  1389. prefix, url)) {
  1390. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1391. " Problems when submitting via SCP" << std::endl);
  1392. ofs << " Problems when submitting via SCP" << std::endl;
  1393. return -1;
  1394. }
  1395. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1396. " Submission successful" << std::endl, this->Quiet);
  1397. ofs << " Submission successful" << std::endl;
  1398. return 0;
  1399. } else if (dropMethod == "cp") {
  1400. std::string location = this->CTest->GetCTestConfiguration("DropLocation");
  1401. // change to the build directory so that we can uses a relative path
  1402. // on windows since scp doesn't support "c:" a drive in the path
  1403. cmWorkingDirectory workdir(buildDirectory);
  1404. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1405. " Change directory: " << buildDirectory << std::endl,
  1406. this->Quiet);
  1407. if (!this->SubmitUsingCP("Testing/" + this->CTest->GetCurrentTag(), files,
  1408. prefix, location)) {
  1409. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1410. " Problems when submitting via CP" << std::endl);
  1411. ofs << " Problems when submitting via cp" << std::endl;
  1412. return -1;
  1413. }
  1414. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  1415. " Submission successful" << std::endl, this->Quiet);
  1416. ofs << " Submission successful" << std::endl;
  1417. return 0;
  1418. }
  1419. cmCTestLog(this->CTest, ERROR_MESSAGE, " Unknown submission method: \""
  1420. << dropMethod << "\"" << std::endl);
  1421. return -1;
  1422. }
  1423. std::string cmCTestSubmitHandler::GetSubmitResultsPrefix()
  1424. {
  1425. std::string buildname =
  1426. cmCTest::SafeBuildIdField(this->CTest->GetCTestConfiguration("BuildName"));
  1427. std::string name = this->CTest->GetCTestConfiguration("Site") + "___" +
  1428. buildname + "___" + this->CTest->GetCurrentTag() + "-" +
  1429. this->CTest->GetTestModelString() + "___XML___";
  1430. return name;
  1431. }
  1432. void cmCTestSubmitHandler::SelectParts(std::set<cmCTest::Part> const& parts)
  1433. {
  1434. // Check whether each part is selected.
  1435. for (cmCTest::Part p = cmCTest::PartStart; p != cmCTest::PartCount;
  1436. p = cmCTest::Part(p + 1)) {
  1437. this->SubmitPart[p] =
  1438. (std::set<cmCTest::Part>::const_iterator(parts.find(p)) != parts.end());
  1439. }
  1440. }
  1441. void cmCTestSubmitHandler::SelectFiles(cmCTest::SetOfStrings const& files)
  1442. {
  1443. this->Files.insert(files.begin(), files.end());
  1444. }