mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2025-08-09 04:22:44 +03:00
Add some tests (#1978)
* Test for best_effort_wfe_or_timeout sev issue best_effort_wfe_or_timeout should not ignore an outstanding sev See https://github.com/raspberrypi/pico-sdk/issues/1812 * Test for alarm being set in the past issue See https://github.com/raspberrypi/pico-sdk/issues/1953
This commit is contained in:
@@ -72,6 +72,8 @@ static bool repeating_timer_callback(struct repeating_timer *t) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int issue_195_test(void);
|
int issue_195_test(void);
|
||||||
|
int issue_1812_test(void);
|
||||||
|
int issue_1953_test(void);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
setup_default_uart();
|
setup_default_uart();
|
||||||
@@ -192,13 +194,19 @@ int main() {
|
|||||||
|
|
||||||
PICOTEST_END_SECTION();
|
PICOTEST_END_SECTION();
|
||||||
|
|
||||||
|
|
||||||
PICOTEST_START_SECTION("Repeating timertest");
|
PICOTEST_START_SECTION("Repeating timertest");
|
||||||
for(uint i=0;i<NUM_REPEATING_TIMERS;i++) {
|
for(uint i=0;i<NUM_REPEATING_TIMERS;i++) {
|
||||||
|
|
||||||
add_repeating_timer_us(500+ (rand() & 1023), repeating_timer_callback, (void *)(uintptr_t)i, repeating_timers + i);
|
add_repeating_timer_us(500+ (rand() & 1023), repeating_timer_callback, (void *)(uintptr_t)i, repeating_timers + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep_ms(3000);
|
// issue #1953 will lockup here if sleep_us >= 6us (PICO_TIME_SLEEP_OVERHEAD_ADJUST_US)
|
||||||
|
absolute_time_t timeout = make_timeout_time_ms(3000);
|
||||||
|
while(absolute_time_diff_us(get_absolute_time(), timeout) > 0) {
|
||||||
|
sleep_us(5);
|
||||||
|
}
|
||||||
|
|
||||||
uint callbacks = 0;
|
uint callbacks = 0;
|
||||||
for(uint i=0;i<NUM_REPEATING_TIMERS;i++) {
|
for(uint i=0;i<NUM_REPEATING_TIMERS;i++) {
|
||||||
PICOTEST_CHECK(cancel_repeating_timer(repeating_timers + i), "Cancelling repeating timer should succeed");
|
PICOTEST_CHECK(cancel_repeating_timer(repeating_timers + i), "Cancelling repeating timer should succeed");
|
||||||
@@ -226,6 +234,17 @@ int main() {
|
|||||||
if (issue_195_test()) {
|
if (issue_195_test()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
issue_1812_test();
|
||||||
|
|
||||||
|
// Destroy alarm pools (except for default)
|
||||||
|
for(uint i=0; i<NUM_ALARMS; i++) {
|
||||||
|
if (i != alarm_pool_timer_alarm_num(alarm_pool_get_default())) {
|
||||||
|
alarm_pool_destroy(pools[i]);
|
||||||
|
pools[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1953_test();
|
||||||
|
|
||||||
PICOTEST_END_TEST();
|
PICOTEST_END_TEST();
|
||||||
}
|
}
|
||||||
@@ -255,3 +274,54 @@ int issue_195_test(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setting an alarm should not swallow a sev
|
||||||
|
int issue_1812_test(void) {
|
||||||
|
PICOTEST_START_SECTION("Issue #1812 defect - Setting an alarm should not ignore a sev");
|
||||||
|
|
||||||
|
__sev(); // Make sure the call below does not ignore this
|
||||||
|
absolute_time_t before = get_absolute_time();
|
||||||
|
bool result = best_effort_wfe_or_timeout(make_timeout_time_ms(1000));
|
||||||
|
int64_t diff = absolute_time_diff_us(before, get_absolute_time());
|
||||||
|
PICOTEST_CHECK(diff < 250 && !result, "sev ignored by best_effort_wfe_or_timeout")
|
||||||
|
|
||||||
|
PICOTEST_END_SECTION();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool timer_callback_issue_1953(repeating_timer_t *rt) {
|
||||||
|
static int counter;
|
||||||
|
counter++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Callback should only occur if the alarm is set in the past
|
||||||
|
static void alarm_pool_stuck_issue_1953(uint alarm) {
|
||||||
|
hard_assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int issue_1953_test(void) {
|
||||||
|
PICOTEST_START_SECTION("Issue #1953 defect - Alarm can be set in the past");
|
||||||
|
int alarm = hardware_alarm_claim_unused(true);
|
||||||
|
hardware_alarm_set_callback(alarm, alarm_pool_stuck_issue_1953);
|
||||||
|
|
||||||
|
repeating_timer_t timer1;
|
||||||
|
repeating_timer_t timer2;
|
||||||
|
|
||||||
|
assert(add_repeating_timer_us(10, timer_callback_issue_1953, NULL, &timer1));
|
||||||
|
assert(add_repeating_timer_us(100, timer_callback_issue_1953, NULL, &timer2));
|
||||||
|
|
||||||
|
int iterations = 0;
|
||||||
|
while(iterations < 100) {
|
||||||
|
iterations++;
|
||||||
|
hardware_alarm_set_target(alarm, make_timeout_time_ms(1000));
|
||||||
|
sleep_us(500); // lockup in here without the fix for #1953
|
||||||
|
hardware_alarm_cancel(alarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel_repeating_timer(&timer1);
|
||||||
|
cancel_repeating_timer(&timer2);
|
||||||
|
|
||||||
|
hardware_alarm_unclaim(alarm);
|
||||||
|
PICOTEST_END_SECTION();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user