test: setup logging during nmtst_init_assert_logging()

Before, when having a test with nmtst_init_assert_logging(),
the caller was expected to setup logging separately according
to the log level that the test asserts against.

Since 5e74891b58, the logging
level can be reset via NMTST_DEBUG also for tests that
assert logging. In this case, it would be useful, if the test
would not overwrite the logging level that is set externally
via NMTST_DEBUG.

Instead, let the test pass the logging configuration to
nmtst_init_assert_logging(), and nmtst will setup logging
-- either according to NMTST_DEBUG or as passed in.

This way, setting the log level works also for no-expect-message
tests:

  NMTST_DEBUG="debug,no-expect-message,log-level=TRACE" $TEST
This commit is contained in:
Thomas Haller
2015-03-26 13:03:58 +01:00
parent 07f95c371c
commit b6d3b98655
9 changed files with 29 additions and 17 deletions

View File

@@ -169,7 +169,7 @@ nmtst_free (void)
}
inline static void
__nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_level, const char *log_domains)
__nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_level, const char *log_domains, gboolean *out_set_logging)
{
const char *nmtst_debug;
gboolean is_debug = FALSE;
@@ -178,6 +178,11 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
GArray *debug_messages = g_array_new (TRUE, FALSE, sizeof (char *));
int i;
gboolean no_expect_message = FALSE;
gboolean _out_set_logging;
if (!out_set_logging)
out_set_logging = &_out_set_logging;
*out_set_logging = FALSE;
g_assert (!nmtst_initialized ());
@@ -275,6 +280,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
gboolean success = TRUE;
#ifdef __NETWORKMANAGER_LOGGING_H__
success = nm_logging_setup (log_level, log_domains, NULL, NULL);
*out_set_logging = TRUE;
#endif
g_assert (success);
} else if (__nmtst_internal.no_expect_message) {
@@ -291,6 +297,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
gboolean success;
success = nm_logging_setup (log_level, log_domains, NULL, NULL);
*out_set_logging = TRUE;
g_assert (success);
}
#endif
@@ -336,18 +343,27 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
inline static void
nmtst_init_with_logging (int *argc, char ***argv, const char *log_level, const char *log_domains)
{
__nmtst_init (argc, argv, FALSE, log_level, log_domains);
__nmtst_init (argc, argv, FALSE, log_level, log_domains, NULL);
}
inline static void
nmtst_init_assert_logging (int *argc, char ***argv)
nmtst_init_assert_logging (int *argc, char ***argv, const char *log_level, const char *log_domains)
{
__nmtst_init (argc, argv, TRUE, NULL, NULL);
gboolean set_logging;
__nmtst_init (argc, argv, TRUE, NULL, NULL, &set_logging);
if (!set_logging) {
gboolean success;
success = nm_logging_setup (log_level, log_domains, NULL, NULL);
g_assert (success);
}
}
#else
inline static void
nmtst_init (int *argc, char ***argv, gboolean assert_logging)
{
__nmtst_init (argc, argv, assert_logging, NULL, NULL);
__nmtst_init (argc, argv, assert_logging, NULL, NULL, NULL);
}
#endif