From ebaf8900579a730d137e8c0305c9f9dfaadb59cc Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Wed, 28 Aug 2019 10:05:05 +0200 Subject: [PATCH] core: add test to show nm_ipX_config_replace() bug Add test to show a wrong result of ip_ipX_config_replace() due to a bug in _nm_ip_config_add_obj(). When an address is added to the tail of the index and another address with the same id already exists, the existing object is left at the same place, breaking the order of addresses. (cherry picked from commit 24741bff8b3ef97960d3ee54e7fc6257ab9a1408) --- src/tests/test-ip4-config.c | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/tests/test-ip4-config.c b/src/tests/test-ip4-config.c index d4d0c1bbf7..0d9c055b5f 100644 --- a/src/tests/test-ip4-config.c +++ b/src/tests/test-ip4-config.c @@ -74,6 +74,49 @@ build_test_config (void) return config; } +static void +test_replace (void) +{ + gs_unref_object NMIP4Config *config1 = NULL; + gs_unref_object NMIP4Config *config2 = NULL; + NMPlatformIP4Address addr; + gboolean relevant_changes; + + config1 = nmtst_ip4_config_new (1); + + addr = *nmtst_platform_ip4_address ("172.16.0.1", NULL, 24); + addr.timestamp = 10; + addr.preferred = 3600; + addr.lifetime = 7200; + nm_ip4_config_add_address (config1, &addr); + + addr = *nmtst_platform_ip4_address ("172.16.0.2", NULL, 24); + addr.timestamp = 10; + addr.preferred = 3600; + addr.lifetime = 7200; + nm_ip4_config_add_address (config1, &addr); + + config2 = nmtst_ip4_config_new (1); + + addr = *nmtst_platform_ip4_address ("192.168.1.1", NULL, 24); + addr.timestamp = 40; + addr.preferred = 60; + addr.lifetime = 120; + nm_ip4_config_add_address (config2, &addr); + + addr = *nmtst_platform_ip4_address ("172.16.0.2", NULL, 24); + addr.timestamp = 40; + addr.preferred = 60; + addr.lifetime = 120; + nm_ip4_config_add_address (config2, &addr); + + g_assert (nm_ip4_config_replace (config2, config1, &relevant_changes)); + g_assert (relevant_changes); + + /* FIXME: this currently fails due to a bug in replace() */ + g_assert (!nm_ip4_config_equal (config1, config2)); +} + static void test_subtract (void) { @@ -339,6 +382,7 @@ main (int argc, char **argv) { nmtst_init_with_logging (&argc, &argv, NULL, "DEFAULT"); + g_test_add_func ("/ip4-config/replace", test_replace); g_test_add_func ("/ip4-config/subtract", test_subtract); g_test_add_func ("/ip4-config/compare-with-source", test_compare_with_source); g_test_add_func ("/ip4-config/add-address-with-source", test_add_address_with_source);