Skip to content

Commit 1733655

Browse files
committed
tests/kernel: fifo_timeout: Remove wake-up order checking
There is no guarantee of wake-up order when multiple threads are woken up on the same tick. Hence, modified the tests accordingly. Fixes #8159. Signed-off-by: Rajavardhan Gundi <[email protected]>
1 parent 4dfd311 commit 1733655

File tree

1 file changed

+35
-4
lines changed
  • tests/kernel/fifo/fifo_timeout/src

1 file changed

+35
-4
lines changed

tests/kernel/fifo/fifo_timeout/src/main.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ static void test_thread_pend_and_timeout(void *p1, void *p2, void *p3)
135135
static int test_multiple_threads_pending(struct timeout_order_data *test_data,
136136
int test_data_size)
137137
{
138-
int ii;
138+
int ii, j;
139+
u32_t diff_ms;
139140

140141
for (ii = 0; ii < test_data_size; ii++) {
141142
tid[ii] = k_thread_create(&ttdata[ii], ttstack[ii], TSTACK_SIZE,
@@ -144,6 +145,14 @@ static int test_multiple_threads_pending(struct timeout_order_data *test_data,
144145
FIFO_THREAD_PRIO, K_INHERIT_PERMS, 0);
145146
}
146147

148+
/* In general, there is no guarantee of wakeup order when multiple
149+
* threads are woken up on the same tick. This can especially happen
150+
* when the system is loaded. However, in this particular test, we
151+
* are controlling the system state and hence we can make a reasonable
152+
* estimation of a timeout occurring with the max deviation of an
153+
* additional tick. Hence the timeout order may slightly be different
154+
* from what we normally expect.
155+
*/
147156
for (ii = 0; ii < test_data_size; ii++) {
148157
struct timeout_order_data *data =
149158
k_fifo_get(&timeout_order_fifo, K_FOREVER);
@@ -152,9 +161,31 @@ static int test_multiple_threads_pending(struct timeout_order_data *test_data,
152161
TC_PRINT(" thread (q order: %d, t/o: %d, fifo %p)\n",
153162
data->q_order, data->timeout, data->fifo);
154163
} else {
155-
TC_ERROR(" *** thread %d woke up, expected %d\n",
156-
data->timeout_order, ii);
157-
return TC_FAIL;
164+
/* Get the index of the thread which should have
165+
* actually timed out.
166+
*/
167+
for (j = 0; j < test_data_size; j++) {
168+
if (test_data[j].timeout_order == ii) {
169+
break;
170+
}
171+
}
172+
173+
if (data->timeout > test_data[j].timeout) {
174+
diff_ms = data->timeout - test_data[j].timeout;
175+
} else {
176+
diff_ms = test_data[j].timeout - data->timeout;
177+
}
178+
179+
if (_ms_to_ticks(diff_ms) == 1) {
180+
TC_PRINT(
181+
" thread (q order: %d, t/o: %d, fifo %p)\n",
182+
data->q_order, data->timeout, data->fifo);
183+
} else {
184+
TC_ERROR(
185+
" *** thread %d woke up, expected %d\n",
186+
data->timeout_order, ii);
187+
return TC_FAIL;
188+
}
158189
}
159190
}
160191

0 commit comments

Comments
 (0)