Skip to content

Commit

Permalink
WORKAROUND for TICKLESS : add DeepSleepLock
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromecoutant committed Jul 17, 2018
1 parent 0f80394 commit c4f0eaf
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
8 changes: 8 additions & 0 deletions TESTS/mbed_drivers/lp_ticker/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void increment_multi_counter(void)
*/
void test_multi_ticker(void)
{
DeepSleepLock lock;

LowPowerTicker ticker[TICKER_COUNT];
const uint32_t extra_wait = 10; // extra 10ms wait time

Expand Down Expand Up @@ -105,6 +107,8 @@ void test_multi_ticker(void)
// (e.g. when head event is removed), it's good to check if
// no more callbacks were triggered during detaching.
TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);

lock.unlock();
}

/** Test multi callback time
Expand Down Expand Up @@ -140,6 +144,8 @@ void test_multi_call_time(void)
*/
void test_detach(void)
{
DeepSleepLock lock;

LowPowerTicker ticker;
int32_t ret;
const float ticker_time_s = 0.1f;
Expand All @@ -157,6 +163,8 @@ void test_detach(void)

ret = sem.wait(wait_time_ms);
TEST_ASSERT_EQUAL(0, ret);

lock.unlock();
}

/** Test single callback time via attach
Expand Down
8 changes: 8 additions & 0 deletions TESTS/mbed_drivers/race_test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ static void main_class_race()

void test_case_func_race()
{
DeepSleepLock lock;

Callback<void()> cb(main_func_race);
Thread t1(osPriorityNormal, TEST_STACK_SIZE);
Thread t2(osPriorityNormal, TEST_STACK_SIZE);
Expand All @@ -91,10 +93,14 @@ void test_case_func_race()

// Reset instance count
instance_count = 0;

lock.unlock();
}

void test_case_class_race()
{
DeepSleepLock lock;

Callback<void()> cb(main_class_race);
Thread t1(osPriorityNormal, TEST_STACK_SIZE);
Thread t2(osPriorityNormal, TEST_STACK_SIZE);
Expand All @@ -113,6 +119,8 @@ void test_case_class_race()

// Reset instance count
instance_count = 0;

lock.unlock();
}

Case cases[] = {
Expand Down
20 changes: 20 additions & 0 deletions TESTS/mbed_drivers/timeout/timeout_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class AttachUSTester: public TimeoutType {
template<typename T>
void test_single_call(void)
{
DeepSleepLock lock;

Semaphore sem(0, 1);
T timeout;

Expand All @@ -88,6 +90,8 @@ void test_single_call(void)
TEST_ASSERT_EQUAL(0, sem_slots);

timeout.detach();

lock.unlock();
}

/** Template for tests: callback not called when cancelled
Expand All @@ -105,6 +109,8 @@ void test_single_call(void)
template<typename T>
void test_cancel(void)
{
DeepSleepLock lock;

Semaphore sem(0, 1);
T timeout;

Expand All @@ -116,6 +122,8 @@ void test_cancel(void)

sem_slots = sem.wait(TEST_DELAY_MS + 1);
TEST_ASSERT_EQUAL(0, sem_slots);

lock.unlock();
}

/** Template for tests: callback override
Expand All @@ -137,6 +145,8 @@ void test_cancel(void)
template<typename T>
void test_override(void)
{
DeepSleepLock lock;

Semaphore sem1(0, 1);
Semaphore sem2(0, 1);
T timeout;
Expand All @@ -153,6 +163,8 @@ void test_override(void)
TEST_ASSERT_EQUAL(0, sem_slots);

timeout.detach();

lock.unlock();
}

/** Template for tests: multiple Timeouts
Expand All @@ -172,13 +184,17 @@ void test_override(void)
template<typename T>
void test_multiple(void)
{
DeepSleepLock lock;

volatile uint32_t callback_count = 0;
T timeouts[NUM_TIMEOUTS];
for (size_t i = 0; i < NUM_TIMEOUTS; i++) {
timeouts[i].attach_callback(mbed::callback(cnt_callback, &callback_count), TEST_DELAY_US);
}
Thread::wait(TEST_DELAY_MS + 1);
TEST_ASSERT_EQUAL(NUM_TIMEOUTS, callback_count);

lock.unlock();
}

/** Template for tests: zero delay
Expand All @@ -196,13 +212,17 @@ void test_multiple(void)
template<typename T>
void test_no_wait(void)
{
DeepSleepLock lock;

Semaphore sem(0, 1);
T timeout;
timeout.attach_callback(mbed::callback(sem_callback, &sem), 0ULL);

int32_t sem_slots = sem.wait(0);
TEST_ASSERT_EQUAL(1, sem_slots);
timeout.detach();

lock.unlock();
}

/** Template for tests: accuracy of timeout delay
Expand Down
4 changes: 4 additions & 0 deletions TESTS/mbedmicro-rtos-mbed/rtostimer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ void test_created_stopped()
*/
void test_stop()
{
DeepSleepLock lock;

Semaphore sem(0, 1);
RtosTimer rtostimer(mbed::callback(sem_callback, &sem), osTimerOnce);

Expand All @@ -271,6 +273,8 @@ void test_stop()

status = rtostimer.stop();
TEST_ASSERT_EQUAL(osErrorResource, status);

lock.unlock();
}

/** Test timer started with infinite delay
Expand Down
14 changes: 13 additions & 1 deletion TESTS/mbedmicro-rtos-mbed/systimer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if !MBED_TICKLESS
#ifndef MBED_TICKLESS
#error [NOT_SUPPORTED] Tickless mode not supported for this target.
#endif

Expand Down Expand Up @@ -198,6 +198,8 @@ void test_get_time(void)
*/
void test_cancel_tick(void)
{
DeepSleepLock lock;

SysTimerTest st;
st.cancel_tick();
st.schedule_tick(TEST_TICKS);
Expand All @@ -206,6 +208,8 @@ void test_cancel_tick(void)
int32_t sem_slots = st.sem_wait((DELAY_US + DELAY_DELTA_US) / 1000ULL);
TEST_ASSERT_EQUAL_INT32(0, sem_slots);
TEST_ASSERT_EQUAL_UINT32(0, st.get_tick());

lock.unlock();
}

/** Test schedule zero
Expand All @@ -216,11 +220,15 @@ void test_cancel_tick(void)
*/
void test_schedule_zero(void)
{
DeepSleepLock lock;

SysTimerTest st;

st.schedule_tick(0UL);
int32_t sem_slots = st.sem_wait(0UL);
TEST_ASSERT_EQUAL_INT32(1, sem_slots);

lock.unlock();
}

/** Test handler called once
Expand All @@ -234,6 +242,8 @@ void test_schedule_zero(void)
*/
void test_handler_called_once(void)
{
DeepSleepLock lock;

SysTimerTest st;
st.schedule_tick(TEST_TICKS);
us_timestamp_t t1 = st.get_time();
Expand All @@ -249,6 +259,8 @@ void test_handler_called_once(void)
sem_slots = st.sem_wait((DELAY_US + DELAY_DELTA_US) / 1000ULL);
TEST_ASSERT_EQUAL_INT32(0, sem_slots);
TEST_ASSERT_EQUAL_UINT32(1, st.get_tick());

lock.unlock();
}

#if DEVICE_SLEEP
Expand Down

0 comments on commit c4f0eaf

Please sign in to comment.