From 161611566221cd7a147c45d070f7d1ca4914ba43 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 14 May 2022 23:37:19 -0500 Subject: [PATCH] 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. --- scripts/code.py | 22 ++++++++++++---------- scripts/coverage.py | 22 ++++++++++++---------- scripts/data.py | 22 ++++++++++++---------- scripts/stack.py | 22 ++++++++++++---------- scripts/structs.py | 22 ++++++++++++---------- scripts/summary.py | 20 +++++++++++--------- scripts/test.py | 3 +-- 7 files changed, 72 insertions(+), 61 deletions(-) diff --git a/scripts/code.py b/scripts/code.py index b394e9cd..66502fa9 100755 --- a/scripts/code.py +++ b/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})) diff --git a/scripts/coverage.py b/scripts/coverage.py index b3a90ed2..e4b754af 100755 --- a/scripts/coverage.py +++ b/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})) diff --git a/scripts/data.py b/scripts/data.py index 4b8e00da..efef4ff1 100755 --- a/scripts/data.py +++ b/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})) diff --git a/scripts/stack.py b/scripts/stack.py index 0c652d8d..6cdfc46f 100755 --- a/scripts/stack.py +++ b/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})) diff --git a/scripts/structs.py b/scripts/structs.py index e8d7193e..de266b87 100755 --- a/scripts/structs.py +++ b/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[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})) diff --git a/scripts/summary.py b/scripts/summary.py index 7ce769bf..2aab274d 100755 --- a/scripts/summary.py +++ b/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})) diff --git a/scripts/test.py b/scripts/test.py index 048b1811..9d94f006 100755 --- a/scripts/test.py +++ b/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}))