summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2019-08-28 10:05:05 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2019-08-28 16:08:28 +0200
commit24741bff8b3ef97960d3ee54e7fc6257ab9a1408 (patch)
treea3120b86efe0142ba2778adc043bc85857b7f21a
parent0300c1823ae4f13d3f0c3df10edc84fc217013c7 (diff)
downloadNetworkManager-24741bff8b3ef97960d3ee54e7fc6257ab9a1408.tar.gz
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.
-rw-r--r--src/tests/test-ip4-config.c44
1 files changed, 44 insertions, 0 deletions
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
@@ -75,6 +75,49 @@ build_test_config (void)
}
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)
{
NMIP4Config *src, *dst;
@@ -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);