summaryrefslogtreecommitdiffstats
path: root/Source/CTest
diff options
context:
space:
mode:
authorZach Mullen <zach.mullen@kitware.com>2009-09-10 15:18:05 (GMT)
committerZach Mullen <zach.mullen@kitware.com>2009-09-10 15:18:05 (GMT)
commitc57fb18920be6b17e82eca3399df083b811ebe13 (patch)
tree2ad1594e0735dbcdc2f3ca305984c73bcbf0dc6f /Source/CTest
parent4b4e801eba8efe6da7407ec3364b3fd04eb59e81 (diff)
downloadCMake-c57fb18920be6b17e82eca3399df083b811ebe13.zip
CMake-c57fb18920be6b17e82eca3399df083b811ebe13.tar.gz
CMake-c57fb18920be6b17e82eca3399df083b811ebe13.tar.bz2
Added some ctest batch capabilities
Diffstat (limited to 'Source/CTest')
-rw-r--r--Source/CTest/cmCTestBatchTestHandler.cxx119
-rw-r--r--Source/CTest/cmCTestBatchTestHandler.h29
2 files changed, 148 insertions, 0 deletions
diff --git a/Source/CTest/cmCTestBatchTestHandler.cxx b/Source/CTest/cmCTestBatchTestHandler.cxx
new file mode 100644
index 0000000..b7bef5b
--- /dev/null
+++ b/Source/CTest/cmCTestBatchTestHandler.cxx
@@ -0,0 +1,119 @@
+#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"; //fork and continue
+ }
+ fout.flush();
+ fout.close();
+}
+
+//---------------------------------------------------------
+void cmCTestBatchTestHandler::WriteSrunArgs(int test, std::fstream& fout)
+{
+ cmCTestTestHandler::cmCTestTestProperties* properties =
+ this->Properties[test];
+
+ fout << "srun --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)
+ for(; i != args.end(); ++i)
+ {
+ fout << *i << " "; //args to the test executable
+ }
+ //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
+ }
+}
diff --git a/Source/CTest/cmCTestBatchTestHandler.h b/Source/CTest/cmCTestBatchTestHandler.h
new file mode 100644
index 0000000..f0c5c1f
--- /dev/null
+++ b/Source/CTest/cmCTestBatchTestHandler.h
@@ -0,0 +1,29 @@
+#ifndef cmCTestBatchTestHandler_h
+#define cmCTestBatchTestHandler_h
+
+#include <cmStandardIncludes.h>
+#include <cmCTestTestHandler.h>
+#include <cmCTestMultiProcessHandler.h>
+#include <cmCTestRunTest.h>
+
+/** \class cmCTestBatchTestHandler
+ * \brief run parallel ctest
+ *
+ * cmCTestBatchTestHandler
+ */
+class cmCTestBatchTestHandler : public cmCTestMultiProcessHandler
+{
+public:
+ ~cmCTestBatchTestHandler();
+ virtual void RunTests();
+protected:
+ void WriteBatchScript();
+ void WriteSrunArgs(int test, std::fstream& fout);
+ void WriteTestCommand(int test, std::fstream& fout);
+
+ void SubmitBatchScript();
+
+ std::string Script;
+};
+
+#endif