~dynamite-a-d/ubuntu/precise/cmake/fix-for-972419

« back to all changes in this revision

Viewing changes to Source/CTest/cmCTestSubmitHandler.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Modestas Vainius
  • Date: 2010-11-13 02:16:34 UTC
  • mto: (3.3.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20101113021634-hsdooj6tr1q3tf0l
Tags: upstream-2.8.3
ImportĀ upstreamĀ versionĀ 2.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include "cmVersion.h"
16
16
#include "cmGeneratedFileStream.h"
17
17
#include "cmCTest.h"
 
18
#include "cmXMLParser.h"
18
19
 
19
20
#include <cmsys/Process.h>
20
21
#include <cmsys/Base64.h>
31
32
 
32
33
typedef std::vector<char> cmCTestSubmitHandlerVectorOfChar;
33
34
 
 
35
//----------------------------------------------------------------------------
 
36
class cmCTestSubmitHandler::ResponseParser: public cmXMLParser
 
37
{
 
38
public:
 
39
  ResponseParser() { this->Status = STATUS_OK; }
 
40
  ~ResponseParser() {}
 
41
 
 
42
public:
 
43
 
 
44
  enum StatusType
 
45
    {
 
46
    STATUS_OK,
 
47
    STATUS_WARNING,
 
48
    STATUS_ERROR
 
49
    };
 
50
 
 
51
  StatusType Status;
 
52
  std::string CDashVersion;
 
53
  std::string Filename;
 
54
  std::string MD5;
 
55
  std::string Message;
 
56
 
 
57
private:
 
58
 
 
59
  std::vector<char> CurrentValue;
 
60
 
 
61
  std::string GetCurrentValue()
 
62
    {
 
63
    std::string val;
 
64
    if(this->CurrentValue.size())
 
65
      {
 
66
      val.assign(&this->CurrentValue[0], this->CurrentValue.size());
 
67
      }
 
68
    return val;
 
69
    }
 
70
 
 
71
  virtual void StartElement(const char* name, const char** atts)
 
72
    {
 
73
    this->CurrentValue.clear();
 
74
    if(strcmp(name, "cdash") == 0)
 
75
      {
 
76
      this->CDashVersion = this->FindAttribute(atts, "version");
 
77
      }
 
78
    }
 
79
 
 
80
  virtual void CharacterDataHandler(const char* data, int length)
 
81
    {
 
82
    this->CurrentValue.insert(this->CurrentValue.end(), data, data+length);
 
83
    }
 
84
 
 
85
  virtual void EndElement(const char* name)
 
86
    {
 
87
    if(strcmp(name, "status") == 0)
 
88
      {
 
89
      std::string status = cmSystemTools::UpperCase(this->GetCurrentValue());
 
90
      if(status == "OK" || status == "SUCCESS")
 
91
        {
 
92
        this->Status = STATUS_OK;
 
93
        }
 
94
      else if(status == "WARNING")
 
95
        {
 
96
        this->Status = STATUS_WARNING;
 
97
        }
 
98
      else
 
99
        {
 
100
        this->Status = STATUS_ERROR;
 
101
        }
 
102
      }
 
103
    else if(strcmp(name, "filename") == 0)
 
104
      {
 
105
      this->Filename = this->GetCurrentValue();
 
106
      }
 
107
    else if(strcmp(name, "md5") == 0)
 
108
      {
 
109
      this->MD5 = this->GetCurrentValue();
 
110
      }
 
111
    else if(strcmp(name, "message") == 0)
 
112
      {
 
113
      this->Message = this->GetCurrentValue();
 
114
      }
 
115
    }
 
116
};
 
117
 
 
118
 
34
119
static size_t
35
120
cmCTestSubmitHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
36
121
  void *data)
367
452
        = url + ((url.find("?",0) == cmStdString::npos) ? "?" : "&")
368
453
        + "FileName=" + ofile;
369
454
 
 
455
      upload_as += "&MD5=";
 
456
 
 
457
      if(cmSystemTools::IsOn(this->GetOption("InternalTest")))
 
458
        {
 
459
        upload_as += "bad_md5sum";
 
460
        }
 
461
      else
 
462
        {
 
463
        char md5[33];
 
464
        cmSystemTools::ComputeFileMD5(local_file.c_str(), md5);
 
465
        md5[32] = 0;
 
466
        upload_as += md5;
 
467
        }
 
468
 
370
469
      struct stat st;
371
470
      if ( ::stat(local_file.c_str(), &st) )
372
471
        {
382
481
        << local_file.c_str() << " to "
383
482
        << upload_as.c_str() << " Size: " << st.st_size << std::endl);
384
483
 
385
 
 
386
484
      // specify target
387
485
      ::curl_easy_setopt(curl,CURLOPT_URL, upload_as.c_str());
388
486
 
411
509
      // Now run off and do what you've been told!
412
510
      res = ::curl_easy_perform(curl);
413
511
 
 
512
      if(cmSystemTools::IsOn(this->GetOption("InternalTest")) &&
 
513
         cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
 
514
         this->CTest->GetCDashVersion().c_str(), "1.7"))
 
515
        {
 
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"
 
520
          "</cdash>\n";
 
521
        chunk.clear();
 
522
        chunk.assign(mock_output.begin(), mock_output.end());
 
523
        }
 
524
 
414
525
      if ( chunk.size() > 0 )
415
526
        {
416
527
        cmCTestLog(this->CTest, DEBUG, "CURL output: ["
425
536
          << std::endl);
426
537
        }
427
538
 
 
539
      // If curl failed for any reason, or checksum fails, wait and retry
 
540
      //
 
541
      if(res != CURLE_OK || this->HasErrors)
 
542
        {
 
543
        std::string retryDelay = this->GetOption("RetryDelay") == NULL ?
 
544
          "" : this->GetOption("RetryDelay");
 
545
        std::string retryCount = this->GetOption("RetryCount") == NULL ?
 
546
          "" : this->GetOption("RetryCount");
 
547
 
 
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());
 
552
 
 
553
        for(int i = 0; i < count; i++)
 
554
          {
 
555
          cmCTestLog(this->CTest, HANDLER_OUTPUT,
 
556
            "   Submit failed, waiting " << delay << " seconds...\n");
 
557
 
 
558
          double stop = cmSystemTools::GetTime() + delay;
 
559
          while(cmSystemTools::GetTime() < stop)
 
560
            {
 
561
            cmSystemTools::Delay(100);
 
562
            }
 
563
 
 
564
          cmCTestLog(this->CTest, HANDLER_OUTPUT,
 
565
            "   Retry submission: Attempt " << (i + 1) << " of "
 
566
            << count << std::endl);
 
567
 
 
568
          ::fclose(ftpfile);
 
569
          ftpfile = ::fopen(local_file.c_str(), "rb");
 
570
          ::curl_easy_setopt(curl, CURLOPT_INFILE, ftpfile);
 
571
 
 
572
          chunk.clear();
 
573
          chunkDebug.clear();
 
574
          this->HasErrors = false;
 
575
 
 
576
          res = ::curl_easy_perform(curl);
 
577
 
 
578
          if ( chunk.size() > 0 )
 
579
            {
 
580
            cmCTestLog(this->CTest, DEBUG, "CURL output: ["
 
581
              << cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "]"
 
582
              << std::endl);
 
583
            this->ParseResponse(chunk);
 
584
            }
 
585
 
 
586
          if(res == CURLE_OK && !this->HasErrors)
 
587
            {
 
588
            break;
 
589
            }
 
590
          }
 
591
        }
 
592
 
428
593
      fclose(ftpfile);
429
594
      if ( res )
430
595
        {
467
632
::ParseResponse(cmCTestSubmitHandlerVectorOfChar chunk)
468
633
{
469
634
  std::string output = "";
 
635
  output.append(chunk.begin(), chunk.end());
470
636
 
471
 
  for(cmCTestSubmitHandlerVectorOfChar::iterator i = chunk.begin();
472
 
      i != chunk.end(); ++i)
 
637
  if(output.find("<cdash") != output.npos)
473
638
    {
474
 
    output += *i;
 
639
    ResponseParser parser;
 
640
    parser.Parse(output.c_str());
 
641
 
 
642
    if(parser.Status != ResponseParser::STATUS_OK)
 
643
      {
 
644
      this->HasErrors = true;
 
645
      cmCTestLog(this->CTest, HANDLER_OUTPUT, "   Submission failed: " <<
 
646
        parser.Message << std::endl);
 
647
      return;
 
648
      }
475
649
    }
476
650
  output = cmSystemTools::UpperCase(output);
477
 
  
478
651
  if(output.find("WARNING") != std::string::npos)
479
652
    {
480
653
    this->HasWarnings = true;
483
656
    {
484
657
    this->HasErrors = true;
485
658
    }
486
 
  
 
659
 
487
660
  if(this->HasWarnings || this->HasErrors)
488
661
    {
489
662
    cmCTestLog(this->CTest, HANDLER_OUTPUT, "   Server Response:\n" <<
490
663
          cmCTestLogWrite(&*chunk.begin(), chunk.size()) << "\n");
491
664
    }
492
 
  
493
665
}
494
666
 
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
593
765
                       << std::endl
594
766
                       << "   Error message was: " << error_buffer 
595
767
                       << std::endl;