X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPBS%2FTest%2FTest_ePBS.cxx;h=1040faae9374eec5b416cf263acb17e71c30f771;hb=a58d413c34de0d83ba055c56b168ad0657e92a29;hp=a5bf92c0453980a290d0de0081a02bdc9fe31d16;hpb=f52e8524c7f4ba4849499d6fd1ec99b372acc0f0;p=tools%2Flibbatch.git diff --git a/src/PBS/Test/Test_ePBS.cxx b/src/PBS/Test/Test_ePBS.cxx index a5bf92c..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 @@ -29,52 +29,83 @@ #include #include +#include +#include #include #include #include #include #include #include -#include + +#include using namespace std; using namespace Batch; +void print_usage() +{ + cout << "usage: Test_ePBS PROTOCOL" << endl; + cout << " PROTOCOL \"SSH\" or \"RSH\"" << endl; +} + int main(int argc, char** argv) { + // Parse argument + if (argc != 2) { + print_usage(); + return 1; + } + CommunicationProtocolType protocol; + if (strcmp(argv[1], "SSH") == 0) + protocol = SSH; + else if (strcmp(argv[1], "RSH") == 0) + protocol = RSH; + else { + print_usage(); + return 1; + } + cout << "*******************************************************************************************" << endl; - cout << "This program tests the batch submission based on PBS emulation. Passwordless SSH" << endl; - cout << "authentication must be used for this test to pass (this can be configured with ssh-agent" << endl; - cout << "for instance). You also need to create a directory \"tmp/Batch\" in your home directory on" << endl; - cout << "the PBS server before running this test." << endl; + cout << "This program tests the batch submission based on PBS emulation. Passwordless authentication" << endl; + cout << "must be used for this test to pass. For SSH, this can be configured with ssh-agent for" << endl; + cout << "instance. For RSH, this can be configured with the .rhosts file." << endl; cout << "*******************************************************************************************" << endl; // eventually remove any previous result remove("result.txt"); try { + // Parse the test configuration file + SimpleParser parser; + parser.parseTestConfigFile(); + const string & homedir = parser.getValue("TEST_EPBS_HOMEDIR"); + const string & host = parser.getValue("TEST_EPBS_HOST"); + const string & user = parser.getValue("TEST_EPBS_USER"); + const string & queue = parser.getValue("TEST_EPBS_QUEUE"); + int timeout = parser.getValueAsInt("TEST_EPBS_TIMEOUT"); + // Define the job... Job job; // ... and its parameters ... Parametre p; - p["EXECUTABLE"] = "./test-script.sh"; - p["NAME"] = "Test_ePBS"; - p["WORKDIR"] = string(TEST_PBS_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"] = TEST_PBS_USER; - p["NBPROC"] = 1; - p["MAXWALLTIME"] = 1; - p["MAXRAMSIZE"] = 4; - p["HOMEDIR"] = TEST_PBS_HOMEDIR; - p["QUEUE"] = TEST_PBS_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 (SSH_AUTH_SOCK env var is important for ssh agent authentication) + // ... and its environment Environnement e; - e["SSH_AUTH_SOCK"] = getenv("SSH_AUTH_SOCK"); + e["MYENVVAR"] = "MYVALUE"; job.setEnvironnement(e); cout << job << endl; @@ -83,44 +114,47 @@ 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)(TEST_PBS_HOST, "ssh", "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 - string state = "Undefined"; - for (int i=0 ; i<10 && state != "U"; i++) { - sleep(2); - JobInfo jinfo = jobid.queryJob(); - state = jinfo.getParametre()["STATE"].str(); - cout << "State is \"" << state << "\"" << endl; - } + string state = bm->waitForJobEnd(jobid, timeout); - if (state == "U") { + 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; } } catch (GenericException e) { - cerr << "Batch library exception of type " << e.type << ": " << e.message << endl; + cerr << "Error: " << e << endl; + return 1; + } catch (ParserException e) { + cerr << "Parser error: " << e.what() << endl; + return 1; } // test the result file - string exp = "c = 12"; - string res; - ifstream f("result.txt"); - getline(f, res); - f.close(); - - cout << "result found : " << res << ", expected : " << exp << endl; - - if (res == exp) - return 0; - else + try { + SimpleParser resultParser; + resultParser.parse("resultdir/seconddirname/result.txt"); + cout << "Result:" << endl << resultParser; + const string & envvar = resultParser.getValue("MYENVVAR"); + int result = resultParser.getValueAsInt("c"); + if (envvar == "MYVALUE" && result == 12) { + cout << "OK, Expected result found." << endl; + return 0; + } else { + cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; + return 1; + } + } catch (ParserException e) { + cerr << "Parser error on result file: " << e.what() << endl; return 1; + } }