1 // Copyright (C) 2007-2008 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
33 #include <Batch_Job.hxx>
34 #include <Batch_BatchManagerCatalog.hxx>
35 #include <Batch_FactBatchManager.hxx>
36 #include <Batch_FactBatchManager_eClient.hxx>
37 #include <Batch_BatchManager.hxx>
38 #include <Batch_BatchManager_eClient.hxx>
40 #include <SimpleParser.hxx>
44 #define sleep(seconds) Sleep((seconds)*1000)
45 #define usleep(useconds) Sleep((useconds)/1000)
49 using namespace Batch;
51 const int MAX_SLEEP_TIME = 600;
55 cout << "usage: Test_ePBS PROTOCOL" << endl;
56 cout << " PROTOCOL \"SSH\" or \"RSH\"" << endl;
59 int main(int argc, char** argv)
66 CommunicationProtocolType protocol;
67 if (strcmp(argv[1], "SSH") == 0)
69 else if (strcmp(argv[1], "RSH") == 0)
76 cout << "*******************************************************************************************" << endl;
77 cout << "This program tests the batch submission based on PBS emulation. Passwordless authentication" << endl;
78 cout << "must be used for this test to pass. For SSH, this can be configured with ssh-agent for" << endl;
79 cout << "instance. For RSH, this can be configured with the .rhosts file." << endl;
80 cout << "*******************************************************************************************" << endl;
82 // eventually remove any previous result
86 // Parse the test configuration file
88 parser.parseTestConfigFile();
89 const string & homedir = parser.getValue("TEST_EPBS_HOMEDIR");
90 const string & host = parser.getValue("TEST_EPBS_HOST");
91 const string & user = parser.getValue("TEST_EPBS_USER");
92 const string & queue = parser.getValue("TEST_EPBS_QUEUE");
93 int timeout = parser.getValueAsInt("TEST_EPBS_TIMEOUT");
97 // ... and its parameters ...
99 p["EXECUTABLE"] = "./test-script.sh";
100 p["NAME"] = string("Test_ePBS_") + argv[1];
101 p["WORKDIR"] = homedir + "/tmp/Batch";
102 p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh");
103 p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh");
104 p["OUTFILE"] = Couple("result.txt", "tmp/Batch/result.txt");
105 p["TMPDIR"] = "tmp/Batch/";
108 p["MAXWALLTIME"] = 1;
109 p["MAXRAMSIZE"] = 1000;
110 p["HOMEDIR"] = homedir;
113 // ... and its environment
115 e["MYENVVAR"] = "MYVALUE";
116 job.setEnvironnement(e);
120 BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
122 // Create a BatchManager of type ePBS on localhost
123 FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS"));
124 BatchManager_eClient * bm = (*fbm)(host.c_str(), protocol, "lam");
126 // Submit the job to the BatchManager
127 JobId jobid = bm->submitJob(job);
128 cout << jobid.__repr__() << endl;
130 // Wait for the end of the job
133 bool testTimeout = (timeout > -1);
134 bool timeoutReached = (testTimeout && time >= timeout);
135 JobInfo jinfo = jobid.queryJob();
136 string state = jinfo.getParametre()["STATE"].str();
137 cout << "State is \"" << state << "\"";
138 while (!timeoutReached && state != "U" && state != "C") {
139 cout << ", sleeping " << sleeptime << "s..." << endl;
142 timeoutReached = (testTimeout && time >= timeout);
144 if (testTimeout && sleeptime > timeout - time)
145 sleeptime = timeout - time;
146 if (sleeptime > MAX_SLEEP_TIME)
147 sleeptime = MAX_SLEEP_TIME;
148 jinfo = jobid.queryJob();
149 state = jinfo.getParametre()["STATE"].str();
150 cout << "State is \"" << state << "\"";
154 if (state == "U" || state == "C") {
155 cout << "Job " << jobid.__repr__() << " is done" << endl;
156 bm->importOutputFiles(job, ".");
158 cerr << "Timeout while executing job" << endl;
162 } catch (GenericException e) {
163 cerr << "Error: " << e << endl;
165 } catch (ParserException e) {
166 cerr << "Parser error: " << e.what() << endl;
170 // test the result file
172 SimpleParser resultParser;
173 resultParser.parse("result.txt");
174 cout << "Result:" << endl << resultParser;
175 const string & envvar = resultParser.getValue("MYENVVAR");
176 int result = resultParser.getValueAsInt("c");
177 if (envvar == "MYVALUE" && result == 12) {
178 cout << "OK, Expected result found." << endl;
181 cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl;
184 } catch (ParserException e) {
185 cerr << "Parser error on result file: " << e.what() << endl;