1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 * Author : Renaud BARATE - EDF R&D
34 #include <Batch_Constants.hxx>
35 #include <Batch_Job.hxx>
36 #include <Batch_BatchManagerCatalog.hxx>
37 #include <Batch_FactBatchManager.hxx>
38 #include <Batch_BatchManager.hxx>
40 #include <SimpleParser.hxx>
43 using namespace Batch;
47 cout << "usage: Test_ePBS PROTOCOL" << endl;
48 cout << " PROTOCOL \"SSH\" or \"RSH\"" << endl;
51 int main(int argc, char** argv)
58 CommunicationProtocolType protocol;
59 if (strcmp(argv[1], "SSH") == 0)
61 else if (strcmp(argv[1], "RSH") == 0)
68 cout << "*******************************************************************************************" << endl;
69 cout << "This program tests the batch submission based on PBS emulation. Passwordless authentication" << endl;
70 cout << "must be used for this test to pass. For SSH, this can be configured with ssh-agent for" << endl;
71 cout << "instance. For RSH, this can be configured with the .rhosts file." << endl;
72 cout << "*******************************************************************************************" << endl;
74 // eventually remove any previous result
78 // Parse the test configuration file
80 parser.parseTestConfigFile();
81 const string & homedir = parser.getValue("TEST_EPBS_HOMEDIR");
82 const string & host = parser.getValue("TEST_EPBS_HOST");
83 const string & user = parser.getValue("TEST_EPBS_USER");
84 const string & queue = parser.getValue("TEST_EPBS_QUEUE");
85 int timeout = parser.getValueAsInt("TEST_EPBS_TIMEOUT");
89 // ... and its parameters ...
91 p[EXECUTABLE] = "./test-script.sh";
92 p[NAME] = string("Test_ePBS_") + argv[1];
93 p[WORKDIR] = homedir + "/tmp/Batch";
94 p[INFILE] = Couple("seta.sh", "tmp/Batch/seta.sh");
95 p[INFILE] += Couple("setb.sh", "tmp/Batch/setb.sh");
96 p[OUTFILE] = Couple("result.txt", "tmp/Batch/result.txt");
100 p[HOMEDIR] = homedir;
103 // ... and its environment
105 e["MYENVVAR"] = "MYVALUE";
106 job.setEnvironnement(e);
110 BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
112 // Create a BatchManager of type ePBS on localhost
113 FactBatchManager * fbm = c("PBS");
114 BatchManager * bm = (*fbm)(host.c_str(), user.c_str(), protocol, "nompi", 8);
116 // Submit the job to the BatchManager
117 JobId jobid = bm->submitJob(job);
118 cout << jobid.__repr__() << endl;
120 // Wait for the end of the job
121 string state = bm->waitForJobEnd(jobid, timeout);
123 if (state == FINISHED || state == FAILED) {
124 cout << "Job " << jobid.__repr__() << " is done" << endl;
125 bm->importOutputFiles(job, "resultdir/seconddirname");
127 cerr << "Timeout while executing job" << endl;
131 } catch (GenericException e) {
132 cerr << "Error: " << e << endl;
134 } catch (ParserException e) {
135 cerr << "Parser error: " << e.what() << endl;
139 // test the result file
141 SimpleParser resultParser;
142 resultParser.parse("resultdir/seconddirname/result.txt");
143 cout << "Result:" << endl << resultParser;
144 const string & envvar = resultParser.getValue("MYENVVAR");
145 int result = resultParser.getValueAsInt("c");
146 if (envvar == "MYVALUE" && result == 12) {
147 cout << "OK, Expected result found." << endl;
150 cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl;
153 } catch (ParserException e) {
154 cerr << "Parser error on result file: " << e.what() << endl;