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 24741bff8b)
This commit is contained in:
Beniamino Galvani 2019-08-28 10:05:05 +02:00
parent faf12086c1
commit ebaf890057

View file

@ -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);