@@ -101,7 +101,7 @@ void single_thread(struct test_data *data)
101
101
/* * Test single thread
102
102
103
103
Given a two threads A & B and a semaphore (with count of 0) and a counter (equals to 0)
104
- when thread B calls @a wait
104
+ when thread B calls @a acquire
105
105
then thread B waits for a token to become available
106
106
then the counter is equal to 0
107
107
when thread A calls @a release on the semaphore
@@ -144,8 +144,8 @@ void timeout_thread(Semaphore *sem)
144
144
/* * Test timeout
145
145
146
146
Given thread and a semaphore with no tokens available
147
- when thread calls @a wait on the semaphore with timeout of 10ms
148
- then the thread waits for 10ms and timeouts after
147
+ when a thread calls @a try_acquire_for with a timeout of 30ms
148
+ then the thread is blocked for up to 30ms and timeouts after.
149
149
*/
150
150
void test_timeout ()
151
151
{
@@ -177,8 +177,10 @@ void test_ticker_release(struct test_data *data)
177
177
/* * Test semaphore acquire
178
178
179
179
Given a semaphore with no tokens available and ticker with the callback registered
180
- when callbacks update the test data and release semaphore
181
- which will unblock the main thread which is blocked on semaphore acquire.
180
+ when the main thread calls @a acquire
181
+ then the main thread is blocked
182
+ when callback calls @a release on the semaphore
183
+ then the main thread is unblocked
182
184
*/
183
185
void test_semaphore_acquire ()
184
186
{
@@ -205,29 +207,29 @@ void test_ticker_try_acquire(Semaphore *sem)
205
207
/* * Test semaphore try acquire
206
208
207
209
Given a semaphore with no tokens available and ticker with the callback registered
208
- when callbacks try to acquire the semaphore will fail .
210
+ when callback tries to acquire the semaphore, it fails .
209
211
*/
210
212
void test_semaphore_try_acquire ()
211
213
{
212
214
Semaphore sem (0 );
213
215
Ticker t1;
214
216
t1.attach_us (callback (test_ticker_try_acquire, &sem), 3000 );
215
- ThisThread::sleep_for (3 );
217
+ ThisThread::sleep_for (4 );
216
218
t1.detach ();
217
219
}
218
220
219
221
220
222
/* * Test semaphore try timeout
221
223
222
224
Given a semaphore with no tokens available
223
- when the main thread calls @a wait on the semaphore with try timeout of 5ms
224
- then the main thread waits for 5ms and timeouts after
225
+ when the main thread calls @a try_acquire_for with 3ms timeout
226
+ then the main thread is blocked for 3ms and timeouts after
225
227
*/
226
228
void test_semaphore_try_timeout ()
227
229
{
228
230
Semaphore sem (0 );
229
231
bool res;
230
- res = sem.try_acquire_for (5 );
232
+ res = sem.try_acquire_for (3 );
231
233
TEST_ASSERT_FALSE (res);
232
234
}
233
235
@@ -242,16 +244,18 @@ void test_ticker_semaphore_release(struct Semaphore *sem)
242
244
/* * Test semaphore try acquire timeout
243
245
244
246
Given a semaphore with no tokens available and ticker with the callback registered
245
- when callbacks release the semaphore will unblock the main thread
246
- which is waiting for semaphore with a timeout.
247
+ when the main thread calls @a try_acquire_for with 10ms timeout
248
+ then the main thread is blocked for up to 10ms
249
+ when callback call @a release on the semaphore after 3ms
250
+ then the main thread is unblocked.
247
251
*/
248
252
void test_semaphore_try_acquire_timeout ()
249
253
{
250
254
Semaphore sem (0 );
251
255
bool res;
252
256
Ticker t1;
253
257
t1.attach_us (callback (test_ticker_semaphore_release, &sem), 3000 );
254
- res = sem.try_acquire_for (30 );
258
+ res = sem.try_acquire_for (10 );
255
259
t1.detach ();
256
260
TEST_ASSERT_TRUE (res);
257
261
}
@@ -260,12 +264,12 @@ void test_semaphore_try_acquire_timeout()
260
264
261
265
Test 1 token no timeout
262
266
Given thread and a semaphore with one token available
263
- when thread calls @a wait on the semaphore with timeout of 0ms
267
+ when thread calls @a try_acquire with timeout of 0ms
264
268
then the thread acquires the token immediately
265
269
266
270
Test 0 tokens no timeout
267
271
Given thread and a semaphore with no tokens available
268
- when thread calls @a wait on the semaphore with timeout of 0ms
272
+ when thread calls @a try_acquire with timeout of 0ms
269
273
then the thread returns immediately without acquiring a token
270
274
*/
271
275
template <int T>
@@ -285,7 +289,7 @@ void test_no_timeout()
285
289
/* * Test multiple tokens wait
286
290
287
291
Given a thread and a semaphore initialized with 5 tokens
288
- when thread calls @a wait 6 times on the semaphore
292
+ when thread calls @a try_acquire 6 times in a loop
289
293
then the token counts goes to zero
290
294
*/
291
295
void test_multiple_tokens_wait ()
0 commit comments