-
Notifications
You must be signed in to change notification settings - Fork 3k
Extends test set for Ticker class #5261
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
25be029
to
9135ac8
Compare
TESTS/mbed_drivers/ticker/main.cpp
Outdated
/* CPU clock */ | ||
extern uint32_t SystemCoreClock; | ||
|
||
#define TOLERANCE_FACTOR 15000.0f |
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 you document why that value was chosen as the tolerance factor ?
TESTS/mbed_drivers/ticker/main.cpp
Outdated
Ticker ticker; | ||
int32_t ret; | ||
|
||
ticker.attach(callback(wait_callback_sem), 0.1f); |
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.
The semaphore can be local and there is no need to create a new function to release the semaphore:
Semaphore sem(0, 1);
ticker.attach(callback(&sem, &Semaphore::release), 0.1f);
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.
but attach
expects Callback<void()> func
and Semaphore::release
return osStatus
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.
changed to local semaphore passed as pointer
Semaphore sem(0, 1);
ticker.attach(callback(sem_release, &sem), 0.1f);
TESTS/mbed_drivers/ticker/main.cpp
Outdated
|
||
/** Test many tickers run one after the other | ||
|
||
Given a 16 Tickers |
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.
Given a 16 Tickers
TESTS/mbed_drivers/ticker/main.cpp
Outdated
ticker[i].attach_us(callback(wait_callback_multi), 100 * 1000); | ||
} | ||
|
||
Thread::wait(105); |
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.
Would be better if this value was not hard coded but computed from the time set in attach_us
.
TESTS/mbed_drivers/ticker/main.cpp
Outdated
ticker[i].attach_us(callback(wait_callback_multi), (100 + i) * 1000); | ||
} | ||
|
||
Thread::wait(120); |
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.
Would be better if this value was not hard coded but computed from the time set in attach_us.
TESTS/mbed_drivers/ticker/main.cpp
Outdated
while(!ticker_callback_flag); | ||
time_diff = gtimer.read_us(); | ||
|
||
TEST_ASSERT_UINT32_WITHIN(TOLERANCE, 100000, time_diff); |
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.
Please do not hardcode 100000. A local variable constant well named would help maintenance and readability.
TESTS/mbed_drivers/ticker/main.cpp
Outdated
ticker_callback_flag = true; | ||
} | ||
|
||
void wait_callback_multi(void) |
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.
May we have a better naming ? increment_multi_counter
for instance.
TESTS/mbed_drivers/ticker/main.cpp
Outdated
|
||
void wait_callback_flag(void) |
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.
May we have a better naming ? stop_gtimer
for instance.
4a3f680
to
4243404
Compare
@pan- updated after review |
c89f9e7
to
69f7fd8
Compare
There was a fix merged recently that is causing this PR to be rebased |
c17f0df
to
423f131
Compare
@pan- Are you happy with the new version? |
Note to self, this should pass nightly 3 times in a row before going in. |
Build : SUCCESSBuild number : 18 |
TESTS/mbed_drivers/ticker/main.cpp
Outdated
@@ -85,7 +123,8 @@ void ticker_callback_2_switch_to_1(void) { | |||
ticker_callback_2_led(); | |||
} | |||
|
|||
void wait_and_print() { | |||
void wait_and_print() |
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 function is not used, would it be possible to remove it as well as symbols only used by it ?
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.
removed
TESTS/mbed_drivers/ticker/main.cpp
Outdated
volatile uint32_t callback_trigger_count = 0; | ||
static const int test_timeout = 240; | ||
static const int total_ticks = 10; | ||
|
||
extern uint32_t SystemCoreClock; /* CPU clock */ |
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 portable way to access to that declaration from an header ?
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.
on most platforms osKernelGetSysTimerFreq
works
but look #4986
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 portable way to access to that declaration from an header ?
I wish there was as this is part of cmsis, they declare it there as extern symbol in the cmsis startup files
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 noticed lately that there was some changes and now osKernelGetSysTimerFreq
return SystemCoreClock
for all platforms. It uses osRtxSysTimerGetFreq
and there is no platform overriding it so below default implementation is used for all targets
...
osRtxInfo.kernel.sys_freq = SystemCoreClock;
...
__WEAK uint32_t osRtxSysTimerGetFreq (void) {
return osRtxInfo.kernel.sys_freq;
}
So now we could use osKernelGetSysTimerFreq
instead SystemCoreClock
TESTS/mbed_drivers/ticker/main.cpp
Outdated
|
||
|
||
volatile bool ticker_callback_flag; | ||
volatile uint32_t multi_counter; |
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.
Ideally those variables should be accessed atomically, volatile does not guarantee atomicity.
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.
you mean increment/change atomically ?
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, use atomic operations we provide
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.
there is no function: core_util_atomic_incr_u32(volatile uint32_t *valuePtr
so we have to cast to remove volatile: core_util_atomic_incr_u32((uint32_t*)&multi_counter, 1);
Other option is to use just core_util_critical_section
to protect multi_counter
change
O mayby we should have volatile
versions of core_util_atomic_
functions ?
@0xc0170 @pan- what do you think ?
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.
volatile
should not be required for atomic access because the memory order we use is similar to std::memory_order_seq_cst
so data access should not be reordered.
TESTS/mbed_drivers/ticker/main.cpp
Outdated
|
||
volatile int ticker_count = 0; | ||
volatile bool print_tick = false; | ||
|
||
void ticker_callback_1_switch_to_2(void); | ||
void ticker_callback_2_switch_to_1(void); | ||
|
||
void ticker_callback_0(void) { | ||
void ticker_callback_0(void) |
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.
increment_ticker_counter
?
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.
changed
TESTS/mbed_drivers/ticker/main.cpp
Outdated
++callback_trigger_count; | ||
} | ||
|
||
void ticker_callback_1_led(void) { | ||
void ticker_callback_1_led(void) |
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.
switch_led1_state
?
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.
changed
TESTS/mbed_drivers/ticker/main.cpp
Outdated
led1 = !led1; | ||
} | ||
|
||
void ticker_callback_2_led(void) { | ||
void ticker_callback_2_led(void) |
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.
switch_led2_state
?
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.
changed
423f131
to
5421213
Compare
/morph test |
Build : FAILUREBuild number : 38 |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputExample Build failed! |
/morph test |
5421213
to
5fb0759
Compare
Build : FAILUREBuild number : 60 |
5fb0759
to
4660555
Compare
Build : SUCCESSBuild number : 112 Triggering tests/test mbed-os |
Test : FAILUREBuild number : 45 |
Can you look at |
4660555
to
aaa15bc
Compare
@maciejbocianski what's the status of that? |
/morph build |
Build : SUCCESSBuild number : 499 Triggering tests/morph test |
/morph test |
Exporter Build : SUCCESSBuild number : 144 |
Test : SUCCESSBuild number : 339 |
@pan- Can you please review the latest update? |
Description
New test suite for Ticker class with fixes
Fix for NRF51/NRF51 included - time measure accuracy improved
Alternative version of fix #5255 included
Fixes for fails on KL46Z / MAX32625MBED / MAX32630FTHR / NCS36510 not inclcuded
Problems with KL46Z / MAX32625MBED / MAX32630FTHR / NCS36510 looks similar to #5004
Not all callbacks executed and
TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);
fails (see below code)Status
HOLD
Related PRs
#5006 - reverted due to fails
#5255
Related issues:
#5004
#5291
Blocked by
#5309
#5307 - seems to be fixed by #5390 waitng for retest