libnm/client/test: always run the cleanup test

The part where a device was created and its cleanup on client
description was only run randomly.

This is silly and gave me hard time. No reason not to be always running
it.
This commit is contained in:
Lubomir Rintel 2022-11-11 22:19:41 +01:00
parent 253bb3579f
commit d3490a92db

View file

@ -791,50 +791,15 @@ activate_cb(GObject *object, GAsyncResult *result, gpointer user_data)
g_main_loop_quit(info->loop);
}
static void
_dev_eth0_1_state_changed_cb(NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
int *p_count_call)
static NMClient *
_activate_virtual(NMTstcServiceInfo *sinfo)
{
const GPtrArray *arr;
g_assert(p_count_call);
g_assert_cmpint(*p_count_call, ==, 0);
(*p_count_call)++;
g_assert(NM_IS_DEVICE_VLAN(device));
g_assert_cmpint(old_state, >=, NM_DEVICE_STATE_PREPARE);
g_assert_cmpint(old_state, <=, NM_DEVICE_STATE_ACTIVATED);
g_assert_cmpint(new_state, ==, NM_DEVICE_STATE_UNKNOWN);
arr = nm_device_get_available_connections(device);
g_assert(arr);
g_assert_cmpint(arr->len, ==, 0);
g_assert(!nm_device_get_active_connection(device));
}
static void
test_activate_virtual(void)
{
nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL;
gs_unref_object NMClient *client = NULL;
NMConnection *conn;
NMSettingConnection *s_con;
NMSettingVlan *s_vlan;
TestACInfo info = {gl.loop, NULL, 0};
TestConnectionInfo conn_info = {gl.loop, NULL};
if (nmtst_test_skip_slow())
return;
sinfo = nmtstc_service_init();
if (!nmtstc_service_available(sinfo))
return;
NMClient *client = NULL;
NMConnection *conn;
NMSettingConnection *s_con;
NMSettingVlan *s_vlan;
TestACInfo info = {gl.loop, NULL, 0};
TestConnectionInfo conn_info = {gl.loop, NULL};
client = nmtstc_client_new(TRUE);
@ -881,55 +846,107 @@ test_activate_virtual(void)
nm_clear_g_signal_handler(info.device, &info.ac_signal_id);
}
if (nmtst_get_rand_bool()) {
/* OK, enough for this run. Let's see whether we can tear down
* successfully at this point. */
return client;
}
static void
test_activate_virtual(void)
{
nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL;
if (nmtst_test_skip_slow())
return;
}
{
NMDevice *dev_eth0_1;
NMActiveConnection *ac;
const GPtrArray *arr;
gulong sig_id;
int call_count = 0;
gboolean take_ref = nmtst_get_rand_bool();
sinfo = nmtstc_service_init();
if (!nmtstc_service_available(sinfo))
return;
/* ensure we got all the necessary events in place. */
nmtst_main_loop_run(gl.loop, 50);
g_object_unref(_activate_virtual(sinfo));
}
dev_eth0_1 = nm_client_get_device_by_iface(client, "eth0.1");
g_assert(NM_IS_DEVICE_VLAN(dev_eth0_1));
if (take_ref)
g_object_ref(dev_eth0_1);
static void
_dev_eth0_1_state_changed_cb(NMDevice *device,
NMDeviceState new_state,
NMDeviceState old_state,
NMDeviceStateReason reason,
int *p_count_call)
{
const GPtrArray *arr;
g_assert(p_count_call);
g_assert_cmpint(*p_count_call, ==, 0);
(*p_count_call)++;
g_assert(NM_IS_DEVICE_VLAN(device));
g_assert_cmpint(old_state, >=, NM_DEVICE_STATE_PREPARE);
g_assert_cmpint(old_state, <=, NM_DEVICE_STATE_ACTIVATED);
g_assert_cmpint(new_state, ==, NM_DEVICE_STATE_UNKNOWN);
arr = nm_device_get_available_connections(device);
g_assert(arr);
g_assert_cmpint(arr->len, ==, 0);
g_assert(!nm_device_get_active_connection(device));
}
static void
test_activate_virtual_teardown(void)
{
nmtstc_auto_service_cleanup NMTstcServiceInfo *sinfo = NULL;
gs_unref_object NMClient *client = NULL;
NMDevice *dev_eth0_1;
NMActiveConnection *ac;
const GPtrArray *arr;
gulong sig_id;
int call_count = 0;
gboolean take_ref = nmtst_get_rand_bool();
if (nmtst_test_skip_slow())
return;
sinfo = nmtstc_service_init();
if (!nmtstc_service_available(sinfo))
return;
client = _activate_virtual(sinfo);
/* ensure we got all the necessary events in place. */
nmtst_main_loop_run(gl.loop, 50);
dev_eth0_1 = nm_client_get_device_by_iface(client, "eth0.1");
g_assert(NM_IS_DEVICE_VLAN(dev_eth0_1));
if (take_ref)
g_object_ref(dev_eth0_1);
arr = nm_device_get_available_connections(dev_eth0_1);
g_assert(arr);
g_assert_cmpint(arr->len, ==, 1);
ac = nm_device_get_active_connection(dev_eth0_1);
g_assert(NM_IS_ACTIVE_CONNECTION(ac));
sig_id = g_signal_connect(dev_eth0_1,
"state-changed",
G_CALLBACK(_dev_eth0_1_state_changed_cb),
&call_count);
g_clear_object(&client);
g_assert_cmpint(call_count, ==, 1);
if (take_ref) {
arr = nm_device_get_available_connections(dev_eth0_1);
g_assert(arr);
g_assert_cmpint(arr->len, ==, 1);
g_assert_cmpint(arr->len, ==, 0);
ac = nm_device_get_active_connection(dev_eth0_1);
g_assert(NM_IS_ACTIVE_CONNECTION(ac));
g_assert(!nm_device_get_active_connection(dev_eth0_1));
sig_id = g_signal_connect(dev_eth0_1,
"state-changed",
G_CALLBACK(_dev_eth0_1_state_changed_cb),
&call_count);
nm_clear_g_signal_handler(dev_eth0_1, &sig_id);
g_clear_object(&client);
g_assert_cmpint(call_count, ==, 1);
if (take_ref) {
arr = nm_device_get_available_connections(dev_eth0_1);
g_assert(arr);
g_assert_cmpint(arr->len, ==, 0);
g_assert(!nm_device_get_active_connection(dev_eth0_1));
nm_clear_g_signal_handler(dev_eth0_1, &sig_id);
g_object_unref(dev_eth0_1);
}
g_object_unref(dev_eth0_1);
}
}
@ -1603,7 +1620,8 @@ main(int argc, char **argv)
g_test_add_func("/libnm/devices-array", test_devices_array);
g_test_add_func("/libnm/client-nm-running", test_client_nm_running);
g_test_add_func("/libnm/active-connections", test_active_connections);
g_test_add_func("/libnm/activate-virtual", test_activate_virtual);
g_test_add_func("/libnm/activate-virtual/without-teardown", test_activate_virtual);
g_test_add_func("/libnm/activate-virtual/with-teardown", test_activate_virtual_teardown);
g_test_add_func("/libnm/device-connection-compatibility", test_device_connection_compatibility);
g_test_add_func("/libnm/connection/invalid", test_connection_invalid);
g_test_add_func("/libnm/test_client_wait_shutdown", test_client_wait_shutdown);