Skip to content

Commit c4f0eaf

Browse files
committed
WORKAROUND for TICKLESS : add DeepSleepLock
1 parent 0f80394 commit c4f0eaf

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

TESTS/mbed_drivers/lp_ticker/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ void increment_multi_counter(void)
7171
*/
7272
void test_multi_ticker(void)
7373
{
74+
DeepSleepLock lock;
75+
7476
LowPowerTicker ticker[TICKER_COUNT];
7577
const uint32_t extra_wait = 10; // extra 10ms wait time
7678

@@ -105,6 +107,8 @@ void test_multi_ticker(void)
105107
// (e.g. when head event is removed), it's good to check if
106108
// no more callbacks were triggered during detaching.
107109
TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);
110+
111+
lock.unlock();
108112
}
109113

110114
/** Test multi callback time
@@ -140,6 +144,8 @@ void test_multi_call_time(void)
140144
*/
141145
void test_detach(void)
142146
{
147+
DeepSleepLock lock;
148+
143149
LowPowerTicker ticker;
144150
int32_t ret;
145151
const float ticker_time_s = 0.1f;
@@ -157,6 +163,8 @@ void test_detach(void)
157163

158164
ret = sem.wait(wait_time_ms);
159165
TEST_ASSERT_EQUAL(0, ret);
166+
167+
lock.unlock();
160168
}
161169

162170
/** Test single callback time via attach

TESTS/mbed_drivers/race_test/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ static void main_class_race()
7373

7474
void test_case_func_race()
7575
{
76+
DeepSleepLock lock;
77+
7678
Callback<void()> cb(main_func_race);
7779
Thread t1(osPriorityNormal, TEST_STACK_SIZE);
7880
Thread t2(osPriorityNormal, TEST_STACK_SIZE);
@@ -91,10 +93,14 @@ void test_case_func_race()
9193

9294
// Reset instance count
9395
instance_count = 0;
96+
97+
lock.unlock();
9498
}
9599

96100
void test_case_class_race()
97101
{
102+
DeepSleepLock lock;
103+
98104
Callback<void()> cb(main_class_race);
99105
Thread t1(osPriorityNormal, TEST_STACK_SIZE);
100106
Thread t2(osPriorityNormal, TEST_STACK_SIZE);
@@ -113,6 +119,8 @@ void test_case_class_race()
113119

114120
// Reset instance count
115121
instance_count = 0;
122+
123+
lock.unlock();
116124
}
117125

118126
Case cases[] = {

TESTS/mbed_drivers/timeout/timeout_tests.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class AttachUSTester: public TimeoutType {
7373
template<typename T>
7474
void test_single_call(void)
7575
{
76+
DeepSleepLock lock;
77+
7678
Semaphore sem(0, 1);
7779
T timeout;
7880

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

9092
timeout.detach();
93+
94+
lock.unlock();
9195
}
9296

9397
/** Template for tests: callback not called when cancelled
@@ -105,6 +109,8 @@ void test_single_call(void)
105109
template<typename T>
106110
void test_cancel(void)
107111
{
112+
DeepSleepLock lock;
113+
108114
Semaphore sem(0, 1);
109115
T timeout;
110116

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

117123
sem_slots = sem.wait(TEST_DELAY_MS + 1);
118124
TEST_ASSERT_EQUAL(0, sem_slots);
125+
126+
lock.unlock();
119127
}
120128

121129
/** Template for tests: callback override
@@ -137,6 +145,8 @@ void test_cancel(void)
137145
template<typename T>
138146
void test_override(void)
139147
{
148+
DeepSleepLock lock;
149+
140150
Semaphore sem1(0, 1);
141151
Semaphore sem2(0, 1);
142152
T timeout;
@@ -153,6 +163,8 @@ void test_override(void)
153163
TEST_ASSERT_EQUAL(0, sem_slots);
154164

155165
timeout.detach();
166+
167+
lock.unlock();
156168
}
157169

158170
/** Template for tests: multiple Timeouts
@@ -172,13 +184,17 @@ void test_override(void)
172184
template<typename T>
173185
void test_multiple(void)
174186
{
187+
DeepSleepLock lock;
188+
175189
volatile uint32_t callback_count = 0;
176190
T timeouts[NUM_TIMEOUTS];
177191
for (size_t i = 0; i < NUM_TIMEOUTS; i++) {
178192
timeouts[i].attach_callback(mbed::callback(cnt_callback, &callback_count), TEST_DELAY_US);
179193
}
180194
Thread::wait(TEST_DELAY_MS + 1);
181195
TEST_ASSERT_EQUAL(NUM_TIMEOUTS, callback_count);
196+
197+
lock.unlock();
182198
}
183199

184200
/** Template for tests: zero delay
@@ -196,13 +212,17 @@ void test_multiple(void)
196212
template<typename T>
197213
void test_no_wait(void)
198214
{
215+
DeepSleepLock lock;
216+
199217
Semaphore sem(0, 1);
200218
T timeout;
201219
timeout.attach_callback(mbed::callback(sem_callback, &sem), 0ULL);
202220

203221
int32_t sem_slots = sem.wait(0);
204222
TEST_ASSERT_EQUAL(1, sem_slots);
205223
timeout.detach();
224+
225+
lock.unlock();
206226
}
207227

208228
/** Template for tests: accuracy of timeout delay

TESTS/mbedmicro-rtos-mbed/rtostimer/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ void test_created_stopped()
254254
*/
255255
void test_stop()
256256
{
257+
DeepSleepLock lock;
258+
257259
Semaphore sem(0, 1);
258260
RtosTimer rtostimer(mbed::callback(sem_callback, &sem), osTimerOnce);
259261

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

272274
status = rtostimer.stop();
273275
TEST_ASSERT_EQUAL(osErrorResource, status);
276+
277+
lock.unlock();
274278
}
275279

276280
/** Test timer started with infinite delay

TESTS/mbedmicro-rtos-mbed/systimer/main.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#if !MBED_TICKLESS
16+
#ifndef MBED_TICKLESS
1717
#error [NOT_SUPPORTED] Tickless mode not supported for this target.
1818
#endif
1919

@@ -198,6 +198,8 @@ void test_get_time(void)
198198
*/
199199
void test_cancel_tick(void)
200200
{
201+
DeepSleepLock lock;
202+
201203
SysTimerTest st;
202204
st.cancel_tick();
203205
st.schedule_tick(TEST_TICKS);
@@ -206,6 +208,8 @@ void test_cancel_tick(void)
206208
int32_t sem_slots = st.sem_wait((DELAY_US + DELAY_DELTA_US) / 1000ULL);
207209
TEST_ASSERT_EQUAL_INT32(0, sem_slots);
208210
TEST_ASSERT_EQUAL_UINT32(0, st.get_tick());
211+
212+
lock.unlock();
209213
}
210214

211215
/** Test schedule zero
@@ -216,11 +220,15 @@ void test_cancel_tick(void)
216220
*/
217221
void test_schedule_zero(void)
218222
{
223+
DeepSleepLock lock;
224+
219225
SysTimerTest st;
220226

221227
st.schedule_tick(0UL);
222228
int32_t sem_slots = st.sem_wait(0UL);
223229
TEST_ASSERT_EQUAL_INT32(1, sem_slots);
230+
231+
lock.unlock();
224232
}
225233

226234
/** Test handler called once
@@ -234,6 +242,8 @@ void test_schedule_zero(void)
234242
*/
235243
void test_handler_called_once(void)
236244
{
245+
DeepSleepLock lock;
246+
237247
SysTimerTest st;
238248
st.schedule_tick(TEST_TICKS);
239249
us_timestamp_t t1 = st.get_time();
@@ -249,6 +259,8 @@ void test_handler_called_once(void)
249259
sem_slots = st.sem_wait((DELAY_US + DELAY_DELTA_US) / 1000ULL);
250260
TEST_ASSERT_EQUAL_INT32(0, sem_slots);
251261
TEST_ASSERT_EQUAL_UINT32(1, st.get_tick());
262+
263+
lock.unlock();
252264
}
253265

254266
#if DEVICE_SLEEP

0 commit comments

Comments
 (0)