@@ -135,7 +135,8 @@ static void test_thread_pend_and_timeout(void *p1, void *p2, void *p3)
135
135
static int test_multiple_threads_pending (struct timeout_order_data * test_data ,
136
136
int test_data_size )
137
137
{
138
- int ii ;
138
+ int ii , j ;
139
+ u32_t diff_ms ;
139
140
140
141
for (ii = 0 ; ii < test_data_size ; ii ++ ) {
141
142
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,
144
145
FIFO_THREAD_PRIO , K_INHERIT_PERMS , 0 );
145
146
}
146
147
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
+ */
147
156
for (ii = 0 ; ii < test_data_size ; ii ++ ) {
148
157
struct timeout_order_data * data =
149
158
k_fifo_get (& timeout_order_fifo , K_FOREVER );
@@ -152,9 +161,31 @@ static int test_multiple_threads_pending(struct timeout_order_data *test_data,
152
161
TC_PRINT (" thread (q order: %d, t/o: %d, fifo %p)\n" ,
153
162
data -> q_order , data -> timeout , data -> fifo );
154
163
} 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
+ }
158
189
}
159
190
}
160
191
0 commit comments