platform/test: introduce _LOGD() macros to fake platform and platform tests
This commit is contained in:
@@ -33,7 +33,33 @@
|
||||
|
||||
#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 {
|
||||
GHashTable *options;
|
||||
@@ -156,7 +182,7 @@ link_get (NMPlatform *platform, int ifindex)
|
||||
|
||||
return device;
|
||||
not_found:
|
||||
debug ("link not found: %d", ifindex);
|
||||
_LOGD ("link not found: %d", ifindex);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,7 @@ ip4_address_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex,
|
||||
g_main_loop_quit (data->loop);
|
||||
|
||||
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
|
||||
@@ -45,7 +45,7 @@ ip6_address_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex,
|
||||
g_main_loop_quit (data->loop);
|
||||
|
||||
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
|
||||
|
@@ -46,7 +46,7 @@ add_signal_full (const char *name, NMPlatformSignalChangeType change_type, GCall
|
||||
void
|
||||
_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)
|
||||
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;
|
||||
@@ -55,7 +55,7 @@ _accept_signal (const char *file, int line, const char *func, SignalData *data)
|
||||
void
|
||||
_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)
|
||||
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;
|
||||
@@ -64,7 +64,7 @@ _accept_signals (const char *file, int line, const char *func, SignalData *data,
|
||||
void
|
||||
_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)
|
||||
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
|
||||
_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)
|
||||
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
|
||||
_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)
|
||||
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;
|
||||
|
||||
if (data->loop) {
|
||||
debug ("Quitting main loop.");
|
||||
_LOGD ("Quitting main loop.");
|
||||
g_main_loop_quit (data->loop);
|
||||
}
|
||||
|
||||
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)
|
||||
g_assert (!nm_platform_link_get_name (NM_PLATFORM_GET, ifindex));
|
||||
@@ -262,9 +262,9 @@ run_command (const char *format, ...)
|
||||
va_start (ap, format);
|
||||
command = g_strdup_vprintf (format, ap);
|
||||
va_end (ap);
|
||||
debug ("Running command: %s", command);
|
||||
_LOGD ("Running command: %s", command);
|
||||
g_assert (!system (command));
|
||||
debug ("Command finished.");
|
||||
_LOGD ("Command finished.");
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
|
@@ -13,7 +13,25 @@
|
||||
|
||||
#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 {
|
||||
int handler_id;
|
||||
|
@@ -25,7 +25,7 @@ ip4_route_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, c
|
||||
g_main_loop_quit (data->loop);
|
||||
|
||||
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
|
||||
@@ -45,7 +45,7 @@ ip6_route_callback (NMPlatform *platform, NMPObjectType obj_type, int ifindex, c
|
||||
g_main_loop_quit (data->loop);
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user