From 4d36de2692d0f6f724cdc10a248a0af86f9f2dcc Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Mon, 25 Jul 2016 15:20:26 +0200 Subject: [PATCH] sat test : replace module by grid and type by session --- commands/test.py | 96 ++++++++++----------- complete_sat.sh | 10 ++- src/scriptTemplate.py | 97 --------------------- src/test/scriptTemplate.py | 4 +- src/test_module.py | 169 ++++++++++++++++++------------------- src/xsl/test.xsl | 18 ++-- 6 files changed, 151 insertions(+), 243 deletions(-) delete mode 100644 src/scriptTemplate.py diff --git a/commands/test.py b/commands/test.py index 9fa8215..7cb9fbc 100644 --- a/commands/test.py +++ b/commands/test.py @@ -41,10 +41,10 @@ parser.add_option('b', 'base', 'string', 'base', parser.add_option('l', 'launcher', 'string', 'launcher', _("Use this option to specify the path to a SALOME launcher to use to " "launch the test scripts of the test base.")) -parser.add_option('m', 'module', 'list', 'modules', - _('Indicate which module(s) to test (subdirectory of the test base).')) -parser.add_option('t', 'type', 'list', 'types', - _('Indicate which type(s) to test (subdirectory of the module).')) +parser.add_option('g', 'grid', 'list', 'grids', + _('Indicate which grid(s) to test (subdirectory of the test base).')) +parser.add_option('s', 'session', 'list', 'sessions', + _('Indicate which session(s) to test (subdirectory of the grid).')) parser.add_option('', 'display', 'string', 'display', _("Set the display where to launch SALOME." "\tIf value is NO then option --show-desktop=0 will be used to launch SALOME.")) @@ -161,43 +161,43 @@ def move_test_results(in_dir, what, out_dir, logger): os.makedirs(outtestbase) #logger.write(" copy testbase %s\n" % testbase, 5) - for module_ in [m for m in os.listdir(intestbase) if os.path.isdir( + for grid_ in [m for m in os.listdir(intestbase) if os.path.isdir( os.path.join(intestbase, m))]: # ignore source configuration directories - if module_[:4] == '.git' or module_ == 'CVS': + if grid_[:4] == '.git' or grid_ == 'CVS': continue - outmodule = os.path.join(outtestbase, module_) - inmodule = os.path.join(intestbase, module_) - os.makedirs(outmodule) - #logger.write(" copy module %s\n" % module_, 5) + outgrid = os.path.join(outtestbase, grid_) + ingrid = os.path.join(intestbase, grid_) + os.makedirs(outgrid) + #logger.write(" copy grid %s\n" % grid_, 5) - if module_ == 'RESSOURCES': - for file_name in os.listdir(inmodule): - if not os.path.isfile(os.path.join(inmodule, + if grid_ == 'RESSOURCES': + for file_name in os.listdir(ingrid): + if not os.path.isfile(os.path.join(ingrid, file_name)): continue - f = open(os.path.join(outmodule, file_name), "w") - f.write(save_file(os.path.join(inmodule, file_name), + f = open(os.path.join(outgrid, file_name), "w") + f.write(save_file(os.path.join(ingrid, file_name), finalPath)) f.close() else: - for type_name in [t for t in os.listdir(inmodule) if - os.path.isdir(os.path.join(inmodule, t))]: - outtype = os.path.join(outmodule, type_name) - intype = os.path.join(inmodule, type_name) - os.makedirs(outtype) + for session_name in [t for t in os.listdir(ingrid) if + os.path.isdir(os.path.join(ingrid, t))]: + outsession = os.path.join(outgrid, session_name) + insession = os.path.join(ingrid, session_name) + os.makedirs(outsession) - for file_name in os.listdir(intype): - if not os.path.isfile(os.path.join(intype, + for file_name in os.listdir(insession): + if not os.path.isfile(os.path.join(insession, file_name)): continue if file_name.endswith('result.py'): - shutil.copy2(os.path.join(intype, file_name), - os.path.join(outtype, file_name)) + shutil.copy2(os.path.join(insession, file_name), + os.path.join(outsession, file_name)) else: - f = open(os.path.join(outtype, file_name), "w") - f.write(save_file(os.path.join(intype, + f = open(os.path.join(outsession, file_name), "w") + f.write(save_file(os.path.join(insession, file_name), finalPath)) f.close() @@ -270,24 +270,24 @@ def create_test_report(config, dest_path, stylesheet, xmlname=""): gn = add_simple_node(tests, "testbase") gn.attrib['name'] = testbase nb, nb_pass, nb_failed, nb_timeout, nb_not_run = 0, 0, 0, 0, 0 - modules = {} - types = {} + grids = {} + sessions = {} for test in tt[testbase]: - #print test.module - if not modules.has_key(test.module): - mn = add_simple_node(gn, "module") - mn.attrib['name'] = test.module - modules[test.module] = mn + #print test.grid + if not grids.has_key(test.grid): + mn = add_simple_node(gn, "grid") + mn.attrib['name'] = test.grid + grids[test.grid] = mn - if not types.has_key("%s/%s" % (test.module, test.type)): - tyn = add_simple_node(mn, "type") - tyn.attrib['name'] = test.type - types["%s/%s" % (test.module, test.type)] = tyn + if not sessions.has_key("%s/%s" % (test.grid, test.session)): + tyn = add_simple_node(mn, "session") + tyn.attrib['name'] = test.session + sessions["%s/%s" % (test.grid, test.session)] = tyn for script in test.script: - tn = add_simple_node(types[ - "%s/%s" % (test.module, test.type)], "test") - tn.attrib['type'] = test.type + tn = add_simple_node(sessions[ + "%s/%s" % (test.grid, test.session)], "test") + tn.attrib['session'] = test.session tn.attrib['script'] = script.name if 'callback' in script: try: @@ -327,8 +327,8 @@ def create_test_report(config, dest_path, stylesheet, xmlname=""): if "amend" in script: amend_test = add_simple_node(amend, "atest") - amend_test.attrib['name'] = os.path.join(test.module, - test.type, + amend_test.attrib['name'] = os.path.join(test.grid, + test.session, script.name) amend_test.attrib['reason'] = script.amend.decode( "UTF-8") @@ -342,8 +342,8 @@ def create_test_report(config, dest_path, stylesheet, xmlname=""): if "known_error" in script: kf_script = add_simple_node(known_errors, "error") - kf_script.attrib['name'] = os.path.join(test.module, - test.type, + kf_script.attrib['name'] = os.path.join(test.grid, + test.session, script.name) kf_script.attrib['date'] = script.known_error.date kf_script.attrib[ @@ -359,8 +359,8 @@ def create_test_report(config, dest_path, stylesheet, xmlname=""): elif script.res == src.KO_STATUS: new_err = add_simple_node(new_errors, "new_error") - script_path = os.path.join(test.module, - test.type, script.name) + script_path = os.path.join(test.grid, + test.session, script.name) new_err.attrib['name'] = script_path new_err.attrib['cmd'] = ("sat testerror %s -s %s -c 'my" " comment' -p %s" % \ @@ -506,8 +506,8 @@ def run(args, runner, logger): logger, base_dir, testbase=test_base, - modules=options.modules, - types=options.types, + grids=options.grids, + sessions=options.sessions, launcher=options.launcher, show_desktop=show_desktop) diff --git a/complete_sat.sh b/complete_sat.sh index f28bbf0..0b4c71b 100755 --- a/complete_sat.sh +++ b/complete_sat.sh @@ -43,6 +43,9 @@ _show_applications() job) opts2=$(echo --jobs_config --name $opts2) ;; + test) + opts2=$(echo --base --display --grid --launcher --session $opts2) + ;; esac COMPREPLY=( $(compgen -W "${opts2}" -- ${cur}) ) @@ -89,7 +92,7 @@ _salomeTools_complete() # first argument => show available commands if [[ ${argc} == 1 ]] then - opts="config log testcommand source patch prepare environ clean configure make makeinstall compile launcher run jobs job shell --help" + opts="config log testcommand source patch prepare environ clean configure make makeinstall compile launcher run jobs job shell test --help" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 fi @@ -213,6 +216,11 @@ _salomeTools_complete() COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; + test) + opts="--base --launcher --grid --session --display" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + ;; *) return 0 ;; esac diff --git a/src/scriptTemplate.py b/src/scriptTemplate.py deleted file mode 100644 index 4f8ebc6..0000000 --- a/src/scriptTemplate.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -#-*- coding:utf-8 -*- - -import os, sys, traceback -import os.path -import time as THEBIGTIME - -# set path -toolsWay = r'${toolsWay}' -resourcesWay = r'${resourcesWay}' -outWay = r'${typeDir}' -tmpDir = r'${tmpDir}' - -listTest = ${listTest} -ignore = ${ignore} - -sys.path.append(toolsWay) -from TOOLS import TOOLS_class -my_tools = TOOLS_class(resourcesWay, tmpDir, toolsWay) - -from TOOLS import SatNotApplicableError - -# on set les variables d'environement -os.environ['TT_BASE_RESSOURCES'] = resourcesWay -sys.path.append(resourcesWay) - -exec_result = open(r'${resultFile}', 'w') -exec_result.write('Open\n') - -__stdout__ = sys.stdout -__stderr__ = sys.stderr - -for test in listTest: - pylog = open(os.path.join(outWay, test[:-3] + ".result.py"), "w") - testout = open(os.path.join(outWay, test[:-3] + ".out.py"), "w") - my_tools.init() - sys.stdout = testout - sys.stderr = testout - - pylog.write('#-*- coding:utf-8 -*-\n') - exec_result.write("Run %s " % test) - exec_result.flush() - - try: - timeStart = THEBIGTIME.time() - execfile(os.path.join(outWay, test), globals(), locals()) - timeTest = THEBIGTIME.time() - timeStart - except SatNotApplicableError, ex: - status = "NA" - reason = str(ex) - exec_result.write("NA\n") - timeTest = THEBIGTIME.time() - timeStart - pylog.write('status = "NA"\n') - pylog.write('time = "' + timeTest.__str__() + '"\n') - pylog.write('callback = "%s"\n' % reason) - except Exception, ex: - status = "KO" - reason = "" - if ignore.has_key(test): - status = "KF" - reason = "Known Failure = %s\n\n" % ignore[test] - exec_result.write("%s\n" % status) - timeTest = THEBIGTIME.time() - timeStart - pylog.write('status = "%s" \n' % status) - pylog.write('time = "' + timeTest.__str__() + '"\n') - pylog.write('callback="""' + reason) - exc_type, exc_value, exc_traceback = sys.exc_info() - traceback.print_exception(exc_type, - exc_value, - exc_traceback, - None, - file=pylog) - pylog.write('"""\n') - else: - exec_result.write("OK\n") - pylog.write('status = "OK"\n') - pylog.write('time = "' + timeTest.__str__() + '"\n') - - testout.close() - sys.stdout = __stdout__ - sys.stderr = __stderr__ - my_tools.writeInFiles(pylog) - pylog.close() - -exec_result.write('Close\n') -exec_result.close() - -if 'PY' not in '${typeName}': - import salome_utils - killScript = os.path.join(os.environ['KERNEL_ROOT_DIR'], - 'bin', - 'salome', - 'killSalome.py') - cmd = '{python} {killScript} {port}'.format(python=os.environ['PYTHONBIN'], - killScript=killScript, - port=salome_utils.getPortNumber()) - os.system(cmd) diff --git a/src/test/scriptTemplate.py b/src/test/scriptTemplate.py index 4f8ebc6..3e2f325 100644 --- a/src/test/scriptTemplate.py +++ b/src/test/scriptTemplate.py @@ -8,7 +8,7 @@ import time as THEBIGTIME # set path toolsWay = r'${toolsWay}' resourcesWay = r'${resourcesWay}' -outWay = r'${typeDir}' +outWay = r'${sessionDir}' tmpDir = r'${tmpDir}' listTest = ${listTest} @@ -85,7 +85,7 @@ for test in listTest: exec_result.write('Close\n') exec_result.close() -if 'PY' not in '${typeName}': +if 'PY' not in '${sessionName}': import salome_utils killScript = os.path.join(os.environ['KERNEL_ROOT_DIR'], 'bin', diff --git a/src/test_module.py b/src/test_module.py index a7bafd1..2d0c08d 100644 --- a/src/test_module.py +++ b/src/test_module.py @@ -37,10 +37,8 @@ import subprocess from . import fork import src -# directories not considered as test modules -C_IGNORE_MODULES = ['.git', '.svn', 'RESSOURCES'] - -C_TESTS_LIGHT_FILE = "TestsLight.txt" +# directories not considered as test grids +C_IGNORE_GRIDS = ['.git', '.svn', 'RESSOURCES'] # Get directory to be used for the temporary files. # @@ -58,15 +56,15 @@ class Test: logger, tmp_working_dir, testbase="", - modules=None, - types=None, + grids=None, + sessions=None, launcher="", show_desktop=True): - self.modules = modules + self.grids = grids self.config = config self.logger = logger self.tmp_working_dir = tmp_working_dir - self.types = types + self.sessions = sessions self.launcher = launcher self.show_desktop = show_desktop @@ -253,8 +251,8 @@ class Test: ## # Searches if the script is declared in known errors pyconf. # Update the status if needed. - def search_known_errors(self, status, test_module, test_type, test): - test_path = os.path.join(test_module, test_type, test) + def search_known_errors(self, status, test_grid, test_session, test): + test_path = os.path.join(test_grid, test_session, test) if not src.config_has_application(self.config): return status, [] @@ -298,8 +296,8 @@ class Test: results = {} for test in listTest: resfile = os.path.join(self.currentDir, - self.currentModule, - self.currentType, + self.currentgrid, + self.currentsession, test[:-3] + ".result.py") # check if .result.py file exists @@ -319,8 +317,8 @@ class Test: expected = [] if status == src.KO_STATUS or status == src.OK_STATUS: status, expected = self.search_known_errors(status, - self.currentModule, - self.currentType, + self.currentgrid, + self.currentsession, test) callback = "" @@ -340,8 +338,8 @@ class Test: # check if .py file exists testfile = os.path.join(self.currentDir, - self.currentModule, - self.currentType, + self.currentgrid, + self.currentsession, test) if not os.path.exists(testfile): @@ -352,8 +350,8 @@ class Test: # check if .out.py file exists outfile = os.path.join(self.currentDir, - self.currentModule, - self.currentType, + self.currentgrid, + self.currentsession, test[:-3] + ".out.py") if not os.path.exists(outfile): @@ -374,20 +372,20 @@ class Test: "test", "scriptTemplate.py"), 'r') template = string.Template(template_file.read()) - + # create substitution dictionary d = dict() d['resourcesWay'] = os.path.join(self.currentDir, 'RESSOURCES') d['tmpDir'] = os.path.join(self.tmp_working_dir, 'WORK') d['toolsWay'] = os.path.join(self.config.VARS.srcDir, "test") - d['typeDir'] = os.path.join(self.currentDir, - self.currentModule, - self.currentType) + d['sessionDir'] = os.path.join(self.currentDir, + self.currentgrid, + self.currentsession) d['resultFile'] = os.path.join(self.tmp_working_dir, 'WORK', 'exec_result') d['listTest'] = listTest - d['typeName'] = self.currentType + d['sessionName'] = self.currentsession d['ignore'] = ignoreList # create script with template @@ -398,7 +396,7 @@ class Test: # Find the getTmpDir function that gives access to *pidict file directory. # (the *pidict file exists when SALOME is launched) def get_tmp_dir(self): - # Rare case where there is no KERNEL in module list + # Rare case where there is no KERNEL in grid list # (for example MED_STANDALONE) if ('APPLICATION' in self.config and 'KERNEL' not in self.config.APPLICATION.products @@ -433,7 +431,7 @@ class Test: shell=True, executable='/bin/bash').communicate()[0].split()[-1] - # import module salome_utils from KERNEL that gives + # import grid salome_utils from KERNEL that gives # the right getTmpDir function (file_, pathname, description) = imp.find_module("salome_utils", @@ -441,17 +439,17 @@ class Test: 'bin', 'salome')]) try: - module = imp.load_module("salome_utils", + grid = imp.load_module("salome_utils", file_, pathname, description) - return module.getLogDir + return grid.getLogDir except: - module = imp.load_module("salome_utils", + grid = imp.load_module("salome_utils", file_, pathname, description) - return module.getTmpDir + return grid.getTmpDir finally: if file_: file_.close() @@ -464,14 +462,14 @@ class Test: return default_value - def generate_launching_commands(self, typename): + def generate_launching_commands(self): # Case where "sat test" is launched in an existing SALOME environment if 'KERNEL_ROOT_DIR' in os.environ: binSalome = "runSalome" binPython = "python" killSalome = "killSalome.py" - # Rare case where there is no KERNEL in module list + # Rare case where there is no KERNEL in grid list # (for example MED_STANDALONE) if ('APPLICATION' in self.config and 'KERNEL' not in self.config.APPLICATION.products): @@ -512,7 +510,7 @@ class Test: # Case where SALOME has NOT the launcher that uses the SalomeContext API if VersionSalome < 730: - binSalome = os.path.join(self.config.APPLI.module_appli_install_dir, + binSalome = os.path.join(self.config.APPLI.grid_appli_install_dir, appdir, "runAppli") binPython = "python" @@ -545,13 +543,13 @@ class Test: ## - # Runs tests of a type (using a single instance of Salome). + # Runs tests of a session (using a single instance of Salome). def run_tests(self, listTest, ignoreList): out_path = os.path.join(self.currentDir, - self.currentModule, - self.currentType) - typename = "%s/%s" % (self.currentModule, self.currentType) - time_out = self.get_test_timeout(typename, + self.currentgrid, + self.currentsession) + sessionname = "%s/%s" % (self.currentgrid, self.currentsession) + time_out = self.get_test_timeout(sessionname, self.config.SITE.test.timeout) time_out_salome = src.get_cfg_param(self.config.SITE.test, @@ -564,18 +562,17 @@ class Test: tmpDir = self.get_tmp_dir() - binSalome, binPython, killSalome = self.generate_launching_commands( - typename) - if self.settings.has_key("run_with_modules") \ - and self.settings["run_with_modules"].has_key(typename): + binSalome, binPython, killSalome = self.generate_launching_commands() + if self.settings.has_key("run_with_grids") \ + and self.settings["run_with_grids"].has_key(sessionname): binSalome = (binSalome + - " -m %s" % self.settings["run_with_modules"][typename]) + " -m %s" % self.settings["run_with_grids"][sessionname]) logWay = os.path.join(self.tmp_working_dir, "WORK", "log_cxx") status = False elapsed = -1 - if self.currentType.startswith("NOGUI_"): + if self.currentsession.startswith("NOGUI_"): # runSalome -t (bash) status, elapsed = fork.batch(binSalome, self.logger, os.path.join(self.tmp_working_dir, @@ -586,7 +583,7 @@ class Test: delai=time_out, log=logWay) - elif self.currentType.startswith("PY_"): + elif self.currentsession.startswith("PY_"): # python script.py status, elapsed = fork.batch(binPython, self.logger, os.path.join(self.tmp_working_dir, @@ -617,8 +614,8 @@ class Test: # create the test result to add in the config object test_info = src.pyconf.Mapping(self.config) test_info.testbase = self.currentTestBase - test_info.module = self.currentModule - test_info.type = self.currentType + test_info.grid = self.currentgrid + test_info.session = self.currentsession test_info.script = src.pyconf.Sequence(self.config) script_results = self.read_results(listTest, elapsed == time_out) @@ -684,22 +681,22 @@ class Test: self.config.TESTS.append(test_info, '') ## - # Runs all tests of a type. - def run_type_tests(self): + # Runs all tests of a session. + def run_session_tests(self): self.logger.write(self.write_test_margin(2), 3) - self.logger.write("Type = %s\n" % src.printcolors.printcLabel( - self.currentType), 3, False) + self.logger.write("Session = %s\n" % src.printcolors.printcLabel( + self.currentsession), 3, False) # prepare list of tests to run tests = os.listdir(os.path.join(self.currentDir, - self.currentModule, - self.currentType)) + self.currentgrid, + self.currentsession)) tests = filter(lambda l: l.endswith(".py"), tests) tests = sorted(tests, key=str.lower) # build list of known failures - cat = "%s/%s/" % (self.currentModule, self.currentType) + cat = "%s/%s/" % (self.currentgrid, self.currentsession) ignoreDict = {} for k in self.ignore_tests.keys(): if k.startswith(cat): @@ -708,33 +705,33 @@ class Test: self.run_tests(tests, ignoreDict) ## - # Runs all tests of a module. - def run_module_tests(self): + # Runs all tests of a grid. + def run_grid_tests(self): self.logger.write(self.write_test_margin(1), 3) - self.logger.write("Module = %s\n" % src.printcolors.printcLabel( - self.currentModule), 3, False) + self.logger.write("grid = %s\n" % src.printcolors.printcLabel( + self.currentgrid), 3, False) - module_path = os.path.join(self.currentDir, self.currentModule) + grid_path = os.path.join(self.currentDir, self.currentgrid) - types = [] - if self.types is not None: - types = self.types # user choice + sessions = [] + if self.sessions is not None: + sessions = self.sessions # user choice else: - # use all scripts in module - types = filter(lambda l: l not in C_IGNORE_MODULES, - os.listdir(module_path)) - types = filter(lambda l: os.path.isdir(os.path.join(module_path, - l)), types) - - types = sorted(types, key=str.lower) - for type_ in types: - if not os.path.exists(os.path.join(module_path, type_)): + # use all scripts in grid + sessions = filter(lambda l: l not in C_IGNORE_GRIDS, + os.listdir(grid_path)) + sessions = filter(lambda l: os.path.isdir(os.path.join(grid_path, + l)), sessions) + + sessions = sorted(sessions, key=str.lower) + for session_ in sessions: + if not os.path.exists(os.path.join(grid_path, session_)): self.logger.write(self.write_test_margin(2), 3) - self.logger.write(src.printcolors.printcWarning("Type %s not " - "found" % type_) + "\n", 3, False) + self.logger.write(src.printcolors.printcWarning("Session %s not" + " found" % session_) + "\n", 3, False) else: - self.currentType = type_ - self.run_type_tests() + self.currentsession = session_ + self.run_session_tests() ## # Runs test testbase. @@ -784,25 +781,25 @@ class Test: else: self.known_errors = None - if self.modules is not None: - modules = self.modules # given by user + if self.grids is not None: + grids = self.grids # given by user else: - # select all the modules (i.e. directories) in the directory - modules = filter(lambda l: l not in C_IGNORE_MODULES, + # select all the grids (i.e. directories) in the directory + grids = filter(lambda l: l not in C_IGNORE_GRIDS, os.listdir(self.currentDir)) - modules = filter(lambda l: os.path.isdir( + grids = filter(lambda l: os.path.isdir( os.path.join(self.currentDir, l)), - modules) + grids) - modules = sorted(modules, key=str.lower) - for module in modules: - if not os.path.exists(os.path.join(self.currentDir, module)): + grids = sorted(grids, key=str.lower) + for grid in grids: + if not os.path.exists(os.path.join(self.currentDir, grid)): self.logger.write(self.write_test_margin(1), 3) self.logger.write(src.printcolors.printcWarning( - "Module %s does not exist\n" % module), 3, False) + "grid %s does not exist\n" % grid), 3, False) else: - self.currentModule = module - self.run_module_tests() + self.currentgrid = grid + self.run_grid_tests() def run_script(self, script_name): if ('APPLICATION' in self.config and diff --git a/src/xsl/test.xsl b/src/xsl/test.xsl index 923468d..7a78fc9 100644 --- a/src/xsl/test.xsl +++ b/src/xsl/test.xsl @@ -133,7 +133,7 @@ - + @@ -146,7 +146,7 @@ - + @@ -259,21 +259,21 @@
- + - +
mod_. - Tests of module + Tests of grid
modulegrid success totalTime
- + - + @@ -343,8 +343,8 @@ - - + +
-- 2.30.2
typesession script result time