diff options
| author | Lubomir Rintel <lkundrak@v3.sk> | 2017-11-15 20:36:44 +0100 |
|---|---|---|
| committer | Lubomir Rintel <lkundrak@v3.sk> | 2017-12-11 10:52:22 +0100 |
| commit | 0b0fb045bcf65e55ae13bbc01dfd849e25e18014 (patch) | |
| tree | 57c7b9d297341f25ac0e1b68432a14e5559f25e3 /src/platform | |
| parent | ff9f27eb1231a8a6cb6e0ca5f172da61da136e96 (diff) | |
| download | NetworkManager-0b0fb045bcf65e55ae13bbc01dfd849e25e18014.tar.gz | |
platform/tests: tests qdisc caching behavior
Just the most rudimentary tests.
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/tests/test-nmp-object.c | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/src/platform/tests/test-nmp-object.c b/src/platform/tests/test-nmp-object.c index a02388d24d..ede5eb17eb 100644 --- a/src/platform/tests/test-nmp-object.c +++ b/src/platform/tests/test-nmp-object.c @@ -15,12 +15,13 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright (C) 2015 Red Hat, Inc. + * Copyright (C) 2015 - 2017 Red Hat, Inc. */ #include "nm-default.h" #include <libudev.h> +#include <linux/pkt_sched.h> #include "platform/nmp-object.h" #include "nm-utils/nm-udev-utils.h" @@ -454,6 +455,93 @@ test_cache_link (void) nmp_cache_free (cache); } +const char noqueue[] = "noqueue"; +const char fq_codel[] = "fq_codel"; +const char ingress[] = "ingress"; + +static const NMPlatformQdisc pl_qdisc_1a = { + .ifindex = 1, + .kind = noqueue, + .addr_family = AF_UNSPEC, + .handle = 0, + .parent = TC_H_ROOT, + .info = 0, +}; + +static const NMPlatformQdisc pl_qdisc_1b = { + .ifindex = 1, + .kind = fq_codel, + .addr_family = AF_UNSPEC, + .handle = 0, + .parent = TC_H_ROOT, + .info = 0, +}; + +static const NMPlatformQdisc pl_qdisc_1c = { + .ifindex = 1, + .kind = ingress, + .addr_family = AF_UNSPEC, + .handle = TC_H_MAKE(TC_H_INGRESS, 0), + .parent = TC_H_INGRESS, + .info = 0, +}; + +static const NMPlatformQdisc pl_qdisc_2 = { + .ifindex = 2, + .kind = fq_codel, + .addr_family = AF_UNSPEC, + .handle = 0, + .parent = TC_H_ROOT, + .info = 0, +}; + +static void +test_cache_qdisc (void) +{ + NMPCache *cache; + nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = NULL; + NMPLookup lookup; + const NMDedupMultiHeadEntry *head_entry; + NMPObject *obj1a = nmp_object_new (NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_1a); + NMPObject *obj1b = nmp_object_new (NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_1b); + NMPObject *obj1c = nmp_object_new (NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_1c); + NMPObject *obj2 = nmp_object_new (NMP_OBJECT_TYPE_QDISC, (NMPlatformObject *) &pl_qdisc_2); + + multi_idx = nm_dedup_multi_index_new (); + cache = nmp_cache_new (multi_idx, nmtst_get_rand_int () % 2); + + g_assert (nmp_cache_lookup_obj (cache, obj1a) == NULL); + + g_assert (nmp_cache_update_netlink (cache, obj1a, FALSE, NULL, NULL) == NMP_CACHE_OPS_ADDED); + g_assert (nmp_cache_lookup_obj (cache, obj1a) == obj1a); + g_assert (nmp_cache_lookup_obj (cache, obj1b) == obj1a); + g_assert (nmp_cache_lookup_obj (cache, obj2) == NULL); + + g_assert (nmp_cache_update_netlink (cache, obj1b, FALSE, NULL, NULL) == NMP_CACHE_OPS_UPDATED); + g_assert (nmp_cache_lookup_obj (cache, obj1a) == obj1b); + g_assert (nmp_cache_lookup_obj (cache, obj1b) == obj1b); + g_assert (nmp_cache_lookup_obj (cache, obj2) == NULL); + + g_assert (nmp_cache_update_netlink (cache, obj1c, FALSE, NULL, NULL) == NMP_CACHE_OPS_ADDED); + g_assert (nmp_cache_lookup_obj (cache, obj1a) == obj1b); + g_assert (nmp_cache_lookup_obj (cache, obj1b) == obj1b); + g_assert (nmp_cache_lookup_obj (cache, obj1c) == obj1c); + g_assert (nmp_cache_lookup_obj (cache, obj2) == NULL); + + g_assert (nmp_cache_update_netlink (cache, obj2, FALSE, NULL, NULL) == NMP_CACHE_OPS_ADDED); + g_assert (nmp_cache_lookup_obj (cache, obj1a) == obj1b); + g_assert (nmp_cache_lookup_obj (cache, obj1b) == obj1b); + g_assert (nmp_cache_lookup_obj (cache, obj2) == obj2); + + head_entry = nmp_cache_lookup (cache, + nmp_lookup_init_object (&lookup, + NMP_OBJECT_TYPE_QDISC, + 1)); + g_assert (head_entry->len == 2); + + nmp_cache_free (cache); +} + /*****************************************************************************/ NMTST_DEFINE (); @@ -500,6 +588,7 @@ main (int argc, char **argv) g_test_add_func ("/nmp-object/obj-base", test_obj_base); g_test_add_func ("/nmp-object/cache_link", test_cache_link); + g_test_add_func ("/nmp-object/cache_qdisc", test_cache_qdisc); result = g_test_run (); |
