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.
53 lines
1.8 KiB
53 lines
1.8 KiB
#include "../lib/u_async.h" |
|
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include "../lib/platform_compat.h" |
|
|
|
|
|
#include "../lib/u_async.h" |
|
#include "../lib/debug_config.h" |
|
|
|
static void test_callback(int fd, void* arg) { |
|
(void)fd; (void)arg; |
|
} |
|
|
|
int main() { |
|
debug_config_init(); |
|
debug_set_level(DEBUG_LEVEL_TRACE); |
|
debug_set_categories(DEBUG_CATEGORY_ALL); |
|
|
|
uasync_t* ua = uasync_create(); |
|
if (!ua) return 1; |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "=== Debug Performance Test ==="); |
|
|
|
// Test 1: Normal add/remove |
|
int sock1 = socket(AF_INET, SOCK_DGRAM, 0); |
|
void* id1 = uasync_add_socket(ua, sock1, test_callback, NULL, NULL, NULL); |
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Added socket %d: id=%p", sock1, id1); |
|
|
|
size_t alloc1, free1, alloc2, free2; |
|
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2); |
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After add: timers %zu/%zu, sockets %zu/%zu", alloc1, free1, alloc2, free2); |
|
|
|
uasync_remove_socket(ua, id1); |
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Removed socket %d", sock1); |
|
|
|
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2); |
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After remove: timers %zu/%zu, sockets %zu/%zu", alloc1, free1, alloc2, free2); |
|
|
|
close(sock1); |
|
|
|
// Test 2: Failed add |
|
int sock2 = 9999; // Invalid socket |
|
void* id2 = uasync_add_socket(ua, sock2, test_callback, NULL, NULL, NULL); |
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Tried to add invalid socket %d: id=%p", sock2, id2); |
|
|
|
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2); |
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "After failed add: timers %zu/%zu, sockets %zu/%zu", alloc1, free1, alloc2, free2); |
|
|
|
uasync_destroy(ua, 0); |
|
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Destroyed uasync"); |
|
|
|
return 0; |
|
}
|
|
|