Skip to content

Commit

Permalink
generate_psa_tests: use automatic dependencies for positive test cases
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
gilles-peskine-arm committed Nov 21, 2024
1 parent 26c06c9 commit 18e5920
Showing 1 changed file with 9 additions and 34 deletions.
43 changes: 9 additions & 34 deletions scripts/generate_psa_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def test_cases_for_not_supported(self) -> Iterator[test_case.TestCase]:

def test_case_for_key_generation(
key_type: str, bits: int,
dependencies: List[str],
*args: str,
result: str = ''
) -> test_case.TestCase:
Expand All @@ -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:
Expand All @@ -182,33 +179,18 @@ def test_cases_for_key_type_key_generation(
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."""
Expand Down Expand Up @@ -496,13 +478,7 @@ def make_test_case(self, key: StorageTestData) -> test_case.TestCase:
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')
Expand All @@ -522,7 +498,6 @@ def make_test_case(self, key: StorageTestData) -> test_case.TestCase:
'"' + key.material.hex() + '"',
'"' + key.hex() + '"',
*extra_arguments])
tc.set_dependencies(dependencies)
return tc

def key_for_lifetime(
Expand Down

0 comments on commit 18e5920

Please sign in to comment.