runSalome.py
runSession.py
runConsole.py
+ runTests.py
salomeConsole.py
${CMAKE_CURRENT_BINARY_DIR}/salomeContextUtils.py
salomeContext.py
local cur prev command options
COMPREPLY=( )
_get_comp_words_by_ref -n = cur prev
- commands='start shell connect killall info help coffee'
+ commands='start shell connect kill killall test info help coffee'
# Algorithm:
# If cursor is at index 1
If command is not given a shell is opened; else execute the given command.\n
* Command may be an executable script or program, either identified by its full path or located in a directory pointed by a system variable (e.g. PATH).\n
* Command may also be a series of Python scripts with arguments: [PYTHON_FILE [args] [PYTHON_FILE [args]...]]
-Python file arguments, if any, must be comma-separated (without blank characters) and prefixed by "args:" (without quotes).
+Python file arguments, if any, must be comma-separated (without blank characters) and prefixed by "args:" keyword (without quotes).
For example:
salome shell hello.py add.py args:1,2 hello.py args:you
will successively say hello, add 1+2, and say hello to you.
--- /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 os
+from optparse import OptionParser
+from salomeContextUtils import getScriptsAndArgs, formatScriptsAndArgs
+
+# 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 = []
+ if exe:
+ usage = "Usage: %s [options] [components]"%exe
+ else:
+ usage = "Usage: %prog [options] [components]"
+ 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
+"""
+ 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
+#
+
+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
+ #
+#
+
+# 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
+#
+
+def runTests(params, args):
+ compoTests = getComponentAndTestFiles(args)
+ print compoTests
+
+
+ # :TODO: run tests
+
+
+
+#
Commands:
=========
- start Starts a SALOME session (through virtual application)
- shell Initializes SALOME environment, and executes scripts passed
- as command arguments
- connect Connects a Python console to the active SALOME session
- killall Kill all SALOME running sessions for current user
- info Display some information about SALOME
- help Show this message
- coffee Yes! SALOME can also make coffee!!
+ start Starts a SALOME session (through virtual application)
+ shell Initializes SALOME environment, and executes scripts passed
+ as command arguments
+ connect Connects a Python console to the active SALOME session
+ kill <port(s)> Terminate SALOME session running on given ports for current user
+ Port numbers must be separated by blank characters
+ killall Kill *all* SALOME running sessions for current user
+ test Run SALOME tests.
+ info Display some information about SALOME
+ help Show this message
+ coffee Yes! SALOME can also make coffee!!
If no command is given, default to start.
Command options:
================
- Use salome <command> --help to show help on command ; available for start
- and shell commands.
+ Use salome <command> --help to show help on command ; available for commands:
+ start, shell, test.
--config=<file,folder,...>
==========================
options = args[1:]
availableCommands = {
- 'start' : '_runAppli',
- 'shell' : '_runSession',
+ 'start' : '_runAppli',
+ 'shell' : '_runSession',
'connect' : '_runConsole',
- 'killall': '_killAll',
- 'info': '_showInfo',
- 'help': '_usage',
- 'coffee' : '_makeCoffee'
+ 'kill' : '_kill',
+ 'killall' : '_killAll',
+ 'test' : '_runTests',
+ 'info' : '_showInfo',
+ 'help' : '_usage',
+ 'coffee' : '_makeCoffee'
}
if not command in availableCommands.keys():
sys.path[:0] = pythonpath
#
- def _runAppli(self, args=None):
- if args is None:
- args = []
+ def _runAppli(self, args=[]):
# Initialize SALOME environment
sys.argv = ['runSalome'] + args
import setenv
runSalome.runSalome()
#
- def _runSession(self, args=None):
- if args is None:
- args = []
+ def _runSession(self, args=[]):
sys.argv = ['runSession'] + args
import runSession
params, args = runSession.configureSession(args, exe="salome shell")
return runSession.runSession(params, args)
#
- def _runConsole(self, args=None):
- if args is None:
- args = []
+ def _runConsole(self, args=[]):
# Initialize SALOME environment
sys.argv = ['runConsole'] + args
import setenv
return proc.communicate()
#
- def _killAll(self, args=None):
- if args is None:
- args = []
+ def _kill(self, args=[]):
+ ports = args
+ if not ports:
+ print "Port number(s) not provided to command: salome kill <port(s)>"
+ return
+
+ from multiprocessing import Process
+ from killSalomeWithPort import killMyPort
+ import tempfile
+ for port in ports:
+ with tempfile.NamedTemporaryFile():
+ p = Process(target = killMyPort, args=(port,))
+ p.start()
+ p.join()
+ pass
+ #
+
+ def _killAll(self, unused=None):
try:
import PortManager # mandatory
from multiprocessing import Process
from killSalome import killAllPorts
killAllPorts()
pass
+ #
+
+ def _runTests(self, args=[]):
+ sys.argv = ['runTests'] + args
+ import runTests
+ params, args = runTests.configureTests(args, exe="salome test")
+
+ sys.argv = ['runTests'] + args
+ import setenv
+ setenv.main(True)
+ return runTests.runTests(params, args)
#
- def _showInfo(self, args=None):
+ def _showInfo(self, unused=None):
print "Running with python", platform.python_version()
self._runAppli(["--version"])
#
usage()
#
- def _makeCoffee(self, args=None):
+ def _makeCoffee(self, unused=None):
print " ("
print " ) ("
print " ___...(-------)-....___"
print " | | | |"
print " \\ \\ | |"
print " `\\ `\\ | |"
- print " `\\ `| |"
- print " _/ /\\ /"
- print " (__/ \\ /"
+ print " `\\ `| SALOME |"
+ print " _/ /\\ 4 EVER /"
+ print " (__/ \\ <3 /"
print " _..---\"\"` \\ /`\"\"---.._"
print " .-\' \\ / \'-."
print " : `-.__ __.-\' :"
# script: the command to be run, e.g. python <script.py>
# args: its input parameters
# out: its output parameters
- def __init__(self, script = None, args = None, out = None):
+ def __init__(self, script=None, args=None, out=None):
self.script = script
self.args = args
self.out = out
return command
#
-# Ensure OMNIORB_USER_PATH is defined. This variable refers to a the folder in which
+# Ensure OMNIORB_USER_PATH is defined. This variable refers to a folder in which
# SALOME will write omniOrb configuration files.
# If OMNIORB_USER_PATH is already set, only checks write access to associated directory ;
# an exception is raised if check fails. It allows users for choosing a specific folder.