Skip to content

Commit d680839

Browse files
author
Tarun Prabhu
committed
Add preliminary code to process test results.
1 parent c070940 commit d680839

File tree

1 file changed

+64
-11
lines changed

1 file changed

+64
-11
lines changed

Fortran/gfortran/utils/update-disabled-tests.py

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ def parse_cmdline_args():
4343
'it. If this option is not provided, and the build directory is not '
4444
'empty, an error will be raised.'
4545
)
46+
ap.add_argument(
47+
'-e',
48+
'--existing',
49+
default = False,
50+
action = 'store_true',
51+
help = 'Don\'t run the tests. Only process existing test results.'
52+
)
4653
ap.add_argument(
4754
'-i',
4855
'--inplace',
@@ -147,7 +154,6 @@ def parse_disabled_file(args, filename):
147154
re_comment = re.compile('^[ ]*#.*$')
148155
re_close = re.compile('^[ ]*[)][ ]*$')
149156

150-
d = os.path.dirname(filename)
151157
record = False
152158
tests = []
153159
with open(filename) as f:
@@ -323,10 +329,60 @@ def build_and_run_tests(args, build_root, config):
323329
)
324330
exit(1)
325331

332+
# Parse the test results. The result is a map whose key is the absolute path
333+
# to the main test file and the value is a boolean indicating whether the test
334+
# passed or failed. build_root is the root of the build directory. config must
335+
# be either 'default' or 'all'.
336+
# { str : * }, os.path, str -> { os.path : bool }
337+
def parse_test_results(args, build_root, config):
338+
if args.verbose or args.dry_run:
339+
print(f'Parsing test results for ${config} configuration')
340+
if args.dry_run:
341+
return {}
342+
343+
j = None
344+
with open(os.path.join(build_root, config + '.json')) as f:
345+
j = json.load(f)
346+
347+
results = {}
348+
for tj in j['tests']:
349+
name = tj['name'].split('::')[1].strip()
350+
elems = name.split('/')
351+
dirs = elems[:-1]
352+
filename = elems[-1]
353+
354+
filename = filename.replace('gfortran-regression-', '')
355+
filename = filename.replace('gfortran-torture-', '')
356+
if dirs[2] == 'regression':
357+
filename = filename.replace('compile-regression', '')
358+
filename = filename.replace('execute-regression', '')
359+
elif dirs[2] == 'torture':
360+
filename = filename.replace('compile-torture', '')
361+
filename = filename.replace('execute-torture', '')
362+
for d in dirs[3:]:
363+
filename = filename.replace('__' + d, '', 1)
364+
filename = filename[2:-5]
365+
366+
base, _, ext = filename.rpartition('_')
367+
fname = '.'.join([base, ext])
368+
# The tests in regression/gomp/appendix-a contain .'s in the name which
369+
# are replaced with _'s in the test name.
370+
if dirs[-1] == 'appendix-a':
371+
fname = fname.replace('_', '.')
372+
373+
f = os.path.join(args.source, *dirs, fname)
374+
if os.path.exists(f):
375+
results[fname] = tj['code'] == 'PASS'
376+
377+
return results
378+
326379
# Compare the test results and get the list of tests to be enabled. The result
327-
# will be a list of paths to tests that should be enabled.
328-
# os.path -> [os.path]
329-
def get_tests_to_be_enabled(build_dir):
380+
# will be a list of paths to tests that should be enabled. build_root is the
381+
# root of the build directory.
382+
# { str : * }, os.path -> [os.path]
383+
def get_tests_to_be_enabled(args, build_root):
384+
results_def = parse_test_results(args, build_root, 'default')
385+
results_all = parse_test_results(args, build_root, 'all')
330386
# TODO: Implement this.
331387
return []
332388

@@ -349,22 +405,19 @@ def main():
349405
for test in parse_disabled_file(args, filename):
350406
check_disabled[d].append(os.path.join(d, test))
351407

352-
print(len(check_disabled))
353-
for d, tests in check_disabled.items():
354-
print(d, len(tests))
355-
exit(0)
356408
build_dir = setup_build_dir(args)
357409

358-
build_and_run_tests(args, build_dir, 'default')
359-
build_and_run_tests(args, build_dir, 'all')
410+
if not args.existing:
411+
build_and_run_tests(args, build_dir, 'default')
412+
build_and_run_tests(args, build_dir, 'all')
360413

361414
enabled = get_tests_to_be_enabled(build_dir)
362415
if args.verbose or args.dry_run:
363416
print(f'Enabling {len(enabled)} tests')
364417
for test in enabled:
365418
print(' ', test)
366419
if not args.dry_run:
367-
update_disabled_lists(args, enabled_tests)
420+
update_disabled_lists(args, enabled)
368421

369422
# Cleanup, if necessary.
370423
teardown_build_dir(args, build_dir)

0 commit comments

Comments
 (0)