From fec4e68f4d620df9058cf48bee396105f08ff204 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 7 Jan 2015 20:32:11 +0100 Subject: [PATCH] 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. (cherry picked from commit bb90127c2a8980e02bb53340ab4bd25f0dfefea8) --- include/nm-test-utils.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index 782aebb58c..69a5d441d7 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -130,7 +130,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 @@ -218,7 +225,6 @@ nmtst_free (void) inline static void __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_level, const char *log_domains, gboolean *out_set_logging) { - static gsize atexit_registered = 0; const char *nmtst_debug; gboolean is_debug = FALSE; char *c_log_level = NULL, *c_log_domains = NULL; @@ -381,11 +387,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 ();