Skip to content

Commit c3473e4

Browse files
committed
Fix events-queue failure on low CPU frequency
1 parent 9ddcdcd commit c3473e4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

TESTS/events/queue/main.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ using namespace utest::v1;
3434
// (for more details about EVENTS_EVENT_SIZE see EventQueue constructor)
3535
#define TEST_EQUEUE_SIZE (18*EVENTS_EVENT_SIZE)
3636

37+
// By empirical, we take 80MHz CPU/2ms delay as base tolerance for time left test.
38+
// For higher CPU frequency, tolerance is fixed to 2ms.
39+
// For lower CPU frequency, tolerance is inversely proportional to CPU frequency.
40+
// E.g.:
41+
// 100MHz: 2ms
42+
// 80MHz: 2ms
43+
// 64MHz: 3ms
44+
// 48MHz: 4ms
45+
#define ALLOWED_TIME_LEFT_TOLERANCE_MS ((SystemCoreClock >= 80000000) ? 2 : ((80000000 * 2 + SystemCoreClock - 1) / SystemCoreClock))
46+
3747
// flag for called
3848
volatile bool touched = false;
3949

@@ -283,7 +293,7 @@ int timeleft_events[2];
283293
void check_time_left(EventQueue *queue, int index, int expected)
284294
{
285295
const int event_id = timeleft_events[index];
286-
TEST_ASSERT_INT_WITHIN(2, expected, queue->time_left(event_id));
296+
TEST_ASSERT_INT_WITHIN(ALLOWED_TIME_LEFT_TOLERANCE_MS, expected, queue->time_left(event_id));
287297
touched = true;
288298
}
289299

0 commit comments

Comments
 (0)