LCOV - code coverage report
Current view: top level - app/test - test_graph.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 202 430 47.0 %
Date: 2025-08-01 17:49:26 Functions: 23 28 82.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 100 262 38.2 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2020 Marvell International Ltd.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "test.h"
       6                 :            : 
       7                 :            : #include <assert.h>
       8                 :            : #include <inttypes.h>
       9                 :            : #include <signal.h>
      10                 :            : #include <stdalign.h>
      11                 :            : #include <stdio.h>
      12                 :            : #include <string.h>
      13                 :            : #include <unistd.h>
      14                 :            : 
      15                 :            : #include <rte_errno.h>
      16                 :            : 
      17                 :            : #ifdef RTE_EXEC_ENV_WINDOWS
      18                 :            : static int
      19                 :            : test_node_list_dump(void)
      20                 :            : {
      21                 :            :         printf("node_list_dump not supported on Windows, skipping test\n");
      22                 :            :         return TEST_SKIPPED;
      23                 :            : }
      24                 :            : 
      25                 :            : #else
      26                 :            : 
      27                 :            : #include <rte_graph.h>
      28                 :            : #include <rte_graph_worker.h>
      29                 :            : #include <rte_mbuf.h>
      30                 :            : #include <rte_mbuf_dyn.h>
      31                 :            : #include <rte_random.h>
      32                 :            : 
      33                 :            : static uint16_t test_node_worker_source(struct rte_graph *graph,
      34                 :            :                                         struct rte_node *node, void **objs,
      35                 :            :                                         uint16_t nb_objs);
      36                 :            : 
      37                 :            : static uint16_t test_node0_worker(struct rte_graph *graph,
      38                 :            :                                   struct rte_node *node, void **objs,
      39                 :            :                                   uint16_t nb_objs);
      40                 :            : 
      41                 :            : static uint16_t test_node1_worker(struct rte_graph *graph,
      42                 :            :                                   struct rte_node *node, void **objs,
      43                 :            :                                   uint16_t nb_objs);
      44                 :            : 
      45                 :            : static uint16_t test_node2_worker(struct rte_graph *graph,
      46                 :            :                                   struct rte_node *node, void **objs,
      47                 :            :                                   uint16_t nb_objs);
      48                 :            : 
      49                 :            : static uint16_t test_node3_worker(struct rte_graph *graph,
      50                 :            :                                   struct rte_node *node, void **objs,
      51                 :            :                                   uint16_t nb_objs);
      52                 :            : 
      53                 :            : #define MBUFF_SIZE 512
      54                 :            : #define MAX_NODES  4
      55                 :            : 
      56                 :            : typedef uint64_t graph_dynfield_t;
      57                 :            : static int graph_dynfield_offset = -1;
      58                 :            : 
      59                 :            : static inline graph_dynfield_t *
      60                 :            : graph_field(struct rte_mbuf *mbuf)
      61                 :            : {
      62                 :          0 :         return RTE_MBUF_DYNFIELD(mbuf, \
      63                 :            :                         graph_dynfield_offset, graph_dynfield_t *);
      64                 :            : }
      65                 :            : 
      66                 :            : static struct rte_mbuf mbuf[MAX_NODES + 1][MBUFF_SIZE];
      67                 :            : static void *mbuf_p[MAX_NODES + 1][MBUFF_SIZE];
      68                 :            : static rte_graph_t graph_id;
      69                 :            : static uint64_t obj_stats[MAX_NODES + 1];
      70                 :            : static uint64_t fn_calls[MAX_NODES + 1];
      71                 :            : static uint32_t dummy_nodes_id[MAX_NODES];
      72                 :            : static uint32_t dummy_nodes_id_count;
      73                 :            : 
      74                 :            : const char *node_patterns[] = {
      75                 :            :         "test_node_source1",     "test_node00",
      76                 :            :         "test_node00-test_node11", "test_node00-test_node22",
      77                 :            :         "test_node00-test_node33",
      78                 :            : };
      79                 :            : 
      80                 :            : const char *node_names[] = {
      81                 :            :         "test_node00",
      82                 :            :         "test_node00-test_node11",
      83                 :            :         "test_node00-test_node22",
      84                 :            :         "test_node00-test_node33",
      85                 :            : };
      86                 :            : 
      87                 :            : struct test_node_register {
      88                 :            :         char name[RTE_NODE_NAMESIZE];
      89                 :            :         rte_node_process_t process;
      90                 :            :         uint16_t nb_edges;
      91                 :            :         const char *next_nodes[MAX_NODES];
      92                 :            : };
      93                 :            : 
      94                 :            : typedef struct {
      95                 :            :         uint32_t idx;
      96                 :            :         struct test_node_register node;
      97                 :            : } test_node_t;
      98                 :            : 
      99                 :            : typedef struct {
     100                 :            :         test_node_t test_node[MAX_NODES];
     101                 :            : } test_main_t;
     102                 :            : 
     103                 :            : static test_main_t test_main = {
     104                 :            :         .test_node = {
     105                 :            :                 {
     106                 :            :                         .node = {
     107                 :            :                                         .name = "test_node00",
     108                 :            :                                         .process = test_node0_worker,
     109                 :            :                                         .nb_edges = 2,
     110                 :            :                                         .next_nodes = {"test_node00-"
     111                 :            :                                                        "test_node11",
     112                 :            :                                                        "test_node00-"
     113                 :            :                                                        "test_node22"},
     114                 :            :                                 },
     115                 :            :                 },
     116                 :            :                 {
     117                 :            :                         .node = {
     118                 :            :                                         .name = "test_node11",
     119                 :            :                                         .process = test_node1_worker,
     120                 :            :                                         .nb_edges = 1,
     121                 :            :                                         .next_nodes = {"test_node00-"
     122                 :            :                                                        "test_node22"},
     123                 :            :                                 },
     124                 :            :                 },
     125                 :            :                 {
     126                 :            :                         .node = {
     127                 :            :                                         .name = "test_node22",
     128                 :            :                                         .process = test_node2_worker,
     129                 :            :                                         .nb_edges = 1,
     130                 :            :                                         .next_nodes = {"test_node00-"
     131                 :            :                                                        "test_node33"},
     132                 :            :                                 },
     133                 :            :                 },
     134                 :            :                 {
     135                 :            :                         .node = {
     136                 :            :                                         .name = "test_node33",
     137                 :            :                                         .process = test_node3_worker,
     138                 :            :                                         .nb_edges = 1,
     139                 :            :                                         .next_nodes = {"test_node00"},
     140                 :            :                                 },
     141                 :            :                 },
     142                 :            :         },
     143                 :            : };
     144                 :            : 
     145                 :            : static int
     146                 :         50 : node_init(const struct rte_graph *graph, struct rte_node *node)
     147                 :            : {
     148                 :            :         RTE_SET_USED(graph);
     149                 :         50 :         *(uint32_t *)node->ctx = node->id;
     150                 :            : 
     151                 :         50 :         return 0;
     152                 :            : }
     153                 :            : 
     154                 :            : static struct rte_node_register test_node_source = {
     155                 :            :         .name = "test_node_source1",
     156                 :            :         .process = test_node_worker_source,
     157                 :            :         .flags = RTE_NODE_SOURCE_F,
     158                 :            :         .nb_edges = 2,
     159                 :            :         .init = node_init,
     160                 :            :         .next_nodes = {"test_node00", "test_node00-test_node11"},
     161                 :            : };
     162                 :        253 : RTE_NODE_REGISTER(test_node_source);
     163                 :            : 
     164                 :            : static struct rte_node_register test_node0 = {
     165                 :            :         .name = "test_node00",
     166                 :            :         .process = test_node0_worker,
     167                 :            :         .init = node_init,
     168                 :            : };
     169                 :        253 : RTE_NODE_REGISTER(test_node0);
     170                 :            : 
     171                 :            : uint16_t
     172                 :          0 : test_node_worker_source(struct rte_graph *graph, struct rte_node *node,
     173                 :            :                         void **objs, uint16_t nb_objs)
     174                 :            : {
     175                 :          0 :         uint32_t obj_node0 = rte_rand() % 100, obj_node1;
     176                 :            :         test_main_t *tm = &test_main;
     177                 :            :         struct rte_mbuf *data;
     178                 :            :         void **next_stream;
     179                 :            :         rte_node_t next;
     180                 :            :         uint32_t i;
     181                 :            : 
     182                 :            :         RTE_SET_USED(objs);
     183                 :            :         nb_objs = RTE_GRAPH_BURST_SIZE;
     184                 :            : 
     185                 :            :         /* Prepare stream for next node 0 */
     186                 :          0 :         obj_node0 = nb_objs * obj_node0 * 0.01;
     187                 :            :         next = 0;
     188                 :          0 :         next_stream = rte_node_next_stream_get(graph, node, next, obj_node0);
     189         [ #  # ]:          0 :         for (i = 0; i < obj_node0; i++) {
     190                 :          0 :                 data = &mbuf[0][i];
     191                 :          0 :                 *graph_field(data) = ((uint64_t)tm->test_node[0].idx << 32) | i;
     192         [ #  # ]:          0 :                 if ((i + 1) == obj_node0)
     193                 :          0 :                         *graph_field(data) |= (1 << 16);
     194                 :          0 :                 next_stream[i] = &mbuf[0][i];
     195                 :            :         }
     196                 :            :         rte_node_next_stream_put(graph, node, next, obj_node0);
     197                 :            : 
     198                 :            :         /* Prepare stream for next node 1 */
     199                 :          0 :         obj_node1 = nb_objs - obj_node0;
     200                 :            :         next = 1;
     201                 :          0 :         next_stream = rte_node_next_stream_get(graph, node, next, obj_node1);
     202         [ #  # ]:          0 :         for (i = 0; i < obj_node1; i++) {
     203                 :          0 :                 data = &mbuf[0][obj_node0 + i];
     204                 :          0 :                 *graph_field(data) = ((uint64_t)tm->test_node[1].idx << 32) | i;
     205         [ #  # ]:          0 :                 if ((i + 1) == obj_node1)
     206                 :          0 :                         *graph_field(data) |= (1 << 16);
     207                 :          0 :                 next_stream[i] = &mbuf[0][obj_node0 + i];
     208                 :            :         }
     209                 :            : 
     210                 :            :         rte_node_next_stream_put(graph, node, next, obj_node1);
     211                 :          0 :         obj_stats[0] += nb_objs;
     212                 :          0 :         fn_calls[0] += 1;
     213                 :          0 :         return nb_objs;
     214                 :            : }
     215                 :            : 
     216                 :            : uint16_t
     217                 :          0 : test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
     218                 :            :                   uint16_t nb_objs)
     219                 :            : {
     220                 :            :         test_main_t *tm = &test_main;
     221                 :            : 
     222         [ #  # ]:          0 :         if (*(uint32_t *)node->ctx == test_node0.id) {
     223                 :          0 :                 uint32_t obj_node0 = rte_rand() % 100, obj_node1;
     224                 :            :                 struct rte_mbuf *data;
     225                 :            :                 uint8_t second_pass = 0;
     226                 :            :                 uint32_t count = 0;
     227                 :            :                 uint32_t i;
     228                 :            : 
     229                 :          0 :                 obj_stats[1] += nb_objs;
     230                 :          0 :                 fn_calls[1] += 1;
     231                 :            : 
     232         [ #  # ]:          0 :                 for (i = 0; i < nb_objs; i++) {
     233                 :          0 :                         data = (struct rte_mbuf *)objs[i];
     234         [ #  # ]:          0 :                         if ((*graph_field(data) >> 32) != tm->test_node[0].idx) {
     235                 :          0 :                                 printf("Data idx miss match at node 0, expected"
     236                 :            :                                        " = %u got = %u\n",
     237                 :            :                                        tm->test_node[0].idx,
     238                 :            :                                        (uint32_t)(*graph_field(data) >> 32));
     239                 :          0 :                                 goto end;
     240                 :            :                         }
     241                 :            : 
     242         [ #  # ]:          0 :                         if ((*graph_field(data) & 0xffff) != (i - count)) {
     243                 :            :                                 printf("Expected buff count miss match at "
     244                 :            :                                        "node 0\n");
     245                 :          0 :                                 goto end;
     246                 :            :                         }
     247                 :            : 
     248         [ #  # ]:          0 :                         if (*graph_field(data) & (0x1 << 16))
     249                 :          0 :                                 count = i + 1;
     250         [ #  # ]:          0 :                         if (*graph_field(data) & (0x1 << 17))
     251                 :            :                                 second_pass = 1;
     252                 :            :                 }
     253                 :            : 
     254         [ #  # ]:          0 :                 if (count != i) {
     255                 :            :                         printf("Count mismatch at node 0\n");
     256                 :          0 :                         goto end;
     257                 :            :                 }
     258                 :            : 
     259                 :          0 :                 obj_node0 = nb_objs * obj_node0 * 0.01;
     260         [ #  # ]:          0 :                 for (i = 0; i < obj_node0; i++) {
     261                 :          0 :                         data = &mbuf[1][i];
     262                 :          0 :                         *graph_field(data) =
     263                 :          0 :                                 ((uint64_t)tm->test_node[1].idx << 32) | i;
     264         [ #  # ]:          0 :                         if ((i + 1) == obj_node0)
     265                 :          0 :                                 *graph_field(data) |= (1 << 16);
     266         [ #  # ]:          0 :                         if (second_pass)
     267                 :          0 :                                 *graph_field(data) |= (1 << 17);
     268                 :            :                 }
     269                 :          0 :                 rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[1][0],
     270                 :            :                                  obj_node0);
     271                 :            : 
     272                 :          0 :                 obj_node1 = nb_objs - obj_node0;
     273         [ #  # ]:          0 :                 for (i = 0; i < obj_node1; i++) {
     274                 :          0 :                         data = &mbuf[1][obj_node0 + i];
     275                 :          0 :                         *graph_field(data) =
     276                 :          0 :                                 ((uint64_t)tm->test_node[2].idx << 32) | i;
     277         [ #  # ]:          0 :                         if ((i + 1) == obj_node1)
     278                 :          0 :                                 *graph_field(data) |= (1 << 16);
     279         [ #  # ]:          0 :                         if (second_pass)
     280                 :          0 :                                 *graph_field(data) |= (1 << 17);
     281                 :            :                 }
     282                 :          0 :                 rte_node_enqueue(graph, node, 1, (void **)&mbuf_p[1][obj_node0],
     283                 :            :                                  obj_node1);
     284                 :            : 
     285         [ #  # ]:          0 :         } else if (*(uint32_t *)node->ctx == tm->test_node[1].idx) {
     286                 :          0 :                 test_node1_worker(graph, node, objs, nb_objs);
     287         [ #  # ]:          0 :         } else if (*(uint32_t *)node->ctx == tm->test_node[2].idx) {
     288                 :          0 :                 test_node2_worker(graph, node, objs, nb_objs);
     289         [ #  # ]:          0 :         } else if (*(uint32_t *)node->ctx == tm->test_node[3].idx) {
     290                 :          0 :                 test_node3_worker(graph, node, objs, nb_objs);
     291                 :            :         } else {
     292                 :            :                 printf("Unexpected node context\n");
     293                 :            :         }
     294                 :            : 
     295                 :          0 : end:
     296                 :          0 :         return nb_objs;
     297                 :            : }
     298                 :            : 
     299                 :            : uint16_t
     300                 :          0 : test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
     301                 :            :                   uint16_t nb_objs)
     302                 :            : {
     303                 :            :         test_main_t *tm = &test_main;
     304                 :            :         uint8_t second_pass = 0;
     305                 :            :         uint32_t obj_node0 = 0;
     306                 :            :         struct rte_mbuf *data;
     307                 :            :         uint32_t count = 0;
     308                 :            :         uint32_t i;
     309                 :            : 
     310                 :          0 :         obj_stats[2] += nb_objs;
     311                 :          0 :         fn_calls[2] += 1;
     312         [ #  # ]:          0 :         for (i = 0; i < nb_objs; i++) {
     313                 :          0 :                 data = (struct rte_mbuf *)objs[i];
     314         [ #  # ]:          0 :                 if ((*graph_field(data) >> 32) != tm->test_node[1].idx) {
     315                 :          0 :                         printf("Data idx miss match at node 1, expected = %u"
     316                 :            :                                " got = %u\n",
     317                 :            :                                tm->test_node[1].idx,
     318                 :            :                                (uint32_t)(*graph_field(data) >> 32));
     319                 :          0 :                         goto end;
     320                 :            :                 }
     321                 :            : 
     322         [ #  # ]:          0 :                 if ((*graph_field(data) & 0xffff) != (i - count)) {
     323                 :            :                         printf("Expected buff count miss match at node 1\n");
     324                 :          0 :                         goto end;
     325                 :            :                 }
     326                 :            : 
     327         [ #  # ]:          0 :                 if (*graph_field(data) & (0x1 << 16))
     328                 :          0 :                         count = i + 1;
     329         [ #  # ]:          0 :                 if (*graph_field(data) & (0x1 << 17))
     330                 :            :                         second_pass = 1;
     331                 :            :         }
     332                 :            : 
     333         [ #  # ]:          0 :         if (count != i) {
     334                 :            :                 printf("Count mismatch at node 1\n");
     335                 :          0 :                 goto end;
     336                 :            :         }
     337                 :            : 
     338                 :            :         obj_node0 = nb_objs;
     339         [ #  # ]:          0 :         for (i = 0; i < obj_node0; i++) {
     340                 :          0 :                 data = &mbuf[2][i];
     341                 :          0 :                 *graph_field(data) = ((uint64_t)tm->test_node[2].idx << 32) | i;
     342         [ #  # ]:          0 :                 if ((i + 1) == obj_node0)
     343                 :          0 :                         *graph_field(data) |= (1 << 16);
     344         [ #  # ]:          0 :                 if (second_pass)
     345                 :          0 :                         *graph_field(data) |= (1 << 17);
     346                 :            :         }
     347                 :          0 :         rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[2][0], obj_node0);
     348                 :            : 
     349                 :          0 : end:
     350                 :          0 :         return nb_objs;
     351                 :            : }
     352                 :            : 
     353                 :            : uint16_t
     354                 :          0 : test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
     355                 :            :                   uint16_t nb_objs)
     356                 :            : {
     357                 :            :         test_main_t *tm = &test_main;
     358                 :            :         uint8_t second_pass = 0;
     359                 :            :         struct rte_mbuf *data;
     360                 :            :         uint32_t count = 0;
     361                 :            :         uint32_t obj_node0;
     362                 :            :         uint32_t i;
     363                 :            : 
     364                 :          0 :         obj_stats[3] += nb_objs;
     365                 :          0 :         fn_calls[3] += 1;
     366         [ #  # ]:          0 :         for (i = 0; i < nb_objs; i++) {
     367                 :          0 :                 data = (struct rte_mbuf *)objs[i];
     368         [ #  # ]:          0 :                 if ((*graph_field(data) >> 32) != tm->test_node[2].idx) {
     369                 :          0 :                         printf("Data idx miss match at node 2, expected = %u"
     370                 :            :                                " got = %u\n",
     371                 :            :                                tm->test_node[2].idx,
     372                 :            :                                (uint32_t)(*graph_field(data) >> 32));
     373                 :          0 :                         goto end;
     374                 :            :                 }
     375                 :            : 
     376         [ #  # ]:          0 :                 if ((*graph_field(data) & 0xffff) != (i - count)) {
     377                 :            :                         printf("Expected buff count miss match at node 2\n");
     378                 :          0 :                         goto end;
     379                 :            :                 }
     380                 :            : 
     381         [ #  # ]:          0 :                 if (*graph_field(data) & (0x1 << 16))
     382                 :          0 :                         count = i + 1;
     383         [ #  # ]:          0 :                 if (*graph_field(data) & (0x1 << 17))
     384                 :            :                         second_pass = 1;
     385                 :            :         }
     386                 :            : 
     387         [ #  # ]:          0 :         if (count != i) {
     388                 :            :                 printf("Count mismatch at node 2\n");
     389                 :          0 :                 goto end;
     390                 :            :         }
     391                 :            : 
     392         [ #  # ]:          0 :         if (!second_pass) {
     393                 :            :                 obj_node0 = nb_objs;
     394         [ #  # ]:          0 :                 for (i = 0; i < obj_node0; i++) {
     395                 :          0 :                         data = &mbuf[3][i];
     396                 :          0 :                         *graph_field(data) =
     397                 :          0 :                                 ((uint64_t)tm->test_node[3].idx << 32) | i;
     398         [ #  # ]:          0 :                         if ((i + 1) == obj_node0)
     399                 :          0 :                                 *graph_field(data) |= (1 << 16);
     400                 :            :                 }
     401                 :          0 :                 rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[3][0],
     402                 :            :                                  obj_node0);
     403                 :            :         }
     404                 :            : 
     405                 :          0 : end:
     406                 :          0 :         return nb_objs;
     407                 :            : }
     408                 :            : 
     409                 :            : uint16_t
     410                 :          0 : test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,
     411                 :            :                   uint16_t nb_objs)
     412                 :            : {
     413                 :            :         test_main_t *tm = &test_main;
     414                 :            :         uint8_t second_pass = 0;
     415                 :            :         struct rte_mbuf *data;
     416                 :            :         uint32_t count = 0;
     417                 :            :         uint32_t obj_node0;
     418                 :            :         uint32_t i;
     419                 :            : 
     420                 :          0 :         obj_stats[4] += nb_objs;
     421                 :          0 :         fn_calls[4] += 1;
     422         [ #  # ]:          0 :         for (i = 0; i < nb_objs; i++) {
     423                 :          0 :                 data = (struct rte_mbuf *)objs[i];
     424         [ #  # ]:          0 :                 if ((*graph_field(data) >> 32) != tm->test_node[3].idx) {
     425                 :          0 :                         printf("Data idx miss match at node 3, expected = %u"
     426                 :            :                                " got = %u\n",
     427                 :            :                                tm->test_node[3].idx,
     428                 :            :                                (uint32_t)(*graph_field(data) >> 32));
     429                 :          0 :                         goto end;
     430                 :            :                 }
     431                 :            : 
     432         [ #  # ]:          0 :                 if ((*graph_field(data) & 0xffff) != (i - count)) {
     433                 :            :                         printf("Expected buff count miss match at node 3\n");
     434                 :          0 :                         goto end;
     435                 :            :                 }
     436                 :            : 
     437         [ #  # ]:          0 :                 if (*graph_field(data) & (0x1 << 16))
     438                 :          0 :                         count = i + 1;
     439         [ #  # ]:          0 :                 if (*graph_field(data) & (0x1 << 17))
     440                 :            :                         second_pass = 1;
     441                 :            :         }
     442                 :            : 
     443         [ #  # ]:          0 :         if (count != i) {
     444                 :            :                 printf("Count mismatch at node 3\n");
     445                 :          0 :                 goto end;
     446                 :            :         }
     447                 :            : 
     448         [ #  # ]:          0 :         if (second_pass) {
     449                 :            :                 printf("Unexpected buffers are at node 3\n");
     450                 :          0 :                 goto end;
     451                 :            :         } else {
     452                 :          0 :                 obj_node0 = nb_objs * 2;
     453         [ #  # ]:          0 :                 for (i = 0; i < obj_node0; i++) {
     454                 :          0 :                         data = &mbuf[4][i];
     455                 :            :                         *graph_field(data) =
     456                 :          0 :                                 ((uint64_t)tm->test_node[0].idx << 32) | i;
     457                 :          0 :                         *graph_field(data) |= (1 << 17);
     458         [ #  # ]:          0 :                         if ((i + 1) == obj_node0)
     459                 :          0 :                                 *graph_field(data) |= (1 << 16);
     460                 :            :                 }
     461                 :          0 :                 rte_node_enqueue(graph, node, 0, (void **)&mbuf_p[4][0],
     462                 :            :                                  obj_node0);
     463                 :            :         }
     464                 :            : 
     465                 :          0 : end:
     466                 :          0 :         return nb_objs;
     467                 :            : }
     468                 :            : 
     469                 :            : static int
     470                 :          1 : test_lookup_functions(void)
     471                 :            : {
     472                 :            :         test_main_t *tm = &test_main;
     473                 :            :         int i;
     474                 :            : 
     475                 :            :         /* Verify the name with ID */
     476         [ +  + ]:          4 :         for (i = 1; i < MAX_NODES; i++) {
     477                 :          3 :                 char *name = rte_node_id_to_name(tm->test_node[i].idx);
     478         [ -  + ]:          3 :                 if (strcmp(name, node_names[i]) != 0) {
     479                 :            :                         printf("Test node name verify by ID = %d failed "
     480                 :            :                                "Expected = %s, got %s\n",
     481                 :            :                                i, node_names[i], name);
     482                 :          0 :                         return -1;
     483                 :            :                 }
     484                 :            :         }
     485                 :            : 
     486                 :            :         /* Verify by name */
     487         [ +  + ]:          4 :         for (i = 1; i < MAX_NODES; i++) {
     488                 :          3 :                 uint32_t idx = rte_node_from_name(node_names[i]);
     489         [ -  + ]:          3 :                 if (idx != tm->test_node[i].idx) {
     490                 :          0 :                         printf("Test node ID verify by name = %s failed "
     491                 :            :                                "Expected = %d, got %d\n",
     492                 :            :                                node_names[i], tm->test_node[i].idx, idx);
     493                 :          0 :                         return -1;
     494                 :            :                 }
     495                 :            :         }
     496                 :            : 
     497                 :            :         /* Verify edge count */
     498         [ +  + ]:          4 :         for (i = 1; i < MAX_NODES; i++) {
     499                 :          3 :                 uint32_t count = rte_node_edge_count(tm->test_node[i].idx);
     500         [ -  + ]:          3 :                 if (count != tm->test_node[i].node.nb_edges) {
     501                 :          0 :                         printf("Test number of edges for node = %s failed Expected = %d, got = %d\n",
     502                 :          0 :                                tm->test_node[i].node.name,
     503                 :            :                                tm->test_node[i].node.nb_edges, count);
     504                 :          0 :                         return -1;
     505                 :            :                 }
     506                 :            :         }
     507                 :            : 
     508                 :            :         /* Verify edge names */
     509         [ +  + ]:          4 :         for (i = 1; i < MAX_NODES; i++) {
     510                 :            :                 uint32_t j, count;
     511                 :            :                 char **next_edges;
     512                 :            : 
     513                 :          3 :                 count = rte_node_edge_get(tm->test_node[i].idx, NULL);
     514         [ -  + ]:          3 :                 if (count != tm->test_node[i].node.nb_edges * sizeof(char *)) {
     515                 :          0 :                         printf("Test number of edge count for node = %s failed Expected = %d, got = %d\n",
     516                 :          0 :                                tm->test_node[i].node.name,
     517                 :            :                                tm->test_node[i].node.nb_edges, count);
     518                 :          0 :                         return -1;
     519                 :            :                 }
     520                 :          3 :                 next_edges = malloc(count);
     521                 :          3 :                 count = rte_node_edge_get(tm->test_node[i].idx, next_edges);
     522         [ -  + ]:          3 :                 if (count != tm->test_node[i].node.nb_edges) {
     523                 :          0 :                         printf("Test number of edges for node = %s failed Expected = %d, got %d\n",
     524                 :          0 :                                tm->test_node[i].node.name,
     525                 :            :                                tm->test_node[i].node.nb_edges, count);
     526                 :          0 :                         free(next_edges);
     527                 :          0 :                         return -1;
     528                 :            :                 }
     529                 :            : 
     530         [ +  + ]:          6 :                 for (j = 0; j < count; j++) {
     531         [ -  + ]:          3 :                         if (strcmp(next_edges[j],
     532                 :            :                                    tm->test_node[i].node.next_nodes[j]) != 0) {
     533                 :            :                                 printf("Edge name miss match, expected = %s got = %s\n",
     534                 :            :                                        tm->test_node[i].node.next_nodes[j],
     535                 :            :                                        next_edges[j]);
     536                 :          0 :                                 free(next_edges);
     537                 :          0 :                                 return -1;
     538                 :            :                         }
     539                 :            :                 }
     540                 :          3 :                 free(next_edges);
     541                 :            :         }
     542                 :            : 
     543                 :            :         return 0;
     544                 :            : }
     545                 :            : 
     546                 :            : static int
     547                 :          1 : test_node_id(void)
     548                 :            : {
     549                 :            :         uint32_t node_id, odummy_id, dummy_id, dummy_id1;
     550                 :            : 
     551                 :          1 :         node_id = rte_node_from_name("test_node00");
     552                 :            : 
     553                 :          1 :         dummy_id = rte_node_clone(node_id, "test_node_id00");
     554         [ -  + ]:          1 :         if (rte_node_is_invalid(dummy_id)) {
     555                 :            :                 printf("Got invalid id when clone\n");
     556                 :          0 :                 return -1;
     557                 :            :         }
     558                 :            : 
     559                 :          1 :         dummy_id1 = rte_node_clone(node_id, "test_node_id01");
     560         [ -  + ]:          1 :         if (rte_node_is_invalid(dummy_id1)) {
     561                 :            :                 printf("Got invalid id when clone\n");
     562                 :          0 :                 return -1;
     563                 :            :         }
     564                 :            : 
     565                 :            :         /* Expect next node id to be node_id + 1 */
     566         [ -  + ]:          1 :         if ((dummy_id + 1) != dummy_id1) {
     567                 :            :                 printf("Node id didn't match, expected = %d got = %d\n",
     568                 :            :                        dummy_id+1, dummy_id1);
     569                 :          0 :                 return -1;
     570                 :            :         }
     571                 :            : 
     572                 :            :         odummy_id = dummy_id;
     573                 :            :         /* Free one of the cloned node */
     574         [ -  + ]:          1 :         if (rte_node_free(dummy_id)) {
     575                 :            :                 printf("Failed to free node\n");
     576                 :          0 :                 return -1;
     577                 :            :         }
     578                 :            : 
     579                 :            :         /* Clone again, should get the same id, that is freed */
     580                 :          1 :         dummy_id = rte_node_clone(node_id, "test_node_id00");
     581         [ -  + ]:          1 :         if (rte_node_is_invalid(dummy_id)) {
     582                 :            :                 printf("Got invalid id when clone\n");
     583                 :          0 :                 return -1;
     584                 :            :         }
     585                 :            : 
     586         [ -  + ]:          1 :         if (dummy_id != odummy_id) {
     587                 :            :                 printf("Node id didn't match, expected = %d got = %d\n",
     588                 :            :                        odummy_id, dummy_id);
     589                 :          0 :                 return -1;
     590                 :            :         }
     591                 :            : 
     592                 :            :         /* Free the node */
     593         [ -  + ]:          1 :         if (rte_node_free(dummy_id)) {
     594                 :            :                 printf("Failed to free node\n");
     595                 :          0 :                 return -1;
     596                 :            :         }
     597                 :            : 
     598         [ -  + ]:          1 :         if (rte_node_free(dummy_id1)) {
     599                 :            :                 printf("Failed to free node\n");
     600                 :          0 :                 return -1;
     601                 :            :         }
     602                 :            : 
     603                 :            :         return 0;
     604                 :            : }
     605                 :            : 
     606                 :            : static int
     607                 :          1 : test_node_clone(void)
     608                 :            : {
     609                 :            :         test_main_t *tm = &test_main;
     610                 :            :         uint32_t node_id, dummy_id;
     611                 :            :         int i;
     612                 :            : 
     613                 :          1 :         node_id = rte_node_from_name("test_node00");
     614                 :          1 :         tm->test_node[0].idx = node_id;
     615                 :            : 
     616                 :          1 :         dummy_nodes_id[dummy_nodes_id_count] = rte_node_clone(node_id, "test_node00");
     617         [ -  + ]:          1 :         if (rte_node_is_invalid(dummy_nodes_id[dummy_nodes_id_count])) {
     618                 :            :                 printf("Got invalid id when clone, Expecting fail\n");
     619                 :          0 :                 return -1;
     620                 :            :         }
     621                 :          1 :         dummy_nodes_id_count++;
     622                 :            : 
     623                 :            :         /* Clone with same name, should fail */
     624                 :          1 :         dummy_id = rte_node_clone(node_id, "test_node00");
     625         [ -  + ]:          1 :         if (!rte_node_is_invalid(dummy_id)) {
     626                 :            :                 printf("Got valid id when clone with same name, Expecting fail\n");
     627                 :          0 :                 return -1;
     628                 :            :         }
     629                 :            : 
     630         [ +  + ]:          4 :         for (i = 1; i < MAX_NODES; i++) {
     631                 :          3 :                 tm->test_node[i].idx =
     632                 :          3 :                         rte_node_clone(node_id, tm->test_node[i].node.name);
     633         [ -  + ]:          3 :                 if (rte_node_is_invalid(tm->test_node[i].idx)) {
     634                 :            :                         printf("Got invalid node id\n");
     635                 :          0 :                         return -1;
     636                 :            :                 }
     637                 :            :         }
     638                 :            : 
     639                 :            :         /* Clone from cloned node should fail */
     640                 :          1 :         dummy_id = rte_node_clone(tm->test_node[1].idx, "dummy_node");
     641         [ -  + ]:          1 :         if (!rte_node_is_invalid(dummy_id)) {
     642                 :            :                 printf("Got valid node id when cloning from cloned node, expected fail\n");
     643                 :          0 :                 return -1;
     644                 :            :         }
     645                 :            : 
     646                 :            :         return 0;
     647                 :            : }
     648                 :            : 
     649                 :            : static int
     650                 :          1 : test_update_edges(void)
     651                 :            : {
     652                 :            :         test_main_t *tm = &test_main;
     653                 :            :         uint32_t node_id;
     654                 :            :         uint16_t count;
     655                 :            :         int i;
     656                 :            : 
     657                 :          1 :         node_id = rte_node_from_name("test_node00");
     658                 :          1 :         count = rte_node_edge_update(node_id, 0,
     659                 :            :                                      tm->test_node[0].node.next_nodes,
     660                 :          1 :                                      tm->test_node[0].node.nb_edges);
     661         [ -  + ]:          1 :         if (count != tm->test_node[0].node.nb_edges) {
     662                 :          0 :                 printf("Update edges failed expected: %d got = %d\n",
     663                 :            :                        tm->test_node[0].node.nb_edges, count);
     664                 :          0 :                 return -1;
     665                 :            :         }
     666                 :            : 
     667         [ +  + ]:          4 :         for (i = 1; i < MAX_NODES; i++) {
     668                 :          3 :                 count = rte_node_edge_update(tm->test_node[i].idx, 0,
     669                 :          3 :                                              tm->test_node[i].node.next_nodes,
     670                 :          3 :                                              tm->test_node[i].node.nb_edges);
     671         [ -  + ]:          3 :                 if (count != tm->test_node[i].node.nb_edges) {
     672                 :          0 :                         printf("Update edges failed expected: %d got = %d\n",
     673                 :            :                                tm->test_node[i].node.nb_edges, count);
     674                 :          0 :                         return -1;
     675                 :            :                 }
     676                 :            : 
     677                 :          3 :                 count = rte_node_edge_shrink(tm->test_node[i].idx,
     678                 :            :                                              tm->test_node[i].node.nb_edges);
     679         [ -  + ]:          3 :                 if (count != tm->test_node[i].node.nb_edges) {
     680                 :            :                         printf("Shrink edges failed\n");
     681                 :          0 :                         return -1;
     682                 :            :                 }
     683                 :            :         }
     684                 :            : 
     685                 :            :         return 0;
     686                 :            : }
     687                 :            : 
     688                 :            : static int
     689                 :          1 : test_create_graph(void)
     690                 :            : {
     691                 :            :         static const char *node_patterns_dummy[] = {
     692                 :            :                 "test_node_source1",     "test_node00",
     693                 :            :                 "test_node00-test_node11", "test_node00-test_node22",
     694                 :            :                 "test_node00-test_node33", "test_node00-dummy_node",
     695                 :            :         };
     696                 :          1 :         struct rte_graph_param gconf = {
     697                 :            :                 .socket_id = SOCKET_ID_ANY,
     698                 :            :                 .nb_node_patterns = 6,
     699                 :            :                 .node_patterns = node_patterns_dummy,
     700                 :            :         };
     701                 :            :         uint32_t node_id;
     702                 :            : 
     703                 :          1 :         node_id = rte_node_from_name("test_node00");
     704                 :          1 :         dummy_nodes_id[dummy_nodes_id_count] = rte_node_clone(node_id, "dummy_node");
     705         [ -  + ]:          1 :         if (rte_node_is_invalid(dummy_nodes_id[dummy_nodes_id_count])) {
     706                 :            :                 printf("Got invalid node id\n");
     707                 :          0 :                 return -1;
     708                 :            :         }
     709                 :          1 :         dummy_nodes_id_count++;
     710                 :            : 
     711                 :          1 :         graph_id = rte_graph_create("worker0", &gconf);
     712         [ -  + ]:          1 :         if (graph_id != RTE_GRAPH_ID_INVALID) {
     713                 :            :                 printf("Graph creation success with isolated node, expected graph creation fail\n");
     714                 :          0 :                 return -1;
     715                 :            :         }
     716                 :            : 
     717                 :          1 :         gconf.nb_node_patterns = 5;
     718                 :          1 :         gconf.node_patterns = node_patterns;
     719                 :          1 :         graph_id = rte_graph_create("worker0", &gconf);
     720         [ -  + ]:          1 :         if (graph_id == RTE_GRAPH_ID_INVALID) {
     721                 :          0 :                 printf("Graph creation failed with error = %d\n", rte_errno);
     722                 :          0 :                 return -1;
     723                 :            :         }
     724                 :            :         return 0;
     725                 :            : }
     726                 :            : 
     727                 :            : static int
     728                 :          1 : test_graph_clone(void)
     729                 :            : {
     730                 :            :         rte_graph_t cloned_graph_id = RTE_GRAPH_ID_INVALID;
     731                 :            :         rte_graph_t main_graph_id = RTE_GRAPH_ID_INVALID;
     732                 :          1 :         struct rte_graph_param graph_conf = {0};
     733                 :            :         int ret = 0;
     734                 :            : 
     735                 :          1 :         main_graph_id = rte_graph_from_name("worker0");
     736         [ -  + ]:          1 :         if (main_graph_id == RTE_GRAPH_ID_INVALID) {
     737                 :            :                 printf("Must create main graph first\n");
     738                 :            :                 ret = -1;
     739                 :            :         }
     740                 :            : 
     741                 :          1 :         graph_conf.dispatch.mp_capacity = 1024;
     742                 :          1 :         graph_conf.dispatch.wq_size_max = 32;
     743                 :            : 
     744                 :          1 :         cloned_graph_id = rte_graph_clone(main_graph_id, "cloned-test0", &graph_conf);
     745                 :            : 
     746         [ -  + ]:          1 :         if (cloned_graph_id == RTE_GRAPH_ID_INVALID) {
     747                 :          0 :                 printf("Graph creation failed with error = %d\n", rte_errno);
     748                 :            :                 ret = -1;
     749                 :            :         }
     750                 :            : 
     751         [ -  + ]:          1 :         if (strcmp(rte_graph_id_to_name(cloned_graph_id), "worker0-cloned-test0")) {
     752                 :          0 :                 printf("Cloned graph should name as %s but get %s\n", "worker0-cloned-test",
     753                 :            :                        rte_graph_id_to_name(cloned_graph_id));
     754                 :            :                 ret = -1;
     755                 :            :         }
     756                 :            : 
     757                 :          1 :         rte_graph_destroy(cloned_graph_id);
     758                 :            : 
     759                 :          1 :         return ret;
     760                 :            : }
     761                 :            : 
     762                 :            : static int
     763                 :          1 : test_graph_id_collisions(void)
     764                 :            : {
     765                 :            :         static const char *node_patterns[] = {"test_node_source1", "test_node00"};
     766                 :          1 :         struct rte_graph_param gconf = {
     767                 :            :                 .socket_id = SOCKET_ID_ANY,
     768                 :            :                 .nb_node_patterns = 2,
     769                 :            :                 .node_patterns = node_patterns,
     770                 :            :         };
     771                 :            :         rte_graph_t g1, g2, g3, g4;
     772                 :            : 
     773                 :          1 :         g1 = rte_graph_create("worker1", &gconf);
     774         [ -  + ]:          1 :         if (g1 == RTE_GRAPH_ID_INVALID) {
     775                 :          0 :                 printf("Graph 1 creation failed with error = %d\n", rte_errno);
     776                 :          0 :                 return -1;
     777                 :            :         }
     778                 :          1 :         g2 = rte_graph_create("worker2", &gconf);
     779         [ -  + ]:          1 :         if (g2 == RTE_GRAPH_ID_INVALID) {
     780                 :          0 :                 printf("Graph 2 creation failed with error = %d\n", rte_errno);
     781                 :          0 :                 return -1;
     782                 :            :         }
     783                 :          1 :         g3 = rte_graph_create("worker3", &gconf);
     784         [ -  + ]:          1 :         if (g3 == RTE_GRAPH_ID_INVALID) {
     785                 :          0 :                 printf("Graph 3 creation failed with error = %d\n", rte_errno);
     786                 :          0 :                 return -1;
     787                 :            :         }
     788   [ +  -  -  + ]:          1 :         if (g1 == g2 || g2 == g3 || g1 == g3) {
     789                 :            :                 printf("Graph ids should be different\n");
     790                 :          0 :                 return -1;
     791                 :            :         }
     792         [ -  + ]:          1 :         if (rte_graph_destroy(g2) < 0) {
     793                 :            :                 printf("Graph 2 suppression failed\n");
     794                 :          0 :                 return -1;
     795                 :            :         }
     796                 :          1 :         g4 = rte_graph_create("worker4", &gconf);
     797         [ -  + ]:          1 :         if (g4 == RTE_GRAPH_ID_INVALID) {
     798                 :          0 :                 printf("Graph 4 creation failed with error = %d\n", rte_errno);
     799                 :          0 :                 return -1;
     800                 :            :         }
     801   [ +  -  -  + ]:          1 :         if (g1 == g3 || g1 == g4 || g3 == g4) {
     802                 :            :                 printf("Graph ids should be different\n");
     803                 :          0 :                 return -1;
     804                 :            :         }
     805                 :          1 :         g2 = rte_graph_clone(g1, "worker2", &gconf);
     806         [ -  + ]:          1 :         if (g2 == RTE_GRAPH_ID_INVALID) {
     807                 :          0 :                 printf("Graph 4 creation failed with error = %d\n", rte_errno);
     808                 :          0 :                 return -1;
     809                 :            :         }
     810   [ +  -  +  -  :          1 :         if (g1 == g2 || g1 == g3 || g1 == g4 || g2 == g3 || g2 == g4 || g3 == g4) {
                   -  + ]
     811                 :            :                 printf("Graph ids should be different\n");
     812                 :          0 :                 return -1;
     813                 :            :         }
     814         [ -  + ]:          1 :         if (rte_graph_destroy(g1) < 0) {
     815                 :            :                 printf("Graph 1 suppression failed\n");
     816                 :          0 :                 return -1;
     817                 :            :         }
     818         [ -  + ]:          1 :         if (rte_graph_destroy(g2) < 0) {
     819                 :            :                 printf("Graph 2 suppression failed\n");
     820                 :          0 :                 return -1;
     821                 :            :         }
     822         [ -  + ]:          1 :         if (rte_graph_destroy(g3) < 0) {
     823                 :            :                 printf("Graph 3 suppression failed\n");
     824                 :          0 :                 return -1;
     825                 :            :         }
     826         [ -  + ]:          1 :         if (rte_graph_destroy(g4) < 0) {
     827                 :            :                 printf("Graph 4 suppression failed\n");
     828                 :          0 :                 return -1;
     829                 :            :         }
     830                 :            :         return 0;
     831                 :            : }
     832                 :            : 
     833                 :            : static int
     834                 :          1 : test_graph_model_mcore_dispatch_node_lcore_affinity_set(void)
     835                 :            : {
     836                 :            :         rte_graph_t cloned_graph_id = RTE_GRAPH_ID_INVALID;
     837                 :            :         unsigned int worker_lcore = RTE_MAX_LCORE;
     838                 :          1 :         struct rte_graph_param graph_conf = {0};
     839                 :            :         rte_node_t nid = RTE_NODE_ID_INVALID;
     840                 :          1 :         char node_name[64] = "test_node00";
     841                 :            :         struct rte_node *node;
     842                 :            :         int ret = 0;
     843                 :            : 
     844                 :          1 :         worker_lcore = rte_get_next_lcore(worker_lcore, true, 1);
     845                 :          1 :         ret = rte_graph_model_mcore_dispatch_node_lcore_affinity_set(node_name, worker_lcore);
     846         [ +  - ]:          1 :         if (ret == 0)
     847                 :            :                 printf("Set node %s affinity to lcore %u\n", node_name, worker_lcore);
     848                 :            : 
     849                 :          1 :         nid = rte_node_from_name(node_name);
     850                 :          1 :         cloned_graph_id = rte_graph_clone(graph_id, "cloned-test1", &graph_conf);
     851                 :          1 :         node = rte_graph_node_get(cloned_graph_id, nid);
     852                 :            : 
     853         [ -  + ]:          1 :         if (node->dispatch.lcore_id != worker_lcore) {
     854                 :            :                 printf("set node affinity failed\n");
     855                 :            :                 ret = -1;
     856                 :            :         }
     857                 :            : 
     858                 :          1 :         rte_graph_destroy(cloned_graph_id);
     859                 :            : 
     860                 :          1 :         return ret;
     861                 :            : }
     862                 :            : 
     863                 :            : static int
     864                 :          1 : test_graph_model_mcore_dispatch_core_bind_unbind(void)
     865                 :            : {
     866                 :            :         rte_graph_t cloned_graph_id = RTE_GRAPH_ID_INVALID;
     867                 :            :         unsigned int worker_lcore = RTE_MAX_LCORE;
     868                 :          1 :         struct rte_graph_param graph_conf = {0};
     869                 :            :         struct rte_graph *graph;
     870                 :            :         int ret = 0;
     871                 :            : 
     872                 :          1 :         worker_lcore = rte_get_next_lcore(worker_lcore, true, 1);
     873                 :          1 :         cloned_graph_id = rte_graph_clone(graph_id, "cloned-test2", &graph_conf);
     874                 :            : 
     875                 :          1 :         ret = rte_graph_worker_model_set(RTE_GRAPH_MODEL_MCORE_DISPATCH);
     876         [ -  + ]:          1 :         if (ret != 0) {
     877                 :            :                 printf("Set graph mcore dispatch model failed\n");
     878                 :          0 :                 goto fail;
     879                 :            :         }
     880                 :            : 
     881                 :          1 :         ret = rte_graph_model_mcore_dispatch_core_bind(cloned_graph_id, worker_lcore);
     882         [ -  + ]:          1 :         if (ret != 0) {
     883                 :          0 :                 printf("bind graph %d to lcore %u failed\n", graph_id, worker_lcore);
     884                 :          0 :                 goto fail;
     885                 :            :         }
     886                 :            : 
     887                 :          1 :         graph = rte_graph_lookup("worker0-cloned-test2");
     888                 :            : 
     889         [ -  + ]:          1 :         if (graph->dispatch.lcore_id != worker_lcore) {
     890                 :          0 :                 printf("bind graph %s(id:%d) with lcore %u failed\n",
     891                 :          0 :                        graph->name, graph->id, worker_lcore);
     892                 :            :                 ret = -1;
     893                 :          0 :                 goto fail;
     894                 :            :         }
     895                 :            : 
     896                 :          1 :         rte_graph_model_mcore_dispatch_core_unbind(cloned_graph_id);
     897         [ +  - ]:          1 :         if (graph->dispatch.lcore_id != RTE_MAX_LCORE) {
     898                 :          0 :                 printf("unbind graph %s(id:%d) failed %d\n",
     899                 :          0 :                        graph->name, graph->id, graph->dispatch.lcore_id);
     900                 :            :                 ret = -1;
     901                 :            :         }
     902                 :            : 
     903                 :          1 : fail:
     904                 :          1 :         rte_graph_destroy(cloned_graph_id);
     905                 :            : 
     906                 :          1 :         return ret;
     907                 :            : }
     908                 :            : 
     909                 :            : static int
     910                 :          1 : test_graph_worker_model_set_get(void)
     911                 :            : {
     912                 :            :         rte_graph_t cloned_graph_id = RTE_GRAPH_ID_INVALID;
     913                 :          1 :         struct rte_graph_param graph_conf = {0};
     914                 :            :         struct rte_graph *graph;
     915                 :            :         int ret = 0;
     916                 :            : 
     917                 :          1 :         cloned_graph_id = rte_graph_clone(graph_id, "cloned-test3", &graph_conf);
     918                 :          1 :         ret = rte_graph_worker_model_set(RTE_GRAPH_MODEL_MCORE_DISPATCH);
     919         [ -  + ]:          1 :         if (ret != 0) {
     920                 :            :                 printf("Set graph mcore dispatch model failed\n");
     921                 :          0 :                 goto fail;
     922                 :            :         }
     923                 :            : 
     924                 :          1 :         graph = rte_graph_lookup("worker0-cloned-test3");
     925         [ +  - ]:          1 :         if (rte_graph_worker_model_get(graph) != RTE_GRAPH_MODEL_MCORE_DISPATCH) {
     926                 :            :                 printf("Get graph worker model failed\n");
     927                 :            :                 ret = -1;
     928                 :            :         }
     929                 :            : 
     930                 :          1 : fail:
     931                 :          1 :         rte_graph_destroy(cloned_graph_id);
     932                 :            : 
     933                 :          1 :         return ret;
     934                 :            : }
     935                 :            : 
     936                 :            : static int
     937                 :          1 : test_graph_walk(void)
     938                 :            : {
     939                 :          1 :         struct rte_graph *graph = rte_graph_lookup("worker0");
     940                 :            :         int i;
     941                 :            : 
     942         [ -  + ]:          1 :         if (!graph) {
     943                 :            :                 printf("Graph lookup failed\n");
     944                 :          0 :                 return -1;
     945                 :            :         }
     946                 :            : 
     947         [ +  + ]:          6 :         for (i = 0; i < 5; i++)
     948                 :          5 :                 rte_graph_walk(graph);
     949                 :            :         return 0;
     950                 :            : }
     951                 :            : 
     952                 :            : static int
     953                 :          1 : test_graph_lookup_functions(void)
     954                 :            : {
     955                 :            :         test_main_t *tm = &test_main;
     956                 :            :         struct rte_node *node;
     957                 :            :         int i;
     958                 :            : 
     959         [ +  + ]:          5 :         for (i = 0; i < MAX_NODES; i++) {
     960                 :          4 :                 node = rte_graph_node_get(graph_id, tm->test_node[i].idx);
     961         [ -  + ]:          4 :                 if (!node) {
     962                 :          0 :                         printf("rte_graph_node_get, failed for node = %d\n",
     963                 :            :                                tm->test_node[i].idx);
     964                 :          0 :                         return -1;
     965                 :            :                 }
     966                 :            : 
     967         [ -  + ]:          4 :                 if (tm->test_node[i].idx != node->id) {
     968                 :            :                         printf("Node id didn't match, expected = %d got = %d\n",
     969                 :            :                                tm->test_node[i].idx, node->id);
     970                 :          0 :                         return 0;
     971                 :            :                 }
     972                 :            : 
     973         [ -  + ]:          4 :                 if (strncmp(node->name, node_names[i], RTE_NODE_NAMESIZE)) {
     974                 :            :                         printf("Node name didn't match, expected = %s got %s\n",
     975                 :            :                                node_names[i], node->name);
     976                 :          0 :                         return -1;
     977                 :            :                 }
     978                 :            :         }
     979                 :            : 
     980         [ +  + ]:          5 :         for (i = 0; i < MAX_NODES; i++) {
     981                 :          4 :                 node = rte_graph_node_get_by_name("worker0", node_names[i]);
     982         [ -  + ]:          4 :                 if (!node) {
     983                 :          0 :                         printf("rte_graph_node_get, failed for node = %d\n",
     984                 :            :                                tm->test_node[i].idx);
     985                 :          0 :                         return -1;
     986                 :            :                 }
     987                 :            : 
     988         [ -  + ]:          4 :                 if (tm->test_node[i].idx != node->id) {
     989                 :            :                         printf("Node id didn't match, expected = %d got = %d\n",
     990                 :            :                                tm->test_node[i].idx, node->id);
     991                 :          0 :                         return 0;
     992                 :            :                 }
     993                 :            : 
     994         [ -  + ]:          4 :                 if (strncmp(node->name, node_names[i], RTE_NODE_NAMESIZE)) {
     995                 :            :                         printf("Node name didn't match, expected = %s got %s\n",
     996                 :            :                                node_names[i], node->name);
     997                 :          0 :                         return -1;
     998                 :            :                 }
     999                 :            :         }
    1000                 :            : 
    1001                 :            :         return 0;
    1002                 :            : }
    1003                 :            : 
    1004                 :            : static int
    1005                 :          5 : graph_cluster_stats_cb_t(bool is_first, bool is_last, void *cookie,
    1006                 :            :                          const struct rte_graph_cluster_node_stats *st)
    1007                 :            : {
    1008                 :            :         int i;
    1009                 :            : 
    1010                 :            :         RTE_SET_USED(is_first);
    1011                 :            :         RTE_SET_USED(is_last);
    1012                 :            :         RTE_SET_USED(cookie);
    1013                 :            : 
    1014         [ +  + ]:         30 :         for (i = 0; i < MAX_NODES + 1; i++) {
    1015                 :         25 :                 rte_node_t id = rte_node_from_name(node_patterns[i]);
    1016         [ +  + ]:         25 :                 if (id == st->id) {
    1017         [ -  + ]:          5 :                         if (obj_stats[i] != st->objs) {
    1018                 :          0 :                                 printf("Obj count miss match for node = %s expected = %"PRId64", got=%"PRId64"\n",
    1019                 :            :                                        node_patterns[i], obj_stats[i],
    1020                 :            :                                        st->objs);
    1021                 :          0 :                                 return -1;
    1022                 :            :                         }
    1023                 :            : 
    1024         [ -  + ]:          5 :                         if (fn_calls[i] != st->calls) {
    1025                 :          0 :                                 printf("Func call miss match for node = %s expected = %"PRId64", got = %"PRId64"\n",
    1026                 :            :                                        node_patterns[i], fn_calls[i],
    1027                 :            :                                        st->calls);
    1028                 :          0 :                                 return -1;
    1029                 :            :                         }
    1030                 :            :                 }
    1031                 :            :         }
    1032                 :            :         return 0;
    1033                 :            : }
    1034                 :            : 
    1035                 :            : static int
    1036                 :          1 : test_print_stats(void)
    1037                 :            : {
    1038                 :            :         struct rte_graph_cluster_stats_param s_param;
    1039                 :            :         struct rte_graph_cluster_stats *stats;
    1040                 :          1 :         const char *pattern = "worker0";
    1041                 :            : 
    1042                 :            :         if (!rte_graph_has_stats_feature())
    1043                 :            :                 return 0;
    1044                 :            : 
    1045                 :            :         /* Prepare stats object */
    1046                 :            :         memset(&s_param, 0, sizeof(s_param));
    1047                 :          1 :         s_param.f = stdout;
    1048                 :          1 :         s_param.socket_id = SOCKET_ID_ANY;
    1049                 :          1 :         s_param.graph_patterns = &pattern;
    1050                 :          1 :         s_param.nb_graph_patterns = 1;
    1051                 :          1 :         s_param.fn = graph_cluster_stats_cb_t;
    1052                 :            : 
    1053                 :          1 :         stats = rte_graph_cluster_stats_create(&s_param);
    1054         [ -  + ]:          1 :         if (stats == NULL) {
    1055                 :            :                 printf("Unable to get stats\n");
    1056                 :          0 :                 return -1;
    1057                 :            :         }
    1058                 :            :         /* Clear screen and move to top left */
    1059                 :          1 :         rte_graph_cluster_stats_get(stats, 0);
    1060                 :          1 :         rte_graph_cluster_stats_destroy(stats);
    1061                 :            : 
    1062                 :          1 :         return 0;
    1063                 :            : }
    1064                 :            : 
    1065                 :            : static int
    1066                 :          1 : graph_setup(void)
    1067                 :            : {
    1068                 :            :         int i, j;
    1069                 :            : 
    1070                 :            :         static const struct rte_mbuf_dynfield graph_dynfield_desc = {
    1071                 :            :                 .name = "test_graph_dynfield",
    1072                 :            :                 .size = sizeof(graph_dynfield_t),
    1073                 :            :                 .align = alignof(graph_dynfield_t),
    1074                 :            :         };
    1075                 :          1 :         graph_dynfield_offset =
    1076                 :          1 :                 rte_mbuf_dynfield_register(&graph_dynfield_desc);
    1077         [ -  + ]:          1 :         if (graph_dynfield_offset < 0) {
    1078                 :            :                 printf("Cannot register mbuf field\n");
    1079                 :          0 :                 return TEST_FAILED;
    1080                 :            :         }
    1081                 :            : 
    1082         [ +  + ]:          6 :         for (i = 0; i <= MAX_NODES; i++) {
    1083         [ +  + ]:       2565 :                 for (j = 0; j < MBUFF_SIZE; j++)
    1084                 :       2560 :                         mbuf_p[i][j] = &mbuf[i][j];
    1085                 :            :         }
    1086         [ -  + ]:          1 :         if (test_node_clone()) {
    1087                 :            :                 printf("test_node_clone: fail\n");
    1088                 :          0 :                 return -1;
    1089                 :            :         }
    1090                 :            :         printf("test_node_clone: pass\n");
    1091                 :            : 
    1092         [ -  + ]:          1 :         if (test_node_id()) {
    1093                 :            :                 printf("test_node_id: fail\n");
    1094                 :          0 :                 return -1;
    1095                 :            :         }
    1096                 :            :         printf("test_node_id: pass\n");
    1097                 :            : 
    1098                 :          1 :         return 0;
    1099                 :            : }
    1100                 :            : 
    1101                 :            : static void
    1102                 :          1 : graph_teardown(void)
    1103                 :            : {
    1104                 :            :         uint32_t i;
    1105                 :            :         int id;
    1106                 :            : 
    1107                 :          1 :         id = rte_graph_destroy(rte_graph_from_name("worker0"));
    1108         [ -  + ]:          1 :         if (id)
    1109                 :            :                 printf("Graph Destroy failed\n");
    1110                 :            : 
    1111         [ +  + ]:          4 :         for (i = 1; i < MAX_NODES; i++) {
    1112         [ -  + ]:          3 :                 if (rte_node_free(test_main.test_node[i].idx)) {
    1113                 :            :                         printf("Node free failed\n");
    1114                 :          0 :                         return;
    1115                 :            :                 }
    1116                 :            :         }
    1117                 :            : 
    1118         [ +  + ]:          3 :         for (i = 0; i < dummy_nodes_id_count; i++) {
    1119         [ -  + ]:          2 :                 if (rte_node_free(dummy_nodes_id[i])) {
    1120                 :            :                         printf("Node free failed\n");
    1121                 :          0 :                         return;
    1122                 :            :                 }
    1123                 :            :         }
    1124                 :          1 :         dummy_nodes_id_count = 0;
    1125                 :            : }
    1126                 :            : 
    1127                 :            : static struct unit_test_suite graph_testsuite = {
    1128                 :            :         .suite_name = "Graph library test suite",
    1129                 :            :         .setup = graph_setup,
    1130                 :            :         .teardown = graph_teardown,
    1131                 :            :         .unit_test_cases = {
    1132                 :            :                 TEST_CASE(test_update_edges),
    1133                 :            :                 TEST_CASE(test_lookup_functions),
    1134                 :            :                 TEST_CASE(test_create_graph),
    1135                 :            :                 TEST_CASE(test_graph_clone),
    1136                 :            :                 TEST_CASE(test_graph_id_collisions),
    1137                 :            :                 TEST_CASE(test_graph_model_mcore_dispatch_node_lcore_affinity_set),
    1138                 :            :                 TEST_CASE(test_graph_model_mcore_dispatch_core_bind_unbind),
    1139                 :            :                 TEST_CASE(test_graph_worker_model_set_get),
    1140                 :            :                 TEST_CASE(test_graph_lookup_functions),
    1141                 :            :                 TEST_CASE(test_graph_walk),
    1142                 :            :                 TEST_CASE(test_print_stats),
    1143                 :            :                 TEST_CASES_END(), /**< NULL terminate unit test array */
    1144                 :            :         },
    1145                 :            : };
    1146                 :            : 
    1147                 :            : static int
    1148                 :          1 : graph_autotest_fn(void)
    1149                 :            : {
    1150                 :          1 :         return unit_test_suite_runner(&graph_testsuite);
    1151                 :            : }
    1152                 :            : 
    1153                 :        253 : REGISTER_FAST_TEST(graph_autotest, true, true, graph_autotest_fn);
    1154                 :            : 
    1155                 :            : static int
    1156                 :          1 : test_node_list_dump(void)
    1157                 :            : {
    1158                 :          1 :         rte_node_list_dump(stdout);
    1159                 :            : 
    1160                 :          1 :         return TEST_SUCCESS;
    1161                 :            : }
    1162                 :            : 
    1163                 :            : #endif /* !RTE_EXEC_ENV_WINDOWS */
    1164                 :            : 
    1165                 :        253 : REGISTER_FAST_TEST(node_list_dump, true, true, test_node_list_dump);

Generated by: LCOV version 1.14