X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPBS%2FTest%2FTest_ePBS.cxx;h=1040faae9374eec5b416cf263acb17e71c30f771;hb=a58d413c34de0d83ba055c56b168ad0657e92a29;hp=19441771cbb1f07952a8c9d2641199bc8f7a1ece;hpb=1827ba2751d7ac527188c3fcd472f4d77f34e719;p=tools%2Flibbatch.git diff --git a/src/PBS/Test/Test_ePBS.cxx b/src/PBS/Test/Test_ePBS.cxx index 1944177..1040faa 100644 --- a/src/PBS/Test/Test_ePBS.cxx +++ b/src/PBS/Test/Test_ePBS.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -40,17 +41,9 @@ #include -#ifdef WIN32 -#include -#define sleep(seconds) Sleep((seconds)*1000) -#define usleep(useconds) Sleep((useconds)/1000) -#endif - using namespace std; using namespace Batch; -const int MAX_SLEEP_TIME = 600; - void print_usage() { cout << "usage: Test_ePBS PROTOCOL" << endl; @@ -97,19 +90,18 @@ int main(int argc, char** argv) Job job; // ... and its parameters ... Parametre p; - p["EXECUTABLE"] = "./test-script.sh"; - p["NAME"] = string("Test_ePBS_") + argv[1]; - p["WORKDIR"] = homedir + "/tmp/Batch"; - p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh"); - p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh"); - p["OUTFILE"] = Couple("result.txt", "tmp/Batch/result.txt"); - p["TMPDIR"] = "tmp/Batch/"; - p["USER"] = user; - p["NBPROC"] = 1; - p["MAXWALLTIME"] = 1; - p["MAXRAMSIZE"] = 1000; - p["HOMEDIR"] = homedir; - p["QUEUE"] = queue; + p[EXECUTABLE] = "./test-script.sh"; + p[NAME] = string("Test_ePBS_") + argv[1]; + p[WORKDIR] = homedir + "/tmp/Batch"; + p[INFILE] = Couple("seta.sh", "tmp/Batch/seta.sh"); + p[INFILE] += Couple("setb.sh", "tmp/Batch/setb.sh"); + p[OUTFILE] = Couple("result.txt", "tmp/Batch/result.txt"); + p[TMPDIR] = "tmp/Batch/"; + p[NBPROC] = 1; + p[MAXWALLTIME] = 1; + p[MAXRAMSIZE] = 1; + p[HOMEDIR] = homedir; + p[QUEUE] = queue; job.setParametre(p); // ... and its environment Environnement e; @@ -122,39 +114,18 @@ int main(int argc, char** argv) // Create a BatchManager of type ePBS on localhost FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS")); - BatchManager_eClient * bm = (*fbm)(host.c_str(), protocol, "lam"); + BatchManager_eClient * bm = (*fbm)(host.c_str(), user.c_str(), protocol, "nompi", 8); // Submit the job to the BatchManager JobId jobid = bm->submitJob(job); cout << jobid.__repr__() << endl; // Wait for the end of the job - int time = 0; - int sleeptime = 1; - bool testTimeout = (timeout > -1); - bool timeoutReached = (testTimeout && time >= timeout); - JobInfo jinfo = jobid.queryJob(); - string state = jinfo.getParametre()["STATE"].str(); - cout << "State is \"" << state << "\""; - while (!timeoutReached && state != "U" && state != "C") { - cout << ", sleeping " << sleeptime << "s..." << endl; - sleep(sleeptime); - time += sleeptime; - timeoutReached = (testTimeout && time >= timeout); - sleeptime *= 2; - if (testTimeout && sleeptime > timeout - time) - sleeptime = timeout - time; - if (sleeptime > MAX_SLEEP_TIME) - sleeptime = MAX_SLEEP_TIME; - jinfo = jobid.queryJob(); - state = jinfo.getParametre()["STATE"].str(); - cout << "State is \"" << state << "\""; - } - cout << endl; + string state = bm->waitForJobEnd(jobid, timeout); - if (state == "U" || state == "C") { + if (state == FINISHED || state == FAILED) { cout << "Job " << jobid.__repr__() << " is done" << endl; - bm->importOutputFiles(job, "."); + bm->importOutputFiles(job, "resultdir/seconddirname"); } else { cerr << "Timeout while executing job" << endl; return 1; @@ -171,7 +142,7 @@ int main(int argc, char** argv) // test the result file try { SimpleParser resultParser; - resultParser.parse("result.txt"); + resultParser.parse("resultdir/seconddirname/result.txt"); cout << "Result:" << endl << resultParser; const string & envvar = resultParser.getValue("MYENVVAR"); int result = resultParser.getValueAsInt("c");