cmCTestBatchTestHandler.cxx 3.5 KB

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