Add functional test for mcore dispatch model including graph clone,
graph model set/get, node worker affinity, graph worker binding/unbinding.
Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
Signed-off-by: Cunming Liang <cunming.liang@intel.com>
Signed-off-by: Zhirun Yan <zhirun.yan@intel.com>
Acked-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
app/test/test_graph.c | 130 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
@@ -660,6 +660,132 @@ test_create_graph(void)
return 0;
}
+static int
+test_graph_clone(void)
+{
+ rte_graph_t cloned_graph_id = RTE_GRAPH_ID_INVALID;
+ rte_graph_t main_graph_id = RTE_GRAPH_ID_INVALID;
+ struct rte_graph_param graph_conf;
+ int ret = 0;
+
+ main_graph_id = rte_graph_from_name("worker0");
+ if (main_graph_id == RTE_GRAPH_ID_INVALID) {
+ printf("Must create main graph first\n");
+ ret = -1;
+ }
+
+ graph_conf.dispatch.mp_capacity = 1024;
+ graph_conf.dispatch.wq_size_max = 32;
+
+ cloned_graph_id = rte_graph_clone(main_graph_id, "cloned-test0", &graph_conf);
+
+ if (cloned_graph_id == RTE_GRAPH_ID_INVALID) {
+ printf("Graph creation failed with error = %d\n", rte_errno);
+ ret = -1;
+ }
+
+ if (strcmp(rte_graph_id_to_name(cloned_graph_id), "worker0-cloned-test0")) {
+ printf("Cloned graph should name as %s but get %s\n", "worker0-cloned-test",
+ rte_graph_id_to_name(cloned_graph_id));
+ ret = -1;
+ }
+
+ rte_graph_destroy(cloned_graph_id);
+
+ return ret;
+}
+
+static int
+test_graph_model_mcore_dispatch_node_lcore_affinity_set(void)
+{
+ rte_graph_t cloned_graph_id = RTE_GRAPH_ID_INVALID;
+ unsigned int worker_lcore = RTE_MAX_LCORE;
+ rte_node_t nid = RTE_NODE_ID_INVALID;
+ char node_name[64] = "test_node00";
+ struct rte_node *node;
+ int ret = 0;
+
+ worker_lcore = rte_get_next_lcore(worker_lcore, true, 1);
+ ret = rte_graph_model_mcore_dispatch_node_lcore_affinity_set(node_name, worker_lcore);
+ if (ret == 0)
+ printf("Set node %s affinity to lcore %u\n", node_name, worker_lcore);
+
+ nid = rte_node_from_name(node_name);
+ cloned_graph_id = rte_graph_clone(graph_id, "cloned-test1", NULL);
+ node = rte_graph_node_get(cloned_graph_id, nid);
+
+ if (node->dispatch.lcore_id != worker_lcore) {
+ printf("set node affinity failed\n");
+ ret = -1;
+ }
+
+ rte_graph_destroy(cloned_graph_id);
+
+ return ret;
+}
+
+static int
+test_graph_model_mcore_dispatch_core_bind_unbind(void)
+{
+ rte_graph_t cloned_graph_id = RTE_GRAPH_ID_INVALID;
+ unsigned int worker_lcore = RTE_MAX_LCORE;
+ struct rte_graph *graph;
+ int ret = 0;
+
+ worker_lcore = rte_get_next_lcore(worker_lcore, true, 1);
+ cloned_graph_id = rte_graph_clone(graph_id, "cloned-test2", NULL);
+
+ ret = rte_graph_model_mcore_dispatch_core_bind(cloned_graph_id, worker_lcore);
+ if (ret != 0) {
+ printf("bind graph %d to lcore %u failed\n", graph_id, worker_lcore);
+ ret = -1;
+ }
+
+ graph = rte_graph_lookup("worker0-cloned-test2");
+
+ if (graph->dispatch.lcore_id != worker_lcore) {
+ printf("bind graph %s(id:%d) with lcore %u failed\n",
+ graph->name, graph->id, worker_lcore);
+ ret = -1;
+ }
+
+ rte_graph_model_mcore_dispatch_core_unbind(cloned_graph_id);
+ if (graph->dispatch.lcore_id != RTE_MAX_LCORE) {
+ printf("unbind graph %s(id:%d) failed %d\n",
+ graph->name, graph->id, graph->dispatch.lcore_id);
+ ret = -1;
+ }
+
+ rte_graph_destroy(cloned_graph_id);
+
+ return ret;
+}
+
+static int
+test_graph_worker_model_set_get(void)
+{
+ rte_graph_t cloned_graph_id = RTE_GRAPH_ID_INVALID;
+ struct rte_graph *graph;
+ int ret = 0;
+
+ cloned_graph_id = rte_graph_clone(graph_id, "cloned-test3", NULL);
+ ret = rte_graph_worker_model_set(RTE_GRAPH_MODEL_MCORE_DISPATCH);
+ if (ret != 0) {
+ printf("Set graph mcore dispatch model failed\n");
+ ret = -1;
+ }
+
+ graph = rte_graph_lookup("worker0-cloned-test3");
+ if (rte_graph_worker_model_get(graph) != RTE_GRAPH_MODEL_MCORE_DISPATCH) {
+ printf("Get graph worker model failed\n");
+ ret = -1;
+ }
+
+ rte_graph_destroy(cloned_graph_id);
+
+ return 0;
+}
+
static int
test_graph_walk(void)
{
@@ -837,6 +963,10 @@ static struct unit_test_suite graph_testsuite = {
TEST_CASE(test_update_edges),
TEST_CASE(test_lookup_functions),
TEST_CASE(test_create_graph),
+ TEST_CASE(test_graph_clone),
+ TEST_CASE(test_graph_model_mcore_dispatch_node_lcore_affinity_set),
+ TEST_CASE(test_graph_model_mcore_dispatch_core_bind_unbind),
+ TEST_CASE(test_graph_worker_model_set_get),
TEST_CASE(test_graph_lookup_functions),
TEST_CASE(test_graph_walk),
TEST_CASE(test_print_stats),