|
Packit Service |
a1bd4f |
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2015 - 2017 Red Hat, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-default.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include <libudev.h>
|
|
Packit |
5756e2 |
#include <linux/pkt_sched.h>
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "platform/nmp-object.h"
|
|
Packit |
5756e2 |
#include "nm-udev-aux/nm-udev-utils.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-test-utils-core.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
struct {
|
|
Packit Service |
a1bd4f |
GList *udev_devices;
|
|
Packit |
5756e2 |
} global;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_obj_base(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
static const union {
|
|
Packit Service |
a1bd4f |
GObject g;
|
|
Packit Service |
a1bd4f |
NMPObject k;
|
|
Packit Service |
a1bd4f |
} x = {};
|
|
Packit Service |
a1bd4f |
static const union {
|
|
Packit Service |
a1bd4f |
GTypeClass k;
|
|
Packit Service |
a1bd4f |
NMPClass c;
|
|
Packit Service |
a1bd4f |
} l = {};
|
|
Packit Service |
a1bd4f |
static const GObject * g = &x.;;
|
|
Packit Service |
a1bd4f |
static const GTypeClass *k = &l.;;
|
|
Packit Service |
a1bd4f |
static const NMPObject * o = &x.;;
|
|
Packit Service |
a1bd4f |
static const NMPClass * c = &l.;;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
NMObjBaseInst * obj;
|
|
Packit Service |
a1bd4f |
gs_unref_object GCancellable *obj_cancellable = g_cancellable_new();
|
|
Packit Service |
a1bd4f |
nm_auto_nmpobj NMPObject *obj_link = nmp_object_new_link(10);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(&g->g_type_instance == (void *) &o->_class);
|
|
Packit Service |
a1bd4f |
g_assert(&g->g_type_instance.g_class == (void *) &o->_class);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(sizeof(o->parent.parent) == sizeof(GTypeInstance));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(&c->parent == (void *) c);
|
|
Packit Service |
a1bd4f |
g_assert(&c->parent.parent.g_type_class == (void *) c);
|
|
Packit Service |
a1bd4f |
g_assert(&c->parent.parent.g_type == (void *) c);
|
|
Packit Service |
a1bd4f |
g_assert(&c->parent.parent.g_type == &k->g_type);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(sizeof(c->parent.parent) == sizeof(GTypeClass));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(&o->parent == (void *) o);
|
|
Packit Service |
a1bd4f |
g_assert(&o->parent.klass == (void *) &o->_class);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
obj = (NMObjBaseInst *) obj_cancellable;
|
|
Packit Service |
a1bd4f |
g_assert(!NMP_CLASS_IS_VALID((NMPClass *) obj->klass));
|
|
Packit Service |
a1bd4f |
g_assert(G_TYPE_CHECK_INSTANCE_TYPE(obj, G_TYPE_CANCELLABLE));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
obj = (NMObjBaseInst *) obj_link;
|
|
Packit Service |
a1bd4f |
g_assert(NMP_CLASS_IS_VALID((NMPClass *) obj->klass));
|
|
Packit Service |
a1bd4f |
g_assert(!G_TYPE_CHECK_INSTANCE_TYPE(obj, G_TYPE_CANCELLABLE));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
_nmp_object_id_equal(const NMPObject *a, const NMPObject *b)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
gboolean a_b = nmp_object_id_equal(a, b);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_assert(NM_IN_SET(a_b, FALSE, TRUE) && a_b == nmp_object_id_equal(b, a));
|
|
Packit Service |
a1bd4f |
return a_b;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
#define nmp_object_id_equal _nmp_object_id_equal
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static gboolean
|
|
Packit Service |
a1bd4f |
_nmp_object_equal(const NMPObject *a, const NMPObject *b)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
gboolean a_b = nmp_object_equal(a, b);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_assert(NM_IN_SET(a_b, FALSE, TRUE) && a_b == nmp_object_equal(b, a));
|
|
Packit Service |
a1bd4f |
return a_b;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
#define nmp_object_equal _nmp_object_equal
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains(const NMPCache * cache,
|
|
Packit Service |
a1bd4f |
const NMDedupMultiHeadEntry *head_entry,
|
|
Packit Service |
a1bd4f |
const NMPObject * obj,
|
|
Packit Service |
a1bd4f |
gboolean visible_only,
|
|
Packit Service |
a1bd4f |
gboolean contains)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMDedupMultiIter iter;
|
|
Packit Service |
a1bd4f |
gboolean found;
|
|
Packit Service |
a1bd4f |
guint i, len;
|
|
Packit Service |
a1bd4f |
const NMPObject *o;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_IS_VALID(obj));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj) == obj);
|
|
Packit Service |
a1bd4f |
g_assert(!head_entry
|
|
Packit Service |
a1bd4f |
|| (head_entry->len > 0
|
|
Packit Service |
a1bd4f |
&& c_list_length(&head_entry->lst_entries_head) == head_entry->len));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
len = head_entry ? head_entry->len : 0;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
found = FALSE;
|
|
Packit Service |
a1bd4f |
i = 0;
|
|
Packit Service |
a1bd4f |
nmp_cache_iter_for_each (&iter, head_entry, &o) {
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_IS_VALID(o));
|
|
Packit Service |
a1bd4f |
if (obj == o) {
|
|
Packit Service |
a1bd4f |
if (!visible_only || nmp_object_is_visible(o)) {
|
|
Packit Service |
a1bd4f |
g_assert(!found);
|
|
Packit Service |
a1bd4f |
found = TRUE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
i++;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(len == i);
|
|
Packit Service |
a1bd4f |
g_assert(!!contains == found);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(const NMPCache * cache,
|
|
Packit Service |
a1bd4f |
gboolean visible_only,
|
|
Packit Service |
a1bd4f |
const NMPObject *obj,
|
|
Packit Service |
a1bd4f |
gboolean contains)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
const NMDedupMultiHeadEntry *head_entry;
|
|
Packit Service |
a1bd4f |
NMPLookup lookup;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_assert(cache);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nmp_lookup_init_obj_type(&lookup, NMP_OBJECT_TYPE_LINK);
|
|
Packit Service |
a1bd4f |
head_entry = nmp_cache_lookup(cache, &lookup);
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains(cache, head_entry, obj, visible_only, contains);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
ops_post_check(NMPCache * cache,
|
|
Packit Service |
a1bd4f |
NMPCacheOpsType ops_type,
|
|
Packit Service |
a1bd4f |
const NMPObject *obj_old,
|
|
Packit Service |
a1bd4f |
const NMPObject *obj_new,
|
|
Packit Service |
a1bd4f |
const NMPObject *obj_new_expected,
|
|
Packit Service |
a1bd4f |
NMPCacheOpsType expected_ops_type)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_assert(cache);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(expected_ops_type, ==, ops_type);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
switch (ops_type) {
|
|
Packit Service |
a1bd4f |
case NMP_CACHE_OPS_ADDED:
|
|
Packit Service |
a1bd4f |
g_assert(!obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_IS_VALID(obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_id_equal(obj_new_expected, obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_equal(obj_new_expected, obj_new));
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case NMP_CACHE_OPS_UPDATED:
|
|
Packit Service |
a1bd4f |
g_assert(obj_old != obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_IS_VALID(obj_old));
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_IS_VALID(obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(obj_old));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_id_equal(obj_new_expected, obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_id_equal(obj_new_expected, obj_old));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_id_equal(obj_old, obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_equal(obj_new_expected, obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_equal(obj_new_expected, obj_old));
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_equal(obj_old, obj_new));
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case NMP_CACHE_OPS_REMOVED:
|
|
Packit Service |
a1bd4f |
g_assert(!obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_IS_VALID(obj_old));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(obj_old));
|
|
Packit Service |
a1bd4f |
if (obj_new_expected)
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_id_equal(obj_new_expected, obj_old));
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
case NMP_CACHE_OPS_UNCHANGED:
|
|
Packit Service |
a1bd4f |
g_assert(obj_old == obj_new);
|
|
Packit Service |
a1bd4f |
if (obj_old) {
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_IS_VALID(obj_old));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(obj_old));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_equal(obj_old, obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_id_equal(obj_new_expected, obj_new));
|
|
Packit Service |
a1bd4f |
} else
|
|
Packit Service |
a1bd4f |
g_assert(!obj_new_expected);
|
|
Packit Service |
a1bd4f |
break;
|
|
Packit Service |
a1bd4f |
default:
|
|
Packit Service |
a1bd4f |
g_assert_not_reached();
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
_nmp_cache_update_netlink(NMPCache * cache,
|
|
Packit Service |
a1bd4f |
NMPObject * obj,
|
|
Packit Service |
a1bd4f |
const NMPObject **out_obj_old,
|
|
Packit Service |
a1bd4f |
const NMPObject **out_obj_new,
|
|
Packit Service |
a1bd4f |
NMPCacheOpsType expected_ops_type)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMPCacheOpsType ops_type;
|
|
Packit Service |
a1bd4f |
const NMPObject *obj_prev;
|
|
Packit Service |
a1bd4f |
const NMPObject *obj_old;
|
|
Packit Service |
a1bd4f |
const NMPObject *obj_new;
|
|
Packit Service |
a1bd4f |
nm_auto_nmpobj NMPObject *obj_new_expected = NULL;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(cache);
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_IS_VALID(obj));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
obj_prev = nmp_cache_lookup_link(cache, NMP_OBJECT_CAST_LINK(obj)->ifindex);
|
|
Packit Service |
a1bd4f |
obj_new_expected = nmp_object_clone(obj, FALSE);
|
|
Packit Service |
a1bd4f |
if (obj_prev && obj_prev->_link.udev.device)
|
|
Packit Service |
a1bd4f |
obj_new_expected->_link.udev.device = udev_device_ref(obj_prev->_link.udev.device);
|
|
Packit Service |
a1bd4f |
_nmp_object_fixup_link_udev_fields(&obj_new_expected, NULL, nmp_cache_use_udev_get(cache));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
ops_type = nmp_cache_update_netlink(cache, obj, FALSE, &obj_old, &obj_new);
|
|
Packit Service |
a1bd4f |
ops_post_check(cache,
|
|
Packit Service |
a1bd4f |
ops_type,
|
|
Packit Service |
a1bd4f |
obj_old,
|
|
Packit Service |
a1bd4f |
obj_new,
|
|
Packit Service |
a1bd4f |
nmp_object_is_alive(obj_new_expected) ? obj_new_expected : NULL,
|
|
Packit Service |
a1bd4f |
expected_ops_type);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (out_obj_new)
|
|
Packit Service |
a1bd4f |
*out_obj_new = obj_new;
|
|
Packit Service |
a1bd4f |
else
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
if (out_obj_old)
|
|
Packit Service |
a1bd4f |
*out_obj_old = obj_old;
|
|
Packit Service |
a1bd4f |
else
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_old);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static const NMPlatformLink pl_link_2 = {
|
|
Packit Service |
a1bd4f |
.ifindex = 2,
|
|
Packit Service |
a1bd4f |
.name = "eth0",
|
|
Packit Service |
a1bd4f |
.type = NM_LINK_TYPE_ETHERNET,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static const NMPlatformLink pl_link_3 = {
|
|
Packit Service |
a1bd4f |
.ifindex = 3,
|
|
Packit Service |
a1bd4f |
.name = "wlan0",
|
|
Packit Service |
a1bd4f |
.type = NM_LINK_TYPE_WIFI,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_cache_link(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMPCache * cache;
|
|
Packit Service |
a1bd4f |
NMPObject * objm1;
|
|
Packit Service |
a1bd4f |
const NMPObject * obj_old, *obj_new;
|
|
Packit Service |
a1bd4f |
NMPObject objs1;
|
|
Packit Service |
a1bd4f |
struct udev_device * udev_device_2 = g_list_nth_data(global.udev_devices, 0);
|
|
Packit Service |
a1bd4f |
struct udev_device * udev_device_3 = g_list_nth_data(global.udev_devices, 0);
|
|
Packit Service |
a1bd4f |
NMPCacheOpsType ops_type;
|
|
Packit Service |
a1bd4f |
nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = NULL;
|
|
Packit Service |
a1bd4f |
gboolean use_udev = nmtst_get_rand_uint32() % 2;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
multi_idx = nm_dedup_multi_index_new();
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
cache = nmp_cache_new(multi_idx, use_udev);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* if we have a link, and don't set is_in_netlink, adding it has no effect. */
|
|
Packit Service |
a1bd4f |
objm1 = nmp_object_new(NMP_OBJECT_TYPE_LINK, (NMPlatformObject *) &pl_link_2);
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_UP_CAST(&objm1->object) == objm1);
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_is_alive(objm1));
|
|
Packit Service |
a1bd4f |
_nmp_cache_update_netlink(cache, objm1, &obj_old, &obj_new, NMP_CACHE_OPS_UNCHANGED);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
g_assert(!obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(!obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_cache_lookup_obj(cache, objm1));
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_2.ifindex)));
|
|
Packit Service |
a1bd4f |
nmp_object_unref(objm1);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* Only when setting @is_in_netlink the link is added. */
|
|
Packit Service |
a1bd4f |
objm1 = nmp_object_new(NMP_OBJECT_TYPE_LINK, (NMPlatformObject *) &pl_link_2);
|
|
Packit Service |
a1bd4f |
objm1->_link.netlink.is_in_netlink = TRUE;
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(objm1));
|
|
Packit Service |
a1bd4f |
_nmp_cache_update_netlink(cache, objm1, &obj_old, &obj_new, NMP_CACHE_OPS_ADDED);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
g_assert(!obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(objm1 == obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_equal(objm1, obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, objm1) == obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_2.ifindex))
|
|
Packit Service |
a1bd4f |
== obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_visible(obj_new));
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, FALSE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, TRUE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(objm1);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* updating the same link with identical value, has no effect. */
|
|
Packit Service |
a1bd4f |
objm1 = nmp_object_new(NMP_OBJECT_TYPE_LINK, (NMPlatformObject *) &pl_link_2);
|
|
Packit Service |
a1bd4f |
objm1->_link.netlink.is_in_netlink = TRUE;
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(objm1));
|
|
Packit Service |
a1bd4f |
_nmp_cache_update_netlink(cache, objm1, &obj_old, &obj_new, NMP_CACHE_OPS_UNCHANGED);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
g_assert(obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(obj_new != objm1);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_equal(objm1, obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, objm1) == obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_2.ifindex))
|
|
Packit Service |
a1bd4f |
== obj_new);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(objm1);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* remove the link from netlink */
|
|
Packit Service |
a1bd4f |
objm1 = nmp_object_new(NMP_OBJECT_TYPE_LINK, (NMPlatformObject *) &pl_link_2);
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_is_alive(objm1));
|
|
Packit Service |
a1bd4f |
_nmp_cache_update_netlink(cache, objm1, &obj_old, &obj_new, NMP_CACHE_OPS_REMOVED);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
g_assert(obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(!obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_cache_lookup_obj(cache, objm1));
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_2.ifindex)));
|
|
Packit Service |
a1bd4f |
nmp_object_unref(objm1);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_old);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (udev_device_2) {
|
|
Packit Service |
a1bd4f |
/* now add the link only with aspect UDEV. */
|
|
Packit Service |
a1bd4f |
ops_type =
|
|
Packit Service |
a1bd4f |
nmp_cache_update_link_udev(cache, pl_link_2.ifindex, udev_device_2, &obj_old, &obj_new);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(ops_type, ==, NMP_CACHE_OPS_ADDED);
|
|
Packit Service |
a1bd4f |
g_assert(!obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(
|
|
Packit Service |
a1bd4f |
nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_2.ifindex))
|
|
Packit Service |
a1bd4f |
== obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_is_visible(obj_new));
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, TRUE, obj_new, FALSE);
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, FALSE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* add it in netlink too. */
|
|
Packit Service |
a1bd4f |
objm1 = nmp_object_new(NMP_OBJECT_TYPE_LINK, (NMPlatformObject *) &pl_link_2);
|
|
Packit Service |
a1bd4f |
objm1->_link.netlink.is_in_netlink = TRUE;
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(objm1));
|
|
Packit Service |
a1bd4f |
_nmp_cache_update_netlink(cache,
|
|
Packit Service |
a1bd4f |
objm1,
|
|
Packit Service |
a1bd4f |
&obj_old,
|
|
Packit Service |
a1bd4f |
&obj_new,
|
|
Packit Service |
a1bd4f |
udev_device_2 ? NMP_CACHE_OPS_UPDATED : NMP_CACHE_OPS_ADDED);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
if (udev_device_2) {
|
|
Packit Service |
a1bd4f |
g_assert(obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_is_visible(obj_old));
|
|
Packit Service |
a1bd4f |
} else
|
|
Packit Service |
a1bd4f |
g_assert(!obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_equal(objm1, obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, objm1) == obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_2.ifindex))
|
|
Packit Service |
a1bd4f |
== obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_visible(obj_new));
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, TRUE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, FALSE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(objm1);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_old);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* remove again from netlink. */
|
|
Packit Service |
a1bd4f |
objm1 = nmp_object_new(NMP_OBJECT_TYPE_LINK, (NMPlatformObject *) &pl_link_2);
|
|
Packit Service |
a1bd4f |
objm1->_link.netlink.is_in_netlink = FALSE;
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_is_alive(objm1));
|
|
Packit Service |
a1bd4f |
_nmp_cache_update_netlink(cache,
|
|
Packit Service |
a1bd4f |
objm1,
|
|
Packit Service |
a1bd4f |
&obj_old,
|
|
Packit Service |
a1bd4f |
&obj_new,
|
|
Packit Service |
a1bd4f |
udev_device_2 ? NMP_CACHE_OPS_UPDATED : NMP_CACHE_OPS_REMOVED);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
if (udev_device_2)
|
|
Packit Service |
a1bd4f |
g_assert(obj_new == objm1);
|
|
Packit Service |
a1bd4f |
else
|
|
Packit Service |
a1bd4f |
g_assert(!obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(obj_old));
|
|
Packit Service |
a1bd4f |
if (udev_device_2) {
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, objm1) == obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(
|
|
Packit Service |
a1bd4f |
nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_2.ifindex))
|
|
Packit Service |
a1bd4f |
== obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_is_visible(obj_new));
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, TRUE, obj_new, FALSE);
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, FALSE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
} else {
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, objm1) == NULL);
|
|
Packit Service |
a1bd4f |
g_assert(
|
|
Packit Service |
a1bd4f |
nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_2.ifindex))
|
|
Packit Service |
a1bd4f |
== NULL);
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_is_alive(obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_is_visible(obj_new));
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
nmp_object_unref(objm1);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_old);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* now another link only with aspect UDEV. */
|
|
Packit Service |
a1bd4f |
if (udev_device_3) {
|
|
Packit Service |
a1bd4f |
/* now add the link only with aspect UDEV. */
|
|
Packit Service |
a1bd4f |
ops_type =
|
|
Packit Service |
a1bd4f |
nmp_cache_update_link_udev(cache, pl_link_3.ifindex, udev_device_3, &obj_old, &obj_new);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(ops_type, ==, NMP_CACHE_OPS_ADDED);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
g_assert(NMP_OBJECT_IS_VALID(obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(!obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(!nmp_object_is_visible(obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(
|
|
Packit Service |
a1bd4f |
nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_3.ifindex))
|
|
Packit Service |
a1bd4f |
== obj_new);
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, TRUE, obj_new, FALSE);
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, FALSE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(obj_new->_link.netlink.is_in_netlink, ==, FALSE);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(obj_new->link.initialized, ==, FALSE);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* add it in netlink too. */
|
|
Packit Service |
a1bd4f |
objm1 = nmp_object_new(NMP_OBJECT_TYPE_LINK, (NMPlatformObject *) &pl_link_3);
|
|
Packit Service |
a1bd4f |
objm1->_link.netlink.is_in_netlink = TRUE;
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_alive(objm1));
|
|
Packit Service |
a1bd4f |
_nmp_cache_update_netlink(cache, objm1, &obj_old, &obj_new, NMP_CACHE_OPS_UPDATED);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
g_assert(obj_old);
|
|
Packit Service |
a1bd4f |
g_assert(obj_new == objm1);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_equal(objm1, obj_new));
|
|
Packit Service |
a1bd4f |
g_assert(!obj_old || !nmp_object_is_visible(obj_old));
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, objm1) == obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(
|
|
Packit Service |
a1bd4f |
nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_3.ifindex))
|
|
Packit Service |
a1bd4f |
== obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_visible(obj_new));
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, TRUE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, FALSE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(obj_new->_link.netlink.is_in_netlink, ==, TRUE);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(obj_new->link.initialized, ==, TRUE);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(objm1);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_old);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* remove UDEV. */
|
|
Packit Service |
a1bd4f |
ops_type = nmp_cache_update_link_udev(cache, pl_link_3.ifindex, NULL, &obj_old, &obj_new);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(ops_type, ==, NMP_CACHE_OPS_UPDATED);
|
|
Packit Service |
a1bd4f |
nmtst_assert_nmp_cache_is_consistent(cache);
|
|
Packit Service |
a1bd4f |
g_assert(obj_old && nmp_object_is_visible(obj_old));
|
|
Packit Service |
a1bd4f |
g_assert(
|
|
Packit Service |
a1bd4f |
nmp_cache_lookup_obj(cache, nmp_object_stackinit_id_link(&objs1, pl_link_3.ifindex))
|
|
Packit Service |
a1bd4f |
== obj_new);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_object_is_visible(obj_new));
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, TRUE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
_assert_cache_multi_lookup_contains_link(cache, FALSE, obj_new, TRUE);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(obj_new->_link.netlink.is_in_netlink, ==, TRUE);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(obj_new->link.initialized, ==, !nmp_cache_use_udev_get(cache));
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_new);
|
|
Packit Service |
a1bd4f |
nmp_object_unref(obj_old);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nmp_cache_free(cache);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
const char noqueue[] = "noqueue";
|
|
Packit |
5756e2 |
const char fq_codel[] = "fq_codel";
|
|
Packit Service |
a1bd4f |
const char ingress[] = "ingress";
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static const NMPlatformQdisc pl_qdisc_1a = {
|
|
Packit Service |
a1bd4f |
.ifindex = 1,
|
|
Packit Service |
a1bd4f |
.kind = noqueue,
|
|
Packit Service |
a1bd4f |
.addr_family = AF_UNSPEC,
|
|
Packit Service |
a1bd4f |
.handle = 0,
|
|
Packit Service |
a1bd4f |
.parent = TC_H_ROOT,
|
|
Packit Service |
a1bd4f |
.info = 0,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static const NMPlatformQdisc pl_qdisc_1b = {
|
|
Packit Service |
a1bd4f |
.ifindex = 1,
|
|
Packit Service |
a1bd4f |
.kind = fq_codel,
|
|
Packit Service |
a1bd4f |
.addr_family = AF_UNSPEC,
|
|
Packit Service |
a1bd4f |
.handle = 0,
|
|
Packit Service |
a1bd4f |
.parent = TC_H_ROOT,
|
|
Packit Service |
a1bd4f |
.info = 0,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static const NMPlatformQdisc pl_qdisc_1c = {
|
|
Packit Service |
a1bd4f |
.ifindex = 1,
|
|
Packit Service |
a1bd4f |
.kind = ingress,
|
|
Packit Service |
a1bd4f |
.addr_family = AF_UNSPEC,
|
|
Packit Service |
a1bd4f |
.handle = TC_H_MAKE(TC_H_INGRESS, 0),
|
|
Packit Service |
a1bd4f |
.parent = TC_H_INGRESS,
|
|
Packit Service |
a1bd4f |
.info = 0,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static const NMPlatformQdisc pl_qdisc_2 = {
|
|
Packit Service |
a1bd4f |
.ifindex = 2,
|
|
Packit Service |
a1bd4f |
.kind = fq_codel,
|
|
Packit Service |
a1bd4f |
.addr_family = AF_UNSPEC,
|
|
Packit Service |
a1bd4f |
.handle = 0,
|
|
Packit Service |
a1bd4f |
.parent = TC_H_ROOT,
|
|
Packit Service |
a1bd4f |
.info = 0,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_cache_qdisc(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMPCache * cache;
|
|
Packit Service |
a1bd4f |
nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = NULL;
|
|
Packit Service |
a1bd4f |
NMPLookup lookup;
|
|
Packit Service |
a1bd4f |
const NMDedupMultiHeadEntry * head_entry;
|
|
Packit Service |
a1bd4f |
nm_auto_nmpobj NMPObject *obj1a =
|
|
Packit Service |
a1bd4f |
nmp_object_new(NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_1a);
|
|
Packit Service |
a1bd4f |
nm_auto_nmpobj NMPObject *obj1b =
|
|
Packit Service |
a1bd4f |
nmp_object_new(NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_1b);
|
|
Packit Service |
a1bd4f |
nm_auto_nmpobj NMPObject *obj1c =
|
|
Packit Service |
a1bd4f |
nmp_object_new(NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_1c);
|
|
Packit Service |
a1bd4f |
nm_auto_nmpobj NMPObject *obj2 =
|
|
Packit Service |
a1bd4f |
nmp_object_new(NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_2);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
multi_idx = nm_dedup_multi_index_new();
|
|
Packit Service |
a1bd4f |
cache = nmp_cache_new(multi_idx, nmtst_get_rand_uint32() % 2);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1a) == NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_update_netlink(cache, obj1a, FALSE, NULL, NULL) == NMP_CACHE_OPS_ADDED);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1a) == obj1a);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1b) == obj1a);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj2) == NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_update_netlink(cache, obj1b, FALSE, NULL, NULL) == NMP_CACHE_OPS_UPDATED);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1a) == obj1b);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1b) == obj1b);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj2) == NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_update_netlink(cache, obj1c, FALSE, NULL, NULL) == NMP_CACHE_OPS_ADDED);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1a) == obj1b);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1b) == obj1b);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1c) == obj1c);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj2) == NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_update_netlink(cache, obj2, FALSE, NULL, NULL) == NMP_CACHE_OPS_ADDED);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1a) == obj1b);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj1b) == obj1b);
|
|
Packit Service |
a1bd4f |
g_assert(nmp_cache_lookup_obj(cache, obj2) == obj2);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
head_entry = nmp_cache_lookup(cache, nmp_lookup_init_object(&lookup, NMP_OBJECT_TYPE_QDISC, 1));
|
|
Packit Service |
a1bd4f |
g_assert(head_entry->len == 2);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nmp_cache_free(cache);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NMTST_DEFINE();
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
int
|
|
Packit Service |
a1bd4f |
main(int argc, char **argv)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
int result;
|
|
Packit Service |
a1bd4f |
NMUdevClient *udev_client;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nmtst_init_assert_logging(&argc, &argv, "INFO", "DEFAULT");
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
udev_client = nm_udev_client_new((const char *[]){"net", NULL}, NULL, NULL);
|
|
Packit Service |
a1bd4f |
{
|
|
Packit Service |
a1bd4f |
struct udev_enumerate * enumerator;
|
|
Packit Service |
a1bd4f |
struct udev_list_entry *devices, *l;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
enumerator = nm_udev_client_enumerate_new(udev_client);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Demand that the device is initialized (udev rules ran,
|
|
Packit Service |
a1bd4f |
* device has a stable name now) in case udev is running
|
|
Packit Service |
a1bd4f |
* (not in a container). */
|
|
Packit Service |
a1bd4f |
if (access("/sys", W_OK) == 0)
|
|
Packit Service |
a1bd4f |
udev_enumerate_add_match_is_initialized(enumerator);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
udev_enumerate_scan_devices(enumerator);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
devices = udev_enumerate_get_list_entry(enumerator);
|
|
Packit Service |
a1bd4f |
for (l = devices; l != NULL; l = udev_list_entry_get_next(l)) {
|
|
Packit Service |
a1bd4f |
struct udev_device *udevice;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
udevice = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerator),
|
|
Packit Service |
a1bd4f |
udev_list_entry_get_name(l));
|
|
Packit Service |
a1bd4f |
if (udevice == NULL)
|
|
Packit Service |
a1bd4f |
continue;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
global.udev_devices = g_list_prepend(global.udev_devices, udevice);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
global.udev_devices = g_list_reverse(global.udev_devices);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
udev_enumerate_unref(enumerator);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_test_add_func("/nmp-object/obj-base", test_obj_base);
|
|
Packit Service |
a1bd4f |
g_test_add_func("/nmp-object/cache_link", test_cache_link);
|
|
Packit Service |
a1bd4f |
g_test_add_func("/nmp-object/cache_qdisc", test_cache_qdisc);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
result = g_test_run();
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
while (global.udev_devices) {
|
|
Packit Service |
a1bd4f |
udev_device_unref(global.udev_devices->data);
|
|
Packit Service |
a1bd4f |
global.udev_devices = g_list_delete_link(global.udev_devices, global.udev_devices);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_udev_client_unref(udev_client);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return result;
|
|
Packit |
5756e2 |
}
|