From cb8aa80b96849b5e268a1ceb1f2c4bc8851837f7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Aguerre?= Date: Mon, 16 Feb 2015 11:05:46 +0100 Subject: [PATCH] add commands: kill, test add commands: kill, test --- bin/CMakeLists.txt | 1 + bin/appliskel/.salome-completion.sh | 2 +- bin/runTests.py | 120 ++++++++++++++++++++++++++++ bin/salomeContext.py | 86 ++++++++++++++------ bin/salomeContextUtils.py.in | 4 +- 5 files changed, 185 insertions(+), 28 deletions(-) create mode 100644 bin/runTests.py 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 273878609..705129f83 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 context shell connect killall info help coffee' + commands='start context shell connect kill killall test info help coffee' # Algorithm: # If cursor is at index 1 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 38e508025..f9c641b4e 100644 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -45,17 +45,31 @@ Commands: shell Initializes SALOME context, 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!! + 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= ========================== @@ -214,10 +228,12 @@ class SalomeContext: 'context' : '_setContext', '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(): @@ -324,10 +340,8 @@ class SalomeContext: sys.path[:0] = pythonpath # - def _runAppli(self, args=None): - if args is None: - args = [] - # Initialize SALOME context + def _runAppli(self, args=[]): + # Initialize SALOME environment sys.argv = ['runSalome'] + args import setenv setenv.main(True) @@ -356,9 +370,7 @@ class SalomeContext: return proc.communicate() # - 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") @@ -370,10 +382,8 @@ class SalomeContext: return runSession.runSession(params, args) # - def _runConsole(self, args=None): - if args is None: - args = [] - # Initialize SALOME context + def _runConsole(self, args=[]): + # Initialize SALOME environment sys.argv = ['runConsole'] + args import setenv setenv.main(True) @@ -383,9 +393,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 @@ -403,10 +428,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"]) # @@ -415,7 +451,7 @@ class SalomeContext: usage() # - def _makeCoffee(self, args=None): + def _makeCoffee(self, unused=None): print " (" print " ) (" print " ___...(-------)-....___" @@ -426,9 +462,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 4d6d02ebb..724106a6e 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 @@ -269,7 +269,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. -- 2.39.2