summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-01-07 20:32:11 +0100
committerThomas Haller <thaller@redhat.com>2015-01-07 22:47:27 +0100
commitbb90127c2a8980e02bb53340ab4bd25f0dfefea8 (patch)
tree57f51a414dbc1cf36da94a395cfe7db0af6f1dc4
parentcf0a87c5e4a7e8366cf52a3431221c2ccc72b7d2 (diff)
downloadNetworkManager-bb90127c2a8980e02bb53340ab4bd25f0dfefea8.tar.gz
tests: check for no pending expected_messages on exit of tests
On the end of the test there should be no unchecked expected messages. Register a destructor function in nmtst to assert against that. Also call nmtst_free() in the destructor. That way, we always release the allocated data without requiring the test to do it explicitly.
-rw-r--r--include/nm-test-utils.h15
1 files changed, 8 insertions, 7 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h
index dcfa46eba3..a26bffad26 100644
--- a/include/nm-test-utils.h
+++ b/include/nm-test-utils.h
@@ -75,7 +75,14 @@ struct __nmtst_internal
extern struct __nmtst_internal __nmtst_internal;
#define NMTST_DEFINE() \
- struct __nmtst_internal __nmtst_internal = { 0 };
+struct __nmtst_internal __nmtst_internal = { 0 }; \
+\
+__attribute__ ((destructor)) static void \
+_nmtst_exit (void) \
+{ \
+ nmtst_free (); \
+ g_test_assert_expected_messages (); \
+}
inline static gboolean
@@ -163,7 +170,6 @@ nmtst_free (void)
inline static void
__nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_level, const char *log_domains)
{
- static gsize atexit_registered = 0;
const char *nmtst_debug;
gboolean is_debug = FALSE;
char *c_log_level = NULL, *c_log_domains = NULL;
@@ -307,11 +313,6 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
g_free (c_log_level);
g_free (c_log_domains);
- if (g_once_init_enter (&atexit_registered)) {
- atexit (nmtst_free);
- g_once_init_leave (&atexit_registered, 1);
- }
-
#ifdef __NETWORKMANAGER_UTILS_H__
/* ensure that monotonic timestamp is called (because it initially logs a line) */
nm_utils_get_monotonic_timestamp_s ();