cmCTestBatchTestHandler.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 (auto const& t : this->Tests) {
  27. this->WriteSrunArgs(t.first, fout);
  28. this->WriteTestCommand(t.first, fout);
  29. fout << "\n";
  30. }
  31. fout.flush();
  32. fout.close();
  33. }
  34. void cmCTestBatchTestHandler::WriteSrunArgs(int test, std::ostream& fout)
  35. {
  36. cmCTestTestHandler::cmCTestTestProperties* properties =
  37. this->Properties[test];
  38. fout << "srun ";
  39. // fout << "--jobid=" << test << " ";
  40. fout << "-J=" << properties->Name << " ";
  41. // Write dependency information
  42. /*if(!this->Tests[test].empty())
  43. {
  44. fout << "-P=afterany";
  45. for(TestSet::iterator i = this->Tests[test].begin();
  46. i != this->Tests[test].end(); ++i)
  47. {
  48. fout << ":" << *i;
  49. }
  50. fout << " ";
  51. }*/
  52. if (properties->RunSerial) {
  53. fout << "--exclusive ";
  54. }
  55. if (properties->Processors > 1) {
  56. fout << "-n" << properties->Processors << " ";
  57. }
  58. }
  59. void cmCTestBatchTestHandler::WriteTestCommand(int test, std::ostream& fout)
  60. {
  61. std::vector<std::string> args = this->Properties[test]->Args;
  62. std::vector<std::string> processArgs;
  63. std::string command;
  64. command = this->TestHandler->FindTheExecutable(args[1].c_str());
  65. command = cmSystemTools::ConvertToOutputPath(command.c_str());
  66. // Prepends memcheck args to our command string if this is a memcheck
  67. this->TestHandler->GenerateTestCommand(processArgs, test);
  68. processArgs.push_back(command);
  69. for (std::string const& arg : processArgs) {
  70. fout << arg << " ";
  71. }
  72. std::vector<std::string>::iterator i = args.begin();
  73. ++i; // the test name
  74. ++i; // the executable (command)
  75. if (args.size() > 2) {
  76. fout << "'";
  77. }
  78. while (i != args.end()) {
  79. fout << "\"" << *i << "\""; // args to the test executable
  80. ++i;
  81. if (i == args.end() && args.size() > 2) {
  82. fout << "'";
  83. }
  84. fout << " ";
  85. }
  86. // TODO ZACH build TestResult.FullCommandLine
  87. // this->TestResult.FullCommandLine = this->TestCommand;
  88. }
  89. void cmCTestBatchTestHandler::SubmitBatchScript()
  90. {
  91. cmProcess sbatch;
  92. std::vector<std::string> args;
  93. args.push_back(this->Script);
  94. args.push_back("-o");
  95. args.push_back(this->CTest->GetBinaryDir() + "/Testing/CTestBatch.txt");
  96. sbatch.SetCommand("sbatch");
  97. sbatch.SetCommandArguments(args);
  98. /*if(sbatch.StartProcess())
  99. {
  100. //success condition
  101. }
  102. else
  103. {
  104. //fail condition
  105. }*/
  106. }