You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
54 lines
1.5 KiB
#include "u_async.h" |
|
#include <stdio.h> |
|
#include "../lib/debug_config.h" |
|
|
|
/* Test statistics */ |
|
static struct { |
|
int tests_run; |
|
int tests_passed; |
|
int tests_failed; |
|
|
|
/* Timer statistics */ |
|
int timer_callbacks; |
|
int timer_cancellations; |
|
int immediate_timeouts; |
|
|
|
/* Socket statistics */ |
|
int socket_events; |
|
int socket_errors; |
|
|
|
/* Error statistics */ |
|
int memory_allocation_errors; |
|
int invalid_parameter_errors; |
|
int race_condition_errors; |
|
} test_stats = {0}; |
|
|
|
/* Timer callback for testing */ |
|
static void test_timer_callback(void* arg) { |
|
test_stats.timer_callbacks++; |
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Timer callback fired. Total callbacks: %d", test_stats.timer_callbacks); |
|
} |
|
|
|
int main() { |
|
debug_config_init(); |
|
debug_set_level(DEBUG_LEVEL_TRACE); |
|
debug_set_categories(DEBUG_CATEGORY_ALL); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Before any tests: immediate_timeouts = %d", test_stats.immediate_timeouts); |
|
|
|
uasync_t* ua = uasync_create(); |
|
|
|
/* Set 5 immediate timeouts */ |
|
for (int i = 0; i < 5; i++) { |
|
void* timer = uasync_set_timeout(ua, 0, NULL, test_timer_callback); |
|
} |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After setting 5 immediate timeouts, before poll: immediate_timeouts = %d", test_stats.immediate_timeouts); |
|
|
|
uasync_poll(ua, 1); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After poll: immediate_timeouts = %d", test_stats.immediate_timeouts); |
|
|
|
uasync_destroy(ua, 0); |
|
return 0; |
|
}
|
|
|