mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-02-24 04:16:46 +00:00
check_test_cases: parametrize iteration functions by the action
Parametrize the code that iterates over test case descriptions by the function to apply on each description. No behavior change. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
fb4f933f8e
commit
d34e9e450f
|
@ -76,10 +76,13 @@ def check_description(results, seen, file_name, line_number, description):
|
||||||
len(description))
|
len(description))
|
||||||
seen[description] = line_number
|
seen[description] = line_number
|
||||||
|
|
||||||
def check_test_suite(results, data_file_name):
|
def walk_test_suite(function, results, descriptions, data_file_name):
|
||||||
"""Check the test cases in the given unit test data file."""
|
"""Iterate over the test cases in the given unit test data file.
|
||||||
|
|
||||||
|
Call function(results, descriptions, data_file_name, line_number, description)
|
||||||
|
on each description.
|
||||||
|
"""
|
||||||
in_paragraph = False
|
in_paragraph = False
|
||||||
descriptions = {}
|
|
||||||
with open(data_file_name, 'rb') as data_file:
|
with open(data_file_name, 'rb') as data_file:
|
||||||
for line_number, line in enumerate(data_file, 1):
|
for line_number, line in enumerate(data_file, 1):
|
||||||
line = line.rstrip(b'\r\n')
|
line = line.rstrip(b'\r\n')
|
||||||
|
@ -90,13 +93,16 @@ def check_test_suite(results, data_file_name):
|
||||||
continue
|
continue
|
||||||
if not in_paragraph:
|
if not in_paragraph:
|
||||||
# This is a test case description line.
|
# This is a test case description line.
|
||||||
check_description(results, descriptions,
|
function(results, descriptions,
|
||||||
data_file_name, line_number, line)
|
data_file_name, line_number, line)
|
||||||
in_paragraph = True
|
in_paragraph = True
|
||||||
|
|
||||||
def check_ssl_opt_sh(results, file_name):
|
def walk_ssl_opt_sh(function, results, descriptions, file_name):
|
||||||
"""Check the test cases in ssl-opt.sh or a file with a similar format."""
|
"""Iterate over the test cases in ssl-opt.sh or a file with a similar format.
|
||||||
descriptions = {}
|
|
||||||
|
Call function(results, descriptions, file_name, line_number, description)
|
||||||
|
on each description.
|
||||||
|
"""
|
||||||
with open(file_name, 'rb') as file_contents:
|
with open(file_name, 'rb') as file_contents:
|
||||||
for line_number, line in enumerate(file_contents, 1):
|
for line_number, line in enumerate(file_contents, 1):
|
||||||
# Assume that all run_test calls have the same simple form
|
# Assume that all run_test calls have the same simple form
|
||||||
|
@ -106,8 +112,23 @@ def check_ssl_opt_sh(results, file_name):
|
||||||
if not m:
|
if not m:
|
||||||
continue
|
continue
|
||||||
description = m.group(1)
|
description = m.group(1)
|
||||||
check_description(results, descriptions,
|
function(results, descriptions,
|
||||||
file_name, line_number, description)
|
file_name, line_number, description)
|
||||||
|
|
||||||
|
def walk_all(function, results):
|
||||||
|
"""Iterate over all named test cases.
|
||||||
|
|
||||||
|
Call function(results, {}, file_name, line_number, description)
|
||||||
|
on each description.
|
||||||
|
"""
|
||||||
|
test_directories = collect_test_directories()
|
||||||
|
for directory in test_directories:
|
||||||
|
for data_file_name in glob.glob(os.path.join(directory, 'suites',
|
||||||
|
'*.data')):
|
||||||
|
walk_test_suite(function, results, {}, data_file_name)
|
||||||
|
ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
|
||||||
|
if os.path.exists(ssl_opt_sh):
|
||||||
|
walk_ssl_opt_sh(function, results, {}, ssl_opt_sh)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description=__doc__)
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
@ -118,15 +139,8 @@ def main():
|
||||||
action='store_false', dest='quiet',
|
action='store_false', dest='quiet',
|
||||||
help='Show warnings (default: on; undoes --quiet)')
|
help='Show warnings (default: on; undoes --quiet)')
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
test_directories = collect_test_directories()
|
|
||||||
results = Results(options)
|
results = Results(options)
|
||||||
for directory in test_directories:
|
walk_all(check_description, results)
|
||||||
for data_file_name in glob.glob(os.path.join(directory, 'suites',
|
|
||||||
'*.data')):
|
|
||||||
check_test_suite(results, data_file_name)
|
|
||||||
ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
|
|
||||||
if os.path.exists(ssl_opt_sh):
|
|
||||||
check_ssl_opt_sh(results, ssl_opt_sh)
|
|
||||||
if (results.warnings or results.errors) and not options.quiet:
|
if (results.warnings or results.errors) and not options.quiet:
|
||||||
sys.stderr.write('{}: {} errors, {} warnings\n'
|
sys.stderr.write('{}: {} errors, {} warnings\n'
|
||||||
.format(sys.argv[0], results.errors, results.warnings))
|
.format(sys.argv[0], results.errors, results.warnings))
|
||||||
|
|
Loading…
Reference in a new issue