summaryrefslogtreecommitdiff
path: root/Source/CTest/cmCTestBatchTestHandler.cxx
blob: 65566f7d172bcf2bdc5067a80531385c42d42105 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "cmCTestBatchTestHandler.h"
#include "cmProcess.h"
#include "cmStandardIncludes.h"
#include "cmCTest.h"
#include "cmSystemTools.h"
#include <stdlib.h>

cmCTestBatchTestHandler::~cmCTestBatchTestHandler()
{
}

//---------------------------------------------------------
void cmCTestBatchTestHandler::RunTests()
{
  this->WriteBatchScript();
  //this->SubmitBatchScript();
}

//---------------------------------------------------------
void cmCTestBatchTestHandler::WriteBatchScript()
{
  this->Script = this->CTest->GetBinaryDir()
    + "/Testing/CTestBatch.txt";
  std::fstream fout;
  fout.open(this->Script.c_str(), std::ios::out);
  fout << "#!/bin/sh\n";

  for(TestMap::iterator i = this->Tests.begin(); i != this->Tests.end(); ++i)
    {
    this->WriteSrunArgs(i->first, fout);
    this->WriteTestCommand(i->first, fout);
    fout << "\n";
    }
  fout.flush();
  fout.close();
}

//---------------------------------------------------------
void cmCTestBatchTestHandler::WriteSrunArgs(int test, std::fstream& fout)
{
  cmCTestTestHandler::cmCTestTestProperties* properties =
      this->Properties[test];

  fout << "srun ";
  //fout << "--jobid=" << test << " ";
  fout << "-J=" << properties->Name << " ";
 
  //Write dependency information
  /*if(this->Tests[test].size() > 0)
    {
      fout << "-P=afterany";
      for(TestSet::iterator i = this->Tests[test].begin();
          i != this->Tests[test].end(); ++i)
        {
          fout << ":" << *i;
        }
      fout << " ";
    }*/
  if(properties->RunSerial)
    {
    fout << "--exclusive ";
    }
  if(properties->Processors > 1)
    {
    fout << "-n" << properties->Processors << " ";
    }
}

//---------------------------------------------------------
void cmCTestBatchTestHandler::WriteTestCommand(int test, std::fstream& fout)
{
  std::vector<std::string> args = this->Properties[test]->Args;
  std::vector<std::string> processArgs;
  std::string command;

  command = this->TestHandler->FindTheExecutable(args[1].c_str());
  command = cmSystemTools::ConvertToOutputPath(command.c_str());

  //Prepends memcheck args to our command string if this is a memcheck
  this->TestHandler->GenerateTestCommand(processArgs);
  processArgs.push_back(command);

  for(std::vector<std::string>::iterator arg = processArgs.begin();
      arg != processArgs.end(); ++arg)
    {
    fout << *arg << " ";
    }

  std::vector<std::string>::iterator i = args.begin();
  ++i; //the test name
  ++i; //the executable (command)
  if(args.size() > 2)
    {
    fout << "'";
    }
  while(i != args.end())
    {
    fout << "\"" << *i << "\""; //args to the test executable
    ++i;

    if(i == args.end() && args.size() > 2)
      {
      fout << "'";
      }
    fout << " ";
    }
  //TODO ZACH build TestResult.FullCommandLine
  //this->TestResult.FullCommandLine = this->TestCommand;
}

//---------------------------------------------------------
void cmCTestBatchTestHandler::SubmitBatchScript()
{
  cmProcess sbatch;
  std::vector<std::string> args;
  args.push_back(this->Script);
  args.push_back("-o");
  args.push_back(this->CTest->GetBinaryDir()
                 + "/Testing/CTestBatchOutput.txt");

  sbatch.SetCommand("sbatch");
  sbatch.SetCommandArguments(args);
  if(sbatch.StartProcess())
    {
      //success condition
    }
  else
    {
      //fail condition
    }
}