32
33
typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
35
//----------------------------------------------------------------------------
36
class cmCTestSubmitHandler::ResponseParser: public cmXMLParser
39
ResponseParser() { this->Status = STATUS_OK; }
52
std::string CDashVersion;
59
std::vector<char> CurrentValue;
61
std::string GetCurrentValue()
64
if(this->CurrentValue.size())
66
val.assign(&this->CurrentValue[0], this->CurrentValue.size());
71
virtual void StartElement(const char* name, const char** atts)
73
this->CurrentValue.clear();
74
if(strcmp(name, "cdash") == 0)
76
this->CDashVersion = this->FindAttribute(atts, "version");
80
virtual void CharacterDataHandler(const char* data, int length)
82
this->CurrentValue.insert(this->CurrentValue.end(), data, data+length);
85
virtual void EndElement(const char* name)
87
if(strcmp(name, "status") == 0)
89
std::string status = cmSystemTools::UpperCase(this->GetCurrentValue());
90
if(status == "OK" || status == "SUCCESS")
92
this->Status = STATUS_OK;
94
else if(status == "WARNING")
96
this->Status = STATUS_WARNING;
100
this->Status = STATUS_ERROR;
103
else if(strcmp(name, "filename") == 0)
105
this->Filename = this->GetCurrentValue();
107
else if(strcmp(name, "md5") == 0)
109
this->MD5 = this->GetCurrentValue();
111
else if(strcmp(name, "message") == 0)
113
this->Message = this->GetCurrentValue();
35
120
cmCTestSubmitHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
367
452
= url + ((url.find("?",0) == cmStdString::npos) ? "?" : "&")
368
453
+ "FileName=" + ofile;
455
upload_as += "&MD5=";
457
if(cmSystemTools::IsOn(this->GetOption("InternalTest")))
459
upload_as += "bad_md5sum";
464
cmSystemTools::ComputeFileMD5(local_file.c_str(), md5);
371
470
if ( ::stat(local_file.c_str(), &st) )
411
509
// Now run off and do what you've been told!
412
510
res = ::curl_easy_perform(curl);
512
if(cmSystemTools::IsOn(this->GetOption("InternalTest")) &&
513
cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
514
this->CTest->GetCDashVersion().c_str(), "1.7"))
516
// mock failure output for internal test case
517
std::string mock_output = "<cdash version=\"1.7.0\">\n"
518
" <status>ERROR</status>\n"
519
" <message>Checksum failed for file.</message>\n"
522
chunk.assign(mock_output.begin(), mock_output.end());
414
525
if ( chunk.size() > 0 )
416
527
cmCTestLog(this->CTest, DEBUG, "CURL output: ["
539
// If curl failed for any reason, or checksum fails, wait and retry
541
if(res != CURLE_OK || this->HasErrors)
543
std::string retryDelay = this->GetOption("RetryDelay") == NULL ?
544
"" : this->GetOption("RetryDelay");
545
std::string retryCount = this->GetOption("RetryCount") == NULL ?
546
"" : this->GetOption("RetryCount");
548
int delay = retryDelay == "" ? atoi(this->CTest->GetCTestConfiguration(
549
"CTestSubmitRetryDelay").c_str()) : atoi(retryDelay.c_str());
550
int count = retryCount == "" ? atoi(this->CTest->GetCTestConfiguration(
551
"CTestSubmitRetryCount").c_str()) : atoi(retryCount.c_str());
553
for(int i = 0; i < count; i++)
555
cmCTestLog(this->CTest, HANDLER_OUTPUT,
556
" Submit failed, waiting " << delay << " seconds...\n");
558
double stop = cmSystemTools::GetTime() + delay;
559
while(cmSystemTools::GetTime() < stop)
561
cmSystemTools::Delay(100);
564
cmCTestLog(this->CTest, HANDLER_OUTPUT,
565
" Retry submission: Attempt " << (i + 1) << " of "
566
<< count << std::endl);
569
ftpfile = ::fopen(local_file.c_str(), "rb");
570
::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
574
this->HasErrors = false;
576
res = ::curl_easy_perform(curl);
578
if ( chunk.size() > 0 )
580
cmCTestLog(this->CTest, DEBUG, "CURL output: ["
581
<< cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
583
this->ParseResponse(chunk);
586
if(res == CURLE_OK && !this->HasErrors)
467
632
::ParseResponse(cmCTestSubmitHandlerVectorOfChar chunk)
469
634
std::string output = "";
635
output.append(chunk.begin(), chunk.end());
471
for(cmCTestSubmitHandlerVectorOfChar::iterator i = chunk.begin();
472
i != chunk.end(); ++i)
637
if(output.find("<cdash") != output.npos)
639
ResponseParser parser;
640
parser.Parse(output.c_str());
642
if(parser.Status != ResponseParser::STATUS_OK)
644
this->HasErrors = true;
645
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Submission failed: " <<
646
parser.Message << std::endl);
476
650
output = cmSystemTools::UpperCase(output);
478
651
if(output.find("WARNING") != std::string::npos)
480
653
this->HasWarnings = true;
484
657
this->HasErrors = true;
487
660
if(this->HasWarnings || this->HasErrors)
489
662
cmCTestLog(this->CTest, HANDLER_OUTPUT, " Server Response:\n" <<
490
663
cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
495
667
//----------------------------------------------------------------------------
589
761
<< turl.c_str() << std::endl);
590
762
cmCTestLog(this->CTest, ERROR_MESSAGE, " Error message was: "
591
763
<< error_buffer << std::endl);
592
*this->LogFile << "\tTrigerring failed with error: " << error_buffer
764
*this->LogFile << "\tTriggering failed with error: " << error_buffer
594
766
<< " Error message was: " << error_buffer