net/sfc: rename array of SW stats descriptions
[dpdk.git] / app / test / test_graph.c
index cf6df07..81bdcb9 100644 (file)
@@ -12,6 +12,8 @@
 #include <rte_graph.h>
 #include <rte_graph_worker.h>
 #include <rte_mbuf.h>
+#include <rte_mbuf_dyn.h>
+#include <rte_random.h>
 
 #include "test.h"
 
@@ -38,6 +40,16 @@ static uint16_t test_node3_worker(struct rte_graph *graph,
 #define MBUFF_SIZE 512
 #define MAX_NODES  4
 
+typedef uint64_t graph_dynfield_t;
+static int graph_dynfield_offset = -1;
+
+static inline graph_dynfield_t *
+graph_field(struct rte_mbuf *mbuf)
+{
+       return RTE_MBUF_DYNFIELD(mbuf, \
+                       graph_dynfield_offset, graph_dynfield_t *);
+}
+
 static struct rte_mbuf mbuf[MAX_NODES + 1][MBUFF_SIZE];
 static void *mbuf_p[MAX_NODES + 1][MBUFF_SIZE];
 static rte_graph_t graph_id;
@@ -145,7 +157,7 @@ uint16_t
 test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
                        void **objs, uint16_t nb_objs)
 {
-       uint32_t obj_node0 = rand() % 100, obj_node1;
+       uint32_t obj_node0 = rte_rand() % 100, obj_node1;
        test_main_t *tm = &test_main;
        struct rte_mbuf *data;
        void **next_stream;
@@ -161,9 +173,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
        next_stream = rte_node_next_stream_get(graph, node, next, obj_node0);
        for (i = 0; i < obj_node0; i++) {
                data = &mbuf[0][i];
-               data->udata64 = ((uint64_t)tm->test_node[0].idx << 32) | i;
+               *graph_field(data) = ((uint64_t)tm->test_node[0].idx << 32) | i;
                if ((i + 1) == obj_node0)
-                       data->udata64 |= (1 << 16);
+                       *graph_field(data) |= (1 << 16);
                next_stream[i] = &mbuf[0][i];
        }
        rte_node_next_stream_put(graph, node, next, obj_node0);
@@ -174,9 +186,9 @@ test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
        next_stream = rte_node_next_stream_get(graph, node, next, obj_node1);
        for (i = 0; i < obj_node1; i++) {
                data = &mbuf[0][obj_node0 + i];
-               data->udata64 = ((uint64_t)tm->test_node[1].idx << 32) | i;
+               *graph_field(data) = ((uint64_t)tm->test_node[1].idx << 32) | i;
                if ((i + 1) == obj_node1)
-                       data->udata64 |= (1 << 16);
+                       *graph_field(data) |= (1 << 16);
                next_stream[i] = &mbuf[0][obj_node0 + i];
        }
 
@@ -193,7 +205,7 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
        test_main_t *tm = &test_main;
 
        if (*(uint32_t *)node->ctx == test_node0.id) {
-               uint32_t obj_node0 = rand() % 100, obj_node1;
+               uint32_t obj_node0 = rte_rand() % 100, obj_node1;
                struct rte_mbuf *data;
                uint8_t second_pass = 0;
                uint32_t count = 0;
@@ -204,23 +216,23 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
 
                for (i = 0; i < nb_objs; i++) {
                        data = (struct rte_mbuf *)objs[i];
-                       if ((data->udata64 >> 32) != tm->test_node[0].idx) {
+                       if ((*graph_field(data) >> 32) != tm->test_node[0].idx) {
                                printf("Data idx miss match at node 0, expected"
                                       " = %u got = %u\n",
                                       tm->test_node[0].idx,
-                                      (uint32_t)(data->udata64 >> 32));
+                                      (uint32_t)(*graph_field(data) >> 32));
                                goto end;
                        }
 
-                       if ((data->udata64 & 0xffff) != (i - count)) {
+                       if ((*graph_field(data) & 0xffff) != (i - count)) {
                                printf("Expected buff count miss match at "
                                       "node 0\n");
                                goto end;
                        }
 
-                       if (data->udata64 & (0x1 << 16))
+                       if (*graph_field(data) & (0x1 << 16))
                                count = i + 1;
-                       if (data->udata64 & (0x1 << 17))
+                       if (*graph_field(data) & (0x1 << 17))
                                second_pass = 1;
                }
 
@@ -232,12 +244,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
                obj_node0 = nb_objs * obj_node0 * 0.01;
                for (i = 0; i < obj_node0; i++) {
                        data = &mbuf[1][i];
-                       data->udata64 =
+                       *graph_field(data) =
                                ((uint64_t)tm->test_node[1].idx << 32) | i;
                        if ((i + 1) == obj_node0)
-                               data->udata64 |= (1 << 16);
+                               *graph_field(data) |= (1 << 16);
                        if (second_pass)
-                               data->udata64 |= (1 << 17);
+                               *graph_field(data) |= (1 << 17);
                }
                rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[1][0],
                                 obj_node0);
@@ -245,12 +257,12 @@ test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
                obj_node1 = nb_objs - obj_node0;
                for (i = 0; i < obj_node1; i++) {
                        data = &mbuf[1][obj_node0 + i];
-                       data->udata64 =
+                       *graph_field(data) =
                                ((uint64_t)tm->test_node[2].idx << 32) | i;
                        if ((i + 1) == obj_node1)
-                               data->udata64 |= (1 << 16);
+                               *graph_field(data) |= (1 << 16);
                        if (second_pass)
-                               data->udata64 |= (1 << 17);
+                               *graph_field(data) |= (1 << 17);
                }
                rte_node_enqueue(graph, node, 1, (void **)&mbuf_p[1][obj_node0],
                                 obj_node1);
@@ -284,22 +296,22 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
        fn_calls[2] += 1;
        for (i = 0; i < nb_objs; i++) {
                data = (struct rte_mbuf *)objs[i];
-               if ((data->udata64 >> 32) != tm->test_node[1].idx) {
+               if ((*graph_field(data) >> 32) != tm->test_node[1].idx) {
                        printf("Data idx miss match at node 1, expected = %u"
                               " got = %u\n",
                               tm->test_node[1].idx,
-                              (uint32_t)(data->udata64 >> 32));
+                              (uint32_t)(*graph_field(data) >> 32));
                        goto end;
                }
 
-               if ((data->udata64 & 0xffff) != (i - count)) {
+               if ((*graph_field(data) & 0xffff) != (i - count)) {
                        printf("Expected buff count miss match at node 1\n");
                        goto end;
                }
 
-               if (data->udata64 & (0x1 << 16))
+               if (*graph_field(data) & (0x1 << 16))
                        count = i + 1;
-               if (data->udata64 & (0x1 << 17))
+               if (*graph_field(data) & (0x1 << 17))
                        second_pass = 1;
        }
 
@@ -311,11 +323,11 @@ test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
        obj_node0 = nb_objs;
        for (i = 0; i < obj_node0; i++) {
                data = &mbuf[2][i];
-               data->udata64 = ((uint64_t)tm->test_node[2].idx << 32) | i;
+               *graph_field(data) = ((uint64_t)tm->test_node[2].idx << 32) | i;
                if ((i + 1) == obj_node0)
-                       data->udata64 |= (1 << 16);
+                       *graph_field(data) |= (1 << 16);
                if (second_pass)
-                       data->udata64 |= (1 << 17);
+                       *graph_field(data) |= (1 << 17);
        }
        rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[2][0], obj_node0);
 
@@ -338,22 +350,22 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
        fn_calls[3] += 1;
        for (i = 0; i < nb_objs; i++) {
                data = (struct rte_mbuf *)objs[i];
-               if ((data->udata64 >> 32) != tm->test_node[2].idx) {
+               if ((*graph_field(data) >> 32) != tm->test_node[2].idx) {
                        printf("Data idx miss match at node 2, expected = %u"
                               " got = %u\n",
                               tm->test_node[2].idx,
-                              (uint32_t)(data->udata64 >> 32));
+                              (uint32_t)(*graph_field(data) >> 32));
                        goto end;
                }
 
-               if ((data->udata64 & 0xffff) != (i - count)) {
+               if ((*graph_field(data) & 0xffff) != (i - count)) {
                        printf("Expected buff count miss match at node 2\n");
                        goto end;
                }
 
-               if (data->udata64 & (0x1 << 16))
+               if (*graph_field(data) & (0x1 << 16))
                        count = i + 1;
-               if (data->udata64 & (0x1 << 17))
+               if (*graph_field(data) & (0x1 << 17))
                        second_pass = 1;
        }
 
@@ -366,10 +378,10 @@ test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
                obj_node0 = nb_objs;
                for (i = 0; i < obj_node0; i++) {
                        data = &mbuf[3][i];
-                       data->udata64 =
+                       *graph_field(data) =
                                ((uint64_t)tm->test_node[3].idx << 32) | i;
                        if ((i + 1) == obj_node0)
-                               data->udata64 |= (1 << 16);
+                               *graph_field(data) |= (1 << 16);
                }
                rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[3][0],
                                 obj_node0);
@@ -394,22 +406,22 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
        fn_calls[4] += 1;
        for (i = 0; i < nb_objs; i++) {
                data = (struct rte_mbuf *)objs[i];
-               if ((data->udata64 >> 32) != tm->test_node[3].idx) {
+               if ((*graph_field(data) >> 32) != tm->test_node[3].idx) {
                        printf("Data idx miss match at node 3, expected = %u"
                               " got = %u\n",
                               tm->test_node[3].idx,
-                              (uint32_t)(data->udata64 >> 32));
+                              (uint32_t)(*graph_field(data) >> 32));
                        goto end;
                }
 
-               if ((data->udata64 & 0xffff) != (i - count)) {
+               if ((*graph_field(data) & 0xffff) != (i - count)) {
                        printf("Expected buff count miss match at node 3\n");
                        goto end;
                }
 
-               if (data->udata64 & (0x1 << 16))
+               if (*graph_field(data) & (0x1 << 16))
                        count = i + 1;
-               if (data->udata64 & (0x1 << 17))
+               if (*graph_field(data) & (0x1 << 17))
                        second_pass = 1;
        }
 
@@ -425,11 +437,11 @@ test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
                obj_node0 = nb_objs * 2;
                for (i = 0; i < obj_node0; i++) {
                        data = &mbuf[4][i];
-                       data->udata64 =
+                       *graph_field(data) =
                                ((uint64_t)tm->test_node[0].idx << 32) | i;
-                       data->udata64 |= (1 << 17);
+                       *graph_field(data) |= (1 << 17);
                        if ((i + 1) == obj_node0)
-                               data->udata64 |= (1 << 16);
+                               *graph_field(data) |= (1 << 16);
                }
                rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[4][0],
                                 obj_node0);
@@ -496,6 +508,7 @@ test_lookup_functions(void)
                        printf("Test number of edges for node = %s failed Expected = %d, got %d\n",
                               tm->test_node[i].node.name,
                               tm->test_node[i].node.nb_edges, count);
+                       free(next_edges);
                        return -1;
                }
 
@@ -505,6 +518,7 @@ test_lookup_functions(void)
                                printf("Edge name miss match, expected = %s got = %s\n",
                                       tm->test_node[i].node.next_nodes[j],
                                       next_edges[j]);
+                               free(next_edges);
                                return -1;
                        }
                }
@@ -762,6 +776,18 @@ graph_setup(void)
 {
        int i, j;
 
+       static const struct rte_mbuf_dynfield graph_dynfield_desc = {
+               .name = "test_graph_dynfield",
+               .size = sizeof(graph_dynfield_t),
+               .align = __alignof__(graph_dynfield_t),
+       };
+       graph_dynfield_offset =
+               rte_mbuf_dynfield_register(&graph_dynfield_desc);
+       if (graph_dynfield_offset < 0) {
+               printf("Cannot register mbuf field\n");
+               return TEST_FAILED;
+       }
+
        for (i = 0; i <= MAX_NODES; i++) {
                for (j = 0; j < MBUFF_SIZE; j++)
                        mbuf_p[i][j] = &mbuf[i][j];