-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,12 @@ | |
|
||
#include "mbedtls/sha256.h" | ||
|
||
#if defined(MBEDTLS_PLATFORM_C) | ||
#include "mbedtls/platform.h" | ||
#else | ||
#include <stdio.h> | ||
#define mbedtls_printf printf | ||
#endif | ||
|
||
using namespace utest::v1; | ||
|
||
|
@@ -163,5 +169,18 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { | |
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); | ||
|
||
int main() { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Are you suggesting that if an implementation introduces There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 This is an independent design discussion, though, that we should probably have outside of this PR. |
||
if((ret = mbedtls_platform_setup(&platform_ctx))!= 0) | ||
{ | ||
mbedtls_printf("Mbed TLS multitest failed! mbedtls_platform_setup returned %d\n", ret); | ||
return 1; | ||
} | ||
#endif | ||
ret = (Harness::run(specification) ? 0 : 1); | ||
#if defined(MBEDTLS_PLATFORM_C) | ||
mbedtls_platform_teardown(&platform_ctx); | ||
#endif | ||
return 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.
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)