Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/67225/?format=api
https://patches.dpdk.org/api/patches/67225/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/20200326165644.866053-14-jerinj@marvell.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<20200326165644.866053-14-jerinj@marvell.com>", "list_archive_url": "https://inbox.dpdk.org/dev/20200326165644.866053-14-jerinj@marvell.com", "date": "2020-03-26T16:56:29", "name": "[v2,13/28] graph: add unit test case", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "1e141353ab631f11a4af8b1c4b7efa176e911b0d", "submitter": { "id": 1188, "url": "https://patches.dpdk.org/api/people/1188/?format=api", "name": "Jerin Jacob Kollanukkaran", "email": "jerinj@marvell.com" }, "delegate": { "id": 1, "url": "https://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "https://patches.dpdk.org/project/dpdk/patch/20200326165644.866053-14-jerinj@marvell.com/mbox/", "series": [ { "id": 9068, "url": "https://patches.dpdk.org/api/series/9068/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=9068", "date": "2020-03-26T16:56:16", "name": "graph: introduce graph subsystem", "version": 2, "mbox": "https://patches.dpdk.org/series/9068/mbox/" } ], "comments": "https://patches.dpdk.org/api/patches/67225/comments/", "check": "warning", "checks": "https://patches.dpdk.org/api/patches/67225/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@inbox.dpdk.org", "Delivered-To": "patchwork@inbox.dpdk.org", "Received": [ "from dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 9B3B2A057C;\n\tThu, 26 Mar 2020 17:59:13 +0100 (CET)", "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 2782A1C117;\n\tThu, 26 Mar 2020 17:57:26 +0100 (CET)", "from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com\n [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id 1851B1C069\n for <dev@dpdk.org>; Thu, 26 Mar 2020 17:57:25 +0100 (CET)", "from pps.filterd (m0045851.ppops.net [127.0.0.1])\n by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id\n 02QGj6Hx002873; Thu, 26 Mar 2020 09:57:23 -0700", "from sc-exch01.marvell.com ([199.233.58.181])\n by mx0b-0016f401.pphosted.com with ESMTP id 300bpcvu57-1\n (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT);\n Thu, 26 Mar 2020 09:57:22 -0700", "from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH01.marvell.com\n (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2;\n Thu, 26 Mar 2020 09:57:20 -0700", "from SC-EXCH03.marvell.com (10.93.176.83) by DC5-EXCH02.marvell.com\n (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2;\n Thu, 26 Mar 2020 09:57:19 -0700", "from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com\n (10.93.176.83) with Microsoft SMTP Server id 15.0.1497.2 via Frontend\n Transport; Thu, 26 Mar 2020 09:57:19 -0700", "from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14])\n by maili.marvell.com (Postfix) with ESMTP id 468F23F7041;\n Thu, 26 Mar 2020 09:57:17 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com;\n h=from : to : cc :\n subject : date : message-id : in-reply-to : references : mime-version :\n content-transfer-encoding : content-type; s=pfpt0818;\n bh=MU+tRSn1a0HIrD6Iklp+jegQbT2jRG5OrNiW9hVsQbU=;\n b=LvDgP25nYxMJfHihZcV/HlfkjnMbbPZh9NiOHbpEbZ2KBNyuohs0BeynGAauSU4uRyji\n qQAKMLHqhBurTeAwpE77S33nclysTcgsXXUxH5fV3ef5HLfbW0+JIWhjoVSFJ7kXk1Oo\n 4TGvjZNWqc9LeqmtFgFXcELnrVesLfz4NEh/dwvPj0V8LuroeKcziiK+gH0OIJI4GzL3\n hfS05/HpW2Ua2XmPdD34Bq0Cb5RxCfgqzECCFJo6v51yMsiN4jioE0NcRk9ucVS+Xji5\n 6+J52mr13Qu2fh8kZxteQSiy07QZD17ABVP0tE8/OEzBTn9GAhd3pv2LLHo3YzR9jGLM zg==", "From": "<jerinj@marvell.com>", "To": "", "CC": "<dev@dpdk.org>, <thomas@monjalon.net>, <david.marchand@redhat.com>,\n <mdr@ashroe.eu>, <mattias.ronnblom@ericsson.com>,\n <kirankumark@marvell.com>, <pbhagavatula@marvell.com>,\n <ndabilpuram@marvell.com>", "Date": "Thu, 26 Mar 2020 22:26:29 +0530", "Message-ID": "<20200326165644.866053-14-jerinj@marvell.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20200326165644.866053-1-jerinj@marvell.com>", "References": "<20200318213551.3489504-1-jerinj@marvell.com>\n <20200326165644.866053-1-jerinj@marvell.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Content-Type": "text/plain", "X-Proofpoint-Virus-Version": "vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645\n definitions=2020-03-26_08:2020-03-26,\n 2020-03-26 signatures=0", "Subject": "[dpdk-dev] [PATCH v2 13/28] graph: add unit test case", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "From: Kiran Kumar K <kirankumark@marvell.com>\n\nAdding the unit test to test the functionality of node and graph APIs.\nTesting includes registering a node, cloning a node, creating a graph,\nperform graph walk, collecting stats and all node and graph debug APIs.\n\nexample command to test:\necho \"graph_autotest\" | sudo ./build/app/test/dpdk-test -c 0x30\n\nSigned-off-by: Kiran Kumar K <kirankumark@marvell.com>\n---\n app/test/Makefile | 6 +\n app/test/meson.build | 11 +-\n app/test/test_graph.c | 819 ++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 834 insertions(+), 2 deletions(-)\n create mode 100644 app/test/test_graph.c", "diff": "diff --git a/app/test/Makefile b/app/test/Makefile\nindex 1f080d162..ce2e08e12 100644\n--- a/app/test/Makefile\n+++ b/app/test/Makefile\n@@ -221,6 +221,10 @@ SRCS-y += test_event_timer_adapter.c\n SRCS-y += test_event_crypto_adapter.c\n endif\n \n+ifeq ($(CONFIG_RTE_LIBRTE_GRAPH), y)\n+SRCS-y += test_graph.c\n+endif\n+\n ifeq ($(CONFIG_RTE_LIBRTE_RAWDEV),y)\n SRCS-y += test_rawdev.c\n endif\n@@ -240,6 +244,8 @@ endif\n CFLAGS += -DALLOW_EXPERIMENTAL_API\n \n CFLAGS += -O3\n+# Strict-aliasing rules are violated by uint8_t[] to context size casts.\n+CFLAGS += -fno-strict-aliasing\n CFLAGS += $(WERROR_FLAGS)\n \n LDLIBS += -lm\ndiff --git a/app/test/meson.build b/app/test/meson.build\nindex 351d29cb6..0de16290e 100644\n--- a/app/test/meson.build\n+++ b/app/test/meson.build\n@@ -51,6 +51,7 @@ test_sources = files('commands.c',\n \t'test_fib6_perf.c',\n \t'test_func_reentrancy.c',\n \t'test_flow_classify.c',\n+\t'test_graph.c',\n \t'test_hash.c',\n \t'test_hash_functions.c',\n \t'test_hash_multiwriter.c',\n@@ -151,7 +152,9 @@ test_deps = ['acl',\n \t'rib',\n \t'ring',\n \t'stack',\n-\t'timer'\n+\t'timer',\n+\t'graph',\n+\t'node'\n ]\n \n # Each test is marked with flag true/false\n@@ -362,6 +365,8 @@ endif\n \n # specify -D_GNU_SOURCE unconditionally\n cflags += '-D_GNU_SOURCE'\n+# Strict-aliasing rules are violated by uint8_t[] to context size casts.\n+cflags += '-fno-strict-aliasing'\n \n test_dep_objs = []\n if dpdk_conf.has('RTE_LIBRTE_COMPRESSDEV')\n@@ -385,13 +390,15 @@ endforeach\n test_dep_objs += cc.find_library('execinfo', required: false)\n \n link_libs = []\n+link_nodes = []\n if get_option('default_library') == 'static'\n \tlink_libs = dpdk_drivers\n+\tlink_nodes = dpdk_graph_nodes\n endif\n \n dpdk_test = executable('dpdk-test',\n \ttest_sources,\n-\tlink_whole: link_libs,\n+\tlink_whole: link_libs + link_nodes,\n \tdependencies: test_dep_objs,\n \tc_args: [cflags, '-DALLOW_EXPERIMENTAL_API'],\n \tinstall_rpath: driver_install_path,\ndiff --git a/app/test/test_graph.c b/app/test/test_graph.c\nnew file mode 100644\nindex 000000000..a90dc8f30\n--- /dev/null\n+++ b/app/test/test_graph.c\n@@ -0,0 +1,819 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(C) 2020 Marvell International Ltd.\n+ */\n+#include <assert.h>\n+#include <inttypes.h>\n+#include <signal.h>\n+#include <stdio.h>\n+#include <string.h>\n+#include <unistd.h>\n+\n+#include <rte_errno.h>\n+#include <rte_graph.h>\n+#include <rte_graph_worker.h>\n+#include <rte_mbuf.h>\n+\n+#include \"test.h\"\n+\n+static uint16_t test_node_worker_source(struct rte_graph *graph,\n+\t\t\t\t\tstruct rte_node *node, void **objs,\n+\t\t\t\t\tuint16_t nb_objs);\n+\n+static uint16_t test_node0_worker(struct rte_graph *graph,\n+\t\t\t\t struct rte_node *node, void **objs,\n+\t\t\t\t uint16_t nb_objs);\n+\n+static uint16_t test_node1_worker(struct rte_graph *graph,\n+\t\t\t\t struct rte_node *node, void **objs,\n+\t\t\t\t uint16_t nb_objs);\n+\n+static uint16_t test_node2_worker(struct rte_graph *graph,\n+\t\t\t\t struct rte_node *node, void **objs,\n+\t\t\t\t uint16_t nb_objs);\n+\n+static uint16_t test_node3_worker(struct rte_graph *graph,\n+\t\t\t\t struct rte_node *node, void **objs,\n+\t\t\t\t uint16_t nb_objs);\n+\n+#define MBUFF_SIZE 512\n+#define MAX_NODES 4\n+\n+static struct rte_mbuf mbuf[MAX_NODES + 1][MBUFF_SIZE];\n+static void *mbuf_p[MAX_NODES + 1][MBUFF_SIZE];\n+static rte_graph_t graph_id;\n+static uint64_t obj_stats[MAX_NODES + 1];\n+static uint64_t fn_calls[MAX_NODES + 1];\n+\n+const char *node_patterns[] = {\n+\t\"test_node_source1\",\t \"test_node00\",\n+\t\"test_node00-test_node11\", \"test_node00-test_node22\",\n+\t\"test_node00-test_node33\",\n+};\n+\n+const char *node_names[] = {\n+\t\"test_node00\",\n+\t\"test_node00-test_node11\",\n+\t\"test_node00-test_node22\",\n+\t\"test_node00-test_node33\",\n+};\n+\n+struct test_node_register {\n+\tchar name[RTE_NODE_NAMESIZE];\n+\trte_node_process_t process;\n+\tuint16_t nb_edges;\n+\tconst char *next_nodes[MAX_NODES];\n+};\n+\n+typedef struct {\n+\tuint32_t idx;\n+\tstruct test_node_register node;\n+} test_node_t;\n+\n+typedef struct {\n+\ttest_node_t test_node[MAX_NODES];\n+} test_main_t;\n+\n+static test_main_t test_main = {\n+\t.test_node = {\n+\t\t{\n+\t\t\t.node = {\n+\t\t\t\t\t.name = \"test_node00\",\n+\t\t\t\t\t.process = test_node0_worker,\n+\t\t\t\t\t.nb_edges = 2,\n+\t\t\t\t\t.next_nodes = {\"test_node00-\"\n+\t\t\t\t\t\t \"test_node11\",\n+\t\t\t\t\t\t \"test_node00-\"\n+\t\t\t\t\t\t \"test_node22\"},\n+\t\t\t\t},\n+\t\t},\n+\t\t{\n+\t\t\t.node = {\n+\t\t\t\t\t.name = \"test_node11\",\n+\t\t\t\t\t.process = test_node1_worker,\n+\t\t\t\t\t.nb_edges = 1,\n+\t\t\t\t\t.next_nodes = {\"test_node00-\"\n+\t\t\t\t\t\t \"test_node22\"},\n+\t\t\t\t},\n+\t\t},\n+\t\t{\n+\t\t\t.node = {\n+\t\t\t\t\t.name = \"test_node22\",\n+\t\t\t\t\t.process = test_node2_worker,\n+\t\t\t\t\t.nb_edges = 1,\n+\t\t\t\t\t.next_nodes = {\"test_node00-\"\n+\t\t\t\t\t\t \"test_node33\"},\n+\t\t\t\t},\n+\t\t},\n+\t\t{\n+\t\t\t.node = {\n+\t\t\t\t\t.name = \"test_node33\",\n+\t\t\t\t\t.process = test_node3_worker,\n+\t\t\t\t\t.nb_edges = 1,\n+\t\t\t\t\t.next_nodes = {\"test_node00\"},\n+\t\t\t\t},\n+\t\t},\n+\t},\n+};\n+\n+static int\n+node_init(const struct rte_graph *graph, struct rte_node *node)\n+{\n+\tRTE_SET_USED(graph);\n+\t*(uint32_t *)node->ctx = node->id;\n+\n+\treturn 0;\n+}\n+\n+static struct rte_node_register test_node_source = {\n+\t.name = \"test_node_source1\",\n+\t.process = test_node_worker_source,\n+\t.flags = RTE_NODE_SOURCE_F,\n+\t.nb_edges = 2,\n+\t.init = node_init,\n+\t.next_nodes = {\"test_node00\", \"test_node00-test_node11\"},\n+};\n+RTE_NODE_REGISTER(test_node_source);\n+\n+static struct rte_node_register test_node0 = {\n+\t.name = \"test_node00\",\n+\t.process = test_node0_worker,\n+\t.init = node_init,\n+};\n+RTE_NODE_REGISTER(test_node0);\n+\n+uint16_t\n+test_node_worker_source(struct rte_graph *graph, struct rte_node *node,\n+\t\t\tvoid **objs, uint16_t nb_objs)\n+{\n+\tuint32_t obj_node0 = rand() % 100, obj_node1;\n+\ttest_main_t *tm = &test_main;\n+\tstruct rte_mbuf *data;\n+\tvoid **next_stream;\n+\trte_node_t next;\n+\tuint32_t i;\n+\n+\tRTE_SET_USED(objs);\n+\tnb_objs = RTE_GRAPH_BURST_SIZE;\n+\n+\t/* Prepare stream for next node 0 */\n+\tobj_node0 = nb_objs * obj_node0 * 0.01;\n+\tnext = 0;\n+\tnext_stream = rte_node_next_stream_get(graph, node, next, obj_node0);\n+\tfor (i = 0; i < obj_node0; i++) {\n+\t\tdata = &mbuf[0][i];\n+\t\tdata->udata64 = ((uint64_t)tm->test_node[0].idx << 32) | i;\n+\t\tif ((i + 1) == obj_node0)\n+\t\t\tdata->udata64 |= (1 << 16);\n+\t\tnext_stream[i] = &mbuf[0][i];\n+\t}\n+\trte_node_next_stream_put(graph, node, next, obj_node0);\n+\n+\t/* Prepare stream for next node 1 */\n+\tobj_node1 = nb_objs - obj_node0;\n+\tnext = 1;\n+\tnext_stream = rte_node_next_stream_get(graph, node, next, obj_node1);\n+\tfor (i = 0; i < obj_node1; i++) {\n+\t\tdata = &mbuf[0][obj_node0 + i];\n+\t\tdata->udata64 = ((uint64_t)tm->test_node[1].idx << 32) | i;\n+\t\tif ((i + 1) == obj_node1)\n+\t\t\tdata->udata64 |= (1 << 16);\n+\t\tnext_stream[i] = &mbuf[0][obj_node0 + i];\n+\t}\n+\n+\trte_node_next_stream_put(graph, node, next, obj_node1);\n+\tobj_stats[0] += nb_objs;\n+\tfn_calls[0] += 1;\n+\treturn nb_objs;\n+}\n+\n+uint16_t\n+test_node0_worker(struct rte_graph *graph, struct rte_node *node, void **objs,\n+\t\t uint16_t nb_objs)\n+{\n+\ttest_main_t *tm = &test_main;\n+\n+\tif (*(uint32_t *)node->ctx == test_node0.id) {\n+\t\tuint32_t obj_node0 = rand() % 100, obj_node1;\n+\t\tstruct rte_mbuf *data;\n+\t\tuint8_t second_pass = 0;\n+\t\tuint32_t count = 0;\n+\t\tuint32_t i;\n+\n+\t\tobj_stats[1] += nb_objs;\n+\t\tfn_calls[1] += 1;\n+\n+\t\tfor (i = 0; i < nb_objs; i++) {\n+\t\t\tdata = (struct rte_mbuf *)objs[i];\n+\t\t\tif ((data->udata64 >> 32) != tm->test_node[0].idx) {\n+\t\t\t\tprintf(\"Data idx miss match at node 0, expected\"\n+\t\t\t\t \" = %u got = %u\\n\",\n+\t\t\t\t tm->test_node[0].idx,\n+\t\t\t\t (uint32_t)(data->udata64 >> 32));\n+\t\t\t\tgoto end;\n+\t\t\t}\n+\n+\t\t\tif ((data->udata64 & 0xffff) != (i - count)) {\n+\t\t\t\tprintf(\"Expected buff count miss match at \"\n+\t\t\t\t \"node 0\\n\");\n+\t\t\t\tgoto end;\n+\t\t\t}\n+\n+\t\t\tif (data->udata64 & (0x1 << 16))\n+\t\t\t\tcount = i + 1;\n+\t\t\tif (data->udata64 & (0x1 << 17))\n+\t\t\t\tsecond_pass = 1;\n+\t\t}\n+\n+\t\tif (count != i) {\n+\t\t\tprintf(\"Count mismatch at node 0\\n\");\n+\t\t\tgoto end;\n+\t\t}\n+\n+\t\tobj_node0 = nb_objs * obj_node0 * 0.01;\n+\t\tfor (i = 0; i < obj_node0; i++) {\n+\t\t\tdata = &mbuf[1][i];\n+\t\t\tdata->udata64 =\n+\t\t\t\t((uint64_t)tm->test_node[1].idx << 32) | i;\n+\t\t\tif ((i + 1) == obj_node0)\n+\t\t\t\tdata->udata64 |= (1 << 16);\n+\t\t\tif (second_pass)\n+\t\t\t\tdata->udata64 |= (1 << 17);\n+\t\t}\n+\t\trte_node_enqueue(graph, node, 0, (void **)&mbuf_p[1][0],\n+\t\t\t\t obj_node0);\n+\n+\t\tobj_node1 = nb_objs - obj_node0;\n+\t\tfor (i = 0; i < obj_node1; i++) {\n+\t\t\tdata = &mbuf[1][obj_node0 + i];\n+\t\t\tdata->udata64 =\n+\t\t\t\t((uint64_t)tm->test_node[2].idx << 32) | i;\n+\t\t\tif ((i + 1) == obj_node1)\n+\t\t\t\tdata->udata64 |= (1 << 16);\n+\t\t\tif (second_pass)\n+\t\t\t\tdata->udata64 |= (1 << 17);\n+\t\t}\n+\t\trte_node_enqueue(graph, node, 1, (void **)&mbuf_p[1][obj_node0],\n+\t\t\t\t obj_node1);\n+\n+\t} else if (*(uint32_t *)node->ctx == tm->test_node[1].idx) {\n+\t\ttest_node1_worker(graph, node, objs, nb_objs);\n+\t} else if (*(uint32_t *)node->ctx == tm->test_node[2].idx) {\n+\t\ttest_node2_worker(graph, node, objs, nb_objs);\n+\t} else if (*(uint32_t *)node->ctx == tm->test_node[3].idx) {\n+\t\ttest_node3_worker(graph, node, objs, nb_objs);\n+\t} else {\n+\t\tprintf(\"Unexpected node context\\n\");\n+\t}\n+\n+end:\n+\treturn nb_objs;\n+}\n+\n+uint16_t\n+test_node1_worker(struct rte_graph *graph, struct rte_node *node, void **objs,\n+\t\t uint16_t nb_objs)\n+{\n+\ttest_main_t *tm = &test_main;\n+\tuint8_t second_pass = 0;\n+\tuint32_t obj_node0 = 0;\n+\tstruct rte_mbuf *data;\n+\tuint32_t count = 0;\n+\tuint32_t i;\n+\n+\tobj_stats[2] += nb_objs;\n+\tfn_calls[2] += 1;\n+\tfor (i = 0; i < nb_objs; i++) {\n+\t\tdata = (struct rte_mbuf *)objs[i];\n+\t\tif ((data->udata64 >> 32) != tm->test_node[1].idx) {\n+\t\t\tprintf(\"Data idx miss match at node 1, expected = %u\"\n+\t\t\t \" got = %u\\n\",\n+\t\t\t tm->test_node[1].idx,\n+\t\t\t (uint32_t)(data->udata64 >> 32));\n+\t\t\tgoto end;\n+\t\t}\n+\n+\t\tif ((data->udata64 & 0xffff) != (i - count)) {\n+\t\t\tprintf(\"Expected buff count miss match at node 1\\n\");\n+\t\t\tgoto end;\n+\t\t}\n+\n+\t\tif (data->udata64 & (0x1 << 16))\n+\t\t\tcount = i + 1;\n+\t\tif (data->udata64 & (0x1 << 17))\n+\t\t\tsecond_pass = 1;\n+\t}\n+\n+\tif (count != i) {\n+\t\tprintf(\"Count mismatch at node 1\\n\");\n+\t\tgoto end;\n+\t}\n+\n+\tobj_node0 = nb_objs;\n+\tfor (i = 0; i < obj_node0; i++) {\n+\t\tdata = &mbuf[2][i];\n+\t\tdata->udata64 = ((uint64_t)tm->test_node[2].idx << 32) | i;\n+\t\tif ((i + 1) == obj_node0)\n+\t\t\tdata->udata64 |= (1 << 16);\n+\t\tif (second_pass)\n+\t\t\tdata->udata64 |= (1 << 17);\n+\t}\n+\trte_node_enqueue(graph, node, 0, (void **)&mbuf_p[2][0], obj_node0);\n+\n+end:\n+\treturn nb_objs;\n+}\n+\n+uint16_t\n+test_node2_worker(struct rte_graph *graph, struct rte_node *node, void **objs,\n+\t\t uint16_t nb_objs)\n+{\n+\ttest_main_t *tm = &test_main;\n+\tuint8_t second_pass = 0;\n+\tstruct rte_mbuf *data;\n+\tuint32_t count = 0;\n+\tuint32_t obj_node0;\n+\tuint32_t i;\n+\n+\tobj_stats[3] += nb_objs;\n+\tfn_calls[3] += 1;\n+\tfor (i = 0; i < nb_objs; i++) {\n+\t\tdata = (struct rte_mbuf *)objs[i];\n+\t\tif ((data->udata64 >> 32) != tm->test_node[2].idx) {\n+\t\t\tprintf(\"Data idx miss match at node 2, expected = %u\"\n+\t\t\t \" got = %u\\n\",\n+\t\t\t tm->test_node[2].idx,\n+\t\t\t (uint32_t)(data->udata64 >> 32));\n+\t\t\tgoto end;\n+\t\t}\n+\n+\t\tif ((data->udata64 & 0xffff) != (i - count)) {\n+\t\t\tprintf(\"Expected buff count miss match at node 2\\n\");\n+\t\t\tgoto end;\n+\t\t}\n+\n+\t\tif (data->udata64 & (0x1 << 16))\n+\t\t\tcount = i + 1;\n+\t\tif (data->udata64 & (0x1 << 17))\n+\t\t\tsecond_pass = 1;\n+\t}\n+\n+\tif (count != i) {\n+\t\tprintf(\"Count mismatch at node 2\\n\");\n+\t\tgoto end;\n+\t}\n+\n+\tif (!second_pass) {\n+\t\tobj_node0 = nb_objs;\n+\t\tfor (i = 0; i < obj_node0; i++) {\n+\t\t\tdata = &mbuf[3][i];\n+\t\t\tdata->udata64 =\n+\t\t\t\t((uint64_t)tm->test_node[3].idx << 32) | i;\n+\t\t\tif ((i + 1) == obj_node0)\n+\t\t\t\tdata->udata64 |= (1 << 16);\n+\t\t}\n+\t\trte_node_enqueue(graph, node, 0, (void **)&mbuf_p[3][0],\n+\t\t\t\t obj_node0);\n+\t}\n+\n+end:\n+\treturn nb_objs;\n+}\n+\n+uint16_t\n+test_node3_worker(struct rte_graph *graph, struct rte_node *node, void **objs,\n+\t\t uint16_t nb_objs)\n+{\n+\ttest_main_t *tm = &test_main;\n+\tuint8_t second_pass = 0;\n+\tstruct rte_mbuf *data;\n+\tuint32_t count = 0;\n+\tuint32_t obj_node0;\n+\tuint32_t i;\n+\n+\tobj_stats[4] += nb_objs;\n+\tfn_calls[4] += 1;\n+\tfor (i = 0; i < nb_objs; i++) {\n+\t\tdata = (struct rte_mbuf *)objs[i];\n+\t\tif ((data->udata64 >> 32) != tm->test_node[3].idx) {\n+\t\t\tprintf(\"Data idx miss match at node 3, expected = %u\"\n+\t\t\t \" got = %u\\n\",\n+\t\t\t tm->test_node[3].idx,\n+\t\t\t (uint32_t)(data->udata64 >> 32));\n+\t\t\tgoto end;\n+\t\t}\n+\n+\t\tif ((data->udata64 & 0xffff) != (i - count)) {\n+\t\t\tprintf(\"Expected buff count miss match at node 3\\n\");\n+\t\t\tgoto end;\n+\t\t}\n+\n+\t\tif (data->udata64 & (0x1 << 16))\n+\t\t\tcount = i + 1;\n+\t\tif (data->udata64 & (0x1 << 17))\n+\t\t\tsecond_pass = 1;\n+\t}\n+\n+\tif (count != i) {\n+\t\tprintf(\"Count mismatch at node 3\\n\");\n+\t\tgoto end;\n+\t}\n+\n+\tif (second_pass) {\n+\t\tprintf(\"Unexpected buffers are at node 3\\n\");\n+\t\tgoto end;\n+\t} else {\n+\t\tobj_node0 = nb_objs * 2;\n+\t\tfor (i = 0; i < obj_node0; i++) {\n+\t\t\tdata = &mbuf[4][i];\n+\t\t\tdata->udata64 =\n+\t\t\t\t((uint64_t)tm->test_node[0].idx << 32) | i;\n+\t\t\tdata->udata64 |= (1 << 17);\n+\t\t\tif ((i + 1) == obj_node0)\n+\t\t\t\tdata->udata64 |= (1 << 16);\n+\t\t}\n+\t\trte_node_enqueue(graph, node, 0, (void **)&mbuf_p[4][0],\n+\t\t\t\t obj_node0);\n+\t}\n+\n+end:\n+\treturn nb_objs;\n+}\n+\n+static int\n+test_lookup_functions(void)\n+{\n+\ttest_main_t *tm = &test_main;\n+\tint i;\n+\n+\t/* Verify the name with ID */\n+\tfor (i = 1; i < MAX_NODES; i++) {\n+\t\tchar *name = rte_node_id_to_name(tm->test_node[i].idx);\n+\t\tif (strcmp(name, node_names[i]) != 0) {\n+\t\t\tprintf(\"Test node name verify by ID = %d failed \"\n+\t\t\t \"Expected = %s, got %s\\n\",\n+\t\t\t i, node_names[i], name);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\t/* Verify by name */\n+\tfor (i = 1; i < MAX_NODES; i++) {\n+\t\tuint32_t idx = rte_node_from_name(node_names[i]);\n+\t\tif (idx != tm->test_node[i].idx) {\n+\t\t\tprintf(\"Test node ID verify by name = %s failed \"\n+\t\t\t \"Expected = %d, got %d\\n\",\n+\t\t\t node_names[i], tm->test_node[i].idx, idx);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\t/* Verify edge count */\n+\tfor (i = 1; i < MAX_NODES; i++) {\n+\t\tuint32_t count = rte_node_edge_count(tm->test_node[i].idx);\n+\t\tif (count != tm->test_node[i].node.nb_edges) {\n+\t\t\tprintf(\"Test number of edges for node = %s failed Expected = %d, got = %d\\n\",\n+\t\t\t tm->test_node[i].node.name,\n+\t\t\t tm->test_node[i].node.nb_edges, count);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\t/* Verify edge names */\n+\tfor (i = 1; i < MAX_NODES; i++) {\n+\t\tuint32_t j, count;\n+\t\tchar **next_edges;\n+\n+\t\tcount = rte_node_edge_get(tm->test_node[i].idx, NULL);\n+\t\tif (count != tm->test_node[i].node.nb_edges * sizeof(char *)) {\n+\t\t\tprintf(\"Test number of edge count for node = %s failed Expected = %d, got = %d\\n\",\n+\t\t\t tm->test_node[i].node.name,\n+\t\t\t tm->test_node[i].node.nb_edges, count);\n+\t\t\treturn -1;\n+\t\t}\n+\t\tnext_edges = malloc(count);\n+\t\tcount = rte_node_edge_get(tm->test_node[i].idx, next_edges);\n+\t\tif (count != tm->test_node[i].node.nb_edges) {\n+\t\t\tprintf(\"Test number of edges for node = %s failed Expected = %d, got %d\\n\",\n+\t\t\t tm->test_node[i].node.name,\n+\t\t\t tm->test_node[i].node.nb_edges, count);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tfor (j = 0; j < count; j++) {\n+\t\t\tif (strcmp(next_edges[j],\n+\t\t\t\t tm->test_node[i].node.next_nodes[j]) != 0) {\n+\t\t\t\tprintf(\"Edge name miss match, expected = %s got = %s\\n\",\n+\t\t\t\t tm->test_node[i].node.next_nodes[j],\n+\t\t\t\t next_edges[j]);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t}\n+\t\tfree(next_edges);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_node_clone(void)\n+{\n+\ttest_main_t *tm = &test_main;\n+\tuint32_t node_id, dummy_id;\n+\tint i;\n+\n+\tnode_id = rte_node_from_name(\"test_node00\");\n+\ttm->test_node[0].idx = node_id;\n+\n+\t/* Clone with same name, should fail */\n+\tdummy_id = rte_node_clone(node_id, \"test_node00\");\n+\tif (!rte_node_is_invalid(dummy_id)) {\n+\t\tprintf(\"Got valid id when clone with same name, Expecting fail\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tfor (i = 1; i < MAX_NODES; i++) {\n+\t\ttm->test_node[i].idx =\n+\t\t\trte_node_clone(node_id, tm->test_node[i].node.name);\n+\t\tif (rte_node_is_invalid(tm->test_node[i].idx)) {\n+\t\t\tprintf(\"Got invalid node id\\n\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\t/* Clone from cloned node should fail */\n+\tdummy_id = rte_node_clone(tm->test_node[1].idx, \"dummy_node\");\n+\tif (!rte_node_is_invalid(dummy_id)) {\n+\t\tprintf(\"Got valid node id when cloning from cloned node, expected fail\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_update_edges(void)\n+{\n+\ttest_main_t *tm = &test_main;\n+\tuint32_t node_id;\n+\tuint16_t count;\n+\tint i;\n+\n+\tnode_id = rte_node_from_name(\"test_node00\");\n+\tcount = rte_node_edge_update(node_id, 0,\n+\t\t\t\t tm->test_node[0].node.next_nodes,\n+\t\t\t\t tm->test_node[0].node.nb_edges);\n+\tif (count != tm->test_node[0].node.nb_edges) {\n+\t\tprintf(\"Update edges failed expected: %d got = %d\\n\",\n+\t\t tm->test_node[0].node.nb_edges, count);\n+\t\treturn -1;\n+\t}\n+\n+\tfor (i = 1; i < MAX_NODES; i++) {\n+\t\tcount = rte_node_edge_update(tm->test_node[i].idx, 0,\n+\t\t\t\t\t tm->test_node[i].node.next_nodes,\n+\t\t\t\t\t tm->test_node[i].node.nb_edges);\n+\t\tif (count != tm->test_node[i].node.nb_edges) {\n+\t\t\tprintf(\"Update edges failed expected: %d got = %d\\n\",\n+\t\t\t tm->test_node[i].node.nb_edges, count);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tcount = rte_node_edge_shrink(tm->test_node[i].idx,\n+\t\t\t\t\t tm->test_node[i].node.nb_edges);\n+\t\tif (count != tm->test_node[i].node.nb_edges) {\n+\t\t\tprintf(\"Shrink edges failed\\n\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+test_create_graph(void)\n+{\n+\tstatic const char *node_patterns_dummy[] = {\n+\t\t\"test_node_source1\",\t \"test_node00\",\n+\t\t\"test_node00-test_node11\", \"test_node00-test_node22\",\n+\t\t\"test_node00-test_node33\", \"test_node00-dummy_node\",\n+\t};\n+\tstruct rte_graph_param gconf = {\n+\t\t.socket_id = SOCKET_ID_ANY,\n+\t\t.nb_node_patterns = 6,\n+\t\t.node_patterns = node_patterns_dummy,\n+\t};\n+\tuint32_t dummy_node_id;\n+\tuint32_t node_id;\n+\n+\tnode_id = rte_node_from_name(\"test_node00\");\n+\tdummy_node_id = rte_node_clone(node_id, \"dummy_node\");\n+\tif (rte_node_is_invalid(dummy_node_id)) {\n+\t\tprintf(\"Got invalid node id\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tgraph_id = rte_graph_create(\"worker0\", &gconf);\n+\tif (graph_id != RTE_GRAPH_ID_INVALID) {\n+\t\tprintf(\"Graph creation success with isolated node, expected graph creation fail\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tgconf.nb_node_patterns = 5;\n+\tgconf.node_patterns = node_patterns;\n+\tgraph_id = rte_graph_create(\"worker0\", &gconf);\n+\tif (graph_id == RTE_GRAPH_ID_INVALID) {\n+\t\tprintf(\"Graph creation failed with error = %d\\n\", rte_errno);\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\n+\n+static int\n+test_graph_walk(void)\n+{\n+\tstruct rte_graph *graph = rte_graph_lookup(\"worker0\");\n+\tint i;\n+\n+\tif (!graph) {\n+\t\tprintf(\"Graph lookup failed\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tfor (i = 0; i < 5; i++)\n+\t\trte_graph_walk(graph);\n+\treturn 0;\n+}\n+\n+static int\n+test_graph_lookup_functions(void)\n+{\n+\ttest_main_t *tm = &test_main;\n+\tstruct rte_node *node;\n+\tint i;\n+\n+\tfor (i = 0; i < MAX_NODES; i++) {\n+\t\tnode = rte_graph_node_get(graph_id, tm->test_node[i].idx);\n+\t\tif (!node) {\n+\t\t\tprintf(\"rte_graph_node_get, failed for node = %d\\n\",\n+\t\t\t tm->test_node[i].idx);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tif (tm->test_node[i].idx != node->id) {\n+\t\t\tprintf(\"Node id didn't match, expected = %d got = %d\\n\",\n+\t\t\t tm->test_node[i].idx, node->id);\n+\t\t\treturn 0;\n+\t\t}\n+\n+\t\tif (strncmp(node->name, node_names[i], RTE_NODE_NAMESIZE)) {\n+\t\t\tprintf(\"Node name didn't match, expected = %s got %s\\n\",\n+\t\t\t node_names[i], node->name);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\tfor (i = 0; i < MAX_NODES; i++) {\n+\t\tnode = rte_graph_node_get_by_name(\"worker0\", node_names[i]);\n+\t\tif (!node) {\n+\t\t\tprintf(\"rte_graph_node_get, failed for node = %d\\n\",\n+\t\t\t tm->test_node[i].idx);\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tif (tm->test_node[i].idx != node->id) {\n+\t\t\tprintf(\"Node id didn't match, expected = %d got = %d\\n\",\n+\t\t\t tm->test_node[i].idx, node->id);\n+\t\t\treturn 0;\n+\t\t}\n+\n+\t\tif (strncmp(node->name, node_names[i], RTE_NODE_NAMESIZE)) {\n+\t\t\tprintf(\"Node name didn't match, expected = %s got %s\\n\",\n+\t\t\t node_names[i], node->name);\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int\n+graph_cluster_stats_cb_t(bool is_first, bool is_last, void *cookie,\n+\t\t\t const struct rte_graph_cluster_node_stats *st)\n+{\n+\tint i;\n+\n+\tRTE_SET_USED(is_first);\n+\tRTE_SET_USED(is_last);\n+\tRTE_SET_USED(cookie);\n+\n+\tfor (i = 0; i < MAX_NODES + 1; i++) {\n+\t\trte_node_t id = rte_node_from_name(node_patterns[i]);\n+\t\tif (id == st->id) {\n+\t\t\tif (obj_stats[i] != st->objs) {\n+\t\t\t\tprintf(\"Obj count miss match for node = %s expected = %\"PRId64\", got=%\"PRId64\"\\n\",\n+\t\t\t\t node_patterns[i], obj_stats[i],\n+\t\t\t\t st->objs);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\n+\t\t\tif (fn_calls[i] != st->calls) {\n+\t\t\t\tprintf(\"Func call miss match for node = %s expected = %\"PRId64\", got = %\"PRId64\"\\n\",\n+\t\t\t\t node_patterns[i], fn_calls[i],\n+\t\t\t\t st->calls);\n+\t\t\t\treturn -1;\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn 0;\n+}\n+\n+static int\n+test_print_stats(void)\n+{\n+\tstruct rte_graph_cluster_stats_param s_param;\n+\tstruct rte_graph_cluster_stats *stats;\n+\tconst char *pattern = \"worker0\";\n+\n+\tif (!rte_graph_has_stats_feature())\n+\t\treturn 0;\n+\n+\t/* Prepare stats object */\n+\tmemset(&s_param, 0, sizeof(s_param));\n+\ts_param.f = stdout;\n+\ts_param.socket_id = SOCKET_ID_ANY;\n+\ts_param.graph_patterns = &pattern;\n+\ts_param.nb_graph_patterns = 1;\n+\ts_param.fn = graph_cluster_stats_cb_t;\n+\n+\tstats = rte_graph_cluster_stats_create(&s_param);\n+\tif (stats == NULL) {\n+\t\tprintf(\"Unable to get stats\\n\");\n+\t\treturn -1;\n+\t}\n+\t/* Clear screen and move to top left */\n+\trte_graph_cluster_stats_get(stats, 0);\n+\trte_graph_cluster_stats_destroy(stats);\n+\n+\treturn 0;\n+}\n+\n+static int\n+graph_setup(void)\n+{\n+\tint i, j;\n+\n+\tfor (i = 0; i <= MAX_NODES; i++) {\n+\t\tfor (j = 0; j < MBUFF_SIZE; j++)\n+\t\t\tmbuf_p[i][j] = &mbuf[i][j];\n+\t}\n+\tif (test_node_clone()) {\n+\t\tprintf(\"test_node_clone: fail\\n\");\n+\t\treturn -1;\n+\t}\n+\tprintf(\"test_node_clone: pass\\n\");\n+\n+\treturn 0;\n+}\n+\n+static void\n+graph_teardown(void)\n+{\n+\trte_graph_t id;\n+\n+\tid = rte_graph_destroy(\"worker0\");\n+\tif (id == RTE_GRAPH_ID_INVALID)\n+\t\tprintf(\"Graph Destroy failed\\n\");\n+}\n+\n+static struct unit_test_suite graph_testsuite = {\n+\t.suite_name = \"Graph library test suite\",\n+\t.setup = graph_setup,\n+\t.teardown = graph_teardown,\n+\t.unit_test_cases = {\n+\t\tTEST_CASE(test_update_edges),\n+\t\tTEST_CASE(test_lookup_functions),\n+\t\tTEST_CASE(test_create_graph),\n+\t\tTEST_CASE(test_graph_lookup_functions),\n+\t\tTEST_CASE(test_graph_walk),\n+\t\tTEST_CASE(test_print_stats),\n+\t\tTEST_CASES_END(), /**< NULL terminate unit test array */\n+\t},\n+};\n+\n+static int\n+graph_autotest_fn(void)\n+{\n+\treturn unit_test_suite_runner(&graph_testsuite);\n+}\n+\n+REGISTER_TEST_COMMAND(graph_autotest, graph_autotest_fn);\n+\n+static int\n+test_node_list_dump(void)\n+{\n+\trte_node_list_dump(stdout);\n+\n+\treturn TEST_SUCCESS;\n+}\n+REGISTER_TEST_COMMAND(node_list_dump, test_node_list_dump);\n+\n", "prefixes": [ "v2", "13/28" ] }{ "id": 67225, "url": "