test/mem: remove dependency on EAL internals
authorDavid Marchand <david.marchand@redhat.com>
Fri, 25 Oct 2019 13:56:07 +0000 (15:56 +0200)
committerDavid Marchand <david.marchand@redhat.com>
Sun, 27 Oct 2019 09:41:08 +0000 (10:41 +0100)
Rather than dereference the mem_config internal structure, we can rely
on the rte_memzone_walk API and count memzones.

Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
app/test/test_memzone.c

index 7edfd06..4d87444 100644 (file)
 #include <rte_memory.h>
 #include <rte_memzone.h>
 #include <rte_eal.h>
+#include <rte_lcore.h>
 #include <rte_common.h>
 #include <rte_string_fns.h>
 #include <rte_errno.h>
 #include <rte_malloc.h>
 #include "../../lib/librte_eal/common/malloc_elem.h"
-#include "../../lib/librte_eal/common/eal_memcfg.h"
 
 #include "test.h"
 
@@ -927,6 +927,16 @@ test_memzone_free(void)
        return 0;
 }
 
+static int test_memzones_left;
+static int memzone_walk_cnt;
+static void memzone_walk_clb(const struct rte_memzone *mz,
+                            void *arg __rte_unused)
+{
+       memzone_walk_cnt++;
+       if (!strncmp(TEST_MEMZONE_NAME(""), mz->name, RTE_MEMZONE_NAMESIZE))
+               test_memzones_left++;
+}
+
 static int
 test_memzone_basic(void)
 {
@@ -936,8 +946,12 @@ test_memzone_basic(void)
        const struct rte_memzone *memzone4;
        const struct rte_memzone *mz;
        int memzone_cnt_after, memzone_cnt_expected;
-       int memzone_cnt_before =
-                       rte_eal_get_configuration()->mem_config->memzones.count;
+       int memzone_cnt_before;
+
+       memzone_walk_cnt = 0;
+       test_memzones_left = 0;
+       rte_memzone_walk(memzone_walk_clb, NULL);
+       memzone_cnt_before = memzone_walk_cnt;
 
        memzone1 = rte_memzone_reserve(TEST_MEMZONE_NAME("testzone1"), 100,
                                SOCKET_ID_ANY, 0);
@@ -960,8 +974,10 @@ test_memzone_basic(void)
                        (memzone1 != NULL) + (memzone2 != NULL) +
                        (memzone3 != NULL) + (memzone4 != NULL);
 
-       memzone_cnt_after =
-                       rte_eal_get_configuration()->mem_config->memzones.count;
+       memzone_walk_cnt = 0;
+       test_memzones_left = 0;
+       rte_memzone_walk(memzone_walk_clb, NULL);
+       memzone_cnt_after = memzone_walk_cnt;
 
        if (memzone_cnt_after != memzone_cnt_expected)
                return -1;
@@ -1039,30 +1055,26 @@ test_memzone_basic(void)
                return -1;
        }
 
-       memzone_cnt_after =
-                       rte_eal_get_configuration()->mem_config->memzones.count;
+       memzone_walk_cnt = 0;
+       test_memzones_left = 0;
+       rte_memzone_walk(memzone_walk_clb, NULL);
+       memzone_cnt_after = memzone_walk_cnt;
        if (memzone_cnt_after != memzone_cnt_before)
                return -1;
 
        return 0;
 }
 
-static int test_memzones_left;
-static int memzone_walk_cnt;
-static void memzone_walk_clb(const struct rte_memzone *mz,
-                            void *arg __rte_unused)
-{
-       memzone_walk_cnt++;
-       if (!strncmp(TEST_MEMZONE_NAME(""), mz->name, RTE_MEMZONE_NAMESIZE))
-               test_memzones_left++;
-}
-
 static int
 test_memzone(void)
 {
        /* take note of how many memzones were allocated before running */
-       int memzone_cnt =
-                       rte_eal_get_configuration()->mem_config->memzones.count;
+       int memzone_cnt;
+
+       memzone_walk_cnt = 0;
+       test_memzones_left = 0;
+       rte_memzone_walk(memzone_walk_clb, NULL);
+       memzone_cnt = memzone_walk_cnt;
 
        printf("test basic memzone API\n");
        if (test_memzone_basic() < 0)