From d1a865628b0b53ccd5528d13a8dbce8815bd0d30 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 9 Apr 2015 12:17:07 +0200 Subject: [PATCH 01/18] test: make valgrind suppressions file configurable Add a configure option --with-valgrind-suppressions=path to allow specifying a different suppressions file. (cherry picked from commit 4c9a8367742373d594894c6ed7009a505957874d) --- configure.ac | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 8cd0b4207a..a56ef5bfe3 100644 --- a/configure.ac +++ b/configure.ac @@ -859,8 +859,16 @@ AS_IF([test "$with_valgrind" == "yes"], # Add conditionals and substitutions AM_CONDITIONAL(ENABLE_TESTS, test "$enable_tests" != "no") AM_CONDITIONAL(REQUIRE_ROOT_TESTS, test "$enable_tests" == "root") +AC_ARG_WITH(valgrind-suppressions, AS_HELP_STRING([--with-valgrind-suppressions=path], [Use specific valgrind suppression file])) +if test "$with_valgrind" == no; then + with_valgrind_suppressions= +else + if test "$with_valgrind_suppressions" == ""; then + with_valgrind_suppressions='$(top_srcdir)/valgrind.suppressions' + fi +fi AS_IF([test "$with_valgrind" != "no"], - AC_SUBST(VALGRIND_RULES, 'TESTS_ENVIRONMENT = "$(top_srcdir)/tools/run-test-valgrind.sh" "$(LIBTOOL)" "$(with_valgrind)" "$(top_srcdir)/valgrind.suppressions"'), + AC_SUBST(VALGRIND_RULES, 'TESTS_ENVIRONMENT = "$(top_srcdir)/tools/run-test-valgrind.sh" "$(LIBTOOL)" "$(with_valgrind)" '"$with_valgrind_suppressions"), AC_SUBST(VALGRIND_RULES, [])) AM_CONDITIONAL(WITH_VALGRIND, test "${with_valgrind}" != "no") @@ -1084,7 +1092,7 @@ echo echo "Miscellaneous:" echo " documentation: $enable_gtk_doc" echo " tests: $enable_tests" -echo " valgrind: $with_valgrind" +echo " valgrind: $with_valgrind $with_valgrind_suppressions" echo " code coverage: $enable_code_coverage" echo " LTO: $enable_lto" echo From 63e30f5024a669cc9b9aec77026552000b4f8c5d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 10 Apr 2015 07:25:03 +0200 Subject: [PATCH 02/18] build: add --enable-more-asserts configure option and nm_assert() macro NM already has two kinds of assertions: - g_assert*(), conditionally compiled via #ifndef G_DISABLE_ASSERT - g_return*(), conditionally compiled via #ifndef G_DISABLE_CHECKS In theory, one should be able to disable both asserts and NM should still work correctly (and possibly more efficient). In practice, hardly anybody is testing such a configuration and it might be broken. Especially, we don't disable asserts for production builds, both because of less test coverage and because it might reduce our ability to debug. Add a new configure option --enable-more-asserts, which defines NM_MORE_ASSERTS and nm_assert(). This is for expensive asserts, that -- contrary to the asserts above -- are disabled by default. This is useful for extended debugging. (cherry picked from commit 08ecafd2bf672e3e49a90f22dd87fabfa08f4e2c) --- configure.ac | 6 ++++++ include/nm-utils-internal.h | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/configure.ac b/configure.ac index a56ef5bfe3..1a501cd818 100644 --- a/configure.ac +++ b/configure.ac @@ -828,6 +828,12 @@ AM_CONDITIONAL(BUILD_NMTUI, test "$build_nmtui" = yes) NM_COMPILER_WARNINGS +AC_ARG_ENABLE(more-asserts, + AS_HELP_STRING([--enable-more-asserts], [Enable more assertions for debugging (default: no)])) +if test "${enable_more_asserts}" = "yes"; then + AC_DEFINE(NM_MORE_ASSERTS, [1], [Define if more asserts are enabled]) +fi + AC_ARG_ENABLE(lto, AS_HELP_STRING([--enable-lto], [Enable Link Time Optimization for smaller size (default: no)])) if (test "${enable_lto}" = "yes"); then CFLAGS="-flto $CFLAGS" diff --git a/include/nm-utils-internal.h b/include/nm-utils-internal.h index 227a210b2c..06d5d06357 100644 --- a/include/nm-utils-internal.h +++ b/include/nm-utils-internal.h @@ -102,6 +102,14 @@ /*****************************************************************************/ +#ifdef NM_MORE_ASSERTS +#define nm_assert(cond) G_STMT_START { g_assert (cond); } G_STMT_END +#else +#define nm_assert(cond) G_STMT_START { (void) 0; } G_STMT_END +#endif + +/*****************************************************************************/ + #define NM_DEFINE_SINGLETON_INSTANCE(TYPE) \ static TYPE *singleton_instance From b67fbe9561f99fa458776202b1a0f927fc97a3c9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 26 May 2015 18:08:04 +0200 Subject: [PATCH 03/18] core: make nm_assert() always compile condition Even if asserts are not enabled, still let the compiler see what we would assert. Otherwise, we get warnings about unused variables or we migth miss compile errors inside nm_assert(). (cherry picked from commit fe3e1849b7f4d7be9152b488f6926da1d1079a49) --- include/nm-utils-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nm-utils-internal.h b/include/nm-utils-internal.h index 06d5d06357..059d2b7d75 100644 --- a/include/nm-utils-internal.h +++ b/include/nm-utils-internal.h @@ -105,7 +105,7 @@ #ifdef NM_MORE_ASSERTS #define nm_assert(cond) G_STMT_START { g_assert (cond); } G_STMT_END #else -#define nm_assert(cond) G_STMT_START { (void) 0; } G_STMT_END +#define nm_assert(cond) G_STMT_START { if (FALSE) { if (cond) { } } } G_STMT_END #endif /*****************************************************************************/ From 483a0191105034ff4b8a1ec37f37bc9a63b8bf27 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 10 Apr 2015 07:39:14 +0200 Subject: [PATCH 04/18] build: add --enable-more-logging configure option NM core uses nm-logging which is entirely configurable at runtime. Other components use glib-logging, which can also be partly configured via G_MESSAGES_DEBUG. It makes sense to have a compile time option to enable some logging statements that are only useful for heavy debugging. For glib-logging, this is a way to enable/disable extra logging. For nm-logging, we could alternatively configure a least log-level that is enabled at compile time (that way, we could configure to prune all LOGL_TRACE logging). While that might be useful (too), this gives an alternative way to disable/enable logging. Add a configure option --enable-more-logging and a NM_MORE_LOGGING define for that. If we don't find this useful after a while, we can simply remove it, because our logging statements are not part of a "stable" behavior. (cherry picked from commit 63593a19d8e7d7fb5e844f0e3c8ac847e68699cb) --- configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index 1a501cd818..5f1b62e088 100644 --- a/configure.ac +++ b/configure.ac @@ -834,6 +834,12 @@ if test "${enable_more_asserts}" = "yes"; then AC_DEFINE(NM_MORE_ASSERTS, [1], [Define if more asserts are enabled]) fi +AC_ARG_ENABLE(more-logging, + AS_HELP_STRING([--enable-more-logging], [Enable more debug logging (default: no)])) +if test "${enable_more_logging}" = "yes"; then + AC_DEFINE(NM_MORE_LOGGING, [1], [Define if more asserts are enabled]) +fi + AC_ARG_ENABLE(lto, AS_HELP_STRING([--enable-lto], [Enable Link Time Optimization for smaller size (default: no)])) if (test "${enable_lto}" = "yes"); then CFLAGS="-flto $CFLAGS" From 62172a9a9ef2b4478f916b7cd68283df450074b7 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 9 Apr 2015 16:14:47 +0200 Subject: [PATCH 05/18] tests: move all asserts into tests Otherwise the TAP formatter would produce a plan-less output. (cherry picked from commit f627d6db8ececc70285bf858a6aee031a75a337a) --- libnm-core/tests/test-secrets.c | 36 ++--- libnm-core/tests/test-settings-defaults.c | 27 ++-- libnm-util/tests/test-general.c | 153 +++++++++--------- libnm-util/tests/test-secrets.c | 36 ++--- libnm-util/tests/test-settings-defaults.c | 29 ++-- .../ifcfg-rh/tests/test-ifcfg-rh-utils.c | 37 +++-- 6 files changed, 160 insertions(+), 158 deletions(-) diff --git a/libnm-core/tests/test-secrets.c b/libnm-core/tests/test-secrets.c index a915ae7d4e..178fddd526 100644 --- a/libnm-core/tests/test-secrets.c +++ b/libnm-core/tests/test-secrets.c @@ -739,33 +739,23 @@ NMTST_DEFINE (); int main (int argc, char **argv) { - char *base; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif - nmtst_init (&argc, &argv, TRUE); /* The tests */ - test_need_tls_secrets_path (); - test_need_tls_secrets_blob (); - test_need_tls_phase2_secrets_path (); - test_need_tls_phase2_secrets_blob (); + g_test_add_func ("/libnm/need_tls_secrets_path", test_need_tls_secrets_path); + g_test_add_func ("/libnm/need_tls_secrets_blob", test_need_tls_secrets_blob); + g_test_add_func ("/libnm/need_tls_phase2_secrets_path", test_need_tls_phase2_secrets_path); + g_test_add_func ("/libnm/need_tls_phase2_secrets_blob", test_need_tls_phase2_secrets_blob); - test_update_secrets_wifi_single_setting (); - test_update_secrets_wifi_full_hash (); - test_update_secrets_wifi_bad_setting_name (); + g_test_add_func ("/libnm/update_secrets_wifi_single_setting", test_update_secrets_wifi_single_setting); + g_test_add_func ("/libnm/update_secrets_wifi_full_hash", test_update_secrets_wifi_full_hash); + g_test_add_func ("/libnm/update_secrets_wifi_bad_setting_name", test_update_secrets_wifi_bad_setting_name); - test_update_secrets_whole_connection (); - test_update_secrets_whole_connection_empty_hash (); - test_update_secrets_whole_connection_bad_setting (); - test_update_secrets_whole_connection_empty_base_setting (); - test_update_secrets_null_setting_name_with_setting_hash (); + g_test_add_func ("/libnm/update_secrets_whole_connection", test_update_secrets_whole_connection); + g_test_add_func ("/libnm/update_secrets_whole_connection_empty_hash", test_update_secrets_whole_connection_empty_hash); + g_test_add_func ("/libnm/update_secrets_whole_connection_bad_setting", test_update_secrets_whole_connection_bad_setting); + g_test_add_func ("/libnm/update_secrets_whole_connection_empty_base_setting", test_update_secrets_whole_connection_empty_base_setting); + g_test_add_func ("/libnm/update_secrets_null_setting_name_with_setting_hash", test_update_secrets_null_setting_name_with_setting_hash); - base = g_path_get_basename (argv[0]); - fprintf (stdout, "%s: SUCCESS\n", base); - g_free (base); - return 0; + return g_test_run (); } - diff --git a/libnm-core/tests/test-settings-defaults.c b/libnm-core/tests/test-settings-defaults.c index 0e78618723..ace7af694d 100644 --- a/libnm-core/tests/test-settings-defaults.c +++ b/libnm-core/tests/test-settings-defaults.c @@ -101,15 +101,9 @@ test_defaults (GType type, const char *name) g_object_unref (setting); } -int -main (int argc, char **argv) +static void +defaults () { - char *base; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif - /* The tests */ test_defaults (NM_TYPE_SETTING_CONNECTION, NM_SETTING_CONNECTION_SETTING_NAME); test_defaults (NM_TYPE_SETTING_802_1X, NM_SETTING_802_1X_SETTING_NAME); @@ -124,10 +118,17 @@ main (int argc, char **argv) test_defaults (NM_TYPE_SETTING_WIRED, NM_SETTING_WIRED_SETTING_NAME); test_defaults (NM_TYPE_SETTING_WIRELESS, NM_SETTING_WIRELESS_SETTING_NAME); test_defaults (NM_TYPE_SETTING_WIRELESS_SECURITY, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); - - base = g_path_get_basename (argv[0]); - fprintf (stdout, "%s: SUCCESS\n", base); - g_free (base); - return 0; +} + +NMTST_DEFINE (); + +int +main (int argc, char **argv) +{ + nmtst_init (&argc, &argv, TRUE); + + g_test_add_func ("/libnm/defaults", defaults); + + return g_test_run (); } diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c index d8f9dcc4ae..f365dc0438 100644 --- a/libnm-util/tests/test-general.c +++ b/libnm-util/tests/test-general.c @@ -1703,9 +1703,9 @@ test_setting_compare_id (void) } static void -test_setting_compare_secrets (NMSettingSecretFlags secret_flags, - NMSettingCompareFlags comp_flags, - gboolean remove_secret) +_compare_secrets (NMSettingSecretFlags secret_flags, + NMSettingCompareFlags comp_flags, + gboolean remove_secret) { gs_unref_object NMSetting *old = NULL, *new = NULL; gboolean success; @@ -1735,9 +1735,18 @@ test_setting_compare_secrets (NMSettingSecretFlags secret_flags, } static void -test_setting_compare_vpn_secrets (NMSettingSecretFlags secret_flags, - NMSettingCompareFlags comp_flags, - gboolean remove_secret) +test_setting_compare_secrets (void) +{ + _compare_secrets (NM_SETTING_SECRET_FLAG_AGENT_OWNED, NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS, TRUE); + _compare_secrets (NM_SETTING_SECRET_FLAG_NOT_SAVED, NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS, TRUE); + _compare_secrets (NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS, TRUE); + _compare_secrets (NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_COMPARE_FLAG_EXACT, FALSE); +} + +static void +_compare_vpn_secrets (NMSettingSecretFlags secret_flags, + NMSettingCompareFlags comp_flags, + gboolean remove_secret) { gs_unref_object NMSetting *old = NULL, *new = NULL; gboolean success; @@ -1767,6 +1776,15 @@ test_setting_compare_vpn_secrets (NMSettingSecretFlags secret_flags, g_assert (success); } +static void +test_setting_compare_vpn_secrets (void) +{ + _compare_vpn_secrets (NM_SETTING_SECRET_FLAG_AGENT_OWNED, NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS, TRUE); + _compare_vpn_secrets (NM_SETTING_SECRET_FLAG_NOT_SAVED, NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS, TRUE); + _compare_vpn_secrets (NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS, TRUE); + _compare_vpn_secrets (NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_COMPARE_FLAG_EXACT, FALSE); +} + static void test_hwaddr_aton_ether_normal (void) { @@ -2546,84 +2564,73 @@ NMTST_DEFINE (); int main (int argc, char **argv) { - char *base; - nmtst_init (&argc, &argv, TRUE); /* The tests */ - test_setting_vpn_items (); - test_setting_vpn_update_secrets (); - test_setting_vpn_modify_during_foreach (); - test_setting_ip6_config_old_address_array (); - test_setting_gsm_apn_spaces (); - test_setting_gsm_apn_bad_chars (); - test_setting_gsm_apn_underscore (); - test_setting_gsm_without_number (); - test_setting_to_hash_all (); - test_setting_to_hash_no_secrets (); - test_setting_to_hash_only_secrets (); - test_setting_compare_id (); - test_setting_compare_secrets (NM_SETTING_SECRET_FLAG_AGENT_OWNED, NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS, TRUE); - test_setting_compare_secrets (NM_SETTING_SECRET_FLAG_NOT_SAVED, NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS, TRUE); - test_setting_compare_secrets (NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS, TRUE); - test_setting_compare_secrets (NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_COMPARE_FLAG_EXACT, FALSE); - test_setting_compare_vpn_secrets (NM_SETTING_SECRET_FLAG_AGENT_OWNED, NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS, TRUE); - test_setting_compare_vpn_secrets (NM_SETTING_SECRET_FLAG_NOT_SAVED, NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS, TRUE); - test_setting_compare_vpn_secrets (NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS, TRUE); - test_setting_compare_vpn_secrets (NM_SETTING_SECRET_FLAG_NONE, NM_SETTING_COMPARE_FLAG_EXACT, FALSE); - test_setting_old_uuid (); + g_test_add_func ("/libnm/setting_vpn_items", test_setting_vpn_items); + g_test_add_func ("/libnm/setting_vpn_update_secrets", test_setting_vpn_update_secrets); + g_test_add_func ("/libnm/setting_vpn_modify_during_foreach", test_setting_vpn_modify_during_foreach); + g_test_add_func ("/libnm/setting_ip6_config_old_address_array", test_setting_ip6_config_old_address_array); + g_test_add_func ("/libnm/setting_gsm_apn_spaces", test_setting_gsm_apn_spaces); + g_test_add_func ("/libnm/setting_gsm_apn_bad_chars", test_setting_gsm_apn_bad_chars); + g_test_add_func ("/libnm/setting_gsm_apn_underscore", test_setting_gsm_apn_underscore); + g_test_add_func ("/libnm/setting_gsm_without_number", test_setting_gsm_without_number); + g_test_add_func ("/libnm/setting_to_hash_all", test_setting_to_hash_all); + g_test_add_func ("/libnm/setting_to_hash_no_secrets", test_setting_to_hash_no_secrets); + g_test_add_func ("/libnm/setting_to_hash_only_secrets", test_setting_to_hash_only_secrets); + g_test_add_func ("/libnm/setting_compare_id", test_setting_compare_id); + g_test_add_func ("/libnm/setting_compare_secrets", test_setting_compare_secrets); + g_test_add_func ("/libnm/setting_compare_vpn_secrets", test_setting_compare_vpn_secrets); + g_test_add_func ("/libnm/setting_old_uuid", test_setting_old_uuid); - test_connection_to_hash_setting_name (); - test_setting_new_from_hash (); - test_connection_replace_settings (); - test_connection_replace_settings_from_connection (); - test_connection_new_from_hash (); - test_connection_verify_sets_interface_name (); - test_connection_normalize_virtual_iface_name (); + g_test_add_func ("/libnm/connection_to_hash_setting_name", test_connection_to_hash_setting_name); + g_test_add_func ("/libnm/setting_new_from_hash", test_setting_new_from_hash); + g_test_add_func ("/libnm/connection_replace_settings", test_connection_replace_settings); + g_test_add_func ("/libnm/connection_replace_settings_from_connection", test_connection_replace_settings_from_connection); + g_test_add_func ("/libnm/connection_new_from_hash", test_connection_new_from_hash); + g_test_add_func ("/libnm/connection_verify_sets_interface_name", test_connection_verify_sets_interface_name); + g_test_add_func ("/libnm/connection_normalize_virtual_iface_name", test_connection_normalize_virtual_iface_name); - test_setting_connection_permissions_helpers (); - test_setting_connection_permissions_property (); + g_test_add_func ("/libnm/setting_connection_permissions_helpers", test_setting_connection_permissions_helpers); + g_test_add_func ("/libnm/setting_connection_permissions_property", test_setting_connection_permissions_property); - test_connection_compare_same (); - test_connection_compare_key_only_in_a (); - test_connection_compare_setting_only_in_a (); - test_connection_compare_key_only_in_b (); - test_connection_compare_setting_only_in_b (); + g_test_add_func ("/libnm/connection_compare_same", test_connection_compare_same); + g_test_add_func ("/libnm/connection_compare_key_only_in_a", test_connection_compare_key_only_in_a); + g_test_add_func ("/libnm/connection_compare_setting_only_in_a", test_connection_compare_setting_only_in_a); + g_test_add_func ("/libnm/connection_compare_key_only_in_b", test_connection_compare_key_only_in_b); + g_test_add_func ("/libnm/connection_compare_setting_only_in_b", test_connection_compare_setting_only_in_b); - test_connection_diff_a_only (); - test_connection_diff_same (); - test_connection_diff_different (); - test_connection_diff_no_secrets (); - test_connection_diff_inferrable (); - test_connection_good_base_types (); - test_connection_bad_base_types (); + g_test_add_func ("/libnm/connection_diff_a_only", test_connection_diff_a_only); + g_test_add_func ("/libnm/connection_diff_same", test_connection_diff_same); + g_test_add_func ("/libnm/connection_diff_different", test_connection_diff_different); + g_test_add_func ("/libnm/connection_diff_no_secrets", test_connection_diff_no_secrets); + g_test_add_func ("/libnm/connection_diff_inferrable", test_connection_diff_inferrable); + g_test_add_func ("/libnm/connection_good_base_types", test_connection_good_base_types); + g_test_add_func ("/libnm/connection_bad_base_types", test_connection_bad_base_types); - test_hwaddr_aton_ether_normal (); - test_hwaddr_aton_ib_normal (); - test_hwaddr_aton_no_leading_zeros (); - test_hwaddr_aton_malformed (); - test_ip4_prefix_to_netmask (); - test_ip4_netmask_to_prefix (); + g_test_add_func ("/libnm/hwaddr_aton_ether_normal", test_hwaddr_aton_ether_normal); + g_test_add_func ("/libnm/hwaddr_aton_ib_normal", test_hwaddr_aton_ib_normal); + g_test_add_func ("/libnm/hwaddr_aton_no_leading_zeros", test_hwaddr_aton_no_leading_zeros); + g_test_add_func ("/libnm/hwaddr_aton_malformed", test_hwaddr_aton_malformed); + g_test_add_func ("/libnm/ip4_prefix_to_netmask", test_ip4_prefix_to_netmask); + g_test_add_func ("/libnm/ip4_netmask_to_prefix", test_ip4_netmask_to_prefix); - test_connection_changed_signal (); - test_setting_connection_changed_signal (); - test_setting_bond_changed_signal (); - test_setting_ip4_changed_signal (); - test_setting_ip6_changed_signal (); - test_setting_vlan_changed_signal (); - test_setting_vpn_changed_signal (); - test_setting_wired_changed_signal (); - test_setting_wireless_changed_signal (); - test_setting_wireless_security_changed_signal (); - test_setting_802_1x_changed_signal (); + g_test_add_func ("/libnm/connection_changed_signal", test_connection_changed_signal); + g_test_add_func ("/libnm/setting_connection_changed_signal", test_setting_connection_changed_signal); + g_test_add_func ("/libnm/setting_bond_changed_signal", test_setting_bond_changed_signal); + g_test_add_func ("/libnm/setting_ip4_changed_signal", test_setting_ip4_changed_signal); + g_test_add_func ("/libnm/setting_ip6_changed_signal", test_setting_ip6_changed_signal); + g_test_add_func ("/libnm/setting_vlan_changed_signal", test_setting_vlan_changed_signal); + g_test_add_func ("/libnm/setting_vpn_changed_signal", test_setting_vpn_changed_signal); + g_test_add_func ("/libnm/setting_wired_changed_signal", test_setting_wired_changed_signal); + g_test_add_func ("/libnm/setting_wireless_changed_signal", test_setting_wireless_changed_signal); + g_test_add_func ("/libnm/setting_wireless_security_changed_signal", test_setting_wireless_security_changed_signal); + g_test_add_func ("/libnm/setting_802_1x_changed_signal", test_setting_802_1x_changed_signal); - test_libnm_linking (); + g_test_add_func ("/libnm/libnm_linking", test_libnm_linking); - test_nm_utils_uuid_generate_from_string (); + g_test_add_func ("/libnm/nm_utils_uuid_generate_from_string", test_nm_utils_uuid_generate_from_string); - base = g_path_get_basename (argv[0]); - fprintf (stdout, "%s: SUCCESS\n", base); - g_free (base); - return 0; + return g_test_run (); } diff --git a/libnm-util/tests/test-secrets.c b/libnm-util/tests/test-secrets.c index a22edb0fb7..adf3a94a34 100644 --- a/libnm-util/tests/test-secrets.c +++ b/libnm-util/tests/test-secrets.c @@ -734,37 +734,33 @@ test_update_secrets_null_setting_name_with_setting_hash (void) g_object_unref (connection); } +NMTST_DEFINE (); + int main (int argc, char **argv) { GError *error = NULL; - char *base; -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif + nmtst_init (&argc, &argv, TRUE); if (!nm_utils_init (&error)) FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message); /* The tests */ - test_need_tls_secrets_path (); - test_need_tls_secrets_blob (); - test_need_tls_phase2_secrets_path (); - test_need_tls_phase2_secrets_blob (); + g_test_add_func ("/libnm/need_tls_secrets_path", test_need_tls_secrets_path); + g_test_add_func ("/libnm/need_tls_secrets_blob", test_need_tls_secrets_blob); + g_test_add_func ("/libnm/need_tls_phase2_secrets_path", test_need_tls_phase2_secrets_path); + g_test_add_func ("/libnm/need_tls_phase2_secrets_blob", test_need_tls_phase2_secrets_blob); - test_update_secrets_wifi_single_setting (); - test_update_secrets_wifi_full_hash (); - test_update_secrets_wifi_bad_setting_name (); + g_test_add_func ("/libnm/update_secrets_wifi_single_setting", test_update_secrets_wifi_single_setting); + g_test_add_func ("/libnm/update_secrets_wifi_full_hash", test_update_secrets_wifi_full_hash); + g_test_add_func ("/libnm/update_secrets_wifi_bad_setting_name", test_update_secrets_wifi_bad_setting_name); - test_update_secrets_whole_connection (); - test_update_secrets_whole_connection_empty_hash (); - test_update_secrets_whole_connection_bad_setting (); - test_update_secrets_whole_connection_empty_base_setting (); - test_update_secrets_null_setting_name_with_setting_hash (); + g_test_add_func ("/libnm/update_secrets_whole_connection", test_update_secrets_whole_connection); + g_test_add_func ("/libnm/update_secrets_whole_connection_empty_hash", test_update_secrets_whole_connection_empty_hash); + g_test_add_func ("/libnm/update_secrets_whole_connection_bad_setting", test_update_secrets_whole_connection_bad_setting); + g_test_add_func ("/libnm/update_secrets_whole_connection_empty_base_setting", test_update_secrets_whole_connection_empty_base_setting); + g_test_add_func ("/libnm/update_secrets_null_setting_name_with_setting_hash", test_update_secrets_null_setting_name_with_setting_hash); - base = g_path_get_basename (argv[0]); - fprintf (stdout, "%s: SUCCESS\n", base); - g_free (base); - return 0; + return g_test_run (); } diff --git a/libnm-util/tests/test-settings-defaults.c b/libnm-util/tests/test-settings-defaults.c index 7441e1ff5f..70a743cb00 100644 --- a/libnm-util/tests/test-settings-defaults.c +++ b/libnm-util/tests/test-settings-defaults.c @@ -101,18 +101,9 @@ test_defaults (GType type, const char *name) g_object_unref (setting); } -int main (int argc, char **argv) +static void +defaults (void) { - GError *error = NULL; - char *base; - -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif - - if (!nm_utils_init (&error)) - FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message); - /* The tests */ test_defaults (NM_TYPE_SETTING_CONNECTION, NM_SETTING_CONNECTION_SETTING_NAME); test_defaults (NM_TYPE_SETTING_802_1X, NM_SETTING_802_1X_SETTING_NAME); @@ -127,10 +118,16 @@ int main (int argc, char **argv) test_defaults (NM_TYPE_SETTING_WIRED, NM_SETTING_WIRED_SETTING_NAME); test_defaults (NM_TYPE_SETTING_WIRELESS, NM_SETTING_WIRELESS_SETTING_NAME); test_defaults (NM_TYPE_SETTING_WIRELESS_SECURITY, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME); - - base = g_path_get_basename (argv[0]); - fprintf (stdout, "%s: SUCCESS\n", base); - g_free (base); - return 0; } +NMTST_DEFINE (); + +int +main (int argc, char **argv) +{ + nmtst_init (&argc, &argv, TRUE); + + g_test_add_func ("/libnm/defaults", defaults); + + return g_test_run (); +} 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 13f1126e48..68f236afbe 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 @@ -115,15 +115,9 @@ test_ignored (const char *desc, const char *path, gboolean expected_ignored) ASSERT (result == expected_ignored, desc, "unexpected ignore result for path '%s'", path); } -NMTST_DEFINE (); - -int main (int argc, char **argv) +static void +test_name (void) { - char *base; - - nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); - - /* The tests */ test_get_ifcfg_name ("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL); test_get_ifcfg_name ("get-ifcfg-name-good", "/foo/bar/ifcfg-FooBar", FALSE, "FooBar"); test_get_ifcfg_name ("get-ifcfg-name-keys", "/foo/bar/keys-BlahLbah", FALSE, "BlahLbah"); @@ -137,7 +131,11 @@ int main (int argc, char **argv) test_get_ifcfg_name ("get-ifcfg-name-bad2-ifcfg", "/foo/bar/asdfasifcfg-Foobar", FALSE, NULL); test_get_ifcfg_name ("get-ifcfg-name-bad2-keys", "/foo/bar/asdfaskeys-Foobar", FALSE, NULL); test_get_ifcfg_name ("get-ifcfg-name-bad2-route", "/foo/bar/asdfasroute-Foobar", FALSE, NULL); +} +static void +test_path (void) +{ test_get_ifcfg_path ("ifcfg-path-bad", "/foo/bar/adfasdfasdf", NULL); test_get_ifcfg_path ("ifcfg-path-from-keys-no-path", "keys-BlahBlah", "ifcfg-BlahBlah"); test_get_ifcfg_path ("ifcfg-path-from-keys", "/foo/bar/keys-BlahBlah", "/foo/bar/ifcfg-BlahBlah"); @@ -152,7 +150,11 @@ int main (int argc, char **argv) test_get_route_path ("route-path-from-ifcfg-no-path", "ifcfg-FooBar", "route-FooBar"); test_get_route_path ("route-path-from-ifcfg", "/foo/bar/ifcfg-FooBar", "/foo/bar/route-FooBar"); test_get_route_path ("route-path-from-keys", "/foo/bar/keys-FooBar", "/foo/bar/route-FooBar"); +} +static void +test_ignore (void) +{ test_ignored ("ignored-ifcfg", "ifcfg-FooBar", FALSE); test_ignored ("ignored-keys", "keys-FooBar", FALSE); test_ignored ("ignored-route", "route-FooBar", FALSE); @@ -163,10 +165,19 @@ int main (int argc, char **argv) test_ignored ("ignored-rpmnew", "ifcfg-FooBar" RPMNEW_TAG, TRUE); test_ignored ("ignored-augnew", "ifcfg-FooBar" AUGNEW_TAG, TRUE); test_ignored ("ignored-augtmp", "ifcfg-FooBar" AUGTMP_TAG, TRUE); - - base = g_path_get_basename (argv[0]); - fprintf (stdout, "%s: SUCCESS\n", base); - g_free (base); - return 0; +} + +NMTST_DEFINE (); + +int main (int argc, char **argv) +{ + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); + + /* The tests */ + g_test_add_func ("/settings/plugins/ifcfg-rh/name", test_name); + g_test_add_func ("/settings/plugins/ifcfg-rh/path", test_path); + g_test_add_func ("/settings/plugins/ifcfg-rh/ignore", test_ignore); + + return g_test_run (); } From 0e20868f4f9db79380f952482e4554e52069f5d8 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 14 May 2015 14:39:23 +0200 Subject: [PATCH 06/18] tests: always spawn private d-bus Parallel test runs would not be possible without this. (cherry picked from commit d0e25ac8be339e4ddcae93978281493d6dee551c) --- libnm-glib/tests/libnm-glib-test-launch.sh | 8 +++----- libnm/tests/libnm-test-launch.sh | 8 +++----- tools/run-test-valgrind.sh | 8 +++----- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/libnm-glib/tests/libnm-glib-test-launch.sh b/libnm-glib/tests/libnm-glib-test-launch.sh index 42d9fbe26d..980f8345e9 100755 --- a/libnm-glib/tests/libnm-glib-test-launch.sh +++ b/libnm-glib/tests/libnm-glib-test-launch.sh @@ -1,9 +1,7 @@ #!/bin/sh -# Spawn DBus if there's none -if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then - eval `dbus-launch --sh-syntax` - trap "kill $DBUS_SESSION_BUS_PID" EXIT -fi +# Spawn DBus +eval `dbus-launch --sh-syntax` +trap "kill $DBUS_SESSION_BUS_PID" EXIT "$@" diff --git a/libnm/tests/libnm-test-launch.sh b/libnm/tests/libnm-test-launch.sh index 42d9fbe26d..980f8345e9 100755 --- a/libnm/tests/libnm-test-launch.sh +++ b/libnm/tests/libnm-test-launch.sh @@ -1,9 +1,7 @@ #!/bin/sh -# Spawn DBus if there's none -if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then - eval `dbus-launch --sh-syntax` - trap "kill $DBUS_SESSION_BUS_PID" EXIT -fi +# Spawn DBus +eval `dbus-launch --sh-syntax` +trap "kill $DBUS_SESSION_BUS_PID" EXIT "$@" diff --git a/tools/run-test-valgrind.sh b/tools/run-test-valgrind.sh index 200a27d13c..f9f9646eb9 100755 --- a/tools/run-test-valgrind.sh +++ b/tools/run-test-valgrind.sh @@ -4,11 +4,9 @@ LIBTOOL="$1"; shift VALGRIND="$1"; shift SUPPRESSIONS="$1"; shift if [ "$1" = "--launch-dbus" ]; then - # Spawn DBus if there's none - if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then - eval `dbus-launch --sh-syntax` - trap "kill $DBUS_SESSION_BUS_PID" EXIT - fi + # Spawn DBus + eval `dbus-launch --sh-syntax` + trap "kill $DBUS_SESSION_BUS_PID" EXIT shift fi TEST="$1"; shift From 30d37abbc012886089a674f329b693f47caac12c Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 14 May 2015 14:43:05 +0200 Subject: [PATCH 07/18] tests: call g_test_run() even when skipping the test It will return the 77 exit code itself. For TAP output it will also generate the proper test skip marker. (cherry picked from commit 14f4674f64310509a18dc2812759d8f77994b70f) --- include/nm-test-utils.h | 3 --- src/platform/tests/test-common.c | 2 +- src/rdisc/tests/test-rdisc-fake.c | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index 36b0cbd9df..7d5a35aa36 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -97,9 +97,6 @@ #include "gsystem-local-alloc.h" -/* Analog to EXIT_SUCCESS and EXIT_FAILURE. */ -#define EXIT_SKIP (77) - /*******************************************************************************/ /* general purpose functions that have no dependency on other nmtst functions */ diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index 2d37fb837d..2eda47cc8b 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -295,7 +295,7 @@ main (int argc, char **argv) return EXIT_FAILURE; #else g_print ("Skipping test: requires root privileges (%s)\n", program); - return EXIT_SKIP; + return g_test_run (); #endif } diff --git a/src/rdisc/tests/test-rdisc-fake.c b/src/rdisc/tests/test-rdisc-fake.c index 3b525203a2..33672637d0 100644 --- a/src/rdisc/tests/test-rdisc-fake.c +++ b/src/rdisc/tests/test-rdisc-fake.c @@ -439,7 +439,7 @@ main (int argc, char **argv) if (nmtst_test_quick ()) { g_print ("Skipping test: don't run long running test %s (NMTST_DEBUG=slow)\n", str_if_set (g_get_prgname (), "test-rdisc-fake")); - return EXIT_SKIP; + return g_test_run (); } nm_fake_platform_setup (); From df11b267fd2981d0796c0ec25bfd4674ca805aec Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 14 May 2015 14:45:45 +0200 Subject: [PATCH 08/18] build: switch to parallel test harness This will make it possible to use the TAP formatter. (cherry picked from commit 380ed633180a1e20cb70b2cfde482a1cda8278e0) --- .gitignore | 2 ++ configure.ac | 17 ++--------------- libnm-glib/tests/Makefile.am | 2 +- libnm/tests/Makefile.am | 2 +- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index a0511491b8..834be29407 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,8 @@ gtk-doc.make *.pc cscope.*out valgrind-*.log +test-*.log +test-*.trs *-glue.h /ABOUT-NLS diff --git a/configure.ac b/configure.ac index 5f1b62e088..44292e1ad8 100644 --- a/configure.ac +++ b/configure.ac @@ -16,20 +16,7 @@ AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR([build-aux]) -dnl Initialize automake. automake < 1.12 didn't have serial-tests and -dnl gives an error if it sees this, but for automake >= 1.13 -dnl serial-tests is required so we have to include it. Solution is to -dnl test for the version of automake (by running an external command) -dnl and provide it if necessary. Note we have to do this entirely using -dnl m4 macros since automake queries this macro by running -dnl 'autoconf --trace ...'. -m4_define([serial_tests], [ - m4_esyscmd([automake --version | - head -1 | - awk '{split ($NF,a,"."); if (a[1] == 1 && a[2] >= 12) { print "serial-tests" }}' - ]) -]) -AM_INIT_AUTOMAKE(1.11 serial_tests tar-ustar no-dist-gzip dist-bzip2 -Wno-portability) dnl NB: Do not [quote] this parameter. +AM_INIT_AUTOMAKE(1.12 tar-ustar no-dist-gzip dist-bzip2 -Wno-portability) dnl NB: Do not [quote] this parameter. AM_MAINTAINER_MODE([enable]) AM_SILENT_RULES([yes]) @@ -880,7 +867,7 @@ else fi fi AS_IF([test "$with_valgrind" != "no"], - AC_SUBST(VALGRIND_RULES, 'TESTS_ENVIRONMENT = "$(top_srcdir)/tools/run-test-valgrind.sh" "$(LIBTOOL)" "$(with_valgrind)" '"$with_valgrind_suppressions"), + AC_SUBST(VALGRIND_RULES, 'LOG_COMPILER = "$(top_srcdir)/tools/run-test-valgrind.sh" "$(LIBTOOL)" "$(with_valgrind)" '"$with_valgrind_suppressions"), AC_SUBST(VALGRIND_RULES, [])) AM_CONDITIONAL(WITH_VALGRIND, test "${with_valgrind}" != "no") diff --git a/libnm-glib/tests/Makefile.am b/libnm-glib/tests/Makefile.am index cea3b79a74..7168d3dd15 100644 --- a/libnm-glib/tests/Makefile.am +++ b/libnm-glib/tests/Makefile.am @@ -15,7 +15,7 @@ noinst_PROGRAMS = $(TESTS) if WITH_VALGRIND @VALGRIND_RULES@ --launch-dbus else -TESTS_ENVIRONMENT = $(srcdir)/libnm-glib-test-launch.sh +LOG_COMPILER = $(srcdir)/libnm-glib-test-launch.sh endif TESTS = test-nm-client test-remote-settings-client diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am index 56dd17d5f8..a2dafec768 100644 --- a/libnm/tests/Makefile.am +++ b/libnm/tests/Makefile.am @@ -20,7 +20,7 @@ noinst_PROGRAMS = $(TESTS) if WITH_VALGRIND @VALGRIND_RULES@ --launch-dbus else -TESTS_ENVIRONMENT = $(srcdir)/libnm-test-launch.sh +LOG_COMPILER = $(srcdir)/libnm-test-launch.sh endif TESTS = test-nm-client test-remote-settings-client test-secret-agent From fe3e32c0344c10ae2a0add512b409f3ee553a052 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 14 May 2015 14:45:57 +0200 Subject: [PATCH 09/18] tests: use the TAP formatter The test results in standard format are easily integrated into CI systems. (cherry picked from commit 6463ce5dd9ffc1aae3ca9ddc4dac4e25fd815237) --- callouts/tests/Makefile.am | 2 ++ configure.ac | 1 + libnm-core/tests/Makefile.am | 2 ++ libnm-glib/tests/Makefile.am | 2 ++ libnm-util/tests/Makefile.am | 2 ++ libnm/tests/Makefile.am | 2 ++ src/devices/wifi/tests/Makefile.am | 2 ++ src/dhcp-manager/tests/Makefile.am | 2 ++ src/dnsmasq-manager/tests/Makefile.am | 2 ++ src/platform/tests/Makefile.am | 3 ++- src/rdisc/tests/Makefile.am | 2 ++ src/settings/plugins/ibft/tests/Makefile.am | 2 ++ src/settings/plugins/ifcfg-rh/tests/Makefile.am | 2 ++ src/settings/plugins/ifupdown/tests/Makefile.am | 2 ++ src/settings/plugins/keyfile/tests/Makefile.am | 2 ++ src/supplicant-manager/tests/Makefile.am | 2 ++ src/tests/Makefile.am | 2 ++ src/tests/config/Makefile.am | 2 ++ tools/run-test-valgrind.sh | 4 ++-- 19 files changed, 37 insertions(+), 3 deletions(-) diff --git a/callouts/tests/Makefile.am b/callouts/tests/Makefile.am index fface33db3..89b2dd9016 100644 --- a/callouts/tests/Makefile.am +++ b/callouts/tests/Makefile.am @@ -29,6 +29,8 @@ test_dispatcher_envp_LDADD = \ ########################################### @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-dispatcher-envp endif diff --git a/configure.ac b/configure.ac index 44292e1ad8..76d9de5238 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,7 @@ AC_INIT([NetworkManager], [nm_version], AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR([build-aux]) +AC_REQUIRE_AUX_FILE([tap-driver.sh]) AM_INIT_AUTOMAKE(1.12 tar-ustar no-dist-gzip dist-bzip2 -Wno-portability) dnl NB: Do not [quote] this parameter. AM_MAINTAINER_MODE([enable]) diff --git a/libnm-core/tests/Makefile.am b/libnm-core/tests/Makefile.am index 79aa73dbf9..6b79dba80b 100644 --- a/libnm-core/tests/Makefile.am +++ b/libnm-core/tests/Makefile.am @@ -25,6 +25,8 @@ LDADD = \ $(GLIB_LIBS) @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = $(noinst_PROGRAMS) endif diff --git a/libnm-glib/tests/Makefile.am b/libnm-glib/tests/Makefile.am index 7168d3dd15..a01a50e724 100644 --- a/libnm-glib/tests/Makefile.am +++ b/libnm-glib/tests/Makefile.am @@ -17,6 +17,8 @@ if WITH_VALGRIND else LOG_COMPILER = $(srcdir)/libnm-glib-test-launch.sh endif +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-nm-client test-remote-settings-client ####### NMClient and non-settings tests ####### diff --git a/libnm-util/tests/Makefile.am b/libnm-util/tests/Makefile.am index 16a7f8f3fc..f90fe8bf6e 100644 --- a/libnm-util/tests/Makefile.am +++ b/libnm-util/tests/Makefile.am @@ -11,6 +11,8 @@ AM_CPPFLAGS = \ -DTEST_CERT_DIR=\"$(top_srcdir)/libnm-core/tests/certs/\" @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = \ test-settings-defaults \ test-crypto \ diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am index a2dafec768..0e7db21b66 100644 --- a/libnm/tests/Makefile.am +++ b/libnm/tests/Makefile.am @@ -22,6 +22,8 @@ if WITH_VALGRIND else LOG_COMPILER = $(srcdir)/libnm-test-launch.sh endif +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-nm-client test-remote-settings-client test-secret-agent test_nm_client_SOURCES = \ diff --git a/src/devices/wifi/tests/Makefile.am b/src/devices/wifi/tests/Makefile.am index 2a7d784970..72dc7189bd 100644 --- a/src/devices/wifi/tests/Makefile.am +++ b/src/devices/wifi/tests/Makefile.am @@ -24,5 +24,7 @@ test_wifi_ap_utils_SOURCES = \ test_wifi_ap_utils_LDADD = $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-wifi-ap-utils diff --git a/src/dhcp-manager/tests/Makefile.am b/src/dhcp-manager/tests/Makefile.am index 8aa79a29be..2fb39e0417 100644 --- a/src/dhcp-manager/tests/Makefile.am +++ b/src/dhcp-manager/tests/Makefile.am @@ -38,6 +38,8 @@ test_dhcp_utils_LDADD = \ ################################# @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-dhcp-dhclient test-dhcp-utils EXTRA_DIST = \ diff --git a/src/dnsmasq-manager/tests/Makefile.am b/src/dnsmasq-manager/tests/Makefile.am index b51de6aa5d..ed1225549d 100644 --- a/src/dnsmasq-manager/tests/Makefile.am +++ b/src/dnsmasq-manager/tests/Makefile.am @@ -20,5 +20,7 @@ test_dnsmasq_utils_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-dnsmasq-utils diff --git a/src/platform/tests/Makefile.am b/src/platform/tests/Makefile.am index 081023c63d..bc032d212e 100644 --- a/src/platform/tests/Makefile.am +++ b/src/platform/tests/Makefile.am @@ -109,8 +109,9 @@ test_cleanup_linux_CPPFLAGS = \ -DKERNEL_HACKS=1 test_cleanup_linux_LDADD = $(PLATFORM_LDADD) - @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = \ test-address-fake \ test-address-linux \ diff --git a/src/rdisc/tests/Makefile.am b/src/rdisc/tests/Makefile.am index 5d6f8b5bcb..e10b34f003 100644 --- a/src/rdisc/tests/Makefile.am +++ b/src/rdisc/tests/Makefile.am @@ -33,5 +33,7 @@ test_rdisc_fake_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-rdisc-fake diff --git a/src/settings/plugins/ibft/tests/Makefile.am b/src/settings/plugins/ibft/tests/Makefile.am index 3c7c94accd..e7285e0e95 100644 --- a/src/settings/plugins/ibft/tests/Makefile.am +++ b/src/settings/plugins/ibft/tests/Makefile.am @@ -33,6 +33,8 @@ test_ibft_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-ibft endif diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am index a3f6a05204..f629830813 100644 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am @@ -48,6 +48,8 @@ test_ifcfg_rh_utils_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-ifcfg-rh-utils test-ifcfg-rh endif diff --git a/src/settings/plugins/ifupdown/tests/Makefile.am b/src/settings/plugins/ifupdown/tests/Makefile.am index 2e927db931..e43a5113df 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.am +++ b/src/settings/plugins/ifupdown/tests/Makefile.am @@ -25,6 +25,8 @@ test_ifupdown_LDADD = \ # TODO: enable valgrind for ifupdown. Currently it fails. #@VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-ifupdown endif diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index a79e20b5b6..dffa276eb0 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -35,6 +35,8 @@ test_keyfile_LDADD = \ $(CODE_COVERAGE_LDFLAGS) @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-keyfile endif diff --git a/src/supplicant-manager/tests/Makefile.am b/src/supplicant-manager/tests/Makefile.am index 85268dcff9..d53b7ff4c7 100644 --- a/src/supplicant-manager/tests/Makefile.am +++ b/src/supplicant-manager/tests/Makefile.am @@ -19,4 +19,6 @@ test_supplicant_config_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-supplicant-config diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index a96d1ce910..85d6d4cad9 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -87,6 +87,8 @@ EXTRA_DIST = test-secret-agent.py ########################################### @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = \ test-ip4-config \ test-ip6-config \ diff --git a/src/tests/config/Makefile.am b/src/tests/config/Makefile.am index 42c6b9a1b0..5936624cea 100644 --- a/src/tests/config/Makefile.am +++ b/src/tests/config/Makefile.am @@ -24,6 +24,8 @@ test_config_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ +AM_TESTS_FD_REDIRECT = --tap +LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-config EXTRA_DIST = \ diff --git a/tools/run-test-valgrind.sh b/tools/run-test-valgrind.sh index f9f9646eb9..e723d75fbc 100755 --- a/tools/run-test-valgrind.sh +++ b/tools/run-test-valgrind.sh @@ -9,7 +9,7 @@ if [ "$1" = "--launch-dbus" ]; then trap "kill $DBUS_SESSION_BUS_PID" EXIT shift fi -TEST="$1"; shift +TEST="$1" if [ "$NMTST_NO_VALGRIND" != "" ]; then "$TEST" @@ -27,7 +27,7 @@ $LIBTOOL --mode=execute "$VALGRIND" \ --gen-suppressions=all \ --suppressions="$SUPPRESSIONS" \ --log-file="$LOGFILE" \ - "$TEST" + "$@" RESULT=$? if [ $RESULT -eq 0 -a "$(wc -c "$LOGFILE" | awk '{print$1}')" -ne 0 ]; then From 38b2331440342a2cb350113818365efc72b64091 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 26 May 2015 15:34:03 +0200 Subject: [PATCH 10/18] test: fix running valgrind tests with NMTST_NO_VALGRIND Fixes: 6463ce5dd9ffc1aae3ca9ddc4dac4e25fd815237 (cherry picked from commit ce3d1533cc9aaed14bfa8c03fe66365f2dc1e352) --- tools/run-test-valgrind.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run-test-valgrind.sh b/tools/run-test-valgrind.sh index e723d75fbc..fe7b621f44 100755 --- a/tools/run-test-valgrind.sh +++ b/tools/run-test-valgrind.sh @@ -12,7 +12,7 @@ fi TEST="$1" if [ "$NMTST_NO_VALGRIND" != "" ]; then - "$TEST" + "$@" exit $? fi From 2829fadcc1b66679ed484024741c69e0c9e19097 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 25 May 2015 17:15:33 +0200 Subject: [PATCH 11/18] tests: be a bit more helpful when valgrind tests fail (cherry picked from commit dd959087a2aaf4ba3b3b222d65518c98cef930c3) --- tools/run-test-valgrind.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/run-test-valgrind.sh b/tools/run-test-valgrind.sh index fe7b621f44..1b4e2c2f9b 100755 --- a/tools/run-test-valgrind.sh +++ b/tools/run-test-valgrind.sh @@ -36,7 +36,19 @@ if [ $RESULT -eq 0 -a "$(wc -c "$LOGFILE" | awk '{print$1}')" -ne 0 ]; then fi if [ $RESULT -ne 0 -a $RESULT -ne 77 ]; then - echo "Don't forget to check the valgrind log at '`realpath $LOGFILE`'." >&2 + echo "valgrind failed! Check the log at '`realpath $LOGFILE`'." >&2 + UNRESOLVED=$(awk -F: '/obj:\// {print $NF}' "$LOGFILE" | sort | uniq) + if [ -n "$UNRESOLVED" ]; then + echo Some addresses could not be resolved into symbols. >&2 + echo The errors might get suppressed when you install the debuging symbols. >&2 + if [ -x /usr/bin/dnf ]; then + echo Hint: dnf debuginfo-install $UNRESOLVED >&2 + elif [ -x /usr/bin/debuginfo-install ]; then + echo Hint: debuginfo-install $UNRESOLVED >&2 + else + echo Files without debugging symbols: $UNRESOLVED >&2 + fi + fi fi exit $RESULT From c099e9d43b2d59af27b68b3a3fb7e5aa078e2244 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 26 May 2015 13:25:23 +0200 Subject: [PATCH 12/18] tests: don't try to connect to the private socket Even if we're running the tests as root we still want to use the mock service instead of whatever version of daemon runs on the test host. (cherry picked from commit 02e3d6c2866402549c6976f564eb663ff12d3ebd) --- libnm/nm-dbus-helpers.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libnm/nm-dbus-helpers.c b/libnm/nm-dbus-helpers.c index 6bfd4bbd83..a9fc58edf3 100644 --- a/libnm/nm-dbus-helpers.c +++ b/libnm/nm-dbus-helpers.c @@ -93,7 +93,8 @@ _nm_dbus_new_connection (GCancellable *cancellable, GError **error) GDBusConnection *connection = NULL; /* If running as root try the private bus first */ - if (0 == geteuid ()) { + if (0 == geteuid () && !g_test_initialized ()) { + GError *local = NULL; GDBusConnection *p; @@ -203,7 +204,7 @@ _nm_dbus_new_connection_async (GCancellable *cancellable, simple = g_simple_async_result_new (NULL, callback, user_data, _nm_dbus_new_connection_async); /* If running as root try the private bus first */ - if (0 == geteuid ()) { + if (0 == geteuid () && !g_test_initialized ()) { GDBusConnection *p; if (cancellable) { From 0f95b5c3452d72b50b89600a83f96ef61dd13e4f Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Tue, 26 May 2015 15:21:12 +0200 Subject: [PATCH 13/18] builds: only enable TAP driver for glib >= 2.37.6 No TAP support for previous versions and --tap argument is silently ignored, confusing the TAP driver. (cherry picked from commit c47c06470a0de70f5495d8919fd7f6b5369a5070) --- callouts/tests/Makefile.am | 2 -- configure.ac | 6 +++++- libnm-core/tests/Makefile.am | 2 -- libnm-glib/tests/Makefile.am | 2 -- libnm-util/tests/Makefile.am | 2 -- libnm/tests/Makefile.am | 2 -- src/devices/wifi/tests/Makefile.am | 2 -- src/dhcp-manager/tests/Makefile.am | 2 -- src/dnsmasq-manager/tests/Makefile.am | 2 -- src/platform/tests/Makefile.am | 2 -- src/rdisc/tests/Makefile.am | 2 -- src/settings/plugins/ibft/tests/Makefile.am | 2 -- src/settings/plugins/ifcfg-rh/tests/Makefile.am | 2 -- src/settings/plugins/ifupdown/tests/Makefile.am | 2 -- src/settings/plugins/keyfile/tests/Makefile.am | 2 -- src/supplicant-manager/tests/Makefile.am | 2 -- src/tests/Makefile.am | 2 -- src/tests/config/Makefile.am | 2 -- 18 files changed, 5 insertions(+), 35 deletions(-) diff --git a/callouts/tests/Makefile.am b/callouts/tests/Makefile.am index 89b2dd9016..fface33db3 100644 --- a/callouts/tests/Makefile.am +++ b/callouts/tests/Makefile.am @@ -29,8 +29,6 @@ test_dispatcher_envp_LDADD = \ ########################################### @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-dispatcher-envp endif diff --git a/configure.ac b/configure.ac index 76d9de5238..9e4c96d6b1 100644 --- a/configure.ac +++ b/configure.ac @@ -255,7 +255,11 @@ else fi AM_CONDITIONAL(HAVE_DBUS_GLIB_100, test "${have_dbus_glib_100}" = "yes") -PKG_CHECK_MODULES(GLIB, gio-unix-2.0 >= 2.32 gmodule-2.0) +PKG_CHECK_MODULES(GLIB, [gio-unix-2.0 >= 2.37.6 gmodule-2.0], + [AC_SUBST(LOG_DRIVER, '$(top_srcdir)/build-aux/tap-driver.sh'), + AC_SUBST(AM_TESTS_FD_REDIRECT, '--tap')], + [PKG_CHECK_MODULES(GLIB, gio-unix-2.0 >= 2.32 gmodule-2.0) + AC_SUBST(LOG_DRIVER, '$(top_srcdir)/build-aux/test-driver')]) dnl GLIB_VERSION_MIN_REQUIRED should match the version above. dnl GLIB_VERSION_MAX_ALLOWED should be set to the same version; diff --git a/libnm-core/tests/Makefile.am b/libnm-core/tests/Makefile.am index 6b79dba80b..79aa73dbf9 100644 --- a/libnm-core/tests/Makefile.am +++ b/libnm-core/tests/Makefile.am @@ -25,8 +25,6 @@ LDADD = \ $(GLIB_LIBS) @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = $(noinst_PROGRAMS) endif diff --git a/libnm-glib/tests/Makefile.am b/libnm-glib/tests/Makefile.am index a01a50e724..7168d3dd15 100644 --- a/libnm-glib/tests/Makefile.am +++ b/libnm-glib/tests/Makefile.am @@ -17,8 +17,6 @@ if WITH_VALGRIND else LOG_COMPILER = $(srcdir)/libnm-glib-test-launch.sh endif -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-nm-client test-remote-settings-client ####### NMClient and non-settings tests ####### diff --git a/libnm-util/tests/Makefile.am b/libnm-util/tests/Makefile.am index f90fe8bf6e..16a7f8f3fc 100644 --- a/libnm-util/tests/Makefile.am +++ b/libnm-util/tests/Makefile.am @@ -11,8 +11,6 @@ AM_CPPFLAGS = \ -DTEST_CERT_DIR=\"$(top_srcdir)/libnm-core/tests/certs/\" @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = \ test-settings-defaults \ test-crypto \ diff --git a/libnm/tests/Makefile.am b/libnm/tests/Makefile.am index 0e7db21b66..a2dafec768 100644 --- a/libnm/tests/Makefile.am +++ b/libnm/tests/Makefile.am @@ -22,8 +22,6 @@ if WITH_VALGRIND else LOG_COMPILER = $(srcdir)/libnm-test-launch.sh endif -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-nm-client test-remote-settings-client test-secret-agent test_nm_client_SOURCES = \ diff --git a/src/devices/wifi/tests/Makefile.am b/src/devices/wifi/tests/Makefile.am index 72dc7189bd..2a7d784970 100644 --- a/src/devices/wifi/tests/Makefile.am +++ b/src/devices/wifi/tests/Makefile.am @@ -24,7 +24,5 @@ test_wifi_ap_utils_SOURCES = \ test_wifi_ap_utils_LDADD = $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-wifi-ap-utils diff --git a/src/dhcp-manager/tests/Makefile.am b/src/dhcp-manager/tests/Makefile.am index 2fb39e0417..8aa79a29be 100644 --- a/src/dhcp-manager/tests/Makefile.am +++ b/src/dhcp-manager/tests/Makefile.am @@ -38,8 +38,6 @@ test_dhcp_utils_LDADD = \ ################################# @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-dhcp-dhclient test-dhcp-utils EXTRA_DIST = \ diff --git a/src/dnsmasq-manager/tests/Makefile.am b/src/dnsmasq-manager/tests/Makefile.am index ed1225549d..b51de6aa5d 100644 --- a/src/dnsmasq-manager/tests/Makefile.am +++ b/src/dnsmasq-manager/tests/Makefile.am @@ -20,7 +20,5 @@ test_dnsmasq_utils_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-dnsmasq-utils diff --git a/src/platform/tests/Makefile.am b/src/platform/tests/Makefile.am index bc032d212e..92400f9091 100644 --- a/src/platform/tests/Makefile.am +++ b/src/platform/tests/Makefile.am @@ -110,8 +110,6 @@ test_cleanup_linux_CPPFLAGS = \ test_cleanup_linux_LDADD = $(PLATFORM_LDADD) @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = \ test-address-fake \ test-address-linux \ diff --git a/src/rdisc/tests/Makefile.am b/src/rdisc/tests/Makefile.am index e10b34f003..5d6f8b5bcb 100644 --- a/src/rdisc/tests/Makefile.am +++ b/src/rdisc/tests/Makefile.am @@ -33,7 +33,5 @@ test_rdisc_fake_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-rdisc-fake diff --git a/src/settings/plugins/ibft/tests/Makefile.am b/src/settings/plugins/ibft/tests/Makefile.am index e7285e0e95..3c7c94accd 100644 --- a/src/settings/plugins/ibft/tests/Makefile.am +++ b/src/settings/plugins/ibft/tests/Makefile.am @@ -33,8 +33,6 @@ test_ibft_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-ibft endif diff --git a/src/settings/plugins/ifcfg-rh/tests/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/Makefile.am index f629830813..a3f6a05204 100644 --- a/src/settings/plugins/ifcfg-rh/tests/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/Makefile.am @@ -48,8 +48,6 @@ test_ifcfg_rh_utils_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-ifcfg-rh-utils test-ifcfg-rh endif diff --git a/src/settings/plugins/ifupdown/tests/Makefile.am b/src/settings/plugins/ifupdown/tests/Makefile.am index e43a5113df..2e927db931 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.am +++ b/src/settings/plugins/ifupdown/tests/Makefile.am @@ -25,8 +25,6 @@ test_ifupdown_LDADD = \ # TODO: enable valgrind for ifupdown. Currently it fails. #@VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-ifupdown endif diff --git a/src/settings/plugins/keyfile/tests/Makefile.am b/src/settings/plugins/keyfile/tests/Makefile.am index dffa276eb0..a79e20b5b6 100644 --- a/src/settings/plugins/keyfile/tests/Makefile.am +++ b/src/settings/plugins/keyfile/tests/Makefile.am @@ -35,8 +35,6 @@ test_keyfile_LDADD = \ $(CODE_COVERAGE_LDFLAGS) @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-keyfile endif diff --git a/src/supplicant-manager/tests/Makefile.am b/src/supplicant-manager/tests/Makefile.am index d53b7ff4c7..85268dcff9 100644 --- a/src/supplicant-manager/tests/Makefile.am +++ b/src/supplicant-manager/tests/Makefile.am @@ -19,6 +19,4 @@ test_supplicant_config_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-supplicant-config diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 85d6d4cad9..a96d1ce910 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -87,8 +87,6 @@ EXTRA_DIST = test-secret-agent.py ########################################### @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = \ test-ip4-config \ test-ip6-config \ diff --git a/src/tests/config/Makefile.am b/src/tests/config/Makefile.am index 5936624cea..42c6b9a1b0 100644 --- a/src/tests/config/Makefile.am +++ b/src/tests/config/Makefile.am @@ -24,8 +24,6 @@ test_config_LDADD = \ $(top_builddir)/src/libNetworkManager.la @VALGRIND_RULES@ -AM_TESTS_FD_REDIRECT = --tap -LOG_DRIVER = $(top_srcdir)/build-aux/tap-driver.sh TESTS = test-config EXTRA_DIST = \ From dfa26cb0077eeafc84a6539e88d422152328369b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 3 Jun 2015 19:28:01 +0200 Subject: [PATCH 14/18] valgrind: add valgrind suppression for Fedora 22 Fixes for example valgrind tests for ./libnm/tests/test-nm-client: ==25772== Conditional jump or move depends on uninitialised value(s) ==25772== at 0x40198D8: index (strchr.S:106) ==25772== by 0x400777C: expand_dynamic_string_token (dl-load.c:369) ==25772== by 0x400777C: fillin_rpath (dl-load.c:439) ==25772== by 0x4007FCF: _dl_init_paths (dl-load.c:816) ==25772== by 0x4002F38: dl_main (rtld.c:1194) ==25772== by 0x401750F: _dl_sysdep_start (dl-sysdep.c:249) ==25772== by 0x4004C20: _dl_start_final (rtld.c:306) ==25772== by 0x4004C20: _dl_start (rtld.c:412) ==25772== by 0x4000C97: ??? (in /usr/lib64/ld-2.21.so) ==25772== by 0x1: ??? ==25772== by 0xFFEFFF6B2: ??? ==25772== by 0xFFEFFF6EF: ??? ==25772== { Memcheck:Cond fun:index fun:expand_dynamic_string_token fun:fillin_rpath fun:_dl_init_paths fun:dl_main fun:_dl_sysdep_start fun:_dl_start_final fun:_dl_start obj:/usr/lib64/ld-2.21.so obj:* obj:* obj:* } (cherry picked from commit d84ac1baca7912de1ce9084710830772de8edaa8) --- valgrind.suppressions | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/valgrind.suppressions b/valgrind.suppressions index 1368a6041f..7686c225e2 100644 --- a/valgrind.suppressions +++ b/valgrind.suppressions @@ -107,6 +107,20 @@ fun:_dl_init obj:/*/ld-*.so } +{ + # added on Fedora 22 + _dl_expand_dynamic_string_token + Memcheck:Cond + fun:index + fun:expand_dynamic_string_token + ... + fun:dl_main + fun:_dl_sysdep_start + fun:_dl_start_final + fun:_dl_start + obj:/*/ld-*.so + ... +} { all_gobject_init_ctor Memcheck:Leak From 4fa342aefc502afb6d26f67213130fdf2cc8e7cf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 4 Jun 2015 13:03:41 +0200 Subject: [PATCH 15/18] valgrind: add comment to valgrind suppression explaining how to reproduce (cherry picked from commit 0554474720960a12c46a4cdddd8c69d79fcbc250) --- valgrind.suppressions | 3 +++ 1 file changed, 3 insertions(+) diff --git a/valgrind.suppressions b/valgrind.suppressions index 7686c225e2..6bcd4c9d09 100644 --- a/valgrind.suppressions +++ b/valgrind.suppressions @@ -109,6 +109,9 @@ } { # added on Fedora 22 + # This happens when setting LD_LIBRARY_PATH and the linker is searching the libraries to load. + # for example: + # LD_LIBRARY_PATH=./././././././././././././././././libnm/.libs:./libnm-util/.libs:./libnm-glib/.libs _dl_expand_dynamic_string_token Memcheck:Cond fun:index From c2233f44848c61652c4e65df618e5aa0bcd2c3aa Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 4 Jun 2015 12:26:25 +0200 Subject: [PATCH 16/18] tests: don't limit the valgrind tracebacks to 12 frames The glib tracebacks are typically longer. (cherry picked from commit d909e76d9ea21c74e1db9a5e671794a0b1234ad1) --- tools/run-test-valgrind.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/run-test-valgrind.sh b/tools/run-test-valgrind.sh index 1b4e2c2f9b..0cdada7b6b 100755 --- a/tools/run-test-valgrind.sh +++ b/tools/run-test-valgrind.sh @@ -26,6 +26,7 @@ $LIBTOOL --mode=execute "$VALGRIND" \ --leak-check=full \ --gen-suppressions=all \ --suppressions="$SUPPRESSIONS" \ + --num-callers=100 \ --log-file="$LOGFILE" \ "$@" RESULT=$? From a48d92d525fd8963b119d09021686199ec4eb3f3 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Thu, 4 Jun 2015 12:30:30 +0200 Subject: [PATCH 17/18] tests: delete the valgrind logs if they're empty (cherry picked from commit df0676ab00673a76d814762d30b4fab708812b75) --- tools/run-test-valgrind.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/run-test-valgrind.sh b/tools/run-test-valgrind.sh index 0cdada7b6b..cd53306b4c 100755 --- a/tools/run-test-valgrind.sh +++ b/tools/run-test-valgrind.sh @@ -50,6 +50,9 @@ if [ $RESULT -ne 0 -a $RESULT -ne 77 ]; then echo Files without debugging symbols: $UNRESOLVED >&2 fi fi + exit $RESULT fi +find -name "$LOGFILE" -size 0 -delete + exit $RESULT From afb885300f957bdfe33387afeced40507a535b4f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 4 Jun 2015 17:24:08 +0200 Subject: [PATCH 18/18] valgrind: rework run-test-valgrind.sh script not to print unrelated message If the valgrind logfile is empty, don't log an error message with the location of the logfile. Also, if the test didn't fail due to memleaks, log a different message. (cherry picked from commit 2a5d17eb5f9fbb5ae78e6310822b12852afa2c2a) --- tools/run-test-valgrind.sh | 46 ++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/tools/run-test-valgrind.sh b/tools/run-test-valgrind.sh index cd53306b4c..ff5bc44ce3 100755 --- a/tools/run-test-valgrind.sh +++ b/tools/run-test-valgrind.sh @@ -3,6 +3,7 @@ LIBTOOL="$1"; shift VALGRIND="$1"; shift SUPPRESSIONS="$1"; shift +VALGRIND_ERROR=37 if [ "$1" = "--launch-dbus" ]; then # Spawn DBus eval `dbus-launch --sh-syntax` @@ -22,7 +23,7 @@ export G_SLICE=always-malloc export G_DEBUG=gc-friendly $LIBTOOL --mode=execute "$VALGRIND" \ --quiet \ - --error-exitcode=1 \ + --error-exitcode=$VALGRIND_ERROR \ --leak-check=full \ --gen-suppressions=all \ --suppressions="$SUPPRESSIONS" \ @@ -31,28 +32,39 @@ $LIBTOOL --mode=execute "$VALGRIND" \ "$@" RESULT=$? -if [ $RESULT -eq 0 -a "$(wc -c "$LOGFILE" | awk '{print$1}')" -ne 0 ]; then - echo "valgrind succeeded, but log is not empty: $LOGFILE" - exit 1 -fi +test -s "$LOGFILE" +HAS_ERRORS=$? if [ $RESULT -ne 0 -a $RESULT -ne 77 ]; then - echo "valgrind failed! Check the log at '`realpath $LOGFILE`'." >&2 - UNRESOLVED=$(awk -F: '/obj:\// {print $NF}' "$LOGFILE" | sort | uniq) - if [ -n "$UNRESOLVED" ]; then - echo Some addresses could not be resolved into symbols. >&2 - echo The errors might get suppressed when you install the debuging symbols. >&2 - if [ -x /usr/bin/dnf ]; then - echo Hint: dnf debuginfo-install $UNRESOLVED >&2 - elif [ -x /usr/bin/debuginfo-install ]; then - echo Hint: debuginfo-install $UNRESOLVED >&2 - else - echo Files without debugging symbols: $UNRESOLVED >&2 + if [ $HAS_ERRORS -ne 0 ]; then + rm -f "$LOGFILE" + elif [ $RESULT -ne $VALGRIND_ERROR ]; then + # the test (probably) didn't fail due to valgrind. + echo "The test failed. Also check the valgrind log at '`realpath "$LOGFILE"`'" >&2 + else + echo "valgrind failed! Check the log at '`realpath "$LOGFILE"`'" >&2 + UNRESOLVED=$(awk -F: '/obj:\// {print $NF}' "$LOGFILE" | sort | uniq) + if [ -n "$UNRESOLVED" ]; then + echo Some addresses could not be resolved into symbols. >&2 + echo The errors might get suppressed when you install the debuging symbols. >&2 + if [ -x /usr/bin/dnf ]; then + echo Hint: dnf debuginfo-install $UNRESOLVED >&2 + elif [ -x /usr/bin/debuginfo-install ]; then + echo Hint: debuginfo-install $UNRESOLVED >&2 + else + echo Files without debugging symbols: $UNRESOLVED >&2 + fi fi fi exit $RESULT fi -find -name "$LOGFILE" -size 0 -delete +if [ $HAS_ERRORS -eq 0 ]; then + # shouldn't actually happen... + echo "valgrind succeeded, but log is not empty: '`realpath "$LOGFILE"`'" >&2 + exit 1 +fi + +rm -f "$LOGFILE" exit $RESULT