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>
39 #include <Test_PBS_config.h>
42 using namespace Batch;
44 int main(int argc, char** argv)
46 cout << "*******************************************************************************************" << endl;
47 cout << "This program tests the batch submission based on PBS emulation. Passwordless SSH" << endl;
48 cout << "authentication must be used for this test to pass (this can be configured with ssh-agent" << endl;
49 cout << "for instance). You also need to create a directory \"tmp/Batch\" in your home directory on" << endl;
50 cout << "the PBS server before running this test." << endl;
51 cout << "*******************************************************************************************" << endl;
53 // eventually remove any previous result
59 // ... and its parameters ...
61 p["EXECUTABLE"] = "./test-script.sh";
62 p["NAME"] = "Test_ePBS";
63 p["WORKDIR"] = string(TEST_PBS_HOMEDIR) + "/tmp/Batch";
64 p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh");
65 p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh");
66 p["OUTFILE"] = Couple("result.txt", "tmp/Batch/result.txt");
67 p["TMPDIR"] = "tmp/Batch/";
68 p["USER"] = TEST_PBS_USER;
72 p["HOMEDIR"] = TEST_PBS_HOMEDIR;
73 p["QUEUE"] = TEST_PBS_QUEUE;
75 // ... and its environment (SSH_AUTH_SOCK env var is important for ssh agent authentication)
77 const char * sshAuthSock = getenv("SSH_AUTH_SOCK");
78 if (sshAuthSock != NULL) e["SSH_AUTH_SOCK"] = sshAuthSock;
79 job.setEnvironnement(e);
83 BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
85 // Create a BatchManager of type ePBS on localhost
86 FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS"));
87 BatchManager_eClient * bm = (*fbm)(TEST_PBS_HOST, "ssh", "lam");
89 // Submit the job to the BatchManager
90 JobId jobid = bm->submitJob(job);
91 cout << jobid.__repr__() << endl;
93 // Wait for the end of the job
94 string state = "Undefined";
95 for (int i=0 ; i<60 && state != "U"; i++) {
97 JobInfo jinfo = jobid.queryJob();
98 state = jinfo.getParametre()["STATE"].str();
99 cout << "State is \"" << state << "\"" << endl;
103 cout << "Job " << jobid.__repr__() << " is done" << endl;
104 bm->importOutputFiles(job, ".");
106 cerr << "Timeout while executing job" << endl;
110 } catch (GenericException e) {
111 cerr << "Error: " << e << endl;
115 // test the result file
116 string exp = "c = 12";
118 ifstream f("result.txt");
122 cout << "result found : " << res << ", expected : " << exp << endl;