From: barate Date: Mon, 3 Aug 2009 14:51:44 +0000 (+0000) Subject: Moved test configuration from CMake variables to a configuration file X-Git-Tag: V_1_0_0_RC3~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8d2880ced7e70bde6a564df14b93bfd024fd17b1;p=tools%2Flibbatch.git Moved test configuration from CMake variables to a configuration file --- diff --git a/INSTALL b/INSTALL index 24fdc8c..a23ae2d 100644 --- 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 diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index 23007a6..b3756ed 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -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 index 0000000..91b876f --- /dev/null +++ b/src/Core/Test/CMakeLists.txt @@ -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 index 0000000..83f6478 --- /dev/null +++ b/src/Core/Test/SimpleParser.cxx @@ -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 +#include +#include + +#include + +#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::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::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 index 0000000..eacc905 --- /dev/null +++ b/src/Core/Test/SimpleParser.hxx @@ -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 +#include +#include + +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 _configmap; +}; + +#endif /* SIMPLEPARSER_H_ */ diff --git a/src/Core/Test/Test_SimpleParser.cxx b/src/Core/Test/Test_SimpleParser.cxx new file mode 100644 index 0000000..bb446ef --- /dev/null +++ b/src/Core/Test/Test_SimpleParser.cxx @@ -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 +#include + +#include + +#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 index 0000000..3b2cf8b --- /dev/null +++ b/src/Core/Test/Test_config.h.in @@ -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 index 0000000..a318eac --- /dev/null +++ b/src/Core/Test/batchtest.conf @@ -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 diff --git a/src/Local/Batch_BatchManager_Local_RSH.cxx b/src/Local/Batch_BatchManager_Local_RSH.cxx index d727697..74c3a6a 100644 --- a/src/Local/Batch_BatchManager_Local_RSH.cxx +++ b/src/Local/Batch_BatchManager_Local_RSH.cxx @@ -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; diff --git a/src/Local/Test/CMakeLists.txt b/src/Local/Test/CMakeLists.txt index 0a8adfd..dc9e770 100644 --- a/src/Local/Test/CMakeLists.txt +++ b/src/Local/Test/CMakeLists.txt @@ -20,24 +20,6 @@ # 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) diff --git a/src/Local/Test/Test_Local_RSH.cxx b/src/Local/Test/Test_Local_RSH.cxx index e5e2e4f..51f9274 100644 --- a/src/Local/Test/Test_Local_RSH.cxx +++ b/src/Local/Test/Test_Local_RSH.cxx @@ -34,7 +34,14 @@ #include #include #include -#include + +#include + +#ifdef WIN32 +#include +#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 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; diff --git a/src/Local/Test/Test_Local_SH.cxx b/src/Local/Test/Test_Local_SH.cxx index 8e714bc..5eab791 100644 --- a/src/Local/Test/Test_Local_SH.cxx +++ b/src/Local/Test/Test_Local_SH.cxx @@ -34,7 +34,15 @@ #include #include #include + #include +#include + +#ifdef WIN32 +#include +#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 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; diff --git a/src/Local/Test/Test_Local_SSH.cxx b/src/Local/Test/Test_Local_SSH.cxx index db28d9c..3876bb0 100644 --- a/src/Local/Test/Test_Local_SSH.cxx +++ b/src/Local/Test/Test_Local_SSH.cxx @@ -34,7 +34,14 @@ #include #include #include -#include + +#include + +#ifdef WIN32 +#include +#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 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; diff --git a/src/Local/Test/Test_Local_config.h.in b/src/Local/Test/Test_Local_config.h.in index 724e5bd..403b18d 100644 --- a/src/Local/Test/Test_Local_config.h.in +++ b/src/Local/Test/Test_Local_config.h.in @@ -21,19 +21,3 @@ // #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 -#define sleep(seconds) Sleep((seconds)*1000) -#define usleep(useconds) Sleep((useconds)/1000) -#endif diff --git a/src/PBS/Test/CMakeLists.txt b/src/PBS/Test/CMakeLists.txt index 9fd7272..f34be48 100644 --- a/src/PBS/Test/CMakeLists.txt +++ b/src/PBS/Test/CMakeLists.txt @@ -20,30 +20,18 @@ # 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 index a312205..0000000 --- a/src/PBS/Test/Test_PBS_config.h.in +++ /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 -#define sleep(seconds) Sleep((seconds)*1000) -#define usleep(useconds) Sleep((useconds)/1000) -#endif diff --git a/src/PBS/Test/Test_ePBS.cxx b/src/PBS/Test/Test_ePBS.cxx index 46de101..642cd5e 100644 --- a/src/PBS/Test/Test_ePBS.cxx +++ b/src/PBS/Test/Test_ePBS.cxx @@ -36,7 +36,14 @@ #include #include #include -#include + +#include + +#ifdef WIN32 +#include +#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