-
Notifications
You must be signed in to change notification settings - Fork 3k
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 CTest support for greentea tests: events #14986
Conversation
@hazzlim, thank you for your changes. |
e147d50
to
eb8658b
Compare
This pull request has automatically been marked as stale because it has had no recent activity. @ARMmbed/mbed-os-maintainers, please complete review of the changes to move the PR forward. Thank you for your contributions. |
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.
CI failed because test_equeue_multithread
and test_equeue_multithreaded_barrage
use Thread
which needs RTOS and doesn't work with bare metal. You can guard them with #ifdef MBED_CONF_RTOS_PRESENT
.
Note: Thread
requires RTOS, but ThisThread
works fine with bare metal because bare metal is treated like only one thread (i.e. ThisThread
).
It's nice that our CMake test includes a bare metal target.
Thanks Lingkai, I am guarding these tests and also refactoring all the events tests to use chrono to avoid deprecation warning. Already shows that running these extended tests is a good thing! And a good reminder to me to test both profiles locally too. |
3d017fd
to
4daeb86
Compare
You can use bullet points in the PR description to list the PR that must be merged before this one. It shows icons that informs of the status of the PRs as well as their titles. Example: |
@@ -128,7 +152,8 @@ void semaphore_timing_test() | |||
// Test setup | |||
utest::v1::status_t test_setup(const size_t number_of_cases) | |||
{ | |||
GREENTEA_SETUP((number_of_cases + 1)*TEST_EVENTS_TIMING_TIME / 1000, "default_auto"); | |||
GREENTEA_SETUP((number_of_cases + 1) * duration_cast<seconds>(TEST_EVENTS_TIMING_TIME_DURATION).count(), |
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.
Looks like we had some bad style before. Is events/tests/TESTS/events/timing
somehow exclused from astyle
checking?
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’s not excluded...but I just tried running astyle on it (the master branch version) and it returned “Unchanged”. Maybe .astylerc
needs updating?
CI started |
This pull request has automatically been marked as stale because it has had no recent activity. @hazzlim, please carry out any necessary work to get the changes merged. Thank you for your contributions. |
I've identified the targets that don't define ROM size in config - I take it I can just consult the TRM and add all the Some targets seem slightly less straightforward, for example |
c370579
to
cf4a565
Compare
@@ -18,6 +18,7 @@ | |||
#include "greentea-client/test_env.h" | |||
#include "unity.h" | |||
#include "utest.h" | |||
#include <memory> |
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.
In commit message "Greentea: Refactor FAT Filesystem test cases to be independent" there is a typo: "propogated" should be "propagated"
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.
Fixed.
bool check_heap_allocation(size_t bytes) | ||
{ | ||
unique_ptr<uint8_t[]> dummy {new (std::nothrow) uint8_t[bytes]}; | ||
return (dummy != nullptr); |
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.
We should just be able to return dummy.get()
here and a nullptr
will be deduced as false
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.
Good point! I have amended with this change.
void format_partitions(HeapBlockDevice &bd) | ||
{ | ||
// Create two partitions splitting device in ~half | ||
TEST_ASSERT_EQUAL(0, MBRBlockDevice::partition(&bd, 1, 0x83, 0, (BLOCK_COUNT / 2) * BLOCK_SIZE)); |
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.
0x83
should be a named variable.
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.
Done.
TEST_SKIP_UNLESS_MESSAGE(bd, "Not enough heap memory to run test. Test skipped."); | ||
TEST_SKIP_UNLESS_MESSAGE(check_heap_allocation(mem_alloc_threshold), "Not enough heap memory to run test. Test skipped."); | ||
|
||
HeapBlockDevice bd {BLOCK_COUNT * BLOCK_SIZE, BLOCK_SIZE}; |
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 test case seems to make lots of assertions. Any way we can split it up into separate cases?
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 it's a pretty huge number of assertions. I'm not really sure how to split it up however, as verifying the data read matches the data written requires all the steps in the case as far as I can see.
storage/filesystem/fat/tests/TESTS/fat/multipart_fat_filesystem/main.cpp
Outdated
Show resolved
Hide resolved
{ | ||
TEST_SKIP_UNLESS_MESSAGE(check_heap_allocation(mem_alloc_threshold), "Not enough heap memory to run test. Test skipped."); | ||
|
||
// Stage 0 - LittleFS |
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.
Could these "Stages" be separate test cases? The loop looks pretty awkward at the moment with all this "if stage==1" stuff.
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 it's not very readable! I have split the stages into three separate cases in the commit "Greentea: Refactor test with other filesystem".
@@ -57,6 +62,16 @@ float chisq(float sigma) | |||
return pow(gauss(0, sqrt(sigma)), 2); | |||
} | |||
|
|||
// Macro for random duration generation | |||
#define RANDOM_DURATION(sigma) \ |
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.
Could this be a normal function instead of a macro?
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 good point, I have replaced the macro with a function.
unsigned start = equeue_tick(); | ||
int prev = 0; | ||
// equeue_tick() returns an integral millisecond value | ||
auto start = milliseconds{equeue_tick()}; |
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.
Looks like start
should be const
?
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.
Done.
while (prev < TEST_EVENTS_TIMING_TIME) { | ||
int next = equeue_tick() - start; | ||
while (prev < TEST_EVENTS_TIMING_TIME_DURATION) { | ||
auto next = milliseconds{equeue_tick()} - start; |
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.
Looks like next
should be const
?
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.
Done.
auto delay = RANDOM_DURATION(TEST_EVENTS_TIMING_MEAN_DURATION); | ||
|
||
int start = timer.read_us(); | ||
equeue_sema_wait(&sema, delay); | ||
int taken = timer.read_us() - start; | ||
auto start = timer.elapsed_time(); | ||
equeue_sema_wait(&sema, duration_cast<milliseconds>(delay).count()); | ||
auto taken = timer.elapsed_time() - start; |
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.
Looks like most, if not all, of these variables should be const
?
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.
Done.
In the Greentea test suite `multipart_fat_filesystem`, all the test cases are dependent on setup that occurs in the first case. This case formats (with FAT) a HeapBlockDevice that is shared between cases. Alongside this, the first case checks that sufficient heap memory is available for the dynamic memory allocation required for the FAT format process. This check is performed by testing if we can successfully allocate the required number of bytes, and skipping the case if not. The check is then propagated to the other cases by skipping those if the HeapBlockDevice pointer is falsy, which it will be if the first test is skipped. We refactor the cases to be independent of one another. Now each test case checks that sufficient memory can be allocated for FAT formatting, performing said formatting or skipping as indicated by this check. In doing so we replace remove some raw pointers, and replace some C style arrays with std::array, in order to make memory management less error prone.
cf4a565
to
bdc6d9f
Compare
Pull request has been modified.
The test case `test_with_other_fs` uses a fairly awkward loop to test mounting different filesystems consecutively. We split the test case into seperate cases, using more descriptive names and removing the use of raw pointers.
The Greentea test suite multipart_fat_filesystem contains a test case that uses LittleFileSystem and FATFilesystem, and including this case results in a binary too large for the flash memory of some targets. We separate this test case into its own suite and guard this test suite with a check for the size of the target's ROM. This is chosen over simply guarding the individual test case inside the same suite as it will allow the newly created suite to be skipped from CMake when the FAT Filesystem tests are ported to CTest. This issue was previously unidentified because the test suite was disabled by default, requiring the `MBED_EXTENDED_TESTS` macro to be defined, and was therefore not run in CI.
Some events/equeue Greentea test cases use the Thread API and therefore require RTOS to run, but previously this was not checked in the code. We add guards with the macro MBED_CONF_RTOS_PRESENT.
MBED_EXTENDED_TESTS macro was previously required to enable certain Greentea tests, which were disabled by default in order to save CI time. We remove this macro because the time saved in finding bugs or issues with a PR prior to merging is worth the increased testing time.
References to time should do so using std::chrono. We reworked events tests to use std::chrono and new APIs in order to remove deprecation warnings resulting from deprecated API calls. This required addition of a macro for test assertions using std::chrono values. Calls to wait_us() (not deprecated) are replaced with ThisThread::sleep_for() as there is no reason to wait without sleeping. Certain API calls that involve UserAllocatedEvents and do not have std::chrono versions are left unchanged, for example EventQueue.time_left().
Following the approach defined in ARMmbed#14892 and ARMmbed#14902, events greentea tests are ported to enable running with CTest. events/queue and events/timing both require DEVICE_USTICKER.
We are closing this pull request due to inactivity |
Summary of changes
Fixes #14965
MBED_EXTENDED_TESTS
macro is removed and 'extended' tests are enabled by defaultevents/equeue
tests that require RTOS are wrapped in checks for RTOSBUILD_GREENTEA_TESTS
is set. Added checks for macros that indicate the test is not supported and conditionally set theTEST_SKIPPED
argument accordingly.Preceding:
mbed-drivers-ticker
greentea test #14892Impact of changes
None
Migration actions required
None
Documentation
None
Pull request type
Test results
Reviewers
@ARMmbed/mbed-os-core