Browse Source

Replace printf with DEBUG_ macros in test_u_async_comprehensive.c

nodeinfo-routing-update
Evgeny 2 months ago
parent
commit
73f005bbe7
  1. 39
      tests/test_u_async_comprehensive.c

39
tests/test_u_async_comprehensive.c

@ -16,6 +16,7 @@
#include "u_async.h"
#include "timeout_heap.h"
#include "debug_config.h"
/* Test statistics */
static struct {
@ -40,17 +41,17 @@ static struct {
/* Test result tracking */
#define TEST_START(name) do { \
printf("TEST: %s... ", name); \
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "TEST: %s... ", name); \
test_stats.tests_run++; \
} while(0)
#define TEST_PASS() do { \
printf("PASS\n"); \
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "PASS"); \
test_stats.tests_passed++; \
} while(0)
#define TEST_FAIL(msg) do { \
printf("FAIL: %s\n", msg); \
DEBUG_ERROR(DEBUG_CATEGORY_UASYNC, "FAIL: %s", msg); \
test_stats.tests_failed++; \
} while(0)
@ -71,7 +72,7 @@ static struct {
#define ASSERT_EQ(a, b, msg) do { \
if ((a) != (b)) { \
TEST_FAIL(msg); \
printf(" Expected: %ld, Got: %ld\n", (long)(b), (long)(a)); \
DEBUG_ERROR(DEBUG_CATEGORY_UASYNC, " Expected: %ld, Got: %ld", (long)(b), (long)(a)); \
return; \
} \
} while(0)
@ -462,8 +463,12 @@ static void test_concurrent_operations(void) {
/* Main test runner */
int main(void) {
printf("=== lib Comprehensive Unit Tests ===\n");
printf("Testing race conditions, memory management, and error handling\n\n");
debug_config_init();
debug_set_level(DEBUG_LEVEL_INFO);
debug_set_categories(DEBUG_CATEGORY_ALL);
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "=== lib Comprehensive Unit Tests ===");
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Testing race conditions, memory management, and error handling");
/* Run all tests */
test_basic_timers();
@ -475,19 +480,19 @@ int main(void) {
test_concurrent_operations();
/* Print statistics */
printf("\n=== Test Statistics ===\n");
printf("Tests run: %d\n", test_stats.tests_run);
printf("Tests passed: %d\n", test_stats.tests_passed);
printf("Tests failed: %d\n", test_stats.tests_failed);
printf("\nTimer callbacks: %d\n", test_stats.timer_callbacks);
printf("Timer cancellations: %d\n", test_stats.timer_cancellations);
printf("Immediate timeouts: %d\n", test_stats.immediate_timeouts);
printf("Socket events: %d\n", test_stats.socket_events);
printf("Race condition errors: %d\n", test_stats.race_condition_errors);
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "=== Test Statistics ===");
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Tests run: %d", test_stats.tests_run);
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Tests passed: %d", test_stats.tests_passed);
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Tests failed: %d", test_stats.tests_failed);
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Timer callbacks: %d", test_stats.timer_callbacks);
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Timer cancellations: %d", test_stats.timer_cancellations);
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Immediate timeouts: %d", test_stats.immediate_timeouts);
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Socket events: %d", test_stats.socket_events);
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "Race condition errors: %d", test_stats.race_condition_errors);
/* Memory leak detection */
printf("\n=== Memory Leak Detection ===\n");
printf("No memory leaks detected during testing\n");
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "=== Memory Leak Detection ===");
DEBUG_INFO(DEBUG_CATEGORY_UASYNC, "No memory leaks detected during testing");
return (test_stats.tests_failed > 0) ? 1 : 0;
}
Loading…
Cancel
Save