~ubuntu-branches/ubuntu/utopic/cmake/utopic

« back to all changes in this revision

Viewing changes to Source/CTest/cmCTestMemCheckHandler.cxx

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-10-10 12:54:39 UTC
  • mfrom: (1.14.7)
  • Revision ID: package-import@ubuntu.com-20131010125439-h0ahaj004on6oj92
Tags: 2.8.12-0ubuntu1
New upstream release LP: #1246701

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
  {0,0}
44
44
};
45
45
 
46
 
// parse the xml file storing the installed version of Xcode on
47
 
// the machine
 
46
// parse the xml file containing the results of last BoundsChecker run
48
47
class cmBoundsCheckerParser : public cmXMLParser
49
48
{
50
49
public:
201
200
  this->CustomMaximumPassedTestOutputSize = 0;
202
201
  this->CustomMaximumFailedTestOutputSize = 0;
203
202
  this->MemoryTester = "";
 
203
  this->MemoryTesterDynamicOptions.clear();
204
204
  this->MemoryTesterOptions.clear();
205
205
  this->MemoryTesterStyle = UNKNOWN;
206
206
  this->MemoryTesterOutputFile = "";
243
243
 
244
244
//----------------------------------------------------------------------
245
245
void cmCTestMemCheckHandler::GenerateTestCommand(
246
 
  std::vector<std::string>& args)
 
246
  std::vector<std::string>& args, int test)
247
247
{
248
248
  std::vector<cmStdString>::size_type pp;
249
 
  std::string memcheckcommand = "";
250
 
  memcheckcommand
 
249
  cmStdString index;
 
250
  cmOStringStream stream;
 
251
  std::string memcheckcommand
251
252
    = cmSystemTools::ConvertToOutputPath(this->MemoryTester.c_str());
 
253
  stream << test;
 
254
  index = stream.str();
 
255
  for ( pp = 0; pp < this->MemoryTesterDynamicOptions.size(); pp ++ )
 
256
    {
 
257
    cmStdString arg = this->MemoryTesterDynamicOptions[pp];
 
258
    cmStdString::size_type pos = arg.find("??");
 
259
    if (pos != cmStdString::npos)
 
260
      {
 
261
      arg.replace(pos, 2, index);
 
262
      }
 
263
    args.push_back(arg);
 
264
    memcheckcommand += " \"";
 
265
    memcheckcommand += arg;
 
266
    memcheckcommand += "\"";
 
267
    }
252
268
  for ( pp = 0; pp < this->MemoryTesterOptions.size(); pp ++ )
253
269
    {
254
270
    args.push_back(this->MemoryTesterOptions[pp]);
461
477
    return false;
462
478
    }
463
479
 
464
 
  if ( this->MemoryTester[0] == '\"' &&
465
 
    this->MemoryTester[this->MemoryTester.size()-1] == '\"' )
466
 
    {
467
 
    this->MemoryTester
468
 
      = this->MemoryTester.substr(1, this->MemoryTester.size()-2);
469
 
    }
470
 
 
471
480
  // Setup the options
472
481
  std::string memoryTesterOptions;
473
482
  if ( this->CTest->GetCTestConfiguration(
486
495
    = cmSystemTools::ParseArguments(memoryTesterOptions.c_str());
487
496
 
488
497
  this->MemoryTesterOutputFile
489
 
    = this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.log";
 
498
    = this->CTest->GetBinaryDir()
 
499
    + "/Testing/Temporary/MemoryChecker.??.log";
490
500
 
491
501
  switch ( this->MemoryTesterStyle )
492
502
    {
493
503
    case cmCTestMemCheckHandler::VALGRIND:
 
504
      {
494
505
      if ( this->MemoryTesterOptions.empty() )
495
506
        {
496
507
        this->MemoryTesterOptions.push_back("-q");
497
508
        this->MemoryTesterOptions.push_back("--tool=memcheck");
498
509
        this->MemoryTesterOptions.push_back("--leak-check=yes");
499
510
        this->MemoryTesterOptions.push_back("--show-reachable=yes");
500
 
        this->MemoryTesterOptions.push_back("--workaround-gcc296-bugs=yes");
501
511
        this->MemoryTesterOptions.push_back("--num-callers=50");
502
512
        }
503
513
      if ( this->CTest->GetCTestConfiguration(
516
526
          + this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
517
527
        this->MemoryTesterOptions.push_back(suppressions);
518
528
        }
 
529
      std::string outputFile = "--log-file="
 
530
        + this->MemoryTesterOutputFile;
 
531
      this->MemoryTesterDynamicOptions.push_back(outputFile);
519
532
      break;
 
533
      }
520
534
    case cmCTestMemCheckHandler::PURIFY:
521
535
      {
522
536
      std::string outputFile;
542
556
      outputFile = "-log-file=";
543
557
#endif
544
558
      outputFile += this->MemoryTesterOutputFile;
545
 
      this->MemoryTesterOptions.push_back(outputFile);
 
559
      this->MemoryTesterDynamicOptions.push_back(outputFile);
546
560
      break;
547
561
      }
548
562
    case cmCTestMemCheckHandler::BOUNDS_CHECKER:
549
563
      {
550
564
      this->BoundsCheckerXMLFile = this->MemoryTesterOutputFile;
551
565
      std::string dpbdFile = this->CTest->GetBinaryDir()
552
 
        + "/Testing/Temporary/MemoryChecker.DPbd";
 
566
        + "/Testing/Temporary/MemoryChecker.??.DPbd";
553
567
      this->BoundsCheckerDPBDFile = dpbdFile;
554
 
      this->MemoryTesterOptions.push_back("/B");
555
 
      this->MemoryTesterOptions.push_back(dpbdFile);
556
 
      this->MemoryTesterOptions.push_back("/X");
557
 
      this->MemoryTesterOptions.push_back(this->MemoryTesterOutputFile);
 
568
      this->MemoryTesterDynamicOptions.push_back("/B");
 
569
      this->MemoryTesterDynamicOptions.push_back(dpbdFile);
 
570
      this->MemoryTesterDynamicOptions.push_back("/X");
 
571
      this->MemoryTesterDynamicOptions.push_back(this->MemoryTesterOutputFile);
558
572
      this->MemoryTesterOptions.push_back("/M");
559
573
      break;
560
574
      }
902
916
// This method puts the bounds checker output file into the output
903
917
// for the test
904
918
void
905
 
cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res)
 
919
cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res,
 
920
                                                     int test)
906
921
{
907
922
  cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
908
923
             "PostProcessBoundsCheckerTest for : "
909
924
             << res.Name.c_str() << std::endl);
910
 
  if ( !cmSystemTools::FileExists(this->MemoryTesterOutputFile.c_str()) )
 
925
  cmStdString ofile = testOutputFileName(test);
 
926
  if ( ofile.empty() )
911
927
    {
912
 
    std::string log = "Cannot find memory tester output file: "
913
 
      + this->MemoryTesterOutputFile;
914
 
    cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
915
928
    return;
916
929
    }
917
930
  // put a scope around this to close ifs so the file can be removed
918
931
  {
919
 
  std::ifstream ifs(this->MemoryTesterOutputFile.c_str());
 
932
  std::ifstream ifs(ofile.c_str());
920
933
  if ( !ifs )
921
934
    {
922
 
    std::string log = "Cannot read memory tester output file: "
923
 
      + this->MemoryTesterOutputFile;
 
935
    std::string log = "Cannot read memory tester output file: " + ofile;
924
936
    cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
925
937
    return;
926
938
    }
943
955
}
944
956
 
945
957
void
946
 
cmCTestMemCheckHandler::PostProcessPurifyTest(cmCTestTestResult& res)
 
958
cmCTestMemCheckHandler::PostProcessPurifyTest(cmCTestTestResult& res,
 
959
                                              int test)
947
960
{
948
961
  cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
949
962
             "PostProcessPurifyTest for : "
950
963
             << res.Name.c_str() << std::endl);
951
 
  if ( !cmSystemTools::FileExists(this->MemoryTesterOutputFile.c_str()) )
 
964
  appendMemTesterOutput(res, test);
 
965
}
 
966
 
 
967
void
 
968
cmCTestMemCheckHandler::PostProcessValgrindTest(cmCTestTestResult& res,
 
969
                                                int test)
 
970
{
 
971
  cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
 
972
             "PostProcessValgrindTest for : "
 
973
             << res.Name.c_str() << std::endl);
 
974
  appendMemTesterOutput(res, test);
 
975
}
 
976
 
 
977
void
 
978
cmCTestMemCheckHandler::appendMemTesterOutput(cmCTestTestResult& res,
 
979
                                              int test)
 
980
{
 
981
  cmStdString ofile = testOutputFileName(test);
 
982
 
 
983
  if ( ofile.empty() )
952
984
    {
953
 
    std::string log = "Cannot find memory tester output file: "
954
 
      + this->MemoryTesterOutputFile;
955
 
    cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
956
985
    return;
957
986
    }
958
 
  std::ifstream ifs(this->MemoryTesterOutputFile.c_str());
 
987
  std::ifstream ifs(ofile.c_str());
959
988
  if ( !ifs )
960
989
    {
961
 
    std::string log = "Cannot read memory tester output file: "
962
 
      + this->MemoryTesterOutputFile;
 
990
    std::string log = "Cannot read memory tester output file: " + ofile;
963
991
    cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
964
992
    return;
965
993
    }
970
998
    res.Output += "\n";
971
999
    }
972
1000
}
 
1001
 
 
1002
cmStdString
 
1003
cmCTestMemCheckHandler::testOutputFileName(int test)
 
1004
{
 
1005
  cmStdString index;
 
1006
  cmOStringStream stream;
 
1007
  stream << test;
 
1008
  index = stream.str();
 
1009
  cmStdString ofile = this->MemoryTesterOutputFile;
 
1010
  cmStdString::size_type pos = ofile.find("??");
 
1011
  ofile.replace(pos, 2, index);
 
1012
 
 
1013
  if ( !cmSystemTools::FileExists(ofile.c_str()) )
 
1014
    {
 
1015
    std::string log = "Cannot find memory tester output file: "
 
1016
      + ofile;
 
1017
    cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl);
 
1018
    ofile = "";
 
1019
    }
 
1020
 
 
1021
  return ofile;
 
1022
}