|
|
|
@ -147,9 +147,9 @@ static void test_basic_timers(void) { |
|
|
|
ctx.expected_count = 3; |
|
|
|
ctx.expected_count = 3; |
|
|
|
|
|
|
|
|
|
|
|
/* Set multiple timers with different timeouts */ |
|
|
|
/* Set multiple timers with different timeouts */ |
|
|
|
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback); /* 1ms */ |
|
|
|
void* timer1 = uasync_set_timeout(ua, 10, &ctx, test_timer_callback, "test_t1"); /* 1ms */ |
|
|
|
void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback); /* 2ms */ |
|
|
|
void* timer2 = uasync_set_timeout(ua, 20, &ctx, test_timer_callback, "test_t2"); /* 2ms */ |
|
|
|
void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback); /* 3ms */ |
|
|
|
void* timer3 = uasync_set_timeout(ua, 30, &ctx, test_timer_callback, "test_t3"); /* 3ms */ |
|
|
|
|
|
|
|
|
|
|
|
ASSERT_NOT_NULL(timer1, "Failed to set timer 1"); |
|
|
|
ASSERT_NOT_NULL(timer1, "Failed to set timer 1"); |
|
|
|
ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); |
|
|
|
ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); |
|
|
|
@ -181,9 +181,9 @@ static void test_timer_cancellation_races(void) { |
|
|
|
ctx.expected_count = 2; |
|
|
|
ctx.expected_count = 2; |
|
|
|
|
|
|
|
|
|
|
|
/* Create timers that will be cancelled at different stages */ |
|
|
|
/* Create timers that will be cancelled at different stages */ |
|
|
|
void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback); /* 0.5ms */ |
|
|
|
void* timer1 = uasync_set_timeout(ua, 5, &ctx, test_timer_callback, "test_t1"); /* 0.5ms */ |
|
|
|
void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback); /* 5ms */ |
|
|
|
void* timer2 = uasync_set_timeout(ua, 50, &ctx, test_timer_callback, "test_t2"); /* 5ms */ |
|
|
|
void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback); /* 10ms */ |
|
|
|
void* timer3 = uasync_set_timeout(ua, 100, &ctx, test_timer_callback, "test_t3"); /* 10ms */ |
|
|
|
|
|
|
|
|
|
|
|
ASSERT_NOT_NULL(timer1, "Failed to set timer 1"); |
|
|
|
ASSERT_NOT_NULL(timer1, "Failed to set timer 1"); |
|
|
|
ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); |
|
|
|
ASSERT_NOT_NULL(timer2, "Failed to set timer 2"); |
|
|
|
@ -238,7 +238,7 @@ static void test_immediate_timeouts(void) { |
|
|
|
|
|
|
|
|
|
|
|
/* Set multiple immediate timeouts (0ms) */ |
|
|
|
/* Set multiple immediate timeouts (0ms) */ |
|
|
|
for (int i = 0; i < 5; i++) { |
|
|
|
for (int i = 0; i < 5; i++) { |
|
|
|
void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback); |
|
|
|
void* timer = uasync_set_timeout(ua, 0, &ctx, test_timer_callback, "test_imm"); |
|
|
|
ASSERT_NOT_NULL(timer, "Failed to set immediate timer"); |
|
|
|
ASSERT_NOT_NULL(timer, "Failed to set immediate timer"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -272,7 +272,7 @@ static void test_memory_leak_detection(void) { |
|
|
|
for (int i = 0; i < 10; i++) { |
|
|
|
for (int i = 0; i < 10; i++) { |
|
|
|
test_context_t timer_ctx = {0}; |
|
|
|
test_context_t timer_ctx = {0}; |
|
|
|
timer_ctx.timeout_ms = 100; // Set proper timeout to avoid immediate timeout
|
|
|
|
timer_ctx.timeout_ms = 100; // Set proper timeout to avoid immediate timeout
|
|
|
|
void* timer = uasync_set_timeout(ua, 100, &timer_ctx, test_timer_callback); |
|
|
|
void* timer = uasync_set_timeout(ua, 100, &timer_ctx, test_timer_callback, "test_cancel"); |
|
|
|
ASSERT_NOT_NULL(timer, "Failed to set timer"); |
|
|
|
ASSERT_NOT_NULL(timer, "Failed to set timer"); |
|
|
|
|
|
|
|
|
|
|
|
/* Cancel some, leave others to timeout */ |
|
|
|
/* Cancel some, leave others to timeout */ |
|
|
|
@ -350,7 +350,7 @@ static void test_error_handling(void) { |
|
|
|
ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); |
|
|
|
ASSERT_NOT_NULL(ua, "Failed to create uasync instance"); |
|
|
|
|
|
|
|
|
|
|
|
/* Test invalid parameters */ |
|
|
|
/* Test invalid parameters */ |
|
|
|
void* null_timer = uasync_set_timeout(NULL, 10, NULL, NULL); |
|
|
|
void* null_timer = uasync_set_timeout(NULL, 10, NULL, NULL, "test_null"); |
|
|
|
ASSERT_NULL(null_timer, "Should fail with NULL uasync"); |
|
|
|
ASSERT_NULL(null_timer, "Should fail with NULL uasync"); |
|
|
|
|
|
|
|
|
|
|
|
err_t cancel_result = uasync_cancel_timeout(NULL, NULL); |
|
|
|
err_t cancel_result = uasync_cancel_timeout(NULL, NULL); |
|
|
|
@ -364,7 +364,7 @@ static void test_error_handling(void) { |
|
|
|
test_context_t ctx = {0}; |
|
|
|
test_context_t ctx = {0}; |
|
|
|
ctx.callback_arg = -1; /* Error injection flag */ |
|
|
|
ctx.callback_arg = -1; /* Error injection flag */ |
|
|
|
|
|
|
|
|
|
|
|
void* error_timer = uasync_set_timeout(ua, 5, &ctx, test_error_callback); |
|
|
|
void* error_timer = uasync_set_timeout(ua, 5, &ctx, test_error_callback, "test_err"); |
|
|
|
ASSERT_NOT_NULL(error_timer, "Failed to set error timer"); |
|
|
|
ASSERT_NOT_NULL(error_timer, "Failed to set error timer"); |
|
|
|
|
|
|
|
|
|
|
|
uasync_poll(ua, 10); |
|
|
|
uasync_poll(ua, 10); |
|
|
|
@ -434,7 +434,7 @@ static void test_concurrent_operations(void) { |
|
|
|
individual_ctx->timeout_ms = (i + 1) * 5; // Different timeouts: 5, 10, 15, ..., 50ms
|
|
|
|
individual_ctx->timeout_ms = (i + 1) * 5; // Different timeouts: 5, 10, 15, ..., 50ms
|
|
|
|
individual_ctx->callback_arg = 0; |
|
|
|
individual_ctx->callback_arg = 0; |
|
|
|
|
|
|
|
|
|
|
|
timers[i] = uasync_set_timeout(ua, (i + 1) * 5, individual_ctx, test_timer_callback); |
|
|
|
timers[i] = uasync_set_timeout(ua, (i + 1) * 5, individual_ctx, test_timer_callback, "test_stress"); |
|
|
|
ASSERT_NOT_NULL(timers[i], "Failed to set timer"); |
|
|
|
ASSERT_NOT_NULL(timers[i], "Failed to set timer"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|