cmCTestBatchTestHandler.cxx 3.6 KB

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