Kaynağa Gözat

Fix test.py hang on ctrl-C, cleanup TODOs

A small mistake in test.py's control flow meant the failing test job
would succesfully kill all other test jobs, but then humorously start
up a new process to continue testing.
Christopher Haster 3 yıl önce
ebeveyn
işleme
1616115662
7 değiştirilmiş dosya ile 72 ekleme ve 61 silme
  1. 12 10
      scripts/code.py
  2. 12 10
      scripts/coverage.py
  3. 12 10
      scripts/data.py
  4. 12 10
      scripts/stack.py
  5. 12 10
      scripts/structs.py
  6. 11 9
      scripts/summary.py
  7. 1 2
      scripts/test.py

+ 12 - 10
scripts/code.py

@@ -17,6 +17,15 @@ import collections as co
 
 OBJ_PATHS = ['*.o']
 
+def openio(path, mode='r'):
+    if path == '-':
+        if 'r' in mode:
+            return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
+        else:
+            return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
+    else:
+        return open(path, mode)
+
 def collect(paths, **args):
     results = co.defaultdict(lambda: 0)
     pattern = re.compile(
@@ -64,15 +73,6 @@ def collect(paths, **args):
     return flat_results
 
 def main(**args):
-    def openio(path, mode='r'):
-        if path == '-':
-            if 'r' in mode:
-                return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
-            else:
-                return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
-        else:
-            return open(path, mode)
-
     # find sizes
     if not args.get('use', None):
         # find .o files
@@ -281,4 +281,6 @@ if __name__ == "__main__":
     parser.add_argument('--build-dir',
         help="Specify the relative build directory. Used to map object files \
             to the correct source files.")
-    sys.exit(main(**vars(parser.parse_args())))
+    sys.exit(main(**{k: v
+        for k, v in vars(parser.parse_args()).items()
+        if v is not None}))

+ 12 - 10
scripts/coverage.py

@@ -12,6 +12,15 @@ import bisect as b
 
 INFO_PATHS = ['tests/*.toml.info']
 
+def openio(path, mode='r'):
+    if path == '-':
+        if 'r' in mode:
+            return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
+        else:
+            return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
+    else:
+        return open(path, mode)
+
 def collect(paths, **args):
     file = None
     funcs = []
@@ -66,15 +75,6 @@ def collect(paths, **args):
 
 
 def main(**args):
-    def openio(path, mode='r'):
-        if path == '-':
-            if 'r' in mode:
-                return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
-            else:
-                return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
-        else:
-            return open(path, mode)
-
     # find coverage
     if not args.get('use'):
         # find *.info files
@@ -320,4 +320,6 @@ if __name__ == "__main__":
     parser.add_argument('--build-dir',
         help="Specify the relative build directory. Used to map object files \
             to the correct source files.")
-    sys.exit(main(**vars(parser.parse_args())))
+    sys.exit(main(**{k: v
+        for k, v in vars(parser.parse_args()).items()
+        if v is not None}))

+ 12 - 10
scripts/data.py

@@ -17,6 +17,15 @@ import collections as co
 
 OBJ_PATHS = ['*.o']
 
+def openio(path, mode='r'):
+    if path == '-':
+        if 'r' in mode:
+            return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
+        else:
+            return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
+    else:
+        return open(path, mode)
+
 def collect(paths, **args):
     results = co.defaultdict(lambda: 0)
     pattern = re.compile(
@@ -63,15 +72,6 @@ def collect(paths, **args):
     return flat_results
 
 def main(**args):
-    def openio(path, mode='r'):
-        if path == '-':
-            if 'r' in mode:
-                return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
-            else:
-                return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
-        else:
-            return open(path, mode)
-
     # find sizes
     if not args.get('use', None):
         # find .o files
@@ -280,4 +280,6 @@ if __name__ == "__main__":
     parser.add_argument('--build-dir',
         help="Specify the relative build directory. Used to map object files \
             to the correct source files.")
-    sys.exit(main(**vars(parser.parse_args())))
+    sys.exit(main(**{k: v
+        for k, v in vars(parser.parse_args()).items()
+        if v is not None}))

+ 12 - 10
scripts/stack.py

@@ -15,6 +15,15 @@ import math as m
 
 CI_PATHS = ['*.ci']
 
+def openio(path, mode='r'):
+    if path == '-':
+        if 'r' in mode:
+            return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
+        else:
+            return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
+    else:
+        return open(path, mode)
+
 def collect(paths, **args):
     # parse the vcg format
     k_pattern = re.compile('([a-z]+)\s*:', re.DOTALL)
@@ -116,15 +125,6 @@ def collect(paths, **args):
     return flat_results
 
 def main(**args):
-    def openio(path, mode='r'):
-        if path == '-':
-            if 'r' in mode:
-                return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
-            else:
-                return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
-        else:
-            return open(path, mode)
-
     # find sizes
     if not args.get('use', None):
         # find .ci files
@@ -427,4 +427,6 @@ if __name__ == "__main__":
     parser.add_argument('--build-dir',
         help="Specify the relative build directory. Used to map object files \
             to the correct source files.")
-    sys.exit(main(**vars(parser.parse_args())))
+    sys.exit(main(**{k: v
+        for k, v in vars(parser.parse_args()).items()
+        if v is not None}))

+ 12 - 10
scripts/structs.py

@@ -15,6 +15,15 @@ import collections as co
 
 OBJ_PATHS = ['*.o']
 
+def openio(path, mode='r'):
+    if path == '-':
+        if 'r' in mode:
+            return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
+        else:
+            return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
+    else:
+        return open(path, mode)
+
 def collect(paths, **args):
     decl_pattern = re.compile(
         '^\s+(?P<no>[0-9]+)'
@@ -115,15 +124,6 @@ def collect(paths, **args):
 
 
 def main(**args):
-    def openio(path, mode='r'):
-        if path == '-':
-            if 'r' in mode:
-                return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
-            else:
-                return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
-        else:
-            return open(path, mode)
-
     # find sizes
     if not args.get('use', None):
         # find .o files
@@ -328,4 +328,6 @@ if __name__ == "__main__":
     parser.add_argument('--build-dir',
         help="Specify the relative build directory. Used to map object files \
             to the correct source files.")
-    sys.exit(main(**vars(parser.parse_args())))
+    sys.exit(main(**{k: v
+        for k, v in vars(parser.parse_args()).items()
+        if v is not None}))

+ 11 - 9
scripts/summary.py

@@ -57,16 +57,16 @@ FIELDS = [
 ]
 
 
-def main(**args):
-    def openio(path, mode='r'):
-        if path == '-':
-            if 'r' in mode:
-                return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
-            else:
-                return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
+def openio(path, mode='r'):
+    if path == '-':
+        if 'r' in mode:
+            return os.fdopen(os.dup(sys.stdin.fileno()), 'r')
         else:
-            return open(path, mode)
+            return os.fdopen(os.dup(sys.stdout.fileno()), 'w')
+    else:
+        return open(path, mode)
 
+def main(**args):
     # find results
     results = co.defaultdict(lambda: {})
     for path in args.get('csv_paths', '-'):
@@ -276,4 +276,6 @@ if __name__ == "__main__":
         help="Show file-level calls.")
     parser.add_argument('-Y', '--summary', action='store_true',
         help="Only show the totals.")
-    sys.exit(main(**vars(parser.parse_args())))
+    sys.exit(main(**{k: v
+        for k, v in vars(parser.parse_args()).items()
+        if v is not None}))

+ 1 - 2
scripts/test.py

@@ -49,7 +49,6 @@ def testcase(path):
     _, case, *_ = path.split('#', 2)
     return '%s#%s' % (testsuite(path), case)
 
-# TODO move this out in other files
 def openio(path, mode='r'):
     if path == '-':
         if 'r' in mode:
@@ -728,6 +727,7 @@ def run_stage(name, runner_, **args):
                     # stop other tests
                     for child in children.copy():
                         child.kill()
+                    break
     
 
     # parallel jobs?
@@ -998,7 +998,6 @@ if __name__ == "__main__":
         help="Source file to compile, possibly injecting internal tests.")
     comp_parser.add_argument('-o', '--output',
         help="Output file.")
-    # TODO apply this to other scripts?
     sys.exit(main(**{k: v
         for k, v in vars(parser.parse_args()).items()
         if v is not None}))