Skip to content

Commit b0a224a

Browse files
author
Tarun Prabhu
committed
More robust. More correct.
1 parent bd01414 commit b0a224a

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

Fortran/gfortran/utils/update-test-config.py

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def get_lines(filepath):
103103
with open(filepath, 'r', encoding = get_encoding(filepath)) as f:
104104
lines = f.readlines()
105105
except:
106-
print('WARNING: Could not open file:', os.path.basename(filepath))
106+
print(' WARNING: Could not open file:', os.path.basename(filepath))
107107
finally:
108108
return lines
109109

@@ -144,18 +144,27 @@ def try_match(regex, line, mout):
144144
return True
145145
return False
146146

147+
# Count the number of elements in the list that match satisfy the predicate.
148+
def count_if(l, predicate):
149+
return sum(1 for e in l if predicate(e))
150+
151+
# Count the number of tests in the list that have the given kind.
152+
def count_if_kind(tests, kind):
153+
return count_if(tests, lambda t: t.kind == kind)
154+
147155
# () -> int
148156
def main():
149157
root = get_ancestor(os.path.realpath(__file__), 4)
150158
gfortran = os.path.join(root, 'Fortran', 'gfortran')
151159
subdirs = get_subdirs(gfortran)
152160

153161
for subdir in subdirs:
154-
print(subdir)
155162
files = []
156163
for e in os.scandir(subdir):
157164
if e.is_file() and re_fortran.match(e.name):
158165
files.append(e.path)
166+
if not files:
167+
continue
159168

160169
# Find all the files that are dependencies of some file that is the
161170
# main file in a test.
@@ -169,7 +178,9 @@ def main():
169178
for src in qsplit(m[1]):
170179
dependencies.add(src)
171180

181+
print(subdir)
172182
tests = []
183+
missing_action = []
173184
for f in files:
174185
filename = os.path.basename(f)
175186
if filename in dependencies:
@@ -184,14 +195,26 @@ def main():
184195
for l in get_lines(f):
185196
mout = []
186197
if try_match(re_preprocess, l, mout):
198+
if kind and kind != Test.PREPROCESS:
199+
print(
200+
'ERROR: Overriding action annotation with PREPROCESS'
201+
)
187202
kind = Test.PREPROCESS
188203
elif try_match(re_compile, l, mout):
204+
if kind and kind != Test.COMPILE:
205+
print(
206+
'ERROR: Overriding action annotation with COMPILE'
207+
)
189208
kind = Test.COMPILE
190209
# TODO: Handle the optional target.
191210
elif try_match(re_link, l, mout):
211+
if kind and kind != Test.LINK:
212+
print('ERROR: Overriding action annotation with LINK')
192213
kind = Test.LINK
193214
# TODO: Assume that this has an optional target.
194215
elif try_match(re_run, l, mout):
216+
if kind and kind != Test.RUN:
217+
print('ERROR: Overriding action annotation with RUN')
195218
kind = Test.RUN
196219
# TODO: Handle the optional target.
197220
elif try_match(re_shouldfail, l, mout) or \
@@ -206,22 +229,52 @@ def main():
206229
options.extend(qsplit(m[2]))
207230
# TODO: Handle the optional target.
208231

232+
# If the kind is missing, assume that it is a compile test except
233+
# for torture/execute where it is an execute test.
234+
anc1 = os.path.basename(get_ancestor(f, 1))
235+
anc2 = os.path.basename(get_ancestor(f, 2))
236+
if not kind:
237+
if anc2 == 'torture' and anc1 == 'execute':
238+
kind = Test.RUN
239+
else:
240+
kind = Test.COMPILE
241+
209242
fmt = ' WARNING: {} without action annotation: {}'
210243
if kind:
211244
test = Test(kind, sources, options, targets, expect_error)
212245
tests.append(test)
213246
elif len(sources) > 1:
247+
missing_action.append(filename)
214248
print(fmt.format('Additional sources', filename))
215249
elif len(options) > 1:
250+
missing_action.append(filename)
216251
print(fmt.format('Compile options', filename))
217252
elif expect_error:
253+
missing_action.append(filename)
218254
print(fmt.format('Expect error', filename))
219255
else:
220-
pass
221-
# print(' WARNING: No action annotation:', filename)
222-
for t in tests:
223-
print(' ', str(t))
224-
print(' ', len(tests))
256+
missing_action.append(filename)
257+
print(' WARNING: No action annotation:', filename)
258+
259+
# Count the fortran files in the tests. Eventually, we want to ensure
260+
# that all the fortran files are accounted for
261+
accounted = set([])
262+
for test in tests:
263+
for s in test.sources:
264+
if re_fortran.match(s):
265+
accounted.add(s)
266+
filenames = set([os.path.basename(f) for f in files])
267+
unaccounted = filenames - set(accounted) - set(missing_action)
268+
269+
print(' files:', len(files))
270+
if len(unaccounted):
271+
print(' unaccounted:', sorted(unaccounted))
272+
print(' tests:', len(tests))
273+
print(' preprocess:', count_if_kind(tests, Test.PREPROCESS))
274+
print(' compile:', count_if_kind(tests, Test.COMPILE))
275+
print(' link:', count_if_kind(tests, Test.LINK))
276+
print(' run:', count_if_kind(tests, Test.RUN))
277+
print(' unknown:', len(missing_action))
225278

226279
if __name__ == '__main__':
227280
exit(main())

0 commit comments

Comments
 (0)