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
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)
--- /dev/null
+# 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)
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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_ */
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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}"
--- /dev/null
+# 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
new_arguments += string(param[USER]);
}
+#ifdef WIN32
+ new_arguments += "-n";
+#endif
+
new_arguments += exec_sub_cmd.str();
param[ARGUMENTS] = new_arguments;
# 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)
# 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)
#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;
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;
// 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";
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;
#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;
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 ...
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);
// 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";
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;
#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;
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;
// 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";
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;
//
#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
# 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)
+++ /dev/null
-// 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
#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;
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;
// 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);
// 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();
} catch (GenericException e) {
cerr << "Error: " << e << endl;
return 1;
+ } catch (ParserException e) {
+ cerr << "Parser error: " << e.what() << endl;
+ return 1;
}
// test the result file
# 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()
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"
#
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)