cmCTestBatchTestHandler.cxx 3.1 KB

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