-
Notifications
You must be signed in to change notification settings - Fork 96
Add mbed os conf tests #255
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
Conversation
Add a test in `all.sh` that tests the deafuolt configuration in Mbed OS, as adjusted in the Mbed OS importer script, except setting `MBEDTLS_NO_PLATFORM_ENTROPY` as the tests need entropy source.
1. Add a dependency on `MBEDTLS_GENPRIME` for the test: "PSA generate key: RSA, 1024 bits, good, encrypt (OAEP SHA-256)". 2. Run the import RSA tests only if `MBEDTLS_MPI_MAXSIZE` is larger than `PSA_VENDOR_RSA_MAX_KEY_BITS+8` in bytes.
scripts/config.pl unset MBEDTLS_FS_IO | ||
scripts/config.pl unset MBEDTLS_PSA_ITS_FILE_C # requires a filesystem | ||
scripts/config.pl unset MBEDTLS_PSA_CRYPTO_STORAGE_C # requires PSA ITS | ||
#scripts/config.pl set MBEDTLS_NO_PLATFORM_ENTROPY Need some entropy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this line commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we need some entropy sources, otherwise psa_crypto_init()
will fail
scripts/config.pl unset MBEDTLS_SSL_TRUNCATED_HMAC | ||
scripts/config.pl unset MBEDTLS_PLATFORM_TIME_TYPE_MACRO | ||
scripts/config.pl set MBEDTLS_MPI_MAX_SIZE 512 | ||
make CC=gcc CFLAGS='-Werror -O1' all test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe do a 32-bit build to be slightly closer to Mbed OS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
The idea was to check Mbed OS configuration, but this won't harm
@@ -1120,6 +1120,70 @@ component_test_cmake_out_of_source () { | |||
unset MBEDTLS_ROOT_DIR | |||
} | |||
|
|||
component_test_basic_mbed_os_conf () { | |||
msg "build+test: Mbed OS default configuration" | |||
scripts/config.pl unset MBEDTLS_NET_C |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than call config.pl
a bunch of times, how about defining the Mbed OS configuration in a file in configs
? Or as a filter in config.pl
, if we want to define it by comparison to the default configuration?
General question: where is the Mbed OS configuration defined? |
When Mbed TLS is imported to Mbed OS, the import script is run, adjusting the Mbed TLS config, in the |
Thanks. Could we move that script to the Mbed TLS repository, and use that from |
I think it's doable, and in this case, preferable, but I think we should hear what @Patater has to say on this, since he is more familiar with the script |
Could we make a "reference configuration" for Mbed OS (to live in Mbed TLS's reference configs folder)? We can make the importer just copy over the Mbed OS reference configuration instead of shell-script-modifying it. This means we can delete some code. :) |
It depends whether we want to define the Mbed OS configuration by enumerating its contents or relative to the default configuration. If we add a new option which is enabled by default, should it be also enabled in Mbed OS by default? Furthermore, if we make a reference configuration, how do we document it? It needs to be documented so that people can make informed choices when making custom builds of Mbed OS. |
As Gilles mentioned, |
What's the best way to ship a differential reference configuration?
I feel like the first option would be more portable and slightly easier to maintain, but interested to hear your thoughts as well. |
scripts/config.pl unset MBEDTLS_SSL_TRUNCATED_HMAC | ||
scripts/config.pl unset MBEDTLS_PLATFORM_TIME_TYPE_MACRO | ||
scripts/config.pl set MBEDTLS_MPI_MAX_SIZE 512 | ||
make CC=gcc CFLAGS='-Werror -O1' all test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also add -Wstack-usage=2048 -Werror
to ensure we don't overflow the Mbed OS default main thread stack?
We should also use -Os
, if that's what Mbed OS will default to using.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gah, seems we can't enforce that stack limit until we can fit within that stack limit.
$ make CFLAGS:="-Os -Wstack-usage=2048 -Werror" check
CC bignum.c
bignum.c: In function ‘mbedtls_mpi_exp_mod’:
bignum.c:1926:5: error: stack usage is 3312 bytes [-Werror=stack-usage=]
int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
^~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Makefile:150: recipe for target 'bignum.o' failed
make[2]: *** [bignum.o] Error 1
Makefile:158: recipe for target 'libmbedcrypto.a' failed
make[1]: *** [libmbedcrypto.a] Error 2
Makefile:19: recipe for target 'lib' failed
make: *** [lib] Error 2
What stack size should we test that we don't exceed and recommend Mbed OS users configure if they want to use Mbed TLS? We appear to fit within 6000 bytes.
Gen test_suite_version.c
CC test_suite_version.c
suites/host_test.function: In function ‘execute_tests’:
suites/host_test.function:494:5: error: stack usage might be 5968 bytes [-Werror=stack-usage=]
int execute_tests( int argc , const char ** argv )
^~~~~~~~~~~~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stack consumption in mbedtls_mpi_exp_mod
increases exponentially with MBEDTLS_MPI_WINDOW_SIZE
. It's a space/time compromise, with ~1.5kB difference in stack usage between the min and max value on a 32-bit machine. Maybe we could reduce this value in Mbed OS: currently it uses the best-performance value except on TARGET_STM32F439xI
.
The library and the test suite are written in a very different style when it comes to stack consumption. execute_tests
uses a char buf[5000]
to store a line of the .data
file. I think we should -Wstack-usage
only for the library, not for the test suite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we should run with -Wstack-usage
only for the library for this PR.
In the future, we should build the tests as they'd be used on target, perhaps with our actual on-target testing capability, (so, likely excluding host_test.function): this enables us to catch when on-target testing would run into stack issues. Some test suites allocate unnecessarily large buffers on the stack. We should have a regression test in place to ensure issues like what #278 fixes don't rear their heads again, but adding such tests in this PR is out of scope.
Considering this PR does not appear to be close to be ready (still requires design discussions) or recently active, and we moving away from the mbed-crypto repo for new work, I'm closing this PR and encouraging you to re-open a similar one in mbedtls if you're still interested (perhaps after discussing if this is still appropriate now that Mbed TLS is less strongly connected to Mbed OS). |
Add a test in
all.sh
that configures the default configuration inMbed OS
and fix test dependencies discovered from it.