Skip to content

Fixing lp ticker and sleep manager tests #5063

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 7 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TESTS/mbed_drivers/lp_timeout/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ void lp_timeout_1s_sleep(void)
{
complete = false;

sleep_manager_lock_deep_sleep();
timestamp_t start = us_ticker_read();
lpt.attach(&cb_done, 1);
sleep();
while (!complete);
timestamp_t end = us_ticker_read();
sleep_manager_unlock_deep_sleep();

TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
TEST_ASSERT_TRUE(complete);
Expand Down
10 changes: 5 additions & 5 deletions TESTS/mbed_drivers/timeout/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@

using namespace utest::v1;

#define ONE_MILLI_SEC 1000
#define PERIOD_US 10000

volatile int ticker_count = 0;
volatile uint32_t callback_trigger_count = 0;
static const int test_timeout = 240;
Timeout timeout;

void set_incremeant_count() {
timeout.attach_us(set_incremeant_count, ONE_MILLI_SEC);
timeout.attach_us(set_incremeant_count, PERIOD_US);
++callback_trigger_count;
}

Expand All @@ -56,19 +56,19 @@ void test_case_timeout() {
uint8_t results_size = 0;

greentea_send_kv("timing_drift_check_start", 0);
timeout.attach_us(set_incremeant_count, ONE_MILLI_SEC);
timeout.attach_us(set_incremeant_count, PERIOD_US);

// wait for 1st signal from host
do {
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
expected_key = strcmp(_key, "base_time");
} while (expected_key);

greentea_send_kv(_key, callback_trigger_count * ONE_MILLI_SEC);
greentea_send_kv(_key, callback_trigger_count * PERIOD_US);

// wait for 2nd signal from host
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
greentea_send_kv(_key, callback_trigger_count * ONE_MILLI_SEC);
greentea_send_kv(_key, callback_trigger_count * PERIOD_US);

//get the results from host
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
Expand Down
21 changes: 17 additions & 4 deletions TESTS/mbed_hal/lp_ticker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "mbed.h"
#include "us_ticker_api.h"
#include "lp_ticker_api.h"
#include "TimerEvent.h"

using namespace utest::v1;

Expand All @@ -39,13 +40,23 @@ static const ticker_data_t *lp_ticker_data = get_lp_ticker_data();
#define SHORT_TIMEOUT (600)

void cb_done(uint32_t id) {
complete_timestamp = us_ticker_read();
complete = true;
if ((uint32_t)&delay_event == id) {
complete_timestamp = us_ticker_read();
complete = true;
} else {
// Normal ticker handling
TimerEvent::irq(id);
}
}

void cb_done_deepsleep(uint32_t id) {
complete_timestamp = lp_ticker_read();
complete = true;
if ((uint32_t)&delay_event == id) {
complete_timestamp = lp_ticker_read();
complete = true;
} else {
// Normal ticker handling
TimerEvent::irq(id);
}
}

void lp_ticker_delay_us(uint32_t delay_us, uint32_t tolerance)
Expand Down Expand Up @@ -109,11 +120,13 @@ void lp_ticker_1s_sleep()
ticker_remove_event(lp_ticker_data, &delay_event);
delay_ts = lp_ticker_read() + 1000000;

sleep_manager_lock_deep_sleep();
timestamp_t start = us_ticker_read();
ticker_insert_event(lp_ticker_data, &delay_event, delay_ts, (uint32_t)&delay_event);
sleep();
while (!complete);
timestamp_t end = complete_timestamp;
sleep_manager_unlock_deep_sleep();

TEST_ASSERT_UINT32_WITHIN(LONG_TIMEOUT, 1000000, end - start);
TEST_ASSERT_TRUE(complete);
Expand Down
6 changes: 4 additions & 2 deletions TESTS/mbed_hal/sleep_manager_racecondition/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

using namespace utest::v1;

#define TEST_STACK_SIZE 256

void sleep_manager_locking_thread_test()
{
for (uint32_t i = 0; i < 100; i++) {
Expand All @@ -37,8 +39,8 @@ void sleep_manager_multithread_test()
{
{
Callback<void()> cb(sleep_manager_locking_thread_test);
Thread t1;
Thread t2;
Thread t1(osPriorityNormal, TEST_STACK_SIZE);
Copy link
Contributor Author

@0xc0170 0xc0170 Sep 9, 2017

Choose a reason for hiding this comment

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

this multithreaded test should be guarded by MBED_RTOS_SINGLE_THREAD . I am looking at what this macro is changing, and found only tests that use it and then toolchains python files that define it. Pointers?

It seems to me that we removed this macro from rtos code base (even if this macro is set, you can create multiple threads?), as previously it set task count to 1 as I recall, or not?

Thread t2(osPriorityNormal, TEST_STACK_SIZE);

t1.start(callback(cb));
Thread::wait(25);
Expand Down
4 changes: 3 additions & 1 deletion drivers/Ticker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void Ticker::setup(us_timestamp_t t) {

void Ticker::handler() {
insert_absolute(event.timestamp + _delay);
_function();
if (_function) {
_function();
}
}

} // namespace mbed
4 changes: 3 additions & 1 deletion targets/TARGET_ONSEMI/TARGET_NCS36510/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void fncs36510_deepsleep(void)
/** Enter into deep sleep mode */
__ISB();
__WFI();
__NOP();
__NOP();

/** Wait for the external 32MHz to be power-ed up & running
* Re-power down the 32MHz internal osc
Expand Down Expand Up @@ -115,4 +117,4 @@ void fncs36510_coma(void)
fMacRestoreFrameStoreLUT(MAC_LUT_BackUp); */
}

#endif /* DEVICE_SLEEP */
#endif /* DEVICE_SLEEP */
2 changes: 1 addition & 1 deletion targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -3195,7 +3195,7 @@
},
"OUTPUT_EXT": "hex",
"post_binary_hook": {"function": "NCS36510TargetCode.ncs36510_addfib"},
"macros": ["CM3", "CPU_NCS36510", "TARGET_NCS36510", "LOAD_ADDRESS=0x3000", "MBED_TICKLESS"],
"macros": ["CM3", "CPU_NCS36510", "TARGET_NCS36510", "LOAD_ADDRESS=0x3000"],
"supported_toolchains": ["GCC_ARM", "ARM", "IAR"],
"device_has": ["ANALOGIN", "SERIAL", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "LOWPOWERTIMER", "TRNG", "SPISLAVE"],
"release_versions": ["2", "5"]
Expand Down