cmCTestBatchTestHandler.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "cmCTest.h"
  12. #include "cmProcess.h"
  13. #include "cmStandardIncludes.h"
  14. #include "cmSystemTools.h"
  15. #include <stdlib.h>
  16. cmCTestBatchTestHandler::~cmCTestBatchTestHandler()
  17. {
  18. }
  19. void cmCTestBatchTestHandler::RunTests()
  20. {
  21. this->WriteBatchScript();
  22. this->SubmitBatchScript();
  23. }
  24. void cmCTestBatchTestHandler::WriteBatchScript()
  25. {
  26. this->Script = this->CTest->GetBinaryDir()
  27. + "/Testing/CTestBatch.txt";
  28. cmsys::ofstream fout;
  29. fout.open(this->Script.c_str());
  30. fout << "#!/bin/sh\n";
  31. for(TestMap::iterator i = this->Tests.begin(); i != this->Tests.end(); ++i)
  32. {
  33. this->WriteSrunArgs(i->first, fout);
  34. this->WriteTestCommand(i->first, fout);
  35. fout << "\n";
  36. }
  37. fout.flush();
  38. fout.close();
  39. }
  40. void cmCTestBatchTestHandler::WriteSrunArgs(int test, cmsys::ofstream& fout)
  41. {
  42. cmCTestTestHandler::cmCTestTestProperties* properties =
  43. this->Properties[test];
  44. fout << "srun ";
  45. //fout << "--jobid=" << test << " ";
  46. fout << "-J=" << properties->Name << " ";
  47. //Write dependency information
  48. /*if(!this->Tests[test].empty())
  49. {
  50. fout << "-P=afterany";
  51. for(TestSet::iterator i = this->Tests[test].begin();
  52. i != this->Tests[test].end(); ++i)
  53. {
  54. fout << ":" << *i;
  55. }
  56. fout << " ";
  57. }*/
  58. if(properties->RunSerial)
  59. {
  60. fout << "--exclusive ";
  61. }
  62. if(properties->Processors > 1)
  63. {
  64. fout << "-n" << properties->Processors << " ";
  65. }
  66. }
  67. void cmCTestBatchTestHandler::WriteTestCommand(int test, cmsys::ofstream& fout)
  68. {
  69. std::vector<std::string> args = this->Properties[test]->Args;
  70. std::vector<std::string> processArgs;
  71. std::string command;
  72. command = this->TestHandler->FindTheExecutable(args[1].c_str());
  73. command = cmSystemTools::ConvertToOutputPath(command.c_str());
  74. //Prepends memcheck args to our command string if this is a memcheck
  75. this->TestHandler->GenerateTestCommand(processArgs, test);
  76. processArgs.push_back(command);
  77. for(std::vector<std::string>::iterator arg = processArgs.begin();
  78. arg != processArgs.end(); ++arg)
  79. {
  80. fout << *arg << " ";
  81. }
  82. std::vector<std::string>::iterator i = args.begin();
  83. ++i; //the test name
  84. ++i; //the executable (command)
  85. if(args.size() > 2)
  86. {
  87. fout << "'";
  88. }
  89. while(i != args.end())
  90. {
  91. fout << "\"" << *i << "\""; //args to the test executable
  92. ++i;
  93. if(i == args.end() && args.size() > 2)
  94. {
  95. fout << "'";
  96. }
  97. fout << " ";
  98. }
  99. //TODO ZACH build TestResult.FullCommandLine
  100. //this->TestResult.FullCommandLine = this->TestCommand;
  101. }
  102. void cmCTestBatchTestHandler::SubmitBatchScript()
  103. {
  104. cmProcess sbatch;
  105. std::vector<std::string> args;
  106. args.push_back(this->Script);
  107. args.push_back("-o");
  108. args.push_back(this->CTest->GetBinaryDir()
  109. + "/Testing/CTestBatch.txt");
  110. sbatch.SetCommand("sbatch");
  111. sbatch.SetCommandArguments(args);
  112. /*if(sbatch.StartProcess())
  113. {
  114. //success condition
  115. }
  116. else
  117. {
  118. //fail condition
  119. }*/
  120. }