-
Notifications
You must be signed in to change notification settings - Fork 3k
Add platform setup and teardown calls to mbedtls tests #6749
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
Add platform setup and teardown calls to mbedtls tests #6749
Conversation
ARM Internal Ref: IOTSSL-2245 |
#if defined(MBEDTLS_PLATFORM_C) | ||
#include "mbedtls/platform.h" | ||
#else | ||
#include <stdio.h> |
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.
Is there a reason to include this stuff in the #else
block.
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.
To be consistent with other examples, and to allow compilation on platforms without PLATFORM_C define.
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.
@hanno-arm made a more specific comment #6749 (review)
Harness::run(specification); | ||
int ret = 0; | ||
#if defined(MBEDTLS_PLATFORM_C) | ||
mbedtls_platform_context platform_ctx; |
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.
mbedtls_platform_context
can be defined platform specific. We don't know if it will fit stack of an embedded app. It may be more robust to declare it static.
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.
This declaration is consistent with other examples, and in my opinion should be up to the implementer to change, if the stack is small. I would say that this is a standard place to have the context.
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.
Are you suggesting that if an implementation introduces mbedtls_platform_context
that is inappropriate for the stack then they should change all tests. If we anticipate that, we can avoid it by creating it static
or on heap.
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.
@AndrzejKurek Do you mean Mbed TLS internal example programs or other test programs in the Mbed OS repository?
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.
@hanno-arm I mean our examples. Mbed OS repository examples present mixed approach to how and where are dependencies declared.
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.
@mazimkhan How do we know if someone doesn't prefer to have it on the stack instead? I can introduce your change, but I feel like it's a matter of preferences.
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.
It is about robustness and life time. The life time of platform context is process. It will live as a singleton instance throughout the process. Hence no harm in having it ``static``` or global.
Secondly, it will be robust to have it statically allocated since memory requirement will be checked at compile time. With current implementation it may fail at run time and will require debugging and code change to adjust for the application.
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 don't see the reason to have a platform structure in the first place, as opposed to having parameterless functions mbedtls_platform_setup()
and mbedtls_platform_teardown()
and leaving it to the implementation to allocate and maintain platform specific globals. Also, how would the platform context be actually used in the way it currently works? E.g., how would a custom printf
implementation have access to it?
This is an independent design discussion, though, that we should probably have outside of this PR.
TESTS/mbedtls/multi/main.cpp
Outdated
mbedtls_platform_context platform_ctx; | ||
if((ret = mbedtls_platform_setup(&platform_ctx))!= 0) | ||
{ | ||
mbedtls_printf("Mbed TLS selftest failed! mbedtls_platform_setup returned %d\n", ret); |
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.
Log message is incorrect.
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.
@mazimkhan What would you like to be different here?
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 believe that Azim is talking about the "selftest" log in a "multi" test. Copy and paste error on my side, I'll fix that.
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.
Yes and it could say "platform setup failed".
TESTS/mbedtls/multi/main.cpp
Outdated
#include <stdio.h> | ||
#include <stdlib.h> | ||
#define mbedtls_printf printf | ||
#define mbedtls_snprintf snprintf |
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.
It looks as if we only need mbedtls_printf
in this file, so can we get rid of stdlib.h
, mbedtls_snprintf
, mbedtls_exit
, MBEDTLS_EXIT_SUCCESS
and MBEDTLS_EXIT_FAILURE
?
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, I'll update the PR.
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 share @mazimkhan's objections against the use of platform context structures at the API boundary, but this is an independent design discussion. Taken the current design as granted, I approve the changes in this PR.
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 approve this PR. Although I believe that creating mbedtls_platform_context
on stack is not good. Since it's size is implementation dependent, it can cause run time stack overflow. I suggest creating it global/static/on heap to avoid future run time error.
/morph build |
Build : SUCCESSBuild number : 2012 Triggering tests/morph test |
Test : SUCCESSBuild number : 1822 |
Exporter Build : SUCCESSBuild number : 1664 |
Description
This test adds platform setup and teardown calls to Mbed TLS tests, so that all of the custom cryptographic hardware setup can be performed before running any tests. This has been tested using the current head of mbed-os master, on K64F with GCC_ARM.
Pull request type