From: Cédric Aguerre Date: Mon, 16 Feb 2015 10:05:46 +0000 (+0100) Subject: add commands: kill, test X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4854d5c784cfeb712260e1e67beaf8054e53900f;p=modules%2Fkernel.git add commands: kill, test add commands: kill, test --- diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index c0b21f8a4..f97300c1f 100755 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -48,6 +48,7 @@ SET(SCRIPTS runSalome.py runSession.py runConsole.py + runTests.py salomeConsole.py ${CMAKE_CURRENT_BINARY_DIR}/salomeContextUtils.py salomeContext.py diff --git a/bin/appliskel/.salome-completion.sh b/bin/appliskel/.salome-completion.sh index 1e2d98396..1887e5590 100644 --- a/bin/appliskel/.salome-completion.sh +++ b/bin/appliskel/.salome-completion.sh @@ -51,7 +51,7 @@ _salome() 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 diff --git a/bin/runSession.py b/bin/runSession.py index 1948d4476..3e7af9ba8 100644 --- a/bin/runSession.py +++ b/bin/runSession.py @@ -56,7 +56,7 @@ def configureSession(args=None, exe=None): 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. diff --git a/bin/runTests.py b/bin/runTests.py new file mode 100644 index 000000000..007f8e7aa --- /dev/null +++ b/bin/runTests.py @@ -0,0 +1,120 @@ +# 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="", 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 + + + +# diff --git a/bin/salomeContext.py b/bin/salomeContext.py index 11a980bdb..056fa323f 100644 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -40,21 +40,24 @@ Usage: salome [command] [options] [--config=] 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 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 --help to show help on command ; available for start - and shell commands. + Use salome --help to show help on command ; available for commands: + start, shell, test. --config= ========================== @@ -195,13 +198,15 @@ class SalomeContext: 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(): @@ -305,9 +310,7 @@ class SalomeContext: 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 @@ -317,9 +320,7 @@ class SalomeContext: 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") @@ -331,9 +332,7 @@ class SalomeContext: 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 @@ -344,9 +343,24 @@ class SalomeContext: 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 " + 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 @@ -364,10 +378,21 @@ class SalomeContext: 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"]) # @@ -376,7 +401,7 @@ class SalomeContext: usage() # - def _makeCoffee(self, args=None): + def _makeCoffee(self, unused=None): print " (" print " ) (" print " ___...(-------)-....___" @@ -387,9 +412,9 @@ class SalomeContext: print " | | | |" print " \\ \\ | |" print " `\\ `\\ | |" - print " `\\ `| |" - print " _/ /\\ /" - print " (__/ \\ /" + print " `\\ `| SALOME |" + print " _/ /\\ 4 EVER /" + print " (__/ \\ <3 /" print " _..---\"\"` \\ /`\"\"---.._" print " .-\' \\ / \'-." print " : `-.__ __.-\' :" diff --git a/bin/salomeContextUtils.py.in b/bin/salomeContextUtils.py.in index 71c61f974..460d1e722 100644 --- a/bin/salomeContextUtils.py.in +++ b/bin/salomeContextUtils.py.in @@ -111,7 +111,7 @@ class ScriptAndArgs: # script: the command to be run, e.g. python # 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 @@ -248,7 +248,7 @@ def formatScriptsAndArgs(scriptArgs=None): 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.