Migrating logging to LOG() and LOG_DEVEL() in tests/*

This commit is contained in:
Alexandre Quesnel 2021-02-28 19:57:28 +00:00
parent 058ca37030
commit 6479d54eaa
4 changed files with 63 additions and 44 deletions

View File

@ -1,4 +1,11 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/common
if XRDP_DEBUG
AM_CPPFLAGS += -DXRDP_DEBUG
endif
sbin_PROGRAMS = \
memtest
@ -7,5 +14,8 @@ memtest_SOURCES = \
libmem.c \
memtest.c
memtest_LDADD = \
$(top_builddir)/common/libcommon.la
TESTS = \
memtest

View File

@ -1,21 +1,18 @@
#if defined(HAVE_CONFIG_H)
#include <config_ac.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "log.h"
#define ALIGN_BY 32
#define ALIGN_BY_M1 (ALIGN_BY - 1)
#define ALIGN(_in) (((_in) + ALIGN_BY_M1) & (~ALIGN_BY_M1))
#define LLOG_LEVEL 1
#define LLOGLN(_log_level, _params) \
do { \
if (_log_level < LLOG_LEVEL) \
{ \
printf _params ; \
printf ("\n") ; \
} \
} while (0)
struct mem_item
{
@ -272,30 +269,30 @@ libmem_print(struct mem_info *self)
{
struct mem_item *mi;
LLOGLN(0, ("libmem_print:"));
LLOGLN(0, (" used_head %p", self->used_head));
LLOGLN(0, (" used_tail %p", self->used_tail));
LOG_DEVEL(LOG_LEVEL_DEBUG, "libmem_print:");
LOG_DEVEL(LOG_LEVEL_DEBUG, " used_head %p", self->used_head);
LOG_DEVEL(LOG_LEVEL_DEBUG, " used_tail %p", self->used_tail);
mi = self->used_head;
if (mi != 0)
{
LLOGLN(0, (" used list"));
LOG_DEVEL(LOG_LEVEL_DEBUG, " used list");
while (mi != 0)
{
LLOGLN(0, (" ptr %p prev %p next %p addr 0x%8.8x bytes %d",
mi, mi->prev, mi->next, mi->addr, mi->bytes));
LOG_DEVEL(LOG_LEVEL_DEBUG, " ptr %p prev %p next %p addr 0x%8.8x bytes %d",
mi, mi->prev, mi->next, mi->addr, mi->bytes);
mi = mi->next;
}
}
LLOGLN(0, (" free_head %p", self->free_head));
LLOGLN(0, (" free_tail %p", self->free_tail));
LOG_DEVEL(LOG_LEVEL_DEBUG, " free_head %p", self->free_head);
LOG_DEVEL(LOG_LEVEL_DEBUG, " free_tail %p", self->free_tail);
mi = self->free_head;
if (mi != 0)
{
LLOGLN(0, (" free list"));
LOG_DEVEL(LOG_LEVEL_DEBUG, " free list");
while (mi != 0)
{
LLOGLN(0, (" ptr %p prev %p next %p addr 0x%8.8x bytes %d",
mi, mi->prev, mi->next, mi->addr, mi->bytes));
LOG_DEVEL(LOG_LEVEL_DEBUG, " ptr %p prev %p next %p addr 0x%8.8x bytes %d",
mi, mi->prev, mi->next, mi->addr, mi->bytes);
mi = mi->next;
}
}
@ -344,7 +341,7 @@ libmem_alloc(void *obj, int bytes)
}
else
{
LLOGLN(0, ("libmem_alloc: error"));
LOG_DEVEL(LOG_LEVEL_ERROR, "libmem_alloc: error");
}
return addr;
}
@ -377,7 +374,7 @@ libmem_free(void *obj, unsigned int addr)
}
mi = mi->prev;
}
LLOGLN(0, ("libmem_free: error"));
LOG_DEVEL(LOG_LEVEL_ERROR, "libmem_free: error");
return 1;
}

View File

@ -1,10 +1,15 @@
#if defined(HAVE_CONFIG_H)
#include <config_ac.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "libmem.h"
#include "log.h"
int main(int argc, char **argv)
{
@ -16,6 +21,11 @@ int main(int argc, char **argv)
unsigned int addr5;
int index;
int rd;
struct log_config *config;
config = log_config_init_for_console(LOG_LEVEL_DEBUG, NULL);
log_start_from_param(config);
log_config_free(config);
srand(time(0));
obj = libmem_init(0x80000000, 64 * 1024 * 1024);
@ -57,5 +67,6 @@ int main(int argc, char **argv)
libmem_free(obj, addr5);
}
libmem_deinit(obj);
log_end();
return 0;
}

View File

@ -35,6 +35,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include "log.h"
#include "os_calls.h"
#include "string_calls.h"
@ -92,7 +93,7 @@ main_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)
if (error != 0)
{
g_writeln("bind failed");
LOG(LOG_LEVEL_WARNING, "bind failed");
}
/* listen for an incoming connection */
@ -102,7 +103,7 @@ main_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)
if (error == 0)
{
g_writeln("listening for connection");
LOG(LOG_LEVEL_INFO, "listening for connection");
}
}
@ -138,7 +139,7 @@ main_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)
if (error == 0)
{
g_writeln("got connection");
LOG(LOG_LEVEL_INFO, "got connection");
}
}
@ -166,7 +167,7 @@ main_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)
if (i > 99)
{
g_writeln("timeout connecting");
LOG(LOG_LEVEL_ERROR, "timeout connecting");
error = 1;
}
@ -178,7 +179,7 @@ main_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)
if ((error != 0) && (!g_terminated))
{
g_writeln("error connecting to remote\r\n");
LOG(LOG_LEVEL_ERROR, "error connecting to remote\r\n");
}
}
@ -205,14 +206,11 @@ main_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)
if (hexdump)
{
g_writeln("from remove, the socket from connect");
g_hexdump(g_buf, count);
LOG_HEXDUMP(LOG_LEVEL_INFO, "from remove, the socket from connect", g_buf, count);
}
#if 0
g_writeln("local_io_count: %d\tremote_io_count: %d",
g_loc_io_count, g_rem_io_count);
#endif
LOG(LOG_LEVEL_DEBUG, "local_io_count: %d\tremote_io_count: %d",
g_loc_io_count, g_rem_io_count);
sent = 0;
while ((sent < count) && (error == 0) && (!g_terminated))
@ -251,14 +249,11 @@ main_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)
if (hexdump)
{
g_writeln("from accepted, the socket from accept");
g_hexdump(g_buf, count);
LOG_HEXDUMP(LOG_LEVEL_INFO, "from accepted, the socket from accept", g_buf, count);
}
#if 0
g_writeln("local_io_count: %d\tremote_io_count: %d",
g_loc_io_count, g_rem_io_count);
#endif
LOG(LOG_LEVEL_DEBUG, "local_io_count: %d\tremote_io_count: %d",
g_loc_io_count, g_rem_io_count);
sent = 0;
while ((sent < count) && (error == 0) && (!g_terminated))
@ -288,8 +283,8 @@ main_loop(char *local_port, char *remote_ip, char *remote_port, int hexdump)
g_tcp_close(lis_sck);
g_tcp_close(con_sck);
g_tcp_close(acc_sck);
g_writeln("acc_to_con %d", acc_to_con);
g_writeln("con_to_acc %d", con_to_acc);
LOG(LOG_LEVEL_INFO, "acc_to_con %d", acc_to_con);
LOG(LOG_LEVEL_INFO, "con_to_acc %d", con_to_acc);
return 0;
}
@ -307,15 +302,15 @@ usage(void)
void
proxy_shutdown(int sig)
{
g_writeln("shutting down");
LOG(LOG_LEVEL_INFO, "shutting down");
g_terminated = 1;
}
void
clear_counters(int sig)
{
g_writeln("cleared counters at: local_io_count: %d remote_io_count: %d",
g_loc_io_count, g_rem_io_count);
LOG(LOG_LEVEL_DEBUG, "cleared counters at: local_io_count: %d remote_io_count: %d",
g_loc_io_count, g_rem_io_count);
g_loc_io_count = 0;
g_rem_io_count = 0;
}
@ -325,6 +320,7 @@ int
main(int argc, char **argv)
{
int dump;
struct log_config *config;
if (argc < 4)
{
@ -337,6 +333,10 @@ main(int argc, char **argv)
g_signal_usr1(clear_counters); /* SIGUSR1 */
g_signal_terminate(proxy_shutdown); /* SIGTERM */
config = log_config_init_for_console(LOG_LEVEL_INFO, NULL);
log_start_from_param(config);
log_config_free(config);
if (argc < 5)
{
while (!g_terminated)
@ -356,6 +356,7 @@ main(int argc, char **argv)
}
}
log_end();
g_deinit();
return 0;
}