mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-28 00:21:48 +03:00
Remove duplicates from enumerated test inputs
When generating expressions to construct test case data, there can be duplicate values, for example if a value of the form C(A) is present as such in test_suite_psa_crypto_metadata.data and also constructed by enumerating the argument A for the constructor C. Eliminate such duplicates in generate_expressions. This commit removes many test cases that were exact duplicates (and were near-duplicates differing only in whitespace before the whitespace normalization). Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@ -173,6 +173,15 @@ class PSAMacroEnumerator:
|
|||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
raise Exception('distribute_arguments({})'.format(name)) from e
|
raise Exception('distribute_arguments({})'.format(name)) from e
|
||||||
|
|
||||||
|
def distribute_arguments_without_duplicates(
|
||||||
|
self, seen: Set[str], name: str
|
||||||
|
) -> Iterator[str]:
|
||||||
|
"""Same as `distribute_arguments`, but don't repeat seen results."""
|
||||||
|
for result in self.distribute_arguments(name):
|
||||||
|
if result not in seen:
|
||||||
|
seen.add(result)
|
||||||
|
yield result
|
||||||
|
|
||||||
def generate_expressions(self, names: Iterable[str]) -> Iterator[str]:
|
def generate_expressions(self, names: Iterable[str]) -> Iterator[str]:
|
||||||
"""Generate expressions covering values constructed from the given names.
|
"""Generate expressions covering values constructed from the given names.
|
||||||
|
|
||||||
@ -185,7 +194,11 @@ class PSAMacroEnumerator:
|
|||||||
* ``macros.generate_expressions(macros.key_types)`` generates all
|
* ``macros.generate_expressions(macros.key_types)`` generates all
|
||||||
key types.
|
key types.
|
||||||
"""
|
"""
|
||||||
return itertools.chain(*map(self.distribute_arguments, names))
|
seen = set() #type: Set[str]
|
||||||
|
return itertools.chain(*(
|
||||||
|
self.distribute_arguments_without_duplicates(seen, name)
|
||||||
|
for name in names
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
class PSAMacroCollector(PSAMacroEnumerator):
|
class PSAMacroCollector(PSAMacroEnumerator):
|
||||||
|
Reference in New Issue
Block a user