Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tools and contrib spelling mistakes
[simgrid.git] / tools / tesh / tesh.py
index f9ef1d4..4996630 100755 (executable)
@@ -5,12 +5,11 @@
 tesh -- testing shell
 ========================
 
-Copyright (c) 2012-2019. The SimGrid Team. All rights reserved.
+Copyright (c) 2012-2020. The SimGrid Team. All rights reserved.
 
 This program is free software; you can redistribute it and/or modify it
 under the terms of the license (GNU LGPL) which comes with this package.
 
-
 #TODO: child of child of child that printfs. Does it work?
 #TODO: a child dies after its parent. What happen?
 
@@ -25,7 +24,6 @@ under the terms of the license (GNU LGPL) which comes with this package.
 
 """
 
-
 import sys
 import os
 import shlex
@@ -47,14 +45,12 @@ else:
 #
 #
 
-
 def isWindows():
     return sys.platform.startswith('win')
 
 # Singleton metaclass that works in Python 2 & 3
 # http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python
 
-
 class _Singleton(type):
     """ A metaclass that creates a Singleton base class when called. """
     _instances = {}
@@ -64,11 +60,9 @@ class _Singleton(type):
             cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
         return cls._instances[cls]
 
-
 class Singleton(_Singleton('SingletonMeta', (object,), {})):
     pass
 
-
 SIGNALS_TO_NAMES_DICT = dict((getattr(signal, n), n)
                              for n in dir(signal) if n.startswith('SIG') and '_' not in n)
 
@@ -238,7 +232,7 @@ class Cmd(object):
         self.cwd = os.getcwd()
 
         self.ignore_output = False
-        self.expect_return = 0
+        self.expect_return = [0]
 
         self.output_display = False
 
@@ -314,8 +308,8 @@ class Cmd(object):
             vdefault = m.group(2)
             if vname in os.environ:
                 return "$" + vname
-            else:
-                return vdefault
+            return vdefault
+
         self.args = re.sub(r"\${(\w+):=([^}]*)}", replace_perl_variables, self.args)
 
         # replace bash environment variables ($THINGS) to their values
@@ -427,7 +421,7 @@ class Cmd(object):
             logs.append("(ignoring the output of <{cmd}> as requested)".format(cmd=cmdName))
         else:
             stdouta = stdout_data.split("\n")
-            while len(stdouta) > 0 and stdouta[-1] == "":
+            while stdouta and stdouta[-1] == "":
                 del stdouta[-1]
             stdouta = self.remove_ignored_lines(stdouta)
             stdcpy = stdouta[:]
@@ -447,7 +441,7 @@ class Cmd(object):
                     lineterm="",
                     fromfile='expected',
                     tofile='obtained'))
-            if len(diff) > 0:
+            if diff:
                 logs.append("Output of <{cmd}> mismatch:".format(cmd=cmdName))
                 if self.sort >= 0:  # If sorted, truncate the diff output and show the unsorted version
                     difflen = 0
@@ -471,7 +465,7 @@ class Cmd(object):
                 if TeshState().keep:
                     f = open('obtained', 'w')
                     obtained = stdout_data.split("\n")
-                    while len(obtained) > 0 and obtained[-1] == "":
+                    while obtained and obtained[-1] == "":
                         del obtained[-1]
                     obtained = self.remove_ignored_lines(obtained)
                     for line in obtained:
@@ -487,7 +481,7 @@ class Cmd(object):
             print('\n'.join(logs))
             return
 
-        if proc.returncode != self.expect_return:
+        if not proc.returncode in self.expect_return:
             if proc.returncode >= 0:
                 logs.append("Test suite `{file}': NOK (<{cmd}> returned code {code})".format(
                     file=FileReader().filename, cmd=cmdName, code=proc.returncode))
@@ -514,14 +508,12 @@ class Cmd(object):
     def can_run(self):
         return self.args is not None
 
-
 ##############
 #
 # Main
 #
 #
 
-
 if __name__ == '__main__':
     signal.signal(signal.SIGINT, signal_handler)
     signal.signal(signal.SIGTERM, signal_handler)
@@ -539,7 +531,7 @@ if __name__ == '__main__':
     group1.add_argument(
         '--ignore-jenkins',
         action='store_true',
-        help='ignore all cruft generated on SimGrid continous integration servers')
+        help='ignore all cruft generated on SimGrid continuous integration servers')
     group1.add_argument('--wrapper', metavar='arg', help='Run each command in the provided wrapper (eg valgrind)')
     group1.add_argument(
         '--keep',
@@ -553,7 +545,7 @@ if __name__ == '__main__':
         os.chdir(options.cd)
 
     if options.ignore_jenkins:
-        print("Ignore all cruft seen on SimGrid's continous integration servers")
+        print("Ignore all cruft seen on SimGrid's continuous integration servers")
         # Note: regexps should match at the beginning of lines
         TeshState().ignore_regexps_common = [
             re.compile(r"profiling:"),
@@ -609,7 +601,7 @@ if __name__ == '__main__':
     line = f.readfullline()
     while line is not None:
         # print(">>============="+line+"==<<")
-        if len(line) == 0:
+        if not line:
             #print ("END CMD block")
             if cmd.run_if_possible():
                 cmd = Cmd()
@@ -648,16 +640,17 @@ if __name__ == '__main__':
             cmd.output_display = True
             cmd.ignore_output = True
         elif line[0:15] == "! expect return":
-            cmd.expect_return = int(line[16:])
+            cmd.expect_return = [int(line[16:])]
             #print("expect return "+str(int(line[16:])))
         elif line[0:15] == "! expect signal":
-            sig = line[16:]
-            # get the signal integer value from the signal module
-            if sig not in signal.__dict__:
-                fatal_error("unrecognized signal '" + sig + "'")
-            sig = int(signal.__dict__[sig])
-            # popen return -signal when a process ends with a signal
-            cmd.expect_return = -sig
+            cmd.expect_return = []
+            for sig in (line[16:]).split("|"):
+                # get the signal integer value from the signal module
+                if sig not in signal.__dict__:
+                    fatal_error("unrecognized signal '" + sig + "'")
+                sig = int(signal.__dict__[sig])
+                # popen return -signal when a process ends with a signal
+                cmd.expect_return.append(-sig)
         elif line[0:len("! timeout ")] == "! timeout ":
             if "no" in line[len("! timeout "):]:
                 cmd.timeout = None