Salome HOME
Added PBS test based on Torque.
authorbarate <barate>
Mon, 7 Sep 2009 10:01:22 +0000 (10:01 +0000)
committerbarate <barate>
Mon, 7 Sep 2009 10:01:22 +0000 (10:01 +0000)
src/Core/Test/batchtest.conf
src/PBS/Batch_BatchManager_PBS.cxx
src/PBS/Batch_BatchManager_PBS.hxx
src/PBS/Test/CMakeLists.txt
src/PBS/Test/Test_PBS.cxx [new file with mode: 0644]
src/PBS/Test/Test_ePBS.cxx

index a318eac3357c5db610d5f4ce437b2acf00b6cf4b..00b322865be4eb3c66f87ee6955ec9b466f4217e 100644 (file)
@@ -23,6 +23,11 @@ TEST_LOCAL_SSH_FINALIZATION_TIME = 5          # Finalization time (in seconds) f
 
 TEST_PBS_HOST = "localhost"                   # PBS server host
 TEST_PBS_USER = "username"                    # Login for the PBS server
-TEST_PBS_HOMEDIR = "/home/username"           # Home directory on PBS server
 TEST_PBS_QUEUE = "queuename"                  # Queue to submit test job on PBS server
 TEST_PBS_TIMEOUT = 120                        # Execution timeout (in seconds) for PBS Batch test
+
+TEST_EPBS_HOST = "localhost"                  # PBS server host
+TEST_EPBS_USER = "username"                   # Login for the PBS server
+TEST_EPBS_HOMEDIR = "/home/username"          # Home directory on PBS server
+TEST_EPBS_QUEUE = "queuename"                 # Queue to submit test job on PBS server
+TEST_EPBS_TIMEOUT = 120                       # Execution timeout (in seconds) for PBS Batch test
index dd2b1b812db5fc6aa70982a9c1f53db630d8f515..ccd48f5178f1dec45f5fa87b1fc809ef6eaad8f2 100644 (file)
@@ -90,12 +90,7 @@ namespace Batch {
     // On se connecte au serveur PBS
     _connect = pbs_connect(const_cast< char * >(_hostname.c_str()));
     if (_connect < 0) { // si erreur
-      char * errmsg = pbs_geterrmsg(_connect);
-      string msg = "PBS Server on host \"";
-      msg += _hostname;
-      msg += "\" : ";
-      msg += errmsg ? errmsg : "Reason unknown";
-      throw ConnexionFailureException(msg.c_str());
+      throw ConnexionFailureException(getErrorMessage("connect").c_str());
     }
   }
 
@@ -105,14 +100,23 @@ namespace Batch {
     // On se deconnecte du serveur PBS
     int rc = pbs_disconnect(_connect);
     if (rc < 0) { // si erreur
-      string msg = "PBS Server on host \"";
-      msg += _hostname;
-      msg += "\" : ";
-      msg += pbs_geterrmsg(_connect);
-      throw ConnexionFailureException(msg.c_str());
+      throw ConnexionFailureException(getErrorMessage("disconnect").c_str());
     }
   }
 
+  string BatchManager_PBS::getErrorMessage(const char * operation) const
+  {
+    char * msg = pbs_geterrmsg(_connect);
+    stringstream sstr;
+    sstr << "PBS " << operation << " error (host \"" << _hostname << "\"): ";
+    if (msg != NULL) {
+      sstr << msg;
+    } else {
+      sstr << "code = " << pbs_errno << " (" << pbse_to_txt(pbs_errno) << ")";
+    }
+    return sstr.str();
+  }
+
   // Methode pour le controle des jobs : soumet un job au gestionnaire
   const JobId BatchManager_PBS::submitJob(const Job & job)
   {
@@ -123,9 +127,7 @@ namespace Batch {
                            jobpbs.getDestination(),
                            NULL);
     if (!ref) { // si erreur
-      char * msg = pbs_geterrmsg(_connect);
-      if (!msg) msg = "unknown";
-      throw APIInternalFailureException(string("PBS submit error. Reason : ") + msg);
+      throw APIInternalFailureException(getErrorMessage("submit").c_str());
     }
 
     JobId id(this, string(ref));
@@ -139,9 +141,7 @@ namespace Batch {
     char * ref = const_cast< char * >(jobid.getReference().c_str());
     int rc = pbs_deljob(_connect, ref, 0);
     if (rc) { // si erreur
-      char * msg = pbs_geterrmsg(_connect);
-      if (!msg) msg = "unknown";
-      throw APIInternalFailureException(string("PBS deljob error. Reason : ") + msg);
+      throw APIInternalFailureException(getErrorMessage("deljob").c_str());
     }
   }
    
@@ -151,9 +151,7 @@ namespace Batch {
     char * ref = const_cast< char * >(jobid.getReference().c_str());
     int rc = pbs_holdjob(_connect, ref, USER_HOLD, 0);
     if (rc) { // si erreur
-      char * msg = pbs_geterrmsg(_connect);
-      if (!msg) msg = "unknown";
-      throw APIInternalFailureException(string("PBS holdjob error. Reason : ") + msg);
+      throw APIInternalFailureException(getErrorMessage("holdjob").c_str());
     }
   }
 
@@ -163,9 +161,7 @@ namespace Batch {
     char * ref = const_cast< char * >(jobid.getReference().c_str());
     int rc = pbs_rlsjob(_connect, ref, USER_HOLD, 0);
     if (rc) { // si erreur
-      char * msg = pbs_geterrmsg(_connect);
-      if (!msg) msg = "unknown";
-      throw APIInternalFailureException(string("PBS rlsjob error. Reason : ") + msg);
+      throw APIInternalFailureException(getErrorMessage("rlsjob").c_str());
     }
   }
 
@@ -182,9 +178,7 @@ namespace Batch {
                          jobpbs.getAttributes(),
                          NULL);
     if (rc) { // si erreur
-      char * msg = pbs_geterrmsg(_connect);
-      if (!msg) msg = "unknown";
-      throw APIInternalFailureException(string("PBS alterjob error. Reason : ") + msg);
+      throw APIInternalFailureException(getErrorMessage("alterjob").c_str());
     }
                
   }
index ee6ac82187e66ca6682beb536ef21cede0e611ff..0db818fccc1509cb476742f1bb1c582aa09647e0 100644 (file)
@@ -80,6 +80,8 @@ namespace Batch {
 
 
   protected:
+    std::string getErrorMessage(const char * operation) const;
+
     int _connect; // PBS connect id
 
   private:
index f34be4848b7a5b97ed947212ab691a08ae6e92a4..0ac39cd336442d6998074ba6ec07ab9934d2fdf7 100644 (file)
@@ -31,7 +31,13 @@ include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
-# Build the test program and add the test
+# Build the test programs and add the tests
 add_executable(Test_ePBS Test_ePBS.cxx)
 target_link_libraries(Test_ePBS Batch SimpleParser)
 ADD_TEST(ePBS Test_ePBS)
+
+IF (BUILD_PBS_INTERFACE AND PBS_FOUND)
+    add_executable(Test_PBS Test_PBS.cxx)
+    target_link_libraries(Test_PBS Batch SimpleParser)
+    ADD_TEST(PBS Test_PBS)
+ENDIF (BUILD_PBS_INTERFACE AND PBS_FOUND)
diff --git a/src/PBS/Test/Test_PBS.cxx b/src/PBS/Test/Test_PBS.cxx
new file mode 100644 (file)
index 0000000..e58278d
--- /dev/null
@@ -0,0 +1,146 @@
+//  Copyright (C) 2007-2008  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
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Test_PBS.cxx :
+ *
+ * Author : Renaud BARATE - EDF R&D
+ * Date   : September 2009
+ *
+ */
+
+#include <iostream>
+#include <fstream>
+
+#include <Batch_Job.hxx>
+#include <Batch_BatchManagerCatalog.hxx>
+#include <Batch_FactBatchManager.hxx>
+#include <Batch_BatchManager.hxx>
+
+#include <SimpleParser.hxx>
+
+#ifdef WIN32
+#include <Windows.h>
+#include <direct.h>
+#define sleep(seconds) Sleep((seconds)*1000)
+#define usleep(useconds) Sleep((useconds)/1000)
+#endif
+
+using namespace std;
+using namespace Batch;
+
+int main(int argc, char** argv)
+{
+  cout << "*******************************************************************************************" << endl;
+  cout << "This program tests the batch submission based on PBS." << endl;
+  cout << "*******************************************************************************************" << endl;
+
+  // eventually remove any previous result
+  remove("result.txt");
+
+  try {
+    // Parse the test configuration file
+    SimpleParser parser;
+    parser.parseTestConfigFile();
+    const string & host = parser.getValue("TEST_PBS_HOST");
+    const string & user = parser.getValue("TEST_PBS_USER");
+    const string & queue = parser.getValue("TEST_PBS_QUEUE");
+    int timeout = parser.getValueAsInt("TEST_PBS_TIMEOUT");
+
+    char * cwd =
+#ifdef WIN32
+      _getcwd(NULL, 0);
+#else
+      new char [PATH_MAX];
+    getcwd(cwd, PATH_MAX);
+#endif
+    string workdir = cwd;
+    delete [] cwd;
+
+    // Define the job...
+    Job job;
+    // ... and its parameters ...
+    Parametre p;
+    p["EXECUTABLE"]    = "test-script.sh";
+    p["NAME"]          = "Test_PBS";
+    p["INFILE"]        = Couple(workdir + "/seta.sh", "seta.sh");
+    p["INFILE"]       += Couple(workdir + "/setb.sh", "setb.sh");
+    p["OUTFILE"]       = Couple(workdir + "/result.txt", "result.txt");
+    p["USER"]          = user;
+    p["NBPROC"]        = 1;
+    p["MAXWALLTIME"]   = 1;
+    p["MAXRAMSIZE"]    = 4;
+    p["QUEUE"]         = queue;
+    job.setParametre(p);
+    // ... and its environment
+    Environnement e;
+    job.setEnvironnement(e);
+    cout << job << endl;
+
+    // Get the catalog
+    BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
+
+    // Create a BatchManager of type ePBS on localhost
+    FactBatchManager * fbm = c("PBS");
+    BatchManager * bm = (*fbm)(host.c_str());
+
+    // 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<timeout/2 && state != "U" && state != "C"; i++) {
+      sleep(2);
+      JobInfo jinfo = jobid.queryJob();
+      state = jinfo.getParametre()["STATE"].str();
+      cout << "State is \"" << state << "\"" << endl;
+    }
+
+    if (state == "U" || state == "C") {
+      cout << "Job " << jobid.__repr__() << " is done" << endl;
+    } else {
+      cerr << "Timeout while executing job" << endl;
+      return 1;
+    }
+
+  } catch (GenericException e) {
+    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
+    return 1;
+}
index 642cd5eecd6e1fe2f341a33f259d087863893d18..d75d96a4b051a78d3795480f162450134b5f2a14 100644 (file)
@@ -64,11 +64,11 @@ int main(int argc, char** argv)
     // Parse the test configuration file
     SimpleParser parser;
     parser.parseTestConfigFile();
-    const string & homedir = parser.getValue("TEST_PBS_HOMEDIR");
-    const string & host = parser.getValue("TEST_PBS_HOST");
-    const string & user = parser.getValue("TEST_PBS_USER");
-    const string & queue = parser.getValue("TEST_PBS_QUEUE");
-    int timeout = parser.getValueAsInt("TEST_PBS_TIMEOUT");
+    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;