cmCTestBatchTestHandler.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestBatchTestHandler.h"
  11. #include "cmProcess.h"
  12. #include "cmStandardIncludes.h"
  13. #include "cmCTest.h"
  14. #include "cmSystemTools.h"
  15. #include <stdlib.h>
  16. cmCTestBatchTestHandler::~cmCTestBatchTestHandler()
  17. {
  18. }
  19. //---------------------------------------------------------
  20. void cmCTestBatchTestHandler::RunTests()
  21. {
  22. this->WriteBatchScript();
  23. this->SubmitBatchScript();
  24. }
  25. //---------------------------------------------------------
  26. void cmCTestBatchTestHandler::WriteBatchScript()
  27. {
  28. this->Script = this->CTest->GetBinaryDir()
  29. + "/Testing/CTestBatch.txt";
  30. cmsys::ofstream fout;
  31. fout.open(this->Script.c_str());
  32. fout << "#!/bin/sh\n";
  33. for(TestMap::iterator i = this->Tests.begin(); i != this->Tests.end(); ++i)
  34. {
  35. this->WriteSrunArgs(i->first, fout);
  36. this->WriteTestCommand(i->first, fout);
  37. fout << "\n";
  38. }
  39. fout.flush();
  40. fout.close();
  41. }
  42. //---------------------------------------------------------
  43. void cmCTestBatchTestHandler::WriteSrunArgs(int test, cmsys::ofstream& fout)
  44. {
  45. cmCTestTestHandler::cmCTestTestProperties* properties =
  46. this->Properties[test];
  47. fout << "srun ";
  48. //fout << "--jobid=" << test << " ";
  49. fout << "-J=" << properties->Name << " ";
  50. //Write dependency information
  51. /*if(this->Tests[test].size() > 0)
  52. {
  53. fout << "-P=afterany";
  54. for(TestSet::iterator i = this->Tests[test].begin();
  55. i != this->Tests[test].end(); ++i)
  56. {
  57. fout << ":" << *i;
  58. }
  59. fout << " ";
  60. }*/
  61. if(properties->RunSerial)
  62. {
  63. fout << "--exclusive ";
  64. }
  65. if(properties->Processors > 1)
  66. {
  67. fout << "-n" << properties->Processors << " ";
  68. }
  69. }
  70. //---------------------------------------------------------
  71. void cmCTestBatchTestHandler::WriteTestCommand(int test, cmsys::ofstream& fout)
  72. {
  73. std::vector<std::string> args = this->Properties[test]->Args;
  74. std::vector<std::string> processArgs;
  75. std::string command;
  76. command = this->TestHandler->FindTheExecutable(args[1].c_str());
  77. command = cmSystemTools::ConvertToOutputPath(command.c_str());
  78. //Prepends memcheck args to our command string if this is a memcheck
  79. this->TestHandler->GenerateTestCommand(processArgs, test);
  80. processArgs.push_back(command);
  81. for(std::vector<std::string>::iterator arg = processArgs.begin();
  82. arg != processArgs.end(); ++arg)
  83. {
  84. fout << *arg << " ";
  85. }
  86. std::vector<std::string>::iterator i = args.begin();
  87. ++i; //the test name
  88. ++i; //the executable (command)
  89. if(args.size() > 2)
  90. {
  91. fout << "'";
  92. }
  93. while(i != args.end())
  94. {
  95. fout << "\"" << *i << "\""; //args to the test executable
  96. ++i;
  97. if(i == args.end() && args.size() > 2)
  98. {
  99. fout << "'";
  100. }
  101. fout << " ";
  102. }
  103. //TODO ZACH build TestResult.FullCommandLine
  104. //this->TestResult.FullCommandLine = this->TestCommand;
  105. }
  106. //---------------------------------------------------------
  107. void cmCTestBatchTestHandler::SubmitBatchScript()
  108. {
  109. cmProcess sbatch;
  110. std::vector<std::string> args;
  111. args.push_back(this->Script);
  112. args.push_back("-o");
  113. args.push_back(this->CTest->GetBinaryDir()
  114. + "/Testing/CTestBatch.txt");
  115. sbatch.SetCommand("sbatch");
  116. sbatch.SetCommandArguments(args);
  117. /*if(sbatch.StartProcess())
  118. {
  119. //success condition
  120. }
  121. else
  122. {
  123. //fail condition
  124. }*/
  125. }