diff options
author | Thomas Haller <thaller@redhat.com> | 2015-03-26 13:03:58 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-04-08 14:39:16 +0200 |
commit | b6d3b98655d119b155ec024b5eb5b6103111c75c (patch) | |
tree | 6fa3f07cb10b999f6001c848f2a2fd638059e0f8 | |
parent | 07f95c371c5a4699270915bb4872f844fa353c86 (diff) | |
download | NetworkManager-b6d3b98655d119b155ec024b5eb5b6103111c75c.tar.gz |
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 5e74891b58688a19c43fb8e50880166d94a4e901, 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
-rw-r--r-- | include/nm-test-utils.h | 26 | ||||
-rw-r--r-- | src/dhcp-manager/tests/test-dhcp-utils.c | 3 | ||||
-rw-r--r-- | src/settings/plugins/ibft/tests/test-ibft.c | 2 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c | 2 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 2 | ||||
-rw-r--r-- | src/settings/plugins/ifnet/tests/test_all.c | 3 | ||||
-rw-r--r-- | src/settings/plugins/keyfile/tests/test-keyfile.c | 2 | ||||
-rw-r--r-- | src/tests/config/test-config.c | 2 | ||||
-rw-r--r-- | src/tests/test-general-with-expect.c | 4 |
9 files changed, 29 insertions, 17 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index 79fb3b48be..157b3dbc73 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -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 diff --git a/src/dhcp-manager/tests/test-dhcp-utils.c b/src/dhcp-manager/tests/test-dhcp-utils.c index 961bd8a2ed..286c1d7476 100644 --- a/src/dhcp-manager/tests/test-dhcp-utils.c +++ b/src/dhcp-manager/tests/test-dhcp-utils.c @@ -694,8 +694,7 @@ NMTST_DEFINE (); int main (int argc, char **argv) { - nmtst_init_assert_logging (&argc, &argv); - nm_logging_setup ("WARN", "DEFAULT", NULL, NULL); + nmtst_init_assert_logging (&argc, &argv, "WARN", "DEFAULT"); g_test_add_func ("/dhcp/generic-options", test_generic_options); g_test_add_func ("/dhcp/wins-options", test_wins_options); diff --git a/src/settings/plugins/ibft/tests/test-ibft.c b/src/settings/plugins/ibft/tests/test-ibft.c index d5da9ec022..980a9ceed1 100644 --- a/src/settings/plugins/ibft/tests/test-ibft.c +++ b/src/settings/plugins/ibft/tests/test-ibft.c @@ -276,7 +276,7 @@ NMTST_DEFINE (); int main (int argc, char **argv) { - nmtst_init_assert_logging (&argc, &argv); + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); g_test_add_func (TPATH "ibft/dhcp", test_read_ibft_dhcp); g_test_add_func (TPATH "ibft/static", test_read_ibft_static); diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c index 8494c63825..13f1126e48 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils.c @@ -121,7 +121,7 @@ int main (int argc, char **argv) { char *base; - nmtst_init_assert_logging (&argc, &argv); + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); /* The tests */ test_get_ifcfg_name ("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL); diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index e5e4f3d477..24b2f398e3 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -12443,7 +12443,7 @@ NMTST_DEFINE (); int main (int argc, char **argv) { - nmtst_init_assert_logging (&argc, &argv); + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); g_test_add_func (TPATH "svUnescape", test_svUnescape); g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces); diff --git a/src/settings/plugins/ifnet/tests/test_all.c b/src/settings/plugins/ifnet/tests/test_all.c index 9c3991287d..76ed0c7d62 100644 --- a/src/settings/plugins/ifnet/tests/test_all.c +++ b/src/settings/plugins/ifnet/tests/test_all.c @@ -448,8 +448,7 @@ main (int argc, char **argv) nm_linux_platform_setup (); - nmtst_init_assert_logging (&argc, &argv); - nm_logging_setup ("WARN", "DEFAULT", NULL, NULL); + nmtst_init_assert_logging (&argc, &argv, "WARN", "DEFAULT"); f = g_build_filename (argv[1], "net", NULL); ifnet_init (f); diff --git a/src/settings/plugins/keyfile/tests/test-keyfile.c b/src/settings/plugins/keyfile/tests/test-keyfile.c index a86bfed6c2..ab9081621e 100644 --- a/src/settings/plugins/keyfile/tests/test-keyfile.c +++ b/src/settings/plugins/keyfile/tests/test-keyfile.c @@ -3632,7 +3632,7 @@ NMTST_DEFINE (); int main (int argc, char **argv) { - nmtst_init_assert_logging (&argc, &argv); + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); /* The tests */ g_test_add_func ("/keyfile/test_read_valid_wired_connection ", test_read_valid_wired_connection); diff --git a/src/tests/config/test-config.c b/src/tests/config/test-config.c index b03cfc112a..f4d72d333f 100644 --- a/src/tests/config/test-config.c +++ b/src/tests/config/test-config.c @@ -292,7 +292,7 @@ NMTST_DEFINE (); int main (int argc, char **argv) { - nmtst_init_assert_logging (&argc, &argv); + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); /* Initialize the DBus manager singleton explicitly, because it is accessed by * the class initializer of NMDevice (used by the NMTestDevice stub). diff --git a/src/tests/test-general-with-expect.c b/src/tests/test-general-with-expect.c index f5010dae4a..e341ca7988 100644 --- a/src/tests/test-general-with-expect.c +++ b/src/tests/test-general-with-expect.c @@ -338,9 +338,7 @@ NMTST_DEFINE (); int main (int argc, char **argv) { - nmtst_init_assert_logging (&argc, &argv); - - nm_logging_setup ("DEBUG", "DEFAULT", NULL, NULL); + nmtst_init_assert_logging (&argc, &argv, "DEBUG", "DEFAULT"); g_test_add_func ("/general/nm_utils_kill_child", test_nm_utils_kill_child); |