generate_psa_tests: use automatic dependencies for positive test cases

This causes more test cases to be commented out due to mechanisms that are
not implemented, because the code `generate_psa_tests.StorageFormat` was not
trying to skip never-supported dependencies.

To review for correctness, filter the diff of the generated files as
follows to find new skip reasons:
```
grep -E '^\+## # skipped because' | sort -u
```
And check that none of the appearing mechanisms are implemented.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2024-11-21 20:09:11 +01:00
parent a43fe58f8b
commit e1f38eb599
+9 -34
View File
@@ -144,7 +144,6 @@ class KeyTypeNotSupported:
def test_case_for_key_generation(
key_type: str, bits: int,
dependencies: List[str],
*args: str,
result: str = ''
) -> test_case.TestCase:
@@ -158,8 +157,6 @@ def test_case_for_key_generation(
tc.set_key_bits(bits)
tc.set_key_pair_usage('GENERATE')
tc.set_arguments([key_type] + list(args) + [result])
tc.set_dependencies(dependencies)
tc.skip_if_any_not_implemented(dependencies)
return tc
class KeyGenerate:
@@ -182,33 +179,18 @@ class KeyGenerate:
All key types can be generated except for public keys. For public key
PSA_ERROR_INVALID_ARGUMENT status is expected.
"""
result = 'PSA_SUCCESS'
import_dependencies = [psa_information.psa_want_symbol(kt.name)]
if kt.params is not None:
import_dependencies += [psa_information.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 = \
psa_information.fix_key_pair_dependencies(import_dependencies, 'GENERATE')
for bits in kt.sizes_to_test():
if kt.name == 'PSA_KEY_TYPE_RSA_KEY_PAIR':
size_dependency = "PSA_VENDOR_RSA_GENERATE_MIN_KEY_BITS <= " + str(bits)
test_dependencies = generate_dependencies + [size_dependency]
else:
test_dependencies = generate_dependencies
yield test_case_for_key_generation(
tc = test_case_for_key_generation(
kt.expression, bits,
psa_information.finish_family_dependencies(test_dependencies, bits),
str(bits),
result
'PSA_ERROR_INVALID_ARGUMENT' if kt.is_public() else 'PSA_SUCCESS'
)
if kt.is_public():
# 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.
tc.set_dependencies([])
yield tc
def test_cases_for_key_generation(self) -> Iterator[test_case.TestCase]:
"""Generate test cases that exercise the generation of keys."""
@@ -496,13 +478,7 @@ class StorageFormat:
verb = 'save' if self.forward else 'read'
tc = psa_test_case.TestCase()
tc.set_description(verb + ' ' + key.description)
dependencies = psa_information.automatic_dependencies(
key.lifetime.string, key.type.string,
key.alg.string, key.alg2.string,
)
dependencies = psa_information.finish_family_dependencies(dependencies, key.bits)
dependencies += psa_information.generate_deps_from_description(key.description)
dependencies = psa_information.fix_key_pair_dependencies(dependencies, 'BASIC')
tc.add_dependencies(psa_information.generate_deps_from_description(key.description))
tc.set_function('key_storage_' + verb)
tc.set_key_bits(key.bits)
tc.set_key_pair_usage('BASIC')
@@ -522,7 +498,6 @@ class StorageFormat:
'"' + key.material.hex() + '"',
'"' + key.hex() + '"',
*extra_arguments])
tc.set_dependencies(dependencies)
return tc
def key_for_lifetime(