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

PSA client-server: support in the unit test framework #9237

Open
wants to merge 10 commits into
base: development
Choose a base branch
from

Conversation

valeriosetti
Copy link
Contributor

@valeriosetti valeriosetti commented Jun 7, 2024

Description

This is a first attempt to link already existing 'test_suite_xxx' source files to the 'psasim' simulation. So far only a limited subset of test_suite_xxx are tested because of the limited number of PSA APIs functions in psasim. This limit will be lifted once psasim will support all PSA APIs so that's why this PR is to be kept as work-in-progress as long as this support is improved.

Resolves #8968
Resolves #8966

PR checklist

  • changelog not required: it's only for PSASIM
  • 3.6 backport not required
  • 2.28 backport not required
  • tests provided

@valeriosetti valeriosetti added needs-ci Needs to pass CI tests size-s Estimated task size: small (~2d) priority-high High priority - will be reviewed soon labels Jun 7, 2024
@valeriosetti valeriosetti self-assigned this Jun 7, 2024
@valeriosetti valeriosetti added this to To Do in Roadmap Board for Mbed TLS via automation Jun 7, 2024
@valeriosetti valeriosetti force-pushed the issue8968 branch 2 times, most recently from cdde639 to 21150f3 Compare June 7, 2024 15:30
@minosgalanakis minosgalanakis added needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review and removed needs-ci Needs to pass CI tests labels Jun 10, 2024
@valeriosetti valeriosetti force-pushed the issue8968 branch 3 times, most recently from 5c8728a to d530744 Compare June 18, 2024 08:28
@valeriosetti valeriosetti force-pushed the issue8968 branch 2 times, most recently from 9f1136c to 2a52677 Compare June 19, 2024 14:38
@valeriosetti
Copy link
Contributor Author

Question for reviewers: perhaps 81dd9b0 can be set as a separate PR as we did for other commits which were not strictly related to psasim. Wdyt?

@@ -0,0 +1,8 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright headers

@@ -0,0 +1,17 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyright headers

@valeriosetti valeriosetti force-pushed the issue8968 branch 3 times, most recently from 2d401be to 587977b Compare June 20, 2024 07:48
@valeriosetti valeriosetti moved this from To Do to In Review in Roadmap Board for Mbed TLS Jun 20, 2024

msg "build library for client"
helper_crypto_client_build client

msg "build psasim to test psa_client"
rm -f tests/psa-client-server/psasim/test/psa_client # In case left behind
make -C tests/psa-client-server/psasim CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" test/psa_client
rm -f $PSASIM_PATH/test/psa_client # In case left behind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like it could be done in the cleanup_before_psasim_client()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if kept, this should be before make is called - specifically, because we were changing what was being built as psa_client, we want to make sure any existing such executable is removed, because make uses timestamps to determine what to build, and timestamps on other .c files might be older than when the last psa_client program was built.

If we're getting rid of all that (haven't reviewed in detail) we probably don't need this rm at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanup_before_psasim_client is meant to be called after the server has been built and before building the client. However please note that test/psa_client is only built in test_psasim not with standard test_suite_xxx and since test_suite_xxx is the preferred way of testing for the future, I think we can keep this command only here.
Besides I also think that once we'll have a good coverage of test_suite_xxx in the future we can also remove test_psasim because that will be superseded by those tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future we can also remove test_psasim

I think it will be useful to keep this as a smoke test, as if something goes wrong (i.e. we break psasim somehow) it will be very hard to debug once the whole test machinery is involved


msg "test psasim running psa_hash_compute"
tests/psa-client-server/psasim/test/run_test.sh
$PSASIM_PATH/test/run_test.sh


# Next APIs under test: psa_hash_*(). Use our copy of the PSA hash example.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole block could be a helper function

build_psasim() {
    msg "build psasim to test $1"
    rm tests/psa-client-server/psasim/test/psa_client
    rm $PSASIM_PATH/test/psa_client
    make -C $PSASIM_PATH CFLAGS="$ASAN_CFLAGS" LDFLAGS="$ASAN_CFLAGS" MAIN="src/$1.c" test/psa_client
    $PSASIM_PATH/test/run_test.sh
}

This could scale easier and we could even use an iterator to go through all the tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I like this

Copy link
Contributor Author

@valeriosetti valeriosetti Jun 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the comment above, please note that run_test.sh is only useful for test_psasim component not for test_suite_with_psasim and all other upcoming tests relying on test_suite_xxx. Once all PSA functions will be supported, make PSASIM=1 test will be the way to test with psasim (as it is done in test_suite_with_psasim). No need to manually iterate of test_suite_xxx; this is done "for free" by the current test framework. All test_suite_xxx will be linked against our client side implementation of psasim and they will connect to the server that has previously been launched in background.

What can be moved as helper is starting/stopping the PSA server in test_suite_with_psasim:

    (
        cd tests
        msg "start server"
        psa-client-server/psasim/test/start_server.sh
    )

and

    (
        cd tests
        msg "terminate server and cleanup"
        psa-client-server/psasim//test/kill_server.sh
    )

@@ -132,4 +153,13 @@ MBEDTLS_TLS_TEST_OBJS = $(patsubst %.c,%.o,$(wildcard \
${MBEDTLS_TEST_PATH}/src/test_helpers/*.c \
))

# THIS IS A TEMPORARY FIX!!!!!!!
# IT MUST BE REMOVED AS SOON AS LIBPSACLIENT WILL SUPPORT ALL PSA
# FUNCTIONS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what is preventing this fix being removed now?

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Now that we have PSASIM we can really test CRYPTO_CLIENT
functionality and those functions are not needed anymore.

Moreover new test suites that are going to rely on
CRYPTO_CLIENT && !CRYPTO_C would be tested from
test_default_psa_crypto_client_without_crypto_provider()
leading to failures due to stub functions being empty.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
@valeriosetti valeriosetti force-pushed the issue8968 branch 2 times, most recently from 8f333c2 to 446acd0 Compare June 28, 2024 11:02
valeriosetti and others added 4 commits June 29, 2024 16:19
- do not try to close a connection that was never started
- fix data chunks length for psa_write (prevent memcpy-ing
  to large blocks of data)

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit includes the following changes:

- on the psasim side it clears a certain operation slot on
  "finish()" and "abort()" operations

- in all.sh it builds all the test suites, but it just executes
  the constant_time_hmac one because it's one of those that
  quickly show the problem

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
@tom-cosgrove-arm
Copy link
Contributor

tom-cosgrove-arm commented Jun 29, 2024

I've updated psasim: minor fixes to the core so that it includes the necessary changes to psa_sim_generate.pl to regenerate these changes.

I've also removed the changes to psasim: TEMPORARY COMMIT that added psasim_serialize_free_hash_operation() and find_hash_slot_by_operation() - because this is now done a different way.

Instead, on server serialisation, when serialising the operation to send back to the client, we have an extra parameter completed. This is set by abort and finish operations, and not set on others. With this flag, the operation is erased on the server, and we return a handle number of 0 to the client, so that if the client re-uses their operation, we will allocate a new handle for them.

There's also a bit of extra testing code added to aut_psa_hash.c to test this

@tom-cosgrove-arm
Copy link
Contributor

Note that test_suite_with_psasim now takes a very long time to run - the OG test_suite_constant_time_hmac takes a long time; running it over the simulator is even slower :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO-NOT-MERGE needs-review Every commit must be reviewed by at least two team members, needs-reviewer This PR needs someone to pick it up for review 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.

PSA client-server: support in the unit test framework PSA client-server: run unit tests
3 participants