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_BatchManager.hxx>
37 #include <Test_Local_config.h>
40 using namespace Batch;
42 int main(int argc, char** argv)
44 cout << "*******************************************************************************************" << endl;
45 cout << "This program tests the local batch submission based on SH. No specific configuration is" << endl;
46 cout << "needed for this test." << endl;
47 cout << "*******************************************************************************************" << endl;
49 // eventually remove any previous result
55 // ... and its parameters ...
57 p["EXECUTABLE"] = "./copied-test-script.sh";
58 p["NAME"] = "Test_Local_SH";
59 p["WORKDIR"] = "/tmp";
60 p["INFILE"] = Couple("seta.sh", "copied-seta.sh");
61 p["INFILE"] += Couple("setb.sh", "copied-setb.sh");
62 p["INFILE"] += Couple("test-script.sh", "copied-test-script.sh");
63 p["OUTFILE"] = Couple("result.txt", "orig-result.txt");
65 // ... and its environment
67 job.setEnvironnement(e);
71 BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
73 // Create a BatchManager of type Local_SH on localhost
74 FactBatchManager * fbm = c("SH");
75 BatchManager * bm = (*fbm)("localhost");
77 // Submit the job to the BatchManager
78 JobId jobid = bm->submitJob(job);
79 cout << jobid.__repr__() << endl;
81 // Wait for the end of the job
82 string state = "Unknown";
83 for (int i=0 ; i<10 && state != "Done" ; i++) {
85 Versatile paramState = jobid.queryJob().getParametre()["STATE"];
86 state = (paramState.size() > 0) ? paramState.str() : "Unknown";
87 cout << "Job state is: " << state << endl;
90 if (state != "Done") {
91 cerr << "Error: Job not finished after timeout" << endl;
95 cout << "Job " << jobid.__repr__() << " is done" << endl;
97 } catch (GenericException e) {
98 cerr << "Error: " << e << endl;
102 // wait for 2 more seconds for the copy of output files and the cleanup
103 // (there's no cleaner way to do that yet)
106 // test the result file
107 string exp = "c = 12";
109 ifstream f("result.txt");
113 cout << "result found : " << res << ", expected : " << exp << endl;