3 # Copyright (C) 2010-2013 CEA/DEN
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # Python 2/3 compatibility for execfile function
23 def execfile(somefile, global_vars, local_vars):
24 with open(somefile) as f:
25 code = compile(f.read(), somefile, 'exec')
26 exec(code, global_vars, local_vars)
43 # directories not considered as test grids
44 C_IGNORE_GRIDS = ['.git', '.svn', 'RESSOURCES']
48 # Get directory to be used for the temporary files.
50 def getTmpDirDEFAULT():
51 if src.architecture.is_windows():
52 directory = os.getenv("TEMP")
54 # for Linux: use /tmp/logs/{user} folder
55 directory = os.path.join( '/tmp', 'logs', os.getenv("USER", "unknown"))
71 self.tmp_working_dir = tmp_working_dir
72 self.sessions = sessions
73 self.launcher = launcher
74 self.show_desktop = show_desktop
76 res = self.prepare_testbase(testbase)
77 self.test_base_found = True
80 self.test_base_found = False
83 self.known_errors = None
85 # create section for results
86 self.config.TESTS = src.pyconf.Sequence(self.config)
92 self.nb_acknoledge = 0
94 def _copy_dir(self, source, target):
95 if self.config.VARS.python >= "2.6":
96 shutil.copytree(source, target,
98 ignore=shutil.ignore_patterns('.git*','.svn*'))
100 shutil.copytree(source, target,
103 def prepare_testbase_from_dir(self, testbase_name, testbase_dir):
104 self.logger.write(_("get test base from dir: %s\n") % \
105 src.printcolors.printcLabel(testbase_dir), 3)
106 if not os.access(testbase_dir, os.X_OK):
107 raise src.SatException(_("testbase %(name)s (%(dir)s) does not "
108 "exist ...\n") % { 'name': testbase_name,
109 'dir': testbase_dir })
111 self._copy_dir(testbase_dir,
112 os.path.join(self.tmp_working_dir, 'BASES', testbase_name))
114 def prepare_testbase_from_git(self,
119 _("get test base '%(testbase)s' with '%(tag)s' tag from git\n") % {
120 "testbase" : src.printcolors.printcLabel(testbase_name),
121 "tag" : src.printcolors.printcLabel(testbase_tag)},
124 def set_signal(): # pragma: no cover
125 """see http://bugs.python.org/issue1652"""
127 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
129 cmd = "git clone --depth 1 %(base)s %(dir)s"
130 cmd += " && cd %(dir)s"
131 if testbase_tag=='master':
132 cmd += " && git fetch origin %(branch)s"
134 cmd += " && git fetch origin %(branch)s:%(branch)s"
135 cmd += " && git checkout %(branch)s"
136 cmd = cmd % { 'branch': testbase_tag,
137 'base': testbase_base,
138 'dir': testbase_name }
140 self.logger.write("> %s\n" % cmd, 5)
141 if src.architecture.is_windows():
142 # preexec_fn not supported on windows platform
143 res = subprocess.call(cmd,
144 cwd=os.path.join(self.tmp_working_dir, 'BASES'),
146 stdout=self.logger.logTxtFile,
147 stderr=subprocess.PIPE)
149 res = subprocess.call(cmd,
150 cwd=os.path.join(self.tmp_working_dir, 'BASES'),
152 preexec_fn=set_signal,
153 stdout=self.logger.logTxtFile,
154 stderr=subprocess.PIPE)
156 raise src.SatException(_("Error: unable to get test base "
157 "'%(name)s' from git '%(repo)s'.") % \
158 { 'name': testbase_name,
159 'repo': testbase_base })
162 self.logger.error(_("git is not installed. exiting...\n"))
165 def prepare_testbase_from_svn(self, user, testbase_name, testbase_base):
166 self.logger.write(_("get test base '%s' from svn\n") % \
167 src.printcolors.printcLabel(testbase_name), 3)
169 def set_signal(): # pragma: no cover
170 """see http://bugs.python.org/issue1652"""
172 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
174 cmd = "svn checkout --username %(user)s %(base)s %(dir)s"
175 cmd = cmd % { 'user': user,
176 'base': testbase_base,
177 'dir': testbase_name }
179 # Get the application environment
180 self.logger.write(_("Set the application environment\n"), 5)
181 env_appli = src.environment.SalomeEnviron(self.config,
182 src.environment.Environ(dict(os.environ)))
183 env_appli.set_application_env(self.logger)
185 self.logger.write("> %s\n" % cmd, 5)
186 if src.architecture.is_windows():
187 # preexec_fn not supported on windows platform
188 res = subprocess.call(cmd,
189 cwd=os.path.join(self.tmp_working_dir, 'BASES'),
191 stdout=self.logger.logTxtFile,
192 stderr=subprocess.PIPE)
194 res = subprocess.call(cmd,
195 cwd=os.path.join(self.tmp_working_dir, 'BASES'),
197 preexec_fn=set_signal,
198 stdout=self.logger.logTxtFile,
199 stderr=subprocess.PIPE,
200 env=env_appli.environ.environ,)
203 raise src.SatException(_("Error: unable to get test base '%(nam"
204 "e)s' from svn '%(repo)s'.") % \
205 { 'name': testbase_name,
206 'repo': testbase_base })
209 self.logger.error(_("svn is not installed. exiting...\n"))
213 # Configure tests base.
214 def prepare_testbase(self, test_base_name):
215 src.printcolors.print_value(self.logger,
219 self.logger.write("\n", 3, False)
221 # search for the test base
222 test_base_info = None
223 for project_name in self.config.PROJECTS.projects:
224 project_info = self.config.PROJECTS.projects[project_name]
225 if "test_bases" not in project_info:
227 for t_b_info in project_info.test_bases:
228 if t_b_info.name == test_base_name:
229 test_base_info = t_b_info
231 if not test_base_info:
232 if os.path.exists(test_base_name):
233 self.prepare_testbase_from_dir("DIR", test_base_name)
234 self.currentTestBase = "DIR"
237 if not test_base_info:
238 message = (_("########## ERROR: test base '%s' not found\n") %
240 self.logger.write("%s\n" % src.printcolors.printcError(message))
243 if test_base_info.get_sources == "dir":
244 self.prepare_testbase_from_dir(test_base_name,
245 test_base_info.info.dir)
246 elif test_base_info.get_sources == "git":
247 self.prepare_testbase_from_git(test_base_name,
248 test_base_info.info.base,
249 self.config.APPLICATION.test_base.tag)
250 elif test_base_info.get_sources == "svn":
251 svn_user = src.get_cfg_param(test_base_info.info,
253 self.config.USER.svn_user)
254 self.prepare_testbase_from_svn(svn_user,
256 test_base_info.info.base)
258 raise src.SatException(_("unknown source type '%(type)s' for test b"
259 "ase '%(base)s' ...\n") % {
260 'type': test_base_info.get_sources,
261 'base': test_base_name })
263 self.currentTestBase = test_base_name
266 # Searches if the script is declared in known errors pyconf.
267 # Update the status if needed.
268 def search_known_errors(self, status, test_grid, test_session, test):
269 test_path = os.path.join(test_grid, test_session, test)
270 if not src.config_has_application(self.config):
273 if self.known_errors is None:
276 platform = self.config.VARS.arch
277 application = self.config.VARS.application
278 error = self.known_errors.get_error(test_path, application, platform)
282 if status == src.OK_STATUS:
285 self.known_errors.fix_error(error)
287 #testerror.write_test_failures(
288 # self.config.TOOLS.testerror.file_path,
289 # self.known_errors.errors)
290 return status, [ error.date,
296 self.known_errors.unfix_error(error)
298 #testerror.write_test_failures(self.config.TOOLS.testerror.file_path,
299 # self.known_errors.errors)
301 delta = self.known_errors.get_expecting_days(error)
302 kfres = [ error.date, error.expected, error.comment, error.fixed ]
304 return src.KO_STATUS, kfres
305 return src.KNOWNFAILURE_STATUS, kfres
308 # Read the *.result.py files.
309 def read_results(self, listTest, has_timed_out):
311 for test in listTest:
312 resfile = os.path.join(self.currentDir,
315 test[:-3] + ".result.py")
317 # check if <test>.result.py file exists
318 if not os.path.exists(resfile):
319 results[test] = ["?", -1, "", []]
323 print("test script: '%s':\n'%s'\n" % (resfile, open(resfile, 'r').read()))
326 execfile(resfile, gdic, ldic)
328 status = src.TIMEOUT_STATUS
329 if not has_timed_out:
330 status = src.KO_STATUS
333 status = ldic['status']
336 if status == src.KO_STATUS or status == src.OK_STATUS:
337 status, expected = self.search_known_errors(status,
343 if 'callback' in ldic:
344 callback = ldic['callback']
345 elif status == src.KO_STATUS:
348 print("--- CRASH ldic\n%s" % PP.pformat(ldic)) # cvw TODO
349 print("--- CRASH gdic\n%s" % PP.pformat(gdic))
355 exec_time = float(ldic['time'])
359 results[test] = [status, exec_time, callback, expected]
362 results[test] = ["?", -1, "", []]
363 # results[test] = [src.O_STATUS, -1, open(resfile, 'r').read(), []]
365 # check if <test>.py file exists
366 testfile = os.path.join(self.currentDir,
371 if not os.path.exists(testfile):
372 results[test].append('')
374 text = open(testfile, "r").read()
375 results[test].append(text)
377 # check if <test>.out.py file exists
378 outfile = os.path.join(self.currentDir,
381 test[:-3] + ".out.py")
383 if not os.path.exists(outfile):
384 results[test].append('')
386 text = open(outfile, "r").read()
387 results[test].append(text)
392 # Generates the script to be run by Salome.
393 # This python script includes init and close statements and a loop
394 # calling all the scripts of a single directory.
395 def generate_script(self, listTest, script_path, ignoreList):
397 tFile = os.path.join(self.config.VARS.srcDir, "test", "scriptTemplate.py")
398 with open(tFile, 'r') as f:
399 template = string.Template(f.read())
401 # create substitution dictionary
403 d['resourcesWay'] = os.path.join(self.currentDir, 'RESSOURCES')
404 d['tmpDir'] = os.path.join(self.tmp_working_dir, 'WORK')
405 d['toolsWay'] = os.path.join(self.config.VARS.srcDir, "test")
406 d['sessionDir'] = os.path.join(self.currentDir, self.currentgrid, self.currentsession)
407 d['resultFile'] = os.path.join(self.tmp_working_dir, 'WORK', 'exec_result')
408 d['listTest'] = listTest
409 d['sessionName'] = self.currentsession
410 d['ignore'] = ignoreList
412 # create script with template
413 contents = template.safe_substitute(d)
414 if verbose: print("generate_script '%s':\n%s" % (script_path, contents)) # cvw TODO
415 with open(script_path, 'w') as f:
419 # Find the getTmpDir function that gives access to *_pidict file directory.
420 # (the *_pidict file exists when SALOME is launched)
421 def get_tmp_dir(self):
422 # Rare case where there is no KERNEL in grid list
423 # (for example MED_STANDALONE)
424 if ('APPLICATION' in self.config
425 and 'KERNEL' not in self.config.APPLICATION.products
426 and 'KERNEL_ROOT_DIR' not in os.environ):
427 return getTmpDirDEFAULT
429 # Case where "sat test" is launched in an existing SALOME environment
430 if 'KERNEL_ROOT_DIR' in os.environ:
431 root_dir = os.environ['KERNEL_ROOT_DIR']
433 if ('APPLICATION' in self.config and
434 'KERNEL' in self.config.APPLICATION.products):
435 root_dir = src.product.get_product_config(self.config, "KERNEL").install_dir
437 # Case where there the appli option is called (with path to launcher)
438 if len(self.launcher) > 0:
439 # There are two cases : The old application (runAppli)
441 launcherName = os.path.basename(self.launcher)
442 launcherDir = os.path.dirname(self.launcher)
443 if launcherName == 'runAppli':
446 for i in %s/env.d/*.sh;
449 echo $KERNEL_ROOT_DIR
454 echo -e 'import os\nprint(os.environ[\"KERNEL_ROOT_DIR\"])' > tmpscript.py
455 %s shell tmpscript.py
458 if src.architecture.is_windows():
459 subproc_res = subprocess.Popen(cmd,
460 stdout=subprocess.PIPE,
461 shell=True).communicate()
464 subproc_res = subprocess.Popen(cmd,
465 stdout=subprocess.PIPE,
467 executable='/bin/bash').communicate()
470 root_dir = subproc_res[0].split()[-1]
472 # import grid salome_utils from KERNEL that gives
473 # the right getTmpDir function
474 root_dir = root_dir.decode('utf-8')
475 aPath = [os.path.join(root_dir, 'bin', 'salome')]
476 sal_uts = "salome_utils"
478 (file_, pathname, description) = imp.find_module(sal_uts, aPath )
480 msg = "inexisting %s.py in %s" % (sal_uts, aPath)
484 grid = imp.load_module(sal_uts, file_, pathname, description)
485 return grid.getLogDir
487 grid = imp.load_module(sal_uts, file_, pathname, description)
488 return grid.getTmpDir
494 def get_test_timeout(self, test_name, default_value):
495 if ("timeout" in self.settings and
496 test_name in self.settings["timeout"]):
497 return self.settings["timeout"][test_name]
501 def generate_launching_commands(self):
503 # Case where there the appli option is called (with path to launcher)
504 if len(self.launcher) > 0:
505 # There are two cases : The old application (runAppli)
507 launcherName = os.path.basename(self.launcher)
508 launcherDir = os.path.dirname(self.launcher)
509 if os.path.basename(launcherDir) == 'APPLI':
511 binSalome = self.launcher
512 binPython = ("for i in " +
514 "/env.d/*.sh; do source ${i}; done ; python")
515 killSalome = ("for i in " +
517 "/env.d/*.sh; do source ${i}; done ; killSalome.py'")
518 return binSalome, binPython, killSalome
521 binSalome = self.launcher
522 binPython = self.launcher + ' shell'
523 killSalome = self.launcher + ' killall'
524 return binSalome, binPython, killSalome
526 # SALOME version detection and APPLI repository detection
527 VersionSalome = src.get_salome_version(self.config)
529 if "APPLI" in self.config and "application_name" in self.config.APPLI:
530 appdir = self.config.APPLI.application_name
532 # Case where SALOME has NOT the launcher that uses the SalomeContext API
533 if VersionSalome < 730:
534 binSalome = os.path.join(self.config.APPLICATION.workdir,
538 killSalome = "killSalome.py"
539 src.environment.load_environment(self.config, False, self.logger)
540 return binSalome, binPython, killSalome
542 # Case where SALOME has the launcher that uses the SalomeContext API
544 launcher_name = src.get_launcher_name(self.config)
545 binSalome = os.path.join(self.config.APPLICATION.workdir,
548 binPython = binSalome + ' shell'
549 killSalome = binSalome + ' killall'
550 return binSalome, binPython, killSalome
552 return binSalome, binPython, killSalome
556 # Runs tests of a session (using a single instance of Salome).
557 def run_tests(self, listTest, ignoreList):
558 out_path = os.path.join(self.currentDir,
561 if verbose: print("run_tests '%s'\nlistTest: %s\nignoreList: %s" %
562 (self.currentDir, PP.pformat(listTest), PP.pformat(ignoreList))) # cvw TODO
563 sessionname = "%s/%s" % (self.currentgrid, self.currentsession)
564 time_out = self.get_test_timeout(sessionname,
567 time_out_salome = DEFAULT_TIMEOUT
569 # generate wrapper script
570 script_path = os.path.join(out_path, 'wrapperScript.py')
571 self.generate_script(listTest, script_path, ignoreList)
573 tmpDir = self.get_tmp_dir()
575 binSalome, binPython, killSalome = self.generate_launching_commands()
576 if "run_with_grids" in self.settings and \
577 sessionname in self.settings["run_with_grids"]:
578 binSalome = (binSalome + " -m %s" % self.settings["run_with_grids"][sessionname])
580 logWay = os.path.join(self.tmp_working_dir, "WORK", "log_cxx")
584 if self.currentsession.startswith("NOGUI_"):
585 # runSalome -t (bash)
586 status, elapsed = fork.batch(
589 os.path.join(self.tmp_working_dir, "WORK"),
590 [ "-t", "--shutdown-server=1", script_path ],
594 elif self.currentsession.startswith("PY_"):
596 status, elapsed = fork.batch(
599 os.path.join(self.tmp_working_dir, "WORK"),
606 if self.show_desktop: opt = "--show-desktop=0"
607 status, elapsed = fork.batch_salome(
610 os.path.join( self.tmp_working_dir, "WORK"),
611 [ opt, "--shutdown-server=1", script_path ],
616 delaiapp=time_out_salome)
618 self.logger.write("status = %s, elapsed = %s\n" % (status, elapsed), 5)
620 # create the test result to add in the config object
621 test_info = src.pyconf.Mapping(self.config)
622 test_info.testbase = self.currentTestBase
623 test_info.grid = self.currentgrid
624 test_info.session = self.currentsession
625 test_info.script = src.pyconf.Sequence(self.config)
627 script_results = self.read_results(listTest, elapsed == time_out)
628 for sr in sorted(script_results.keys()):
631 # create script result
632 script_info = src.pyconf.Mapping(self.config)
633 script_info.name = sr
634 script_info.res = script_results[sr][0]
635 script_info.time = script_results[sr][1]
636 if script_info.res == src.TIMEOUT_STATUS:
637 script_info.time = time_out
638 if script_info.time < 1e-3: script_info.time = 0
640 callback = script_results[sr][2]
641 if script_info.res != src.OK_STATUS and len(callback) > 0:
642 script_info.callback = callback
644 kfres = script_results[sr][3]
646 script_info.known_error = src.pyconf.Mapping(self.config)
647 script_info.known_error.date = kfres[0]
648 script_info.known_error.expected = kfres[1]
649 script_info.known_error.comment = kfres[2]
650 script_info.known_error.fixed = kfres[3]
652 script_info.content = script_results[sr][4]
653 script_info.out = script_results[sr][5]
655 # add it to the list of results
656 test_info.script.append(script_info, '')
658 # display the results
659 if script_info.time > 0:
660 exectime = "(%7.3f s)" % script_info.time
664 sp = "." * (35 - len(script_info.name))
665 self.logger.write(self.write_test_margin(3), 3)
666 self.logger.write("script %s %s %s %s\n" % (
667 src.printcolors.printcLabel(script_info.name),
669 src.printcolors.printc(script_info.res),
671 if script_info and len(callback) > 0:
672 self.logger.write("Exception in %s\n%s\n" % \
674 src.printcolors.printcWarning(callback)), 2, False)
676 if script_info.res == src.OK_STATUS:
678 elif script_info.res == src.KNOWNFAILURE_STATUS:
679 self.nb_acknoledge += 1
680 elif script_info.res == src.TIMEOUT_STATUS:
682 elif script_info.res == src.NA_STATUS:
684 elif script_info.res == "?":
688 self.config.TESTS.append(test_info, '')
691 # Runs all tests of a session.
692 def run_session_tests(self):
694 self.logger.write(self.write_test_margin(2), 3)
695 self.logger.write("Session = %s\n" % src.printcolors.printcLabel(
696 self.currentsession), 3, False)
698 # prepare list of tests to run
699 tests = os.listdir(os.path.join(self.currentDir,
701 self.currentsession))
702 # avoid result files of previous tests, if presents
703 # tests = filter(lambda l: l.endswith(".py"), tests)
704 tests = [t for t in tests if t.endswith(".py") \
705 and not ( t.endswith(".out.py") or \
706 t.endswith(".result.py") or \
707 t.endswith("wrapperScript.py") \
709 tests = sorted(tests, key=str.lower)
711 # build list of known failures
712 cat = "%s/%s/" % (self.currentgrid, self.currentsession)
714 for k in self.ignore_tests.keys():
715 if k.startswith(cat):
716 ignoreDict[k[len(cat):]] = self.ignore_tests[k]
718 self.run_tests(tests, ignoreDict)
721 # Runs all tests of a grid.
722 def run_grid_tests(self):
723 self.logger.write(self.write_test_margin(1), 3)
724 self.logger.write("grid = %s\n" % src.printcolors.printcLabel(
725 self.currentgrid), 3, False)
727 grid_path = os.path.join(self.currentDir, self.currentgrid)
730 if self.sessions is not None:
731 sessions = self.sessions # user choice
733 # use all scripts in grid
734 sessions = filter(lambda l: l not in C_IGNORE_GRIDS,
735 os.listdir(grid_path))
736 sessions = filter(lambda l: os.path.isdir(os.path.join(grid_path,
739 sessions = sorted(sessions, key=str.lower)
740 existingSessions = self.getSubDirectories(grid_path)
741 for session_ in sessions:
742 if not os.path.exists(os.path.join(grid_path, session_)):
743 self.logger.write(self.write_test_margin(2), 3)
745 Session '%s' not found
746 Existing sessions are:
748 """ % (session_, PP.pformat(sorted(existingSessions)))
749 self.logger.write(src.printcolors.printcWarning(msg), 3, False)
751 self.currentsession = session_
752 self.run_session_tests()
754 def getSubDirectories(self, aDir):
756 get names of first level of sub directories in aDir
757 excluding '.git' etc as beginning with '.'
759 res = os.listdir(aDir)
760 res = [d for d in res if os.path.isdir(os.path.join(aDir, d)) and d[0] != '.']
761 # print("getSubDirectories %s are:\n%s" % (aDir, PP.pformat(res)))
765 # Runs test testbase.
766 def run_testbase_tests(self):
767 res_dir = os.path.join(self.currentDir, "RESSOURCES")
768 os.environ['PYTHONPATH'] = (res_dir +
770 os.environ['PYTHONPATH'])
771 os.environ['TT_BASE_RESSOURCES'] = res_dir
772 src.printcolors.print_value(self.logger,
773 "TT_BASE_RESSOURCES",
776 self.logger.write("\n", 4, False)
778 self.logger.write(self.write_test_margin(0), 3)
779 testbase_label = "Test base = %s\n" % src.printcolors.printcLabel(
780 self.currentTestBase)
781 self.logger.write(testbase_label, 3, False)
782 self.logger.write("-" * len(src.printcolors.cleancolor(testbase_label)),
784 self.logger.write("\n", 3, False)
787 settings_file = os.path.join(res_dir, "test_settings.py")
788 if os.path.exists(settings_file):
790 execfile(settings_file, gdic, ldic)
791 self.logger.write("Load test settings '%s'\n" % settings_file, 5)
792 self.settings = ldic['settings_dic']
793 self.ignore_tests = ldic['known_failures_list']
794 if isinstance(self.ignore_tests, list):
795 self.ignore_tests = {}
796 self.logger.write(src.printcolors.printcWarning(
797 "known_failures_list must be a dictionary (not a list)") + "\n", 1, False)
799 self.ignore_tests = {}
800 self.settings.clear()
802 # read known failures pyconf
803 if "testerror" in self.config.LOCAL:
805 #self.known_errors = testerror.read_test_failures(
806 # self.config.TOOLS.testerror.file_path,
810 self.known_errors = None
812 if self.grids is not None:
813 grids = self.grids # given by user
815 # select all the grids (i.e. directories) in the directory
816 grids = filter(lambda l: l not in C_IGNORE_GRIDS,
817 os.listdir(self.currentDir))
818 grids = filter(lambda l: os.path.isdir(
819 os.path.join(self.currentDir, l)),
822 grids = sorted(grids, key=str.lower)
823 existingGrids = self.getSubDirectories(self.currentDir)
825 if not os.path.exists(os.path.join(self.currentDir, grid)):
826 self.logger.write(self.write_test_margin(1), 3)
828 Grid '%s' does not exist
831 """ % (grid, PP.pformat(sorted(existingGrids)))
832 self.logger.write(src.printcolors.printcWarning(msg), 3, False)
834 self.currentgrid = grid
835 self.run_grid_tests()
837 def run_script(self, script_name):
838 if ('APPLICATION' in self.config and
839 script_name in self.config.APPLICATION):
840 script = self.config.APPLICATION[script_name]
844 self.logger.write("\n", 2, False)
845 if not os.path.exists(script):
846 self.logger.write(src.printcolors.printcWarning("WARNING: scrip"
847 "t not found: %s" % script) + "\n", 2)
849 self.logger.write(src.printcolors.printcHeader("----------- sta"
850 "rt %s" % script_name) + "\n", 2)
851 self.logger.write("Run script: %s\n" % script, 2)
852 subprocess.Popen(script, shell=True).wait()
853 self.logger.write(src.printcolors.printcHeader("----------- end"
854 " %s" % script_name) + "\n", 2)
856 def run_all_tests(self):
857 initTime = datetime.datetime.now()
859 self.run_script('test_setup')
860 self.logger.write("\n", 2, False)
862 self.logger.write(src.printcolors.printcHeader(
863 _("=== STARTING TESTS")) + "\n", 2)
864 self.logger.write("\n", 2, False)
865 self.currentDir = os.path.join(self.tmp_working_dir,
867 self.currentTestBase)
868 self.run_testbase_tests()
870 # calculate total execution time
871 totalTime = datetime.datetime.now() - initTime
872 totalTime -= datetime.timedelta(microseconds=totalTime.microseconds)
873 self.logger.write("\n", 2, False)
874 self.logger.write(src.printcolors.printcHeader(_("=== END TESTS")), 2)
875 self.logger.write(" %s\n" % src.printcolors.printcInfo(str(totalTime)),
882 self.run_script('test_cleanup')
883 self.logger.write("\n", 2, False)
887 res_out = _("Tests Results: %(succeed)d / %(total)d\n") % \
888 { 'succeed': self.nb_succeed, 'total': self.nb_run }
889 if self.nb_succeed == self.nb_run:
890 res_out = src.printcolors.printcSuccess(res_out)
892 res_out = src.printcolors.printcError(res_out)
893 self.logger.write(res_out, 1)
895 if self.nb_timeout > 0:
896 self.logger.write(_("%d tests TIMEOUT\n") % self.nb_timeout, 1)
897 if self.nb_not_run > 0:
898 self.logger.write(_("%d tests not executed\n") % self.nb_not_run, 1)
899 if self.nb_acknoledge > 0:
900 self.logger.write(_("%d tests known failures\n") % self.nb_acknoledge, 1)
902 status = src.OK_STATUS
903 if self.nb_run - self.nb_succeed - self.nb_acknoledge > 0:
904 status = src.KO_STATUS
905 elif self.nb_acknoledge:
906 status = src.KNOWNFAILURE_STATUS
908 self.logger.write(_("Status: %s\n" % status), 3)
910 return self.nb_run - self.nb_succeed - self.nb_acknoledge
913 # Write margin to show test results.
914 def write_test_margin(self, tab):
917 return "| " * (tab - 1) + "+ "