Skip to content

Commit 8c8694c

Browse files
add_test_case_line: data-driven dispatch
No behavior change.
1 parent 84a4581 commit 8c8694c

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

tests/scripts/test_psa_constant_names.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
6161
from exc_value
6262

6363
class Inputs:
64+
# pylint: disable=too-many-instance-attributes
6465
"""Accumulate information about macros to test.
6566
6667
This includes macro names as well as information about their arguments
@@ -93,6 +94,16 @@ def __init__(self):
9394
'KEY_TYPE': self.key_types,
9495
'KEY_USAGE': self.key_usage_flags,
9596
}
97+
# Test functions
98+
self.table_by_test_function = {
99+
'key_type': self.key_types,
100+
'ecc_key_types': self.ecc_curves,
101+
'dh_key_types': self.dh_groups,
102+
'hash_algorithm': self.hash_algorithms,
103+
'mac_algorithm': self.mac_algorithms,
104+
'hmac_algorithm': self.mac_algorithms,
105+
'aead_algorithm': self.aead_algorithms,
106+
}
96107
# macro name -> list of argument names
97108
self.argspecs = {}
98109
# argument name -> list of values
@@ -220,24 +231,17 @@ def parse_header(self, filename):
220231

221232
def add_test_case_line(self, function, argument):
222233
"""Parse a test case data line, looking for algorithm metadata tests."""
234+
sets = []
223235
if function.endswith('_algorithm'):
224236
# As above, ECDH and FFDH algorithms are excluded for now.
225237
# Support for them will be added in the future.
226238
if 'ECDH' in argument or 'FFDH' in argument:
227239
return
228-
self.algorithms.add(argument)
229-
if function == 'hash_algorithm':
230-
self.hash_algorithms.add(argument)
231-
elif function in ['mac_algorithm', 'hmac_algorithm']:
232-
self.mac_algorithms.add(argument)
233-
elif function == 'aead_algorithm':
234-
self.aead_algorithms.add(argument)
235-
elif function == 'key_type':
236-
self.key_types.add(argument)
237-
elif function == 'ecc_key_types':
238-
self.ecc_curves.add(argument)
239-
elif function == 'dh_key_types':
240-
self.dh_groups.add(argument)
240+
sets.append(self.algorithms)
241+
if function in self.table_by_test_function:
242+
sets.append(self.table_by_test_function[function])
243+
for s in sets:
244+
s.add(argument)
241245

242246
# Regex matching a *.data line containing a test function call and
243247
# its arguments. The actual definition is partly positional, but this

0 commit comments

Comments
 (0)