mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-08-04 18:27:46 +00:00
Switch crypto_data_tests.py to automatic dependencies
In `psa_test_cases.TestCase`: * Implement basic support for automatic dependencies, by calling `psa_information.automatic_dependencies`. * Support an alternative dependency prefix. No changes to the generated file. Signed-off-by: Gilles Peskine <[email protected]>
This commit is contained in:
@@ -16,15 +16,6 @@ from . import psa_test_case
|
||||
from . import test_case
|
||||
|
||||
|
||||
def psa_low_level_dependencies(*expressions: str) -> List[str]:
|
||||
"""Infer dependencies of a PSA low-level test case by looking for PSA_xxx symbols.
|
||||
|
||||
This function generates MBEDTLS_PSA_BUILTIN_xxx symbols.
|
||||
"""
|
||||
return psa_information.automatic_dependencies(*expressions,
|
||||
prefix='MBEDTLS_PSA_BUILTIN_')
|
||||
|
||||
|
||||
class HashPSALowLevel:
|
||||
"""Generate test cases for the PSA low-level hash interface."""
|
||||
|
||||
@@ -68,7 +59,7 @@ class HashPSALowLevel:
|
||||
function: str, note: str,
|
||||
arguments: List[str]) -> test_case.TestCase:
|
||||
"""Construct one test case involving a hash."""
|
||||
tc = psa_test_case.TestCase()
|
||||
tc = psa_test_case.TestCase(dependency_prefix='MBEDTLS_PSA_BUILTIN_')
|
||||
tc.set_description('{}{} {}'
|
||||
.format(function,
|
||||
' ' + note if note else '',
|
||||
@@ -76,7 +67,6 @@ class HashPSALowLevel:
|
||||
tc.set_function(function)
|
||||
tc.set_arguments([alg.expression] +
|
||||
['"{}"'.format(arg) for arg in arguments])
|
||||
tc.set_dependencies(psa_low_level_dependencies(alg.expression))
|
||||
return tc
|
||||
|
||||
def test_cases_for_hash(self,
|
||||
|
||||
@@ -9,6 +9,7 @@ import os
|
||||
import re
|
||||
from typing import FrozenSet, List, Optional, Set
|
||||
|
||||
from . import psa_information
|
||||
from . import test_case
|
||||
|
||||
|
||||
@@ -57,16 +58,24 @@ class TestCase(test_case.TestCase):
|
||||
involved in a given test case.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
def __init__(self, dependency_prefix: Optional[str] = None) -> None:
|
||||
"""Construct a test case for a PSA Crypto API call.
|
||||
|
||||
`dependency_prefix`: prefix to use in dependencies. Defaults to
|
||||
``'PSA_WANT_'``. Use ``'MBEDTLS_PSA_BUILTIN_'``
|
||||
when specifically testing builtin implementations.
|
||||
"""
|
||||
super().__init__()
|
||||
del self.dependencies
|
||||
self.manual_dependencies = [] #type: List[str]
|
||||
self.automatic_dependencies = set() #type: Set[str]
|
||||
self.dependency_prefix = dependency_prefix #type: Optional[str]
|
||||
|
||||
@staticmethod
|
||||
def infer_dependencies(_arguments: List[str]) -> List[str]:
|
||||
def infer_dependencies(self, arguments: List[str]) -> List[str]:
|
||||
"""Infer dependencies based on the test case arguments."""
|
||||
return [] # not implemented yet
|
||||
dependencies = psa_information.automatic_dependencies(*arguments,
|
||||
prefix=self.dependency_prefix)
|
||||
return dependencies
|
||||
|
||||
def set_arguments(self, arguments: List[str]) -> None:
|
||||
"""Set test case arguments and automatically infer dependencies."""
|
||||
|
||||
Reference in New Issue
Block a user