2019-05-23 13:11:46 +00:00
|
|
|
from inspect import getmembers, isfunction
|
|
|
|
|
2019-06-10 23:26:39 +00:00
|
|
|
def generate_from_tests(src, phase, bls_active=True):
|
2019-05-23 13:11:46 +00:00
|
|
|
"""
|
|
|
|
Generate a list of test cases by running tests from the given src in generator-mode.
|
2019-06-10 23:26:39 +00:00
|
|
|
:param src: to retrieve tests from (discovered using inspect.getmembers).
|
|
|
|
:param phase: to run tests against particular phase.
|
2019-05-23 13:11:46 +00:00
|
|
|
:param bls_active: optional, to override BLS switch preference. Defaults to True.
|
|
|
|
:return: the list of test cases.
|
|
|
|
"""
|
|
|
|
fn_names = [
|
|
|
|
name for (name, _) in getmembers(src, isfunction)
|
|
|
|
if name.startswith('test_')
|
|
|
|
]
|
|
|
|
out = []
|
|
|
|
print("generating test vectors from tests source: %s" % src.__name__)
|
|
|
|
for name in fn_names:
|
|
|
|
tfn = getattr(src, name)
|
|
|
|
try:
|
2019-06-10 23:26:39 +00:00
|
|
|
test_case = tfn(generator_mode=True, phase=phase, bls_active=bls_active)
|
2019-05-23 20:26:36 +00:00
|
|
|
# If no test case data is returned, the test is ignored.
|
|
|
|
if test_case is not None:
|
|
|
|
out.append(test_case)
|
2019-05-23 13:11:46 +00:00
|
|
|
except AssertionError:
|
|
|
|
print("ERROR: failed to generate vector from test: %s (src: %s)" % (name, src.__name__))
|
|
|
|
return out
|