Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch generate_psa_test.py to automatic dependencies for positive test cases #83

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Nov 21, 2024

This is mostly refactoring around generate_psa_tests.py and supporting Python libraries. Create a class for test case generation that can automatically determine test case dependencies. Use this for generate_psa_tests.py for positive test cases.

Practical effect:

  • Never-executed test cases are now easier to work with, beause they're commented out and have the reason in a comment.
  • Fix some test cases that were not properly detected as never-executed.

This is a step on the forward port of Mbed-TLS/mbedtls#9025. Here, I handle the positive test cases of generate_psa_tests.py, which brings me. to a natural cutoff point.

Follow-up: handling the negative test cases (KeyTypeNotSupported, OpFail).

Status: work in progress. Only tested on 3.6 so far. I'll probably make some changes to the history before this is finalized.

PR checklist

The new class `psa_test_case.TestCase` will automatically infer dependencies
from the test data. The dependency inference is not done yet, this will be
implemented in subsequent commits.

No change to any generated file since this new module is not used yet.

Signed-off-by: Gilles Peskine <[email protected]>
Allow "skipping" a test case, meaning that the test case is generated
commented out. This is useful when systematically generating test cases
according to certain rules, where some generated tests cannot be executed
but we still want them to be visible when auditing the generation output.

Signed-off-by: Gilles Peskine <[email protected]>
But for now, fully override its automatic dependency inference. We will
switch to using the automatic dependencies in future commits.

No change to the generated files.

Signed-off-by: Gilles Peskine <[email protected]>
No change to the generated files.

Signed-off-by: Gilles Peskine <[email protected]>
…anisms

No change to the generated output.

Signed-off-by: Gilles Peskine <[email protected]>
To determine PSA mechanisms that are not implemented, also read `PSA_WANT_`
symbols that cannot (or are not intended to) be configured independently,
and thus are not listed in `psa/crypto_config.h`. Find those symbols in
the config adjustment header `psa/crypto_adjust_config_synonyms.h`.

No impact on generated files yet, because `find_dependencies_not_implemented`
is currently only used on key types that have explicit dependencies. This
will allow using hack_dependencies_not_implemented in other places, for
example to handle algorithm variants like `PSA_WANT_ALG_ECDSA_ANY` which is
inferred from `PSA_WANT_ALG_ECDSA`.

Signed-off-by: Gilles Peskine <[email protected]>
We can't even attempt to generate DSA test cases because
`asymmetric_key_data.py` doesn't have test data for DSA.

Signed-off-by: Gilles Peskine <[email protected]>
When we generate a test case for a mechanism that is not implemented,
comment out the test case rather than giving it a never-fulfilled
dependency. That way we don't create test cases that cannot be executed.

This changes the generated output in the following ways:

* No longer emit test cases with a dependency on
  `DEPENDENCY_NOT_IMPLEMENTED_YET`. All removed lines that start with
  `depends_on:` contain `DEPENDENCY_NOT_IMPLEMENTED_YET.
* Emit commented-out test cases instead: all the new lines are comment lines.

There is no change in which test cases actually get executed. This removes
many test cases from the list of available test cases, which causes some of
the exceptions in `analyze_outcomes.py` to no longer be useful.

Signed-off-by: Gilles Peskine <[email protected]>
No semantic change. In the generated files, `depends_on:` lines have entries
that are reordered.

Signed-off-by: Gilles Peskine <[email protected]>
No change to the generated files (the new code isn't used yet).

Signed-off-by: Gilles Peskine <[email protected]>
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 fixes the dependencies for DH group and elliptic curve families.

No changes to the generated output (the new functionality isn't used yet).

Signed-off-by: Gilles Peskine <[email protected]>
This fixes the dependencies for key pair types, which have finer-grained
dependencies for different operations (BASIC, GENERATE, EXPORT, ...).

No changes to the generated output (the new functionality isn't used yet).

Signed-off-by: Gilles Peskine <[email protected]>
No changes to the generated output (the new functionality isn't used yet).

Signed-off-by: Gilles Peskine <[email protected]>
Automatically skip test cases with not-implemented automatic dependencies.

No changes to the generated output.

Signed-off-by: Gilles Peskine <[email protected]>
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 <[email protected]>
@gilles-peskine-arm gilles-peskine-arm force-pushed the dev/gilles-peskine-arm/psa-storage-test-cases-never-supported-positive-framework branch from 18e5920 to b2ea59e Compare November 27, 2024 18:21
@davidhorstmann-arm
Copy link
Contributor

Needs rebase atop #67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci Needs to pass CI tests needs-work priority-high High priority - will be reviewed soon size-s Estimated task size: small (~2d)
Projects
Development

Successfully merging this pull request may close these issues.

2 participants