Salome HOME
Moved test configuration from CMake variables to a configuration file
authorbarate <barate>
Mon, 3 Aug 2009 14:51:44 +0000 (14:51 +0000)
committerbarate <barate>
Mon, 3 Aug 2009 14:51:44 +0000 (14:51 +0000)
19 files changed:
INSTALL
src/Core/CMakeLists.txt
src/Core/Test/CMakeLists.txt [new file with mode: 0644]
src/Core/Test/SimpleParser.cxx [new file with mode: 0644]
src/Core/Test/SimpleParser.hxx [new file with mode: 0644]
src/Core/Test/Test_SimpleParser.cxx [new file with mode: 0644]
src/Core/Test/Test_config.h.in [new file with mode: 0644]
src/Core/Test/batchtest.conf [new file with mode: 0644]
src/Local/Batch_BatchManager_Local_RSH.cxx
src/Local/Test/CMakeLists.txt
src/Local/Test/Test_Local_RSH.cxx
src/Local/Test/Test_Local_SH.cxx
src/Local/Test/Test_Local_SSH.cxx
src/Local/Test/Test_Local_config.h.in
src/PBS/Test/CMakeLists.txt
src/PBS/Test/Test_PBS_config.h.in [deleted file]
src/PBS/Test/Test_ePBS.cxx
src/Python/Test/Test_Python_Local_SH.py
src/Python/Test/config.py.in

diff --git a/INSTALL b/INSTALL
index 24fdc8c1418ba08916682fa7f3a227ad9f2c6b35..a23ae2d2bc24332dce18b2184793827a1cb5a6aa 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -109,9 +109,12 @@ The build system creates a test target that can be used to automatically test
 some features of the library. The test coverage for this library is currently
 quite poor. Remember that since the tests use connections to remote batch
 systems, the first causes of failure are network and authentication errors. To
-run the tests, you will first have to set several variables in the cache
-(execution host, ...), with ccmake for instance. Then to execute those tests,
-just go to your build directory and type:
+run the tests, you will first have to enable them by setting CMake variable
+TEST_ENABLED to ON. Then copy the file src/Core/Test/batchtest.conf to your
+home directory for instance. Edit this file according to your local
+configuration. Set the environment variable BATCH_TEST_CONFIG_FILE to the path
+to your own configuration file. To execute the autotests, just go to your build
+directory and type:
 
 $ make test
 
index 23007a66ce792b751a277adc3bc792399aa93767..b3756edba1fbe88b9fc49211a0fe1e733d55b051 100644 (file)
@@ -58,3 +58,7 @@ SET(CLASS_LIST Core/Batch_APIInternalFailureException
 APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST})
 APPEND_CLASSES_TO_HDR_FILES(${CLASS_LIST})
 APPEND_CLASSES_TO_HDR_FILES(Core/Batch_Defines)
+
+IF (TEST_ENABLED)
+    add_subdirectory(Test)
+ENDIF (TEST_ENABLED)
diff --git a/src/Core/Test/CMakeLists.txt b/src/Core/Test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..91b876f
--- /dev/null
@@ -0,0 +1,41 @@
+#  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
+#
+
+# Declare the configuration variable for the test scripts
+SET (TEST_CONFIG_FILE_ENV_VAR "BATCH_TEST_CONFIG_FILE" CACHE STRING
+     "Name of the environment variable containing the configuration file name for the tests (only necessary for test target)")
+
+# Configure the config file for the test scripts
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Test_config.h)
+
+# Set the include directories
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
+
+# Build SimpleParser library
+add_library (SimpleParser STATIC SimpleParser.cxx)
+
+# Build the test program
+add_executable(Test_SimpleParser Test_SimpleParser.cxx)
+target_link_libraries(Test_SimpleParser SimpleParser)
+
+# Add the test itself
+ADD_TEST(SimpleParser Test_SimpleParser)
diff --git a/src/Core/Test/SimpleParser.cxx b/src/Core/Test/SimpleParser.cxx
new file mode 100644 (file)
index 0000000..83f6478
--- /dev/null
@@ -0,0 +1,154 @@
+//  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
+//
+/*
+ *  SimpleParser.cpp
+ *
+ *  Created on: 23 juil. 2009
+ *  Author: Renaud BARATE - EDF R&D
+ */
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+#include <Test_config.h>
+
+#include "SimpleParser.hxx"
+
+using namespace std;
+
+
+ParserException::ParserException(string msg) throw()
+  : exception(),
+    _msg(msg)
+{
+}
+
+ParserException::~ParserException() throw()
+{
+}
+
+const char * ParserException::what() const throw()
+{
+  return _msg.c_str();
+}
+
+
+SimpleParser::SimpleParser() throw()
+{
+}
+
+SimpleParser::~SimpleParser() throw()
+{
+}
+
+std::string SimpleParser::trim(const std::string & str) const throw()
+{
+  size_t beg = str.find_first_not_of(" \t");
+  if (beg == string::npos) beg = 0;
+  size_t end = str.find_last_not_of(" \t");
+  return str.substr(beg, end-beg+1);
+}
+
+void SimpleParser::parse(const string & filename) throw(ParserException)
+{
+  ifstream fileStream(filename.c_str());
+  if (!fileStream) {
+    throw ParserException(string("Can't open file ") + filename);
+  }
+  string line;
+  int lineNumber = 1;
+  while (getline(fileStream, line)) {
+    string str = line;
+    // Strip comments
+    size_t pos = str.find_first_of('#');
+    if (pos != string::npos) {
+      str = str.substr(0, pos);
+    }
+    // Strip leading and trailing spaces
+    str = trim(str);
+    if (!str.empty()) {
+      // Find '=' symbol and split the line
+      pos = str.find_first_of('=');
+      if (pos == string::npos) {
+        stringstream msg;
+        msg << "Syntax error (missing =) on line " << lineNumber << ": " << line;
+        throw ParserException(msg.str());
+      } else {
+        string key = trim(str.substr(0, pos));
+        string value = trim(str.substr(pos+1));
+        // Eventually remove '"' symbols at the beginning and at the end of the string
+        if (value.size()>1 && value[0] == '"' && value[value.size()-1] == '"') {
+          value = value.substr(1, value.size()-2);
+        }
+        _configmap[key] = value;
+      }
+    }
+    ++lineNumber;
+  }
+  fileStream.close();
+}
+
+void SimpleParser::parseTestConfigFile() throw(ParserException)
+{
+  char * filename = getenv(TEST_CONFIG_FILE_ENV_VAR);
+  if (filename == NULL) {
+    throw ParserException(string("Environment variable ") + TEST_CONFIG_FILE_ENV_VAR + " is not declared.");
+  } else {
+    parse(filename);
+  }
+}
+
+const string & SimpleParser::getValue(const string & key) const throw(ParserException)
+{
+  map<string,string>::const_iterator iter = _configmap.find(key);
+  if (iter == _configmap.end()) {
+    throw ParserException(string("No value found for key ") + key + ".");
+  }
+  return iter->second;
+}
+
+int SimpleParser::getValueAsInt(const string & key) const throw(ParserException)
+{
+  const string & valueStr = getValue(key);
+  const char * valueCStr = valueStr.c_str();
+  char * end = NULL;
+  int res = strtol(valueCStr, &end, 0);
+  if (*valueCStr == '\0' || *end != '\0') {
+    throw ParserException(string("Invalid value (not integer) for key ") + key + ".");
+  }
+  return res;
+}
+
+ostream & operator <<(ostream & os, const SimpleParser & parser) throw()
+{
+  os << "Configuration map:" << endl;
+  if (parser._configmap.empty()) {
+    os << "Empty map" << endl;
+  } else {
+    map<string,string>::const_iterator iter;
+    for (iter = parser._configmap.begin() ; iter != parser._configmap.end() ; ++iter) {
+      os << iter->first << " = " << iter->second << endl;
+    }
+  }
+  return os;
+}
diff --git a/src/Core/Test/SimpleParser.hxx b/src/Core/Test/SimpleParser.hxx
new file mode 100644 (file)
index 0000000..eacc905
--- /dev/null
@@ -0,0 +1,67 @@
+//  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
+//
+/*
+ *  SimpleParser.hxx
+ *
+ *  Created on: 23 juil. 2009
+ *  Author: Renaud BARATE - EDF R&D
+ */
+
+#ifndef SIMPLEPARSER_H_
+#define SIMPLEPARSER_H_
+
+#include <map>
+#include <string>
+#include <ostream>
+
+class ParserException : public std::exception
+{
+public:
+  ParserException(std::string msg) throw();
+  virtual ~ParserException() throw();
+
+  virtual const char *what() const throw();
+
+private:
+  std::string _msg;
+};
+
+class SimpleParser
+{
+public:
+  SimpleParser() throw();
+  virtual ~SimpleParser() throw();
+
+  void parse(const std::string & filename) throw(ParserException);
+  void parseTestConfigFile() throw(ParserException);
+  const std::string & getValue(const std::string & key) const throw(ParserException);
+  int getValueAsInt(const std::string & key) const throw(ParserException);
+
+  friend std::ostream & operator <<(std::ostream & os, const SimpleParser & parser) throw();
+
+private:
+  std::string trim(const std::string & str) const throw();
+
+  std::map<std::string, std::string> _configmap;
+};
+
+#endif /* SIMPLEPARSER_H_ */
diff --git a/src/Core/Test/Test_SimpleParser.cxx b/src/Core/Test/Test_SimpleParser.cxx
new file mode 100644 (file)
index 0000000..bb446ef
--- /dev/null
@@ -0,0 +1,61 @@
+//  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_SimpleParser.cxx :
+ *
+ *  Created on: 23 juil. 2009
+ *  Author : Renaud BARATE - EDF R&D
+ */
+
+#include <cassert>
+#include <iostream>
+
+#include <Test_config.h>
+
+#include "SimpleParser.hxx"
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+  cout << "*******************************************************************************************" << endl;
+  cout << "This program tests the simple parser that parses the configuration file used in the other" << endl;
+  cout << "tests. For this test, the environment variable " << TEST_CONFIG_FILE_ENV_VAR << " must " << endl;
+  cout << "exist and contain the path to the configuration file to use for the tests." << endl;
+  cout << "*******************************************************************************************" << endl;
+
+  // Create the parser
+  SimpleParser parser;
+
+  try {
+    // Parse the configuration file
+    parser.parseTestConfigFile();
+  } catch (ParserException e) {
+    cerr << "Parser error: " << e.what() << endl;
+    return 1;
+  }
+
+  // Print the configuration
+  cout << parser << endl;
+
+  return 0;
+}
diff --git a/src/Core/Test/Test_config.h.in b/src/Core/Test/Test_config.h.in
new file mode 100644 (file)
index 0000000..3b2cf8b
--- /dev/null
@@ -0,0 +1,23 @@
+//  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
+//
+
+#define TEST_CONFIG_FILE_ENV_VAR "${TEST_CONFIG_FILE_ENV_VAR}"
diff --git a/src/Core/Test/batchtest.conf b/src/Core/Test/batchtest.conf
new file mode 100644 (file)
index 0000000..a318eac
--- /dev/null
@@ -0,0 +1,28 @@
+# This file contains the variables needed to run the autotests for libBatch. Copy this file
+# in your home directory (for instance), edit it to reflect your local configuration, then
+# set the environment variable BATCH_TEST_CONFIG_FILE to the path to your own configuration
+# file.
+# Note that BATCH_TEST_CONFIG_FILE is the default name for this environment variable. It can be
+# changed at compilation time by setting CMake option TEST_CONFIG_FILE_ENV_VAR.
+
+TEST_LOCAL_SH_WORK_DIR = "/tmp"               # Work directory for local SH Batch test
+TEST_LOCAL_SH_TIMEOUT = 2                     # Execution timeout (in seconds) for local SH Batch test
+TEST_LOCAL_SH_FINALIZATION_TIME = 2           # Finalization time (in seconds) for local SH Batch test
+
+TEST_LOCAL_RSH_EXECUTION_HOST = "localhost"   # Execution host for RSH Batch test
+TEST_LOCAL_RSH_USER = "username"              # User name on the execution host for RSH Batch test
+TEST_LOCAL_RSH_WORK_DIR = "/tmp"              # Work directory for RSH Batch test
+TEST_LOCAL_RSH_TIMEOUT = 10                   # Execution timeout (in seconds) for local RSH Batch test
+TEST_LOCAL_RSH_FINALIZATION_TIME = 5          # Finalization time (in seconds) for local RSH Batch test
+
+TEST_LOCAL_SSH_EXECUTION_HOST = "localhost"   # Execution host for SSH Batch test
+TEST_LOCAL_SSH_USER = "username"              # User name on the execution host for SSH Batch test
+TEST_LOCAL_SSH_WORK_DIR = "/tmp"              # Work directory for SSH Batch test
+TEST_LOCAL_SSH_TIMEOUT = 10                   # Execution timeout (in seconds) for local SSH Batch test
+TEST_LOCAL_SSH_FINALIZATION_TIME = 5          # Finalization time (in seconds) for local SSH Batch test
+
+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
index d7276972c9e3ab44ff54c046aeeda9de485bd382..74c3a6af79e511c87720c657cdca29874cbc0426 100644 (file)
@@ -139,6 +139,10 @@ namespace Batch {
       new_arguments += string(param[USER]);
     }
 
+#ifdef WIN32
+    new_arguments += "-n";
+#endif
+
     new_arguments += exec_sub_cmd.str();
 
     param[ARGUMENTS] = new_arguments;
index 0a8adfd9cb67070177449cbc006640d9f4bfc57b..dc9e770ffccbe28e11531e8ee101c5d281804b75 100644 (file)
 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-# Declare the configuration variables for the test scripts
-SET (TEST_LOCAL_SH_WORK_DIR "/tmp" CACHE STRING
-     "Work directory for SH Batch test (only necessary for test target)")
-
-SET (TEST_LOCAL_RSH_EXECUTION_HOST "localhost" CACHE STRING
-     "Execution host for RSH Batch test (only necessary for test target)")
-SET (TEST_LOCAL_RSH_USER $ENV{USER} CACHE STRING
-     "User name on the execution host for RSH Batch test (only necessary for test target)")
-SET (TEST_LOCAL_RSH_WORK_DIR "/tmp" CACHE STRING
-     "Work directory for RSH Batch test (only necessary for test target)")
-
-SET (TEST_LOCAL_SSH_EXECUTION_HOST "localhost" CACHE STRING
-     "Execution host for SSH Batch test (only necessary for test target)")
-SET (TEST_LOCAL_SSH_USER $ENV{USER} CACHE STRING
-     "User name on the execution host for SSH Batch test (only necessary for test target)")
-SET (TEST_LOCAL_SSH_WORK_DIR "/tmp" CACHE STRING
-     "Work directory for SSH Batch test (only necessary for test target)")
-
 # Build the executable to use for the local test program
 add_executable(Exec_Test Exec_Test.cxx)
 GET_TARGET_PROPERTY(EXEC_TEST_FULL_PATH_TEMP Exec_Test LOCATION)
@@ -55,17 +37,18 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test-script.sh ${CMAKE_CURRENT_BINARY
 
 # set the include directories
 include_directories(${CMAKE_SOURCE_DIR}/src/Core)
+include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test)
 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
 # Build the test programs
 add_executable(Test_Local_SH Test_Local_SH.cxx)
-target_link_libraries(Test_Local_SH Batch)
+target_link_libraries(Test_Local_SH Batch SimpleParser)
 
 add_executable(Test_Local_RSH Test_Local_RSH.cxx)
-target_link_libraries(Test_Local_RSH Batch)
+target_link_libraries(Test_Local_RSH Batch SimpleParser)
 
 add_executable(Test_Local_SSH Test_Local_SSH.cxx)
-target_link_libraries(Test_Local_SSH Batch)
+target_link_libraries(Test_Local_SSH Batch SimpleParser)
 
 # Add the tests themselves
 ADD_TEST(Local_SH Test_Local_SH)
index e5e2e4f0833122baa0dba4646a3a167ee98cb21b..51f927492e941654da9d648a52c5481fe36f22be 100644 (file)
 #include <Batch_BatchManagerCatalog.hxx>
 #include <Batch_FactBatchManager.hxx>
 #include <Batch_BatchManager.hxx>
-#include <Test_Local_config.h>
+
+#include <SimpleParser.hxx>
+
+#ifdef WIN32
+#include <Windows.h>
+#define sleep(seconds) Sleep((seconds)*1000)
+#define usleep(useconds) Sleep((useconds)/1000)
+#endif
 
 using namespace std;
 using namespace Batch;
@@ -50,19 +57,28 @@ int main(int argc, char** argv)
   remove("result.txt");
 
   try {
+    // Parse the test configuration file
+    SimpleParser parser;
+    parser.parseTestConfigFile();
+    const string & workdir = parser.getValue("TEST_LOCAL_RSH_WORK_DIR");
+    const string & exechost = parser.getValue("TEST_LOCAL_RSH_EXECUTION_HOST");
+    const string & user = parser.getValue("TEST_LOCAL_RSH_USER");
+    int timeout = parser.getValueAsInt("TEST_LOCAL_RSH_TIMEOUT");
+    int finalizationTime = parser.getValueAsInt("TEST_LOCAL_RSH_FINALIZATION_TIME");
+
     // Define the job...
     Job job;
     // ... and its parameters ...
     Parametre p;
     p["EXECUTABLE"]    = "source copied-test-script.sh";
     p["NAME"]          = "Test_Local_RSH";
-    p["WORKDIR"]       = TEST_LOCAL_RSH_WORK_DIR;
+    p["WORKDIR"]       = workdir;
     p["INFILE"]        = Couple("seta.sh", "copied-seta.sh");
     p["INFILE"]       += Couple("setb.sh", "copied-setb.sh");
     p["INFILE"]       += Couple("test-script.sh", "copied-test-script.sh");
     p["OUTFILE"]       = Couple("result.txt", "orig-result.txt");
-    p["EXECUTIONHOST"] = TEST_LOCAL_RSH_EXECUTION_HOST;
-    p["USER"]          = TEST_LOCAL_RSH_USER;
+    p["EXECUTIONHOST"] = exechost;
+    p["USER"]          = user;
     job.setParametre(p);
     // ... and its environment
     Environnement e;
@@ -82,7 +98,7 @@ int main(int argc, char** argv)
 
     // Wait for the end of the job
     string state = "Unknown";
-    for (int i=0 ; i<100 && state != "Done" ; i++) {
+    for (int i=0 ; i<timeout*10 && state != "Done" ; i++) {
       usleep(100000);
       Versatile paramState = jobid.queryJob().getParametre()["STATE"];
       state = (paramState.size() > 0) ? paramState.str() : "Unknown";
@@ -96,15 +112,18 @@ int main(int argc, char** argv)
 
     cout << "Job " << jobid.__repr__() << " is done" << endl;
 
+    // wait for the copy of output files and the cleanup
+    // (there's no cleaner way to do that yet)
+    sleep(finalizationTime);
+
   } catch (GenericException e) {
     cerr << "Error: " << e << endl;
     return 1;
+  } catch (ParserException e) {
+    cerr << "Parser error: " << e.what() << endl;
+    return 1;
   }
 
-  // wait for 5 more seconds for the copy of output files and the cleanup
-  // (there's no cleaner way to do that yet)
-  sleep(5);
-
   // test the result file
   string exp = "c = 12";
   string res;
index 8e714bce7b5eee4fd94ba5edfc9311dc4a2431f9..5eab7912d45565beba82846c6d1846e7f66de8a9 100644 (file)
 #include <Batch_BatchManagerCatalog.hxx>
 #include <Batch_FactBatchManager.hxx>
 #include <Batch_BatchManager.hxx>
+
 #include <Test_Local_config.h>
+#include <SimpleParser.hxx>
+
+#ifdef WIN32
+#include <Windows.h>
+#define sleep(seconds) Sleep((seconds)*1000)
+#define usleep(useconds) Sleep((useconds)/1000)
+#endif
 
 using namespace std;
 using namespace Batch;
@@ -50,6 +58,13 @@ int main(int argc, char** argv)
   remove("result.txt");
 
   try {
+    // Parse the test configuration file
+    SimpleParser parser;
+    parser.parseTestConfigFile();
+    const string & workdir = parser.getValue("TEST_LOCAL_SH_WORK_DIR");
+    int timeout = parser.getValueAsInt("TEST_LOCAL_SH_TIMEOUT");
+    int finalizationTime = parser.getValueAsInt("TEST_LOCAL_SH_FINALIZATION_TIME");
+
     // Define the job...
     Job job;
     // ... and its parameters ...
@@ -59,7 +74,7 @@ int main(int argc, char** argv)
     p["ARGUMENTS"] += "copied-setb.sh";
     p["ARGUMENTS"] += "orig-result.txt";
     p["NAME"]       = "Test_Local_SH";
-    p["WORKDIR"]    = TEST_LOCAL_SH_WORK_DIR;
+    p["WORKDIR"]    = workdir;
     p["INFILE"]     = Couple("seta.sh", "copied-seta.sh");
     p["INFILE"]    += Couple("setb.sh", "copied-setb.sh");
     p["INFILE"]    += Couple(EXEC_TEST_NAME, string("copied-") + EXEC_TEST_NAME);
@@ -83,7 +98,7 @@ int main(int argc, char** argv)
 
     // Wait for the end of the job
     string state = "Unknown";
-    for (int i=0 ; i<20 && state != "Done" ; i++) {
+    for (int i=0 ; i<timeout*10 && state != "Done" ; i++) {
       usleep(100000);
       Versatile paramState = jobid.queryJob().getParametre()["STATE"];
       state = (paramState.size() > 0) ? paramState.str() : "Unknown";
@@ -97,15 +112,18 @@ int main(int argc, char** argv)
 
     cout << "Job " << jobid.__repr__() << " is done" << endl;
 
+    // wait for the copy of output files and the cleanup
+    // (there's no cleaner way to do that yet)
+    sleep(finalizationTime);
+
   } catch (GenericException e) {
     cerr << "Error: " << e << endl;
     return 1;
+  } catch (ParserException e) {
+    cerr << "Parser error: " << e.what() << endl;
+    return 1;
   }
 
-  // wait for 2 more seconds for the copy of output files and the cleanup
-  // (there's no cleaner way to do that yet)
-  sleep(2);
-
   // test the result file
   string exp = "c = 12";
   string res;
index db28d9cd1065ad6775cf4bd0dae4e6b716f01e9b..3876bb028bc280b75b65b2956c7dd92e17dcab2b 100644 (file)
 #include <Batch_BatchManagerCatalog.hxx>
 #include <Batch_FactBatchManager.hxx>
 #include <Batch_BatchManager.hxx>
-#include <Test_Local_config.h>
+
+#include <SimpleParser.hxx>
+
+#ifdef WIN32
+#include <Windows.h>
+#define sleep(seconds) Sleep((seconds)*1000)
+#define usleep(useconds) Sleep((useconds)/1000)
+#endif
 
 using namespace std;
 using namespace Batch;
@@ -50,19 +57,28 @@ int main(int argc, char** argv)
   remove("result.txt");
 
   try {
+    // Parse the test configuration file
+    SimpleParser parser;
+    parser.parseTestConfigFile();
+    const string & workdir = parser.getValue("TEST_LOCAL_SSH_WORK_DIR");
+    const string & exechost = parser.getValue("TEST_LOCAL_SSH_EXECUTION_HOST");
+    const string & user = parser.getValue("TEST_LOCAL_SSH_USER");
+    int timeout = parser.getValueAsInt("TEST_LOCAL_SSH_TIMEOUT");
+    int finalizationTime = parser.getValueAsInt("TEST_LOCAL_SSH_FINALIZATION_TIME");
+
     // Define the job...
     Job job;
     // ... and its parameters ...
     Parametre p;
     p["EXECUTABLE"]    = "source copied-test-script.sh";
     p["NAME"]          = "Test_Local_SSH";
-    p["WORKDIR"]       = TEST_LOCAL_SSH_WORK_DIR;
+    p["WORKDIR"]       = workdir;
     p["INFILE"]        = Couple("seta.sh", "copied-seta.sh");
     p["INFILE"]       += Couple("setb.sh", "copied-setb.sh");
     p["INFILE"]       += Couple("test-script.sh", "copied-test-script.sh");
     p["OUTFILE"]       = Couple("result.txt", "orig-result.txt");
-    p["EXECUTIONHOST"] = TEST_LOCAL_SSH_EXECUTION_HOST;
-    p["USER"]          = TEST_LOCAL_SSH_USER;
+    p["EXECUTIONHOST"] = exechost;
+    p["USER"]          = user;
     job.setParametre(p);
     // ... and its environment (SSH_AUTH_SOCK env var is important for ssh agent authentication)
     Environnement e;
@@ -84,7 +100,7 @@ int main(int argc, char** argv)
 
     // Wait for the end of the job
     string state = "Unknown";
-    for (int i=0 ; i<100 && state != "Done" ; i++) {
+    for (int i=0 ; i<timeout*10 && state != "Done" ; i++) {
       usleep(100000);
       Versatile paramState = jobid.queryJob().getParametre()["STATE"];
       state = (paramState.size() > 0) ? paramState.str() : "Unknown";
@@ -98,15 +114,18 @@ int main(int argc, char** argv)
 
     cout << "Job " << jobid.__repr__() << " is done" << endl;
 
+    // wait for the copy of output files and the cleanup
+    // (there's no cleaner way to do that yet)
+    sleep(finalizationTime);
+
   } catch (GenericException e) {
     cerr << "Error: " << e << endl;
     return 1;
+  } catch (ParserException e) {
+    cerr << "Parser error: " << e.what() << endl;
+    return 1;
   }
 
-  // wait for 5 more seconds for the copy of output files and the cleanup
-  // (there's no cleaner way to do that yet)
-  sleep(5);
-
   // test the result file
   string exp = "c = 12";
   string res;
index 724e5bd262b52ecdb4ad3241578070b041e18182..403b18d5e14c12d9422f394705aa3bbebb7e9597 100644 (file)
 //
 
 #define EXEC_TEST_NAME "${EXEC_TEST_NAME}"
-
-#define TEST_LOCAL_SH_WORK_DIR "${TEST_LOCAL_SH_WORK_DIR}"
-
-#define TEST_LOCAL_RSH_EXECUTION_HOST "${TEST_LOCAL_RSH_EXECUTION_HOST}"
-#define TEST_LOCAL_RSH_USER "${TEST_LOCAL_RSH_USER}"
-#define TEST_LOCAL_RSH_WORK_DIR "${TEST_LOCAL_RSH_WORK_DIR}"
-
-#define TEST_LOCAL_SSH_EXECUTION_HOST "${TEST_LOCAL_SSH_EXECUTION_HOST}"
-#define TEST_LOCAL_SSH_USER "${TEST_LOCAL_SSH_USER}"
-#define TEST_LOCAL_SSH_WORK_DIR "${TEST_LOCAL_SSH_WORK_DIR}"
-
-#ifdef WIN32
-#include <Windows.h>
-#define sleep(seconds) Sleep((seconds)*1000)
-#define usleep(useconds) Sleep((useconds)/1000)
-#endif
index 9fd72724c53a8cde1e4c7a1f389c3cb855a682f8..f34be4848b7a5b97ed947212ab691a08ae6e92a4 100644 (file)
 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-# Declare the configuration variables for the test scripts
-SET (TEST_PBS_HOST "localhost" CACHE STRING
-     "PBS server host (only necessary for test target)")
-SET (TEST_PBS_USER "username" CACHE STRING
-     "Login for the PBS server (only necessary for test target)")
-SET (TEST_PBS_HOMEDIR "/home/username" CACHE STRING
-     "Home directory on PBS server (only necessary for test target)")
-SET (TEST_PBS_QUEUE "queuename" CACHE STRING
-     "Queue to submit test job on PBS server (only necessary for test target)")
-
-# Configure the config file for all the test scripts
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_PBS_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Test_PBS_config.h)
-
 # Just copy the test scripts to the binary dir
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/seta.sh ${CMAKE_CURRENT_BINARY_DIR}/seta.sh COPYONLY)
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/setb.sh ${CMAKE_CURRENT_BINARY_DIR}/setb.sh COPYONLY)
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test-script.sh ${CMAKE_CURRENT_BINARY_DIR}/test-script.sh COPYONLY)
 
 # set the include directories
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../Core)
+include_directories(${CMAKE_SOURCE_DIR}/src/Core)
+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
 add_executable(Test_ePBS Test_ePBS.cxx)
-target_link_libraries(Test_ePBS Batch)
+target_link_libraries(Test_ePBS Batch SimpleParser)
 ADD_TEST(ePBS Test_ePBS)
diff --git a/src/PBS/Test/Test_PBS_config.h.in b/src/PBS/Test/Test_PBS_config.h.in
deleted file mode 100644 (file)
index a312205..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-//  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
-//
-
-#define TEST_PBS_HOST "${TEST_PBS_HOST}"
-#define TEST_PBS_USER "${TEST_PBS_USER}"
-#define TEST_PBS_HOMEDIR "${TEST_PBS_HOMEDIR}"
-#define TEST_PBS_QUEUE "${TEST_PBS_QUEUE}"
-
-#ifdef WIN32
-#include <Windows.h>
-#define sleep(seconds) Sleep((seconds)*1000)
-#define usleep(useconds) Sleep((useconds)/1000)
-#endif
index 46de101911e055be9756d754f81d7d3e9d737be7..642cd5eecd6e1fe2f341a33f259d087863893d18 100644 (file)
 #include <Batch_FactBatchManager_eClient.hxx>
 #include <Batch_BatchManager.hxx>
 #include <Batch_BatchManager_eClient.hxx>
-#include <Test_PBS_config.h>
+
+#include <SimpleParser.hxx>
+
+#ifdef WIN32
+#include <Windows.h>
+#define sleep(seconds) Sleep((seconds)*1000)
+#define usleep(useconds) Sleep((useconds)/1000)
+#endif
 
 using namespace std;
 using namespace Batch;
@@ -54,23 +61,32 @@ int main(int argc, char** argv)
   remove("result.txt");
 
   try {
+    // 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");
+
     // 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["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"]          = TEST_PBS_USER;
+    p["USER"]          = user;
     p["NBPROC"]        = 1;
     p["MAXWALLTIME"]   = 1;
     p["MAXRAMSIZE"]    = 4;
-    p["HOMEDIR"]       = TEST_PBS_HOMEDIR;
-    p["QUEUE"]         = TEST_PBS_QUEUE;
+    p["HOMEDIR"]       = homedir;
+    p["QUEUE"]         = queue;
     job.setParametre(p);
     // ... and its environment (SSH_AUTH_SOCK env var is important for ssh agent authentication)
     Environnement e;
@@ -84,7 +100,7 @@ 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(), "ssh", "lam");
 
     // Submit the job to the BatchManager
     JobId jobid = bm->submitJob(job);
@@ -92,7 +108,7 @@ int main(int argc, char** argv)
 
     // Wait for the end of the job
     string state = "Undefined";
-    for (int i=0 ; i<60 && state != "U"; i++) {
+    for (int i=0 ; i<timeout/2 && state != "U"; i++) {
       sleep(2);
       JobInfo jinfo = jobid.queryJob();
       state = jinfo.getParametre()["STATE"].str();
@@ -110,6 +126,9 @@ int main(int argc, char** argv)
   } catch (GenericException e) {
     cerr << "Error: " << e << endl;
     return 1;
+  } catch (ParserException e) {
+    cerr << "Parser error: " << e.what() << endl;
+    return 1;
   }
 
   // test the result file
index 4b684b042bbbae10ca377758c9f4834e5987b33d..4ea755c81f7cd92d94b758a4d58f2f3b9635c2de 100644 (file)
@@ -71,7 +71,7 @@ def work():
     # Wait for the end of the job
     state = 'Unknown'
     i=0
-    while state != 'Done' and i<20:
+    while state != 'Done' and i<config.TEST_LOCAL_SH_TIMEOUT*10:
         time.sleep(0.1)
         i+=1
         jinfo = jobid.queryJob()
@@ -87,9 +87,9 @@ def work():
 
     print "Job", jobid, "is done"
 
-    # wait for 2 more seconds for the copy of output files and the cleanup
+    # wait for the copy of output files and the cleanup
     # (there's no cleaner way to do that yet)
-    time.sleep(2)
+    time.sleep(config.TEST_LOCAL_SH_FINALIZATION_TIME)
 
     # test the result file
     exp = "c = 12"
index a732320320143ff1b8607448796224bc9800e6f6..08a8e96fbe760cef5ae8d4b91e5fffb8fa18065d 100644 (file)
 #
 
 import sys
+import os
 sys.path.append('${CMAKE_CURRENT_BINARY_DIR}/..')
 
 EXEC_TEST_FULL_PATH = "${EXEC_TEST_FULL_PATH}"
 EXEC_TEST_NAME = "${EXEC_TEST_NAME}"
 
-TEST_LOCAL_SH_WORK_DIR = "${TEST_LOCAL_SH_WORK_DIR}"
+configfile = os.environ["${TEST_CONFIG_FILE_ENV_VAR}"]
+execfile(configfile)