Backup before replacing all printf with DEBUG_ macros in tests

This commit is contained in:
Evgeny committed 2026-01-26 17:52:50 +03:00
1 parent 1bafe6a681
commit 3ddfb79338
67 files changed
+4486 -8676

No files matched your search

+35 -40
View File
@@ -1,5 +1,4 @@
#include "../lib/u_async.h"
#include "../lib/debug_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -7,46 +6,42 @@
#include <fcntl.h>
static void test_callback(int fd, void* arg) {
(void)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_ALL, "=== 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_ALL, "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_ALL, "After add: timers %zu/%zu, sockets %zu/%zu", alloc1, free1, alloc2, free2);
uasync_remove_socket(ua, id1);
DEBUG_INFO(DEBUG_CATEGORY_ALL, "Removed socket %d", sock1);
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
DEBUG_INFO(DEBUG_CATEGORY_ALL, "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_ALL, "Tried to add invalid socket %d: id=%p", sock2, id2);
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
DEBUG_ERROR(DEBUG_CATEGORY_ALL, "After failed add: timers %zu/%zu, sockets %zu/%zu", alloc1, free1, alloc2, free2);
uasync_destroy(ua, 0);
DEBUG_INFO(DEBUG_CATEGORY_ALL, "Destroyed uasync");
return 0;
uasync_t* ua = uasync_create();
if (!ua) return 1;
printf("=== Debug Performance Test ===\n");
// 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);
printf("Added socket %d: id=%p\n", sock1, id1);
size_t alloc1, free1, alloc2, free2;
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
printf("After add: timers %zu/%zu, sockets %zu/%zu\n", alloc1, free1, alloc2, free2);
uasync_remove_socket(ua, id1);
printf("Removed socket %d\n", sock1);
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
printf("After remove: timers %zu/%zu, sockets %zu/%zu\n", 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);
printf("Tried to add invalid socket %d: id=%p\n", sock2, id2);
uasync_get_stats(ua, &alloc1, &free1, &alloc2, &free2);
printf("After failed add: timers %zu/%zu, sockets %zu/%zu\n", alloc1, free1, alloc2, free2);
uasync_destroy(ua, 0);
printf("Destroyed uasync\n");
return 0;
}