Skip to content

tests/kernel: fifo_timeout: Remove wake-up order checking #10047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions tests/kernel/fifo/fifo_timeout/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ static void test_thread_pend_and_timeout(void *p1, void *p2, void *p3)
static int test_multiple_threads_pending(struct timeout_order_data *test_data,
int test_data_size)
{
int ii;
int ii, j;
u32_t diff_ms;

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

/* In general, there is no guarantee of wakeup order when multiple
* threads are woken up on the same tick. This can especially happen
* when the system is loaded. However, in this particular test, we
* are controlling the system state and hence we can make a reasonable
* estimation of a timeout occurring with the max deviation of an
* additional tick. Hence the timeout order may slightly be different
* from what we normally expect.
*/
for (ii = 0; ii < test_data_size; ii++) {
struct timeout_order_data *data =
k_fifo_get(&timeout_order_fifo, K_FOREVER);
Expand All @@ -152,9 +161,31 @@ static int test_multiple_threads_pending(struct timeout_order_data *test_data,
TC_PRINT(" thread (q order: %d, t/o: %d, fifo %p)\n",
data->q_order, data->timeout, data->fifo);
} else {
TC_ERROR(" *** thread %d woke up, expected %d\n",
data->timeout_order, ii);
return TC_FAIL;
/* Get the index of the thread which should have
* actually timed out.
*/
for (j = 0; j < test_data_size; j++) {
if (test_data[j].timeout_order == ii) {
break;
}
}

if (data->timeout > test_data[j].timeout) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this check is not the one we want.
Whit this code, kernel might wake-up thread earlier than expected and the test will not notice that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is already taken care in "is_timeout_in_range()" function. That function checks for the lower limit while the new code above checks for the upper limit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

diff_ms = data->timeout - test_data[j].timeout;
} else {
diff_ms = test_data[j].timeout - data->timeout;
}

if (_ms_to_ticks(diff_ms) == 1) {
TC_PRINT(
" thread (q order: %d, t/o: %d, fifo %p)\n",
data->q_order, data->timeout, data->fifo);
} else {
TC_ERROR(
" *** thread %d woke up, expected %d\n",
data->timeout_order, ii);
return TC_FAIL;
}
}
}

Expand Down