Skip to content

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

Merged
merged 1 commit into from
Nov 16, 2017

Conversation

maciejbocianski
Copy link
Contributor

@maciejbocianski maciejbocianski commented Oct 5, 2017

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)

#define TICKER_COUNT 16

Ticker ticker[TICKER_COUNT];

multi_counter = 0;
for (int i = 0; i < TICKER_COUNT; i++) {
    ticker[i].attach_us(callback(wait_callback_multi), 100 * 1000);
}

Thread::wait(105);
for (int i = 0; i < TICKER_COUNT; i++) {
    ticker[i].detach();
}

TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);

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

/* CPU clock */
extern uint32_t SystemCoreClock;

#define TOLERANCE_FACTOR 15000.0f
Copy link
Member

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 ?

Ticker ticker;
int32_t ret;

ticker.attach(callback(wait_callback_sem), 0.1f);
Copy link
Member

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);

Copy link
Contributor Author

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

Copy link
Contributor Author

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);


/** Test many tickers run one after the other

Given a 16 Tickers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given a 16 Tickers

ticker[i].attach_us(callback(wait_callback_multi), 100 * 1000);
}

Thread::wait(105);
Copy link
Member

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.

ticker[i].attach_us(callback(wait_callback_multi), (100 + i) * 1000);
}

Thread::wait(120);
Copy link
Member

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.

while(!ticker_callback_flag);
time_diff = gtimer.read_us();

TEST_ASSERT_UINT32_WITHIN(TOLERANCE, 100000, time_diff);
Copy link
Member

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.

ticker_callback_flag = true;
}

void wait_callback_multi(void)
Copy link
Member

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.


void wait_callback_flag(void)
Copy link
Member

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.

@maciejbocianski maciejbocianski force-pushed the ticker_tests2 branch 4 times, most recently from 4a3f680 to 4243404 Compare October 9, 2017 08:10
@maciejbocianski
Copy link
Contributor Author

@pan- updated after review

@maciejbocianski maciejbocianski force-pushed the ticker_tests2 branch 2 times, most recently from c89f9e7 to 69f7fd8 Compare October 9, 2017 13:24
@0xc0170
Copy link
Contributor

0xc0170 commented Oct 9, 2017

There was a fix merged recently that is causing this PR to be rebased

@maciejbocianski maciejbocianski force-pushed the ticker_tests2 branch 2 times, most recently from c17f0df to 423f131 Compare October 9, 2017 13:54
@theotherjimmy
Copy link
Contributor

@pan- Are you happy with the new version?

@theotherjimmy
Copy link
Contributor

Note to self, this should pass nightly 3 times in a row before going in.

@mbed-ci
Copy link

mbed-ci commented Oct 9, 2017

Build : SUCCESS

Build number : 18
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5261/

@@ -85,7 +123,8 @@ void ticker_callback_2_switch_to_1(void) {
ticker_callback_2_led();
}

void wait_and_print() {
void wait_and_print()
Copy link
Member

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

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 */
Copy link
Member

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 ?

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

@maciejbocianski maciejbocianski Oct 11, 2017

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



volatile bool ticker_callback_flag;
volatile uint32_t multi_counter;
Copy link
Member

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.

Copy link
Contributor Author

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 ?

Copy link
Contributor

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

Copy link
Contributor Author

@maciejbocianski maciejbocianski Oct 10, 2017

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 ?

Copy link
Member

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.


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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

increment_ticker_counter ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

++callback_trigger_count;
}

void ticker_callback_1_led(void) {
void ticker_callback_1_led(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch_led1_state ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

led1 = !led1;
}

void ticker_callback_2_led(void) {
void ticker_callback_2_led(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch_led2_state ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 10, 2017

/morph test

@mbed-ci
Copy link

mbed-ci commented Oct 10, 2017

Build : FAILURE

Build number : 38
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5261/

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1560

Example Build failed!

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 10, 2017

/morph test

@mbed-ci
Copy link

mbed-ci commented Oct 10, 2017

Build : FAILURE

Build number : 60
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5261/

@mbed-ci
Copy link

mbed-ci commented Oct 11, 2017

Build : SUCCESS

Build number : 112
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5261/

Triggering tests

/test mbed-os

@mbed-ci
Copy link

mbed-ci commented Oct 12, 2017

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 12, 2017

Can you look at NCS36510 that fails ?

@bulislaw
Copy link
Member

@maciejbocianski what's the status of that?

@maciejbocianski
Copy link
Contributor Author

waiting for #5307 and #5309
In spite of that this devices are unplugged from CI the problem still exist

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 13, 2017

/morph build

@mbed-ci
Copy link

mbed-ci commented Nov 13, 2017

Build : SUCCESS

Build number : 499
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/5261/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build

@studavekar
Copy link
Contributor

/morph test
/morph export-build

@mbed-ci
Copy link

mbed-ci commented Nov 16, 2017

@mbed-ci
Copy link

mbed-ci commented Nov 16, 2017

@maciejbocianski
Copy link
Contributor Author

@0xc0170 tests passed, looks that #5307 is fixed by #5390 so I will resolve #5307 as fixed ?

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 16, 2017

@0xc0170 tests passed, looks that #5307 is fixed by #5390 so I will resolve #5307 as fixed ?

+1 , if you confirm that is fixed, should be !

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 16, 2017

@pan- Can you please review the latest update?

@0xc0170 0xc0170 changed the title Extends test set for Ticker class (round 2) Extends test set for Ticker class Nov 16, 2017
@0xc0170 0xc0170 merged commit 56aa7c3 into ARMmbed:master Nov 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants