Skip to content

Commit a24419b

Browse files
committed
Incorporated the review comments
1 parent 8bc7ffe commit a24419b

File tree

1 file changed

+20
-16
lines changed
  • TESTS/mbedmicro-rtos-mbed/semaphore

1 file changed

+20
-16
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void single_thread(struct test_data *data)
101101
/** Test single thread
102102
103103
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
105105
then thread B waits for a token to become available
106106
then the counter is equal to 0
107107
when thread A calls @a release on the semaphore
@@ -144,8 +144,8 @@ void timeout_thread(Semaphore *sem)
144144
/** Test timeout
145145
146146
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.
149149
*/
150150
void test_timeout()
151151
{
@@ -177,8 +177,10 @@ void test_ticker_release(struct test_data *data)
177177
/** Test semaphore acquire
178178
179179
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
182184
*/
183185
void test_semaphore_acquire()
184186
{
@@ -205,29 +207,29 @@ void test_ticker_try_acquire(Semaphore *sem)
205207
/** Test semaphore try acquire
206208
207209
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.
209211
*/
210212
void test_semaphore_try_acquire()
211213
{
212214
Semaphore sem(0);
213215
Ticker t1;
214216
t1.attach_us(callback(test_ticker_try_acquire, &sem), 3000);
215-
ThisThread::sleep_for(3);
217+
ThisThread::sleep_for(4);
216218
t1.detach();
217219
}
218220

219221

220222
/** Test semaphore try timeout
221223
222224
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
225227
*/
226228
void test_semaphore_try_timeout()
227229
{
228230
Semaphore sem(0);
229231
bool res;
230-
res = sem.try_acquire_for(5);
232+
res = sem.try_acquire_for(3);
231233
TEST_ASSERT_FALSE(res);
232234
}
233235

@@ -242,16 +244,18 @@ void test_ticker_semaphore_release(struct Semaphore *sem)
242244
/** Test semaphore try acquire timeout
243245
244246
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.
247251
*/
248252
void test_semaphore_try_acquire_timeout()
249253
{
250254
Semaphore sem(0);
251255
bool res;
252256
Ticker t1;
253257
t1.attach_us(callback(test_ticker_semaphore_release, &sem), 3000);
254-
res = sem.try_acquire_for(30);
258+
res = sem.try_acquire_for(10);
255259
t1.detach();
256260
TEST_ASSERT_TRUE(res);
257261
}
@@ -260,12 +264,12 @@ void test_semaphore_try_acquire_timeout()
260264
261265
Test 1 token no timeout
262266
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
264268
then the thread acquires the token immediately
265269
266270
Test 0 tokens no timeout
267271
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
269273
then the thread returns immediately without acquiring a token
270274
*/
271275
template<int T>
@@ -285,7 +289,7 @@ void test_no_timeout()
285289
/** Test multiple tokens wait
286290
287291
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
289293
then the token counts goes to zero
290294
*/
291295
void test_multiple_tokens_wait()

0 commit comments

Comments
 (0)