platform/test: introduce _LOGD() macros to fake platform and platform tests

This commit is contained in:
Thomas Haller
2015-08-30 16:35:06 +02:00
parent 6bb26f8680
commit edadef563f
5 changed files with 60 additions and 16 deletions

View File

@@ -33,7 +33,33 @@
#include "nm-test-utils.h" #include "nm-test-utils.h"
#define debug(format, ...) nm_log_dbg (LOGD_PLATFORM, format, __VA_ARGS__) /*********************************************************************************************/
#define _NMLOG_PREFIX_NAME "platform-fake"
#define _NMLOG_DOMAIN LOGD_PLATFORM
#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, platform, __VA_ARGS__)
#define _LOG(level, domain, self, ...) \
G_STMT_START { \
const NMLogLevel __level = (level); \
const NMLogDomain __domain = (domain); \
\
if (nm_logging_enabled (__level, __domain)) { \
char __prefix[32]; \
const char *__p_prefix = _NMLOG_PREFIX_NAME; \
const void *const __self = (self); \
\
if (__self && __self != nm_platform_try_get ()) { \
g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \
__p_prefix = __prefix; \
} \
_nm_log (__level, __domain, 0, \
"%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
__p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \
} \
} G_STMT_END
/*********************************************************************************************/
typedef struct { typedef struct {
GHashTable *options; GHashTable *options;
@@ -156,7 +182,7 @@ link_get (NMPlatform *platform, int ifindex)
return device; return device;
not_found: not_found:
debug ("link not found: %d", ifindex); _LOGD ("link not found: %d", ifindex);
return NULL; return NULL;
} }

View File

@@ -25,7 +25,7 @@ ip4_address_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex,
g_main_loop_quit (data->loop); g_main_loop_quit (data->loop);
data->received_count++; data->received_count++;
debug ("Received signal '%s' %dth time.", data->name, data->received_count); _LOGD ("Received signal '%s' %dth time.", data->name, data->received_count);
} }
static void static void
@@ -45,7 +45,7 @@ ip6_address_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex,
g_main_loop_quit (data->loop); g_main_loop_quit (data->loop);
data->received_count++; data->received_count++;
debug ("Received signal '%s' %dth time.", data->name, data->received_count); _LOGD ("Received signal '%s' %dth time.", data->name, data->received_count);
} }
static void static void

View File

@@ -46,7 +46,7 @@ add_signal_full (const char *name, NMPlatformSignalChangeType change_type, GCall
void void
_accept_signal (const char *file, int line, const char *func, SignalData *data) _accept_signal (const char *file, int line, const char *func, SignalData *data)
{ {
debug ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal one time: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal one time: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data));
if (data->received_count != 1) if (data->received_count != 1)
g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to accept signal one time: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to accept signal one time: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data));
data->received_count = 0; data->received_count = 0;
@@ -55,7 +55,7 @@ _accept_signal (const char *file, int line, const char *func, SignalData *data)
void void
_accept_signals (const char *file, int line, const char *func, SignalData *data, int min, int max) _accept_signals (const char *file, int line, const char *func, SignalData *data, int min, int max)
{ {
debug ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal [%d,%d] times: "SIGNAL_DATA_FMT, file, line, func, min, max, SIGNAL_DATA_ARG (data)); _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal [%d,%d] times: "SIGNAL_DATA_FMT, file, line, func, min, max, SIGNAL_DATA_ARG (data));
if (data->received_count < min || data->received_count > max) if (data->received_count < min || data->received_count > max)
g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to accept signal [%d,%d] times: "SIGNAL_DATA_FMT, file, line, func, min, max, SIGNAL_DATA_ARG (data)); g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to accept signal [%d,%d] times: "SIGNAL_DATA_FMT, file, line, func, min, max, SIGNAL_DATA_ARG (data));
data->received_count = 0; data->received_count = 0;
@@ -64,7 +64,7 @@ _accept_signals (const char *file, int line, const char *func, SignalData *data,
void void
_ensure_no_signal (const char *file, int line, const char *func, SignalData *data) _ensure_no_signal (const char *file, int line, const char *func, SignalData *data)
{ {
debug ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal 0 times: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): Accepting signal 0 times: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data));
if (data->received_count > 0) if (data->received_count > 0)
g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to accept signal 0 times: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to accept signal 0 times: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data));
} }
@@ -72,7 +72,7 @@ _ensure_no_signal (const char *file, int line, const char *func, SignalData *dat
void void
_wait_signal (const char *file, int line, const char *func, SignalData *data) _wait_signal (const char *file, int line, const char *func, SignalData *data)
{ {
debug ("NMPlatformSignalAssert: %s:%d, %s(): wait signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): wait signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data));
if (data->received_count) if (data->received_count)
g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to wait for signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to wait for signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data));
@@ -86,7 +86,7 @@ _wait_signal (const char *file, int line, const char *func, SignalData *data)
void void
_free_signal (const char *file, int line, const char *func, SignalData *data) _free_signal (const char *file, int line, const char *func, SignalData *data)
{ {
debug ("NMPlatformSignalAssert: %s:%d, %s(): free signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); _LOGD ("NMPlatformSignalAssert: %s:%d, %s(): free signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data));
if (data->received_count != 0) if (data->received_count != 0)
g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to free non-accepted signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data)); g_error ("NMPlatformSignalAssert: %s:%d, %s(): failure to free non-accepted signal: "SIGNAL_DATA_FMT, file, line, func, SIGNAL_DATA_ARG (data));
@@ -114,12 +114,12 @@ link_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, NMPlat
return; return;
if (data->loop) { if (data->loop) {
debug ("Quitting main loop."); _LOGD ("Quitting main loop.");
g_main_loop_quit (data->loop); g_main_loop_quit (data->loop);
} }
data->received_count++; data->received_count++;
debug ("Received signal '%s-%s' ifindex %d ifname '%s' %dth time.", data->name, nm_platform_signal_change_type_to_string (data->change_type), ifindex, received->name, data->received_count); _LOGD ("Received signal '%s-%s' ifindex %d ifname '%s' %dth time.", data->name, nm_platform_signal_change_type_to_string (data->change_type), ifindex, received->name, data->received_count);
if (change_type == NM_PLATFORM_SIGNAL_REMOVED) if (change_type == NM_PLATFORM_SIGNAL_REMOVED)
g_assert (!nm_platform_link_get_name (NM_PLATFORM_GET, ifindex)); g_assert (!nm_platform_link_get_name (NM_PLATFORM_GET, ifindex));
@@ -262,9 +262,9 @@ run_command (const char *format, ...)
va_start (ap, format); va_start (ap, format);
command = g_strdup_vprintf (format, ap); command = g_strdup_vprintf (format, ap);
va_end (ap); va_end (ap);
debug ("Running command: %s", command); _LOGD ("Running command: %s", command);
g_assert (!system (command)); g_assert (!system (command));
debug ("Command finished."); _LOGD ("Command finished.");
g_free (command); g_free (command);
} }

View File

@@ -13,7 +13,25 @@
#define DEVICE_NAME "nm-test-device" #define DEVICE_NAME "nm-test-device"
#define debug(...) nm_log_dbg (LOGD_PLATFORM, __VA_ARGS__) /*********************************************************************************************/
#define _NMLOG_PREFIX_NAME "platform-test"
#define _NMLOG_DOMAIN LOGD_PLATFORM
#define _NMLOG(level, ...) _LOG(level, _NMLOG_DOMAIN, __VA_ARGS__)
#define _LOG(level, domain, ...) \
G_STMT_START { \
const NMLogLevel __level = (level); \
const NMLogDomain __domain = (domain); \
\
if (nm_logging_enabled (__level, __domain)) { \
_nm_log (__level, __domain, 0, \
"%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
_NMLOG_PREFIX_NAME _NM_UTILS_MACRO_REST (__VA_ARGS__)); \
} \
} G_STMT_END
/*********************************************************************************************/
typedef struct { typedef struct {
int handler_id; int handler_id;

View File

@@ -25,7 +25,7 @@ ip4_route_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, c
g_main_loop_quit (data->loop); g_main_loop_quit (data->loop);
data->received_count++; data->received_count++;
debug ("Received signal '%s' %dth time.", data->name, data->received_count); _LOGD ("Received signal '%s' %dth time.", data->name, data->received_count);
} }
static void static void
@@ -45,7 +45,7 @@ ip6_route_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, c
g_main_loop_quit (data->loop); g_main_loop_quit (data->loop);
data->received_count++; data->received_count++;
debug ("Received signal '%s' %dth time.", data->name, data->received_count); _LOGD ("Received signal '%s' %dth time.", data->name, data->received_count);
} }
static void static void