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 int main(int argc, char** argv)
53 cout << "*******************************************************************************************" << endl;
54 cout << "This program tests the batch submission based on PBS emulation with RSH. Passwordless RSH" << endl;
55 cout << "authentication must be used for this test to pass (this can be configured with the .rhosts" << endl;
56 cout << "file). You also need to create a directory \"tmp/Batch\" in your home directory on the PBS" << endl;
57 cout << "server before running this test." << endl;
58 cout << "*******************************************************************************************" << endl;
60 // eventually remove any previous result
64 // Parse the test configuration file
66 parser.parseTestConfigFile();
67 const string & homedir = parser.getValue("TEST_EPBS_HOMEDIR");
68 const string & host = parser.getValue("TEST_EPBS_HOST");
69 const string & user = parser.getValue("TEST_EPBS_USER");
70 const string & queue = parser.getValue("TEST_EPBS_QUEUE");
71 int timeout = parser.getValueAsInt("TEST_EPBS_TIMEOUT");
75 // ... and its parameters ...
77 p["EXECUTABLE"] = "./test-script.sh";
78 p["NAME"] = "Test_ePBS_RSH";
79 p["WORKDIR"] = homedir + "/tmp/Batch";
80 p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh");
81 p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh");
82 p["OUTFILE"] = Couple("result.txt", "tmp/Batch/result.txt");
83 p["TMPDIR"] = "tmp/Batch/";
88 p["HOMEDIR"] = homedir;
91 // ... and its environment (SSH_AUTH_SOCK env var is important for ssh agent authentication)
93 const char * sshAuthSock = getenv("SSH_AUTH_SOCK");
94 if (sshAuthSock != NULL) e["SSH_AUTH_SOCK"] = sshAuthSock;
95 job.setEnvironnement(e);
99 BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
101 // Create a BatchManager of type ePBS on localhost
102 FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS"));
103 BatchManager_eClient * bm = (*fbm)(host.c_str(), RSH, "lam");
105 // Submit the job to the BatchManager
106 JobId jobid = bm->submitJob(job);
107 cout << jobid.__repr__() << endl;
109 // Wait for the end of the job
110 string state = "Undefined";
111 for (int i=0 ; i<timeout/2 && state != "U"; i++) {
113 JobInfo jinfo = jobid.queryJob();
114 state = jinfo.getParametre()["STATE"].str();
115 cout << "State is \"" << state << "\"" << endl;
119 cout << "Job " << jobid.__repr__() << " is done" << endl;
120 bm->importOutputFiles(job, ".");
122 cerr << "Timeout while executing job" << endl;
126 } catch (GenericException e) {
127 cerr << "Error: " << e << endl;
129 } catch (ParserException e) {
130 cerr << "Parser error: " << e.what() << endl;
134 // test the result file
135 string exp = "c = 12";
137 ifstream f("result.txt");
141 cout << "result found : " << res << ", expected : " << exp << endl;