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
23 * Test_Local_RSH.cxx :
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_BatchManager.hxx>
38 #include <SimpleParser.hxx>
42 #define sleep(seconds) Sleep((seconds)*1000)
43 #define usleep(useconds) Sleep((useconds)/1000)
47 using namespace Batch;
49 int main(int argc, char** argv)
51 cout << "*******************************************************************************************" << endl;
52 cout << "This program tests the local batch submission based on RSH. Passwordless RSH authentication" << endl;
53 cout << "must be used for this test to pass (this can be configured with the .rhosts file)." << endl;
54 cout << "*******************************************************************************************" << endl;
56 // eventually remove any previous result
60 // Parse the test configuration file
62 parser.parseTestConfigFile();
63 const string & workdir = parser.getValue("TEST_LOCAL_RSH_WORK_DIR");
64 const string & exechost = parser.getValue("TEST_LOCAL_RSH_EXECUTION_HOST");
65 const string & user = parser.getValue("TEST_LOCAL_RSH_USER");
66 int timeout = parser.getValueAsInt("TEST_LOCAL_RSH_TIMEOUT");
67 int finalizationTime = parser.getValueAsInt("TEST_LOCAL_RSH_FINALIZATION_TIME");
71 // ... and its parameters ...
73 p["EXECUTABLE"] = "source copied-test-script.sh";
74 p["NAME"] = "Test_Local_RSH";
75 p["WORKDIR"] = workdir;
76 p["INFILE"] = Couple("seta.sh", "copied-seta.sh");
77 p["INFILE"] += Couple("setb.sh", "copied-setb.sh");
78 p["INFILE"] += Couple("test-script.sh", "copied-test-script.sh");
79 p["OUTFILE"] = Couple("result.txt", "orig-result.txt");
80 p["EXECUTIONHOST"] = exechost;
83 // ... and its environment
85 job.setEnvironnement(e);
89 BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
91 // Create a BatchManager of type Local_RSH on localhost
92 FactBatchManager * fbm = c("RSH");
94 cerr << "Can't get RSH batch manager factory" << endl;
97 BatchManager * bm = (*fbm)("localhost");
99 // Submit the job to the BatchManager
100 JobId jobid = bm->submitJob(job);
101 cout << jobid.__repr__() << endl;
103 // Wait for the end of the job
104 string state = "Unknown";
105 for (int i=0 ; i<timeout*10 && state != FINISHED && state != FAILED ; i++) {
107 Versatile paramState = jobid.queryJob().getParametre()["STATE"];
108 state = (paramState.size() > 0) ? paramState.str() : "Unknown";
109 cout << "Job state is: " << state << endl;
112 if (state != FINISHED && state != FAILED) {
113 cerr << "Error: Job not finished after timeout" << endl;
117 cout << "Job " << jobid.__repr__() << " is done" << endl;
119 // wait for the copy of output files and the cleanup
120 // (there's no cleaner way to do that yet)
121 sleep(finalizationTime);
123 } catch (GenericException e) {
124 cerr << "Error: " << e << endl;
126 } catch (ParserException e) {
127 cerr << "Parser error: " << e.what() << endl;
131 // test the result file
132 string exp = "c = 12";
134 ifstream f("result.txt");
138 cout << "result found : " << res << ", expected : " << exp << endl;