options.verbose = verbose
options.clear = 0
options.prefix = home_dir
- options.module = _config[module]
+ options.module_name = module
+ options.module_path = _config[module]
virtual_salome.link_module(options)
pass
pass
'runAppli', # OBSOLETE (replaced by salome)
'runConsole', # OBSOLETE (replaced by salome)
'runRemote.sh',
- 'runSalomeScript',
+ 'runSalomeScript', # OBSOLETE (replaced by salome)
'runSession', # OBSOLETE (replaced by salome)
'salome',
'update_catalogs.py',
virtual_salome.mkdir(os.path.join(home_dir,'env.d'))
if _config.has_key("prereq_path") and os.path.isfile(_config["prereq_path"]):
- shutil.copyfile(_config["prereq_path"],
+ shutil.copyfile(_config["prereq_path"],
os.path.join(home_dir, 'env.d', 'envProducts.sh'))
pass
else:
pass
if _config.has_key("system_conf_path") and os.path.isfile(_config["system_conf_path"]):
- shutil.copyfile(_config["system_conf_path"],
+ shutil.copyfile(_config["system_conf_path"],
os.path.join(home_dir, 'env.d', 'envConfSystem.sh'))
pass
metavar="<configuration file>",
help="XML configuration file (default %(default)s)")
- parser.add_argument('-v', '--verbose', action='count',
+ parser.add_argument('-v', '--verbose', action='count',
default=0, help="Increase verbosity")
options = parser.parse_args()
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
+ADD_SUBDIRECTORY(salome_tester)
ADD_SUBDIRECTORY(tests)
# ===============================================================
os.environ['APPLI'] = appliPath # needed to convert .sh environment files
os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath
+ sys.path[:0] = [os.path.realpath(os.path.join(absoluteAppliPath, "bin", "salome", "test"))]
sys.path[:0] = [os.path.realpath(os.path.join(absoluteAppliPath, "bin", "salome"))]
# define folder to store omniorb config (initially in virtual application folder)
--- /dev/null
+# Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# 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, or (at your option) any later version.
+#
+# 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
+#
+
+SET(SCRIPTS
+ salome_test_driver.py
+ salome_test_session.py
+)
+
+SALOME_INSTALL_SCRIPTS("${SCRIPTS}" ${SALOME_INSTALL_SCRIPT_SCRIPTS}/appliskel)
--- /dev/null
+This package contains a test driver to run component tests in a SALOME session.
+This note presents the procedure to declare tests that will be runnable from a SALOME application (through the salome command).
+
+
+I. Write, declare, build and install tests
+==========================================
+
+Each module test folder must contain:
+ - a set of test source files
+ - a CMakeLists.txt that:
+ - declare unit tests (not requiring a SALOME session) only
+ - build test files from sources if necessary
+ - install test files in <module_install_path>/bin/salome/test/
+ - install the CTestTestfileInstall.cmake file (see below) as <module_install_path>/bin/salome/test/CTestTestfile.cmake (rename file)
+ - a CTestTestfileInstall.cmake that:
+ - declare tests requiring a SALOME session
+
+The CTestTestfileInstall.cmake can also declare unit tests already declared in CMakeLists.txt. Actually CTestTestfileInstall.cmake declare all tests that will be runnable from SALOME application. This file MUST NOT use cmake environment variables.
+It can refer the ABSOLUTE_APPLI_PATH variable (automatically set when using application).
+If a test has to be run inside a SALOME session, use the salome_test_driver.py script that need as arguments a timeout, the test file to be run and its arguments.
+ SET(SALOME_TEST_DRIVER "$ENV{ABSOLUTE_APPLI_PATH}/bin/salome/appliskel/salome_test_driver.py")
+ SET(TIMEOUT 500)
+ ADD_TEST(SalomeLauncher python ${SALOME_TEST_DRIVER} ${TIMEOUT} test_launcher.py)
+Call explicitly python when using this test driver.
+
+You may want to label each test with the component they are associated to. It is useful to run tests associated to a specific component.
+ SET(COMPONENT_NAME KERNEL)
+ SET_TESTS_PROPERTIES(SalomeLauncher PROPERTIES LABELS "${COMPONENT_NAME}")
+
+
+You can have a look at KERNEL/src/Launcher/Test/ directory for a working example.
+
+
+II. Run tests
+=============
+
+Tests are run with the "salome test" command (in a terminal).
+Enter "salome test --help" for detailed usage.
--- /dev/null
+# Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# 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, or (at your option) any later version.
+#
+# 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
+#
+
+"""
+Usage: salome_test_helper.py <timeout_delay> <test_file.py> [test file arguments]
+"""
+
+import sys
+import os
+import subprocess
+import signal
+
+# Run test
+def runTest(command):
+ print "Running:", " ".join(command)
+ p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ out, err = p.communicate()
+ res = p.returncode
+
+ return res, out, err
+#
+
+# Display output and errors
+def processResult(res, out, err):
+ if out:
+ print out
+ pass
+ if err:
+ print err
+ print "Status code: ", res
+#
+
+# Timeout management
+class TimeoutException(Exception):
+ """Execption raised when test timeout is reached."""
+#
+def timeoutHandler(signum, frame):
+ raise TimeoutException()
+#
+
+if __name__ == "__main__":
+ timeout_delay = sys.argv[1]
+ args = sys.argv[2:]
+
+ # Add explicit call to python executable if a Python script is passed as
+ # first argument
+ if not args:
+ exit(0)
+ _, ext = os.path.splitext(args[0])
+ if ext == ".py":
+ test_and_args = [sys.executable] + args
+ else:
+ test_and_args = args
+
+ # Ensure OMNIORB_USER_PATH is set
+ from salomeContextUtils import setOmniOrbUserPath
+ setOmniOrbUserPath()
+
+ # Set timeout handler
+ print "Test timeout explicitely set to: %s seconds"%timeout_delay
+ signal.alarm(abs(int(timeout_delay)-10))
+ signal.signal(signal.SIGALRM, timeoutHandler)
+
+ # Run test in a new SALOME session
+ from salome_test_session import startSession, terminateSession
+ res = 1
+ try:
+ port = startSession()
+ res, out, err = runTest(test_and_args)
+ processResult(res, out, err)
+ except TimeoutException:
+ print "FAILED : timeout(%s) is reached"%timeout_delay
+ except:
+ import traceback
+ traceback.print_exc()
+ pass
+
+ terminateSession(port)
+ exit(res)
+#
--- /dev/null
+# Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# 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, or (at your option) any later version.
+#
+# 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
+#
+
+import sys
+import os
+
+# Example of args:
+# args=["--gui", "--show-desktop=1", "--splash=0"]
+# args=["--terminal","--modules=MED,PARAVIS,GUI"]
+class SalomeSession(object):
+ def __init__(self, args=[]):
+ sys.argv = ['runSalome'] + args
+
+ if "INGUI" in args:
+ sys.argv += ["--gui"]
+ sys.argv += ["--show-desktop=1"]
+ sys.argv += ["--splash=0"]
+ #sys.argv += ["--standalone=study"]
+ #sys.argv += ["--embedded=SalomeAppEngine,cppContainer,registry,moduleCatalog"]
+ else:
+ sys.argv += ["--terminal"]
+ #sys.argv += ["--modules=MED,PARAVIS,GUI"]
+ pass
+
+ import setenv
+ setenv.main(True)
+
+ import runSalome
+ runSalome.runSalome()
+ #
+#
+
+# Run SALOME
+def startSession():
+ import tempfile
+ log = tempfile.NamedTemporaryFile(suffix='_nsport.log', delete=False)
+ log.close()
+ import salome
+ salome_session = SalomeSession(args=["--ns-port-log=%s"%log.name])
+ salome.salome_init()
+ session_server = salome.naming_service.Resolve('/Kernel/Session')
+ if session_server:
+ session_server.emitMessage("connect_to_study")
+ session_server.emitMessage("activate_viewer/ParaView")
+ pass
+
+ with open(log.name) as f:
+ port = int(f.readline())
+
+ os.remove(log.name)
+ return port
+#
+
+# Terminate SALOME
+def terminateSession(port):
+ import killSalomeWithPort
+ killSalomeWithPort.killMyPort(port)
+#
#
import os
-from optparse import OptionParser
-from salomeContextUtils import getScriptsAndArgs, formatScriptsAndArgs
+import sys
+import select
+import subprocess
-# Use to display newlines (\n) in epilog
-class MyParser(OptionParser):
- def format_epilog(self, formatter):
- return self.epilog
-#
-
-class TestParameters:
- def __init__(self, resources):
- self.resources = resources
-#
-
-def configureTests(args=None, exe=None):
- if args is None:
- args = []
+def __configureTests(args=[], exe=None):
if exe:
- usage = "Usage: %s [options] [components]"%exe
+ usage = "Usage: %s [options]"%exe
else:
- usage = "Usage: %prog [options] [components]"
+ usage = "Usage: %prog [options]"
epilog = """\n
-Run tests of SALOME components (KERNEL, YACS...). If components are not given, run tests of each avaible component.\n
-* Tests can be restricted to a set of components.
-* For each component, a subset of test files may be given using "with:" syntax.\n
-Examples:
-* Running all tests of all available components:
- salome test
-* Running all tests of components KERNEL and YACS:
- salome test KERNEL YACS
-* Running tests named test04 and test07 of component KERNEL:
- salome test KERNEL with:test04,test07
-* Running tests named test04 and test07 of component KERNEL, and tests named test11 and test12 of component YACS:
- salome test KERNEL with:test04,test07 YACS with:test11,test12
-
-Components must be separated by blank characters.
-Tests files, if specified, must be comma-separated (without blank characters) and prefixed by "with:" keyword (without quotes).\n
+Run tests of SALOME components provided with application.\n
+Principal options are:
+ -h,--help
+ Show this help message and exit.
+
+ -V,--verbose
+ Enable verbose output from tests.
+ -VV,--extra-verbose
+ Enable more verbose output from tests.
+ -Q,--quiet
+ Suppress all output.
+
+ -N,--show-only
+ Show available tests (without running them).
+
+ -R <regex>, --tests-regex <regex>
+ Run tests matching regular expression.
+ -E <regex>, --exclude-regex <regex>
+ Exclude tests matching regular expression.
+
+ -L <regex>, --label-regex <regex>
+ Run tests with labels matching regular expression.
+ -LE <regex>, --label-exclude <regex>
+ Exclude tests with labels matching regular expression.
+
+For complete description of available options, pleaser refer to ctest documentation.\n
"""
- parser = MyParser(usage=usage, epilog=epilog)
- parser.add_option("-r", "--resources", metavar="<resources>", default=0,
- action="store", type="string", dest="resources",
- help="A catalog of available resources (if a local test need to connect a remote machine)."
- )
- try:
- (options, args) = parser.parse_args(args)
- except Exception, e:
- print e
- return
-
- params = TestParameters(options.resources)
- return params, args
-#
+ if not args:
+ return []
-class ComponentAndTests:
- # component: the component to be tested
- # tests: subset of component tests to be run
- def __init__(self, component=None, tests=None):
- self.component = component
- self.tests = tests
- #
- def __repr__(self):
- msg = "\n# Component: %s\n"%self.component
- msg += " * Tests: %s\n"%self.tests
- return msg
- #
-#
+ if args[0] in ["-h", "--help"]:
+ print usage + epilog
+ sys.exit(0)
-# Return an array of ComponentAndTests objects
-def getComponentAndTestFiles(args=[]):
- # Syntax of args: component [with:a1,...,an] ... component [with:a1,...,an]
- compoTests = []
- currentKey = None
- withPrefix = "with:"
-
- for i in range(len(args)):
- elt = os.path.expanduser(args[i])
-
- if elt.startswith(withPrefix):
- if not currentKey:
- raise SalomeContextException("test files list must follow corresponding component in command line.")
- elt = elt.replace(withPrefix, '')
- compoTests[len(compoTests)-1].tests = elt.split(",")
- currentKey = None
- else:
- currentKey = elt
- compoTests.append(ComponentAndTests(component=currentKey))
- # end for loop
- return compoTests
+ return args
#
-def runTests(params, args):
- compoTests = getComponentAndTestFiles(args)
- print compoTests
+# tests must be in ${ABSOLUTE_APPLI_PATH}/${__testSubDir}/
+__testSubDir = "bin/salome/test"
+
+# Both display process stdout&stderr to console and capture them to variables
+def __runTest(command, workdir):
+ p = subprocess.Popen(command, cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1)
+ stdout = []
+ stderr = []
+
+ while True:
+ reads = [p.stdout.fileno(), p.stderr.fileno()]
+ ret = select.select(reads, [], [])
+
+ for fd in ret[0]:
+ if fd == p.stdout.fileno():
+ read = p.stdout.readline()
+ sys.stdout.write(read)
+ stdout.append(read)
+ pass
+ if fd == p.stderr.fileno():
+ read = p.stderr.readline()
+ sys.stderr.write(read)
+ stderr.append(read)
+ pass
+ pass
+
+ if p.poll() != None:
+ break
+ pass
+
+ return p.returncode, "".join(stdout), "".join(stderr)
+#
+def runTests(args, exe=None):
+ args = __configureTests(args, exe)
- # :TODO: run tests
+ appliPath = os.getenv("ABSOLUTE_APPLI_PATH")
+ if not appliPath:
+ raise SalomeContextException("Unable to find application path. Please check that the variable ABSOLUTE_APPLI_PATH is set.")
+ testPath = os.path.join(appliPath, __testSubDir)
+ command = ["ctest"] + args
+ res, out, err = __runTest(command, testPath)
+ sys.exit(res)
#
def runSalome(self, args):
# Run this module as a script, in order to use appropriate Python interpreter
# according to current path (initialized from environment files).
-# kill = False
-# for e in args:
-# if "--shutdown-server" in e:
-# kill = True
-# args.remove(e)
-
import os
absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
env_copy = os.environ.copy()
proc = subprocess.Popen(['python', os.path.join(absoluteAppliPath,"bin","salome","salomeContext.py"), pickle.dumps(self), pickle.dumps(args)], shell=False, close_fds=True, env=env_copy)
msg = proc.communicate()
- # if kill:
- # self._killAll(args)
return msg, proc.returncode
#
#
def _runTests(self, args=[]):
- sys.argv = ['runTests'] + args
- import runTests
- params, args = runTests.configureTests(args, exe="salome test")
-
- sys.argv = ['runTests'] + args
+ sys.argv = ['runTests']
import setenv
setenv.main(True)
- return runTests.runTests(params, args)
+ import runTests
+ return runTests.runTests(args, exe="salome test")
#
def _showInfo(self, unused=None):
def link_module(options):
global verbose
- if not options.module:
+ if not options.module_path:
print "Option module is mandatory"
return
- module_dir=os.path.abspath(options.module)
+ module_dir=os.path.abspath(options.module_path)
if not os.path.exists(module_dir):
print "Module %s does not exist" % module_dir
return
return
module_bin_dir=os.path.join(module_dir,'bin','salome')
+ module_test_dir=os.path.join(module_dir,'bin','salome', 'test')
module_idl_dir=os.path.join(module_dir,'idl','salome')
module_lib_dir=os.path.join(module_dir,get_lib_dir(),'salome')
module_pvlib_dir=os.path.join(module_dir,get_lib_dir(),'paraview')
module_sharedoc_examples=os.path.join(module_dir,'share','doc','salome','examples')
bin_dir=os.path.join(home_dir,'bin','salome')
+ test_dir=os.path.join(home_dir,'bin','salome', 'test')
idl_dir=os.path.join(home_dir,'idl','salome')
lib_dir=os.path.join(home_dir,'lib','salome')
pvlib_dir=os.path.join(home_dir,'lib','paraview')
if options.clear:
rmtree(bin_dir)
+ rmtree(test_dir)
rmtree(idl_dir)
rmtree(lib_dir)
rmtree(lib_py_dir)
#directory bin/salome : create it and link content
if os.path.exists(module_bin_dir):
mkdir(bin_dir)
+ mkdir(test_dir)
for fn in os.listdir(module_bin_dir):
- symlink(os.path.join(module_bin_dir, fn), os.path.join(bin_dir, fn))
+ if fn != "test":
+ symlink(os.path.join(module_bin_dir, fn), os.path.join(bin_dir, fn))
pass
pass
else:
print module_bin_dir, " doesn't exist"
pass
+ #directory bin/salome/test : create it and link content
+ if os.path.exists(module_test_dir):
+ # link <appli_path>/bin/salome/test/<module> to <module_path>/bin/salome/test
+ print "link %s --> %s"%(os.path.join(test_dir, options.module_name), module_test_dir)
+ symlink(module_test_dir, os.path.join(test_dir, options.module_name))
+ # register module for testing in CTestTestfile.cmake
+ with open(os.path.join(test_dir, "CTestTestfile.cmake"), "ab") as f:
+ f.write("SUBDIRS(%s)\n"%options.module_name)
+ else:
+ if verbose:
+ print module_bin_dir, " doesn't exist"
+ pass
+
#directory idl/salome : create it and link content
if os.path.exists(module_idl_dir):
mkdir(idl_dir)
if verbose:
print module_pvlib_dir, " doesn't exist"
pass
-
+
#directory lib/pyversio/site-packages/salome : create it and link content
if not os.path.exists(module_lib_py_dir):
print "Python directory %s does not exist" % module_lib_py_dir
symlink(os.path.join(module_sharedoc_tui_dir, fn), os.path.join(sharedoc_tui_dir, fn))
pass
pass
-
+
#directory share/doc/salome/examples : create it and link content
if os.path.exists(module_sharedoc_examples):
mkdir(sharedoc_examples_dir)
-# Copyright (C) 2012-2014 CEA/DEN, EDF R&D
+# Copyright (C) 2012-2015 CEA/DEN, EDF R&D
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# --- rules ---
IF(NOT WIN32)
- ADD_TEST(NAME SalomeLauncher
- COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../UnitTests/prepare_test.py
- ${CMAKE_CURRENT_SOURCE_DIR}/test_launcher.py
- -d KERNEL_ROOT_DIR=${CMAKE_INSTALL_PREFIX}
- )
+# ** Now in CTestTestfileInstall.cmake **
+# ** In this file only remain unit tests (no SALOME session is needed) **
+# ADD_TEST(NAME SalomeLauncher
+# COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../../UnitTests/prepare_test.py
+# ${CMAKE_CURRENT_SOURCE_DIR}/test_launcher.py
+# -d KERNEL_ROOT_DIR=${CMAKE_INSTALL_PREFIX}
+# )
+ INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/test_launcher.py
+ DESTINATION ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test)
+
+ INSTALL(FILES CTestTestfileInstall.cmake
+ DESTINATION ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test
+ RENAME CTestTestfile.cmake)
ENDIF()
--- /dev/null
+# Copyright (C) 2015 CEA/DEN, EDF R&D
+#
+# 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, or (at your option) any later version.
+#
+# 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
+#
+
+SET(SALOME_TEST_DRIVER "$ENV{ABSOLUTE_APPLI_PATH}/bin/salome/appliskel/salome_test_driver.py")
+
+SET(COMPONENT_NAME KERNEL)
+SET(TIMEOUT 500)
+
+IF(NOT WIN32)
+ ADD_TEST(SalomeLauncher python ${SALOME_TEST_DRIVER} ${TIMEOUT} test_launcher.py)
+ SET_TESTS_PROPERTIES(SalomeLauncher PROPERTIES LABELS "${COMPONENT_NAME}"
+ # TIMEOUT 500
+ )
+ # /!\ DO NOT SET TIMEOUT PROPERTY IF USING ${SALOME_TEST_DRIVER}
+ # BUT PASS TIMEOUT VALUE TO THE DRIVER
+
+ENDIF()