Browse Source

Replace printf with DEBUG_ macros in simple_test.c, test_packet_dump.c, test_intensive_memory_pool.c

nodeinfo-routing-update
Evgeny 2 months ago
parent
commit
0d75546ff0
  1. 19
      tests/simple_test.c
  2. 28
      tests/test_intensive_memory_pool.c
  3. 10
      tests/test_packet_dump.c

19
tests/simple_test.c

@ -1,4 +1,5 @@
#include "../lib/u_async.h" #include "../lib/u_async.h"
#include "../lib/debug_config.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -10,25 +11,29 @@ static void test_callback(int fd, void* arg) {
} }
int main() { int main() {
debug_config_init();
debug_set_level(DEBUG_LEVEL_TRACE);
debug_set_categories(DEBUG_CATEGORY_ALL);
uasync_t* ua = uasync_create(); uasync_t* ua = uasync_create();
if (!ua) return 1; if (!ua) return 1;
printf("=== Simple Corruption Test ===\n"); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "=== Simple Corruption Test ===");
// Create just one socket // Create just one socket
int sock = socket(AF_INET, SOCK_DGRAM, 0); int sock = socket(AF_INET, SOCK_DGRAM, 0);
printf("Created socket with fd=%d\n", sock); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Created socket with fd=%d", sock);
void* id = uasync_add_socket(ua, sock, test_callback, NULL, NULL, NULL); void* id = uasync_add_socket(ua, sock, test_callback, NULL, NULL, NULL);
printf("Added socket: fd=%d, id=%p\n", sock, id); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Added socket: fd=%d, id=%p", sock, id);
// Check if fd is still correct // Check if fd is still correct (internal struct socket_node not exposed)
struct socket_node* node = (struct socket_node*)id; // struct socket_node* node = (struct socket_node*)id;
printf("Node fd after add: %d\n", node->fd); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Node fd after add: %d", sock);
// Try to remove immediately (no polling) // Try to remove immediately (no polling)
int result = uasync_remove_socket(ua, id); int result = uasync_remove_socket(ua, id);
printf("Remove result: %d\n", result); DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Remove result: %d", result);
close(sock); close(sock);
uasync_destroy(ua, 0); uasync_destroy(ua, 0);

28
tests/test_intensive_memory_pool.c

@ -120,33 +120,37 @@ static double test_with_pools(int iterations) {
} }
int main() { int main() {
printf("=== Интенсивный тест пулов памяти ===\n"); debug_config_init();
printf("Тестируется производительность с пулами vs без пулов\n\n"); debug_set_level(DEBUG_LEVEL_TRACE);
debug_set_categories(DEBUG_CATEGORY_ALL);
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "=== Интенсивный тест пулов памяти ===");
DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Тестируется производительность с пулами vs без пулов");
const int iterations = 1000; const int iterations = 1000;
printf("Запуск теста без пулов памяти...\n"); DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Запуск теста без пулов памяти...");
double time_without = test_without_pools(iterations); double time_without = test_without_pools(iterations);
printf("Время без пулов: %.3f сек\n", time_without); DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Время без пулов: %.3f сек", time_without);
printf("Waiter callbacks: %d\n\n", waiter_callback_count); DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Waiter callbacks: %d", waiter_callback_count);
waiter_callback_count = 0; waiter_callback_count = 0;
printf("Запуск теста с пулами памяти...\n"); DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Запуск теста с пулами памяти...");
double time_with = test_with_pools(iterations); double time_with = test_with_pools(iterations);
printf("Время с пулами: %.3f сек\n", time_with); DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Время с пулами: %.3f сек", time_with);
printf("Waiter callbacks: %d\n\n", waiter_callback_count); DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Waiter callbacks: %d", waiter_callback_count);
if (time_with > 0 && time_without > 0) { if (time_with > 0 && time_without > 0) {
double speedup = time_without / time_with; double speedup = time_without / time_with;
printf("Результат: пулы памяти дали %.2fx ускорение\n", speedup); DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "Результат: пулы памяти дали %.2fx ускорение", speedup);
if (time_with < time_without) { if (time_with < time_without) {
printf("✅ Пулы памяти эффективны!\n"); DEBUG_INFO(DEBUG_CATEGORY_MEMORY, "✅ Пулы памяти эффективны!");
} else { } else {
printf(" Пулы памяти не дали преимущества в этом тесте\n"); DEBUG_INFO(DEBUG_CATEGORY_MEMORY, " Пулы памяти не дали преимущества в этом тесте");
} }
} else { } else {
printf("❌ Ошибка в тесте с пулами\n"); DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "❌ Ошибка в тесте с пулами");
} }
return 0; return 0;

10
tests/test_packet_dump.c

@ -11,12 +11,16 @@ void test_packet_dump() {
snprintf(hex_buf, sizeof(hex_buf), "%02x%02x%02x%02x%02x%02x", snprintf(hex_buf, sizeof(hex_buf), "%02x%02x%02x%02x%02x%02x",
test_data[0], test_data[1], test_data[2], test_data[3], test_data[4], test_data[5]); test_data[0], test_data[1], test_data[2], test_data[3], test_data[4], test_data[5]);
printf("[ETCP] TEST_SEND: len=%zu hex=%s\n", sizeof(test_data), hex_buf); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "TEST_SEND: len=%zu hex=%s", sizeof(test_data), hex_buf);
printf("[ETCP] TEST_COMPACT: link=NULL type=0x%02x ts=0 len=%zu\n", test_data[0], sizeof(test_data)); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "TEST_COMPACT: link=NULL type=0x%02x ts=0 len=%zu", test_data[0], sizeof(test_data));
} }
int main() { int main() {
printf("=== Testing single-line packet dump ===\n"); debug_config_init();
debug_set_level(DEBUG_LEVEL_TRACE);
debug_set_categories(DEBUG_CATEGORY_ALL);
DEBUG_INFO(DEBUG_CATEGORY_ETCP, "=== Testing single-line packet dump ===");
test_packet_dump(); test_packet_dump();
return 0; return 0;
} }

Loading…
Cancel
Save