generate_psa_tests.py: add key generation result to test case argument list, add comments
Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
diff --git a/scripts/mbedtls_dev/test_case.py b/scripts/mbedtls_dev/test_case.py
index 11117fc..8ec2115 100644
--- a/scripts/mbedtls_dev/test_case.py
+++ b/scripts/mbedtls_dev/test_case.py
@@ -42,7 +42,6 @@
self.dependencies = [] #type: List[str]
self.function = None #type: Optional[str]
self.arguments = [] #type: List[str]
- self.result = '' #type: str
def add_comment(self, *lines: str) -> None:
self.comments += lines
@@ -59,9 +58,6 @@
def set_arguments(self, arguments: List[str]) -> None:
self.arguments = arguments
- def set_result(self, result: str) -> None:
- self.result = result
-
def check_completeness(self) -> None:
if self.description is None:
raise MissingDescription
@@ -86,10 +82,6 @@
if self.dependencies:
out.write('depends_on:' + ':'.join(self.dependencies) + '\n')
out.write(self.function + ':' + ':'.join(self.arguments))
- if self.result:
- out.write(':' + self.result + '\n')
- else:
- out.write('\n')
def write_data_file(filename: str,
test_cases: Iterable[TestCase],
diff --git a/tests/scripts/generate_psa_tests.py b/tests/scripts/generate_psa_tests.py
index 1a35af9..f519f79 100755
--- a/tests/scripts/generate_psa_tests.py
+++ b/tests/scripts/generate_psa_tests.py
@@ -199,7 +199,8 @@
# supported or not depending on implementation capabilities,
# only generate the test case once.
continue
- # Public key cannot be generated
+ # For public key we expect that key generation fails with
+ # INVALID_ARGUMENT. It is handled by KeyGenerate class.
if not kt.name.endswith('_PUBLIC_KEY'):
yield test_case_for_key_type_not_supported(
'generate', kt.expression, bits,
@@ -242,8 +243,7 @@
.format(short_key_type, bits))
tc.set_dependencies(dependencies)
tc.set_function('generate_key')
- tc.set_arguments([key_type] + list(args))
- tc.set_result(result)
+ tc.set_arguments([key_type] + list(args) + [result])
return tc
@@ -256,11 +256,8 @@
ECC_KEY_TYPES = ('PSA_KEY_TYPE_ECC_KEY_PAIR',
'PSA_KEY_TYPE_ECC_PUBLIC_KEY')
- RSA_KEY_TYPES = ('PSA_KEY_TYPE_RSA_KEY_PAIR',
- 'PSA_KEY_TYPE_RSA_PUBLIC_KEY')
-
+ @staticmethod
def test_cases_for_key_type_key_generation(
- self,
kt: crypto_knowledge.KeyType
) -> Iterator[test_case.TestCase]:
"""Return test cases exercising key generation.
@@ -275,11 +272,14 @@
import_dependencies += [psa_want_symbol(sym)
for i, sym in enumerate(kt.params)]
if kt.name.endswith('_PUBLIC_KEY'):
+ # The library checks whether the key type is a public key generically,
+ # before it reaches a point where it needs support for the specific key
+ # type, so it returns INVALID_ARGUMENT for unsupported public key types.
generate_dependencies = []
result = 'PSA_ERROR_INVALID_ARGUMENT'
else:
generate_dependencies = import_dependencies
- if kt.name in self.RSA_KEY_TYPES:
+ if kt.name == 'PSA_KEY_TYPE_RSA_KEY_PAIR':
generate_dependencies.append("MBEDTLS_GENPRIME")
for bits in kt.sizes_to_test():
yield test_case_for_key_generation(