From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 54B5341D3D;
	Fri, 10 Mar 2023 09:10:15 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 116F141149;
	Fri, 10 Mar 2023 09:10:06 +0100 (CET)
Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com
 [67.231.148.174])
 by mails.dpdk.org (Postfix) with ESMTP id E73B240FAE
 for <dev@dpdk.org>; Fri, 10 Mar 2023 09:10:01 +0100 (CET)
Received: from pps.filterd (m0045849.ppops.net [127.0.0.1])
 by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id
 32A7ajpE009832 for <dev@dpdk.org>; Fri, 10 Mar 2023 00:10:01 -0800
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com;
 h=from : to : cc :
 subject : date : message-id : in-reply-to : references : mime-version :
 content-type; s=pfpt0220; bh=eEkQf2UFO+p9nFuFJ+g/09vH+0WaX8oyEg9kx2qj3PY=;
 b=Srafufjf8cN9SxZB/amuCihgWe9X2wXijtm2m4oPWp1etJ5/uNzIH4pXKWpuiYR4WTiL
 jrXsLLRsalPHW2uWoWMyG6B6gPMWlYyMQKrUl5Vc5lhZZ3dcoXnS0zHbLwutbcvB1Ow6
 IorrRfkCR3HuRSwNWfgJAcPav1Oqs0yW8WCPgmM05XOH5jx/3FE4f0781azcdQkVyRHC
 Cq6+7gxI/mreo4ub8m1J6PdxmryKBg9AqWW+O6tkGcz+7S5jWNwB2+zgCLztdQl9oUka
 KiidqaXUdrEFc0RLqq0r7yp4dse3bAO8ruxCbAU9HbeCVIWaQwsgLonG7P1r+iQdVQx+ Tw== 
Received: from dc5-exch01.marvell.com ([199.233.59.181])
 by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3p7n7dhy4p-2
 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT)
 for <dev@dpdk.org>; Fri, 10 Mar 2023 00:10:00 -0800
Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com
 (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.42;
 Fri, 10 Mar 2023 00:09:40 -0800
Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com
 (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.42 via Frontend
 Transport; Fri, 10 Mar 2023 00:09:39 -0800
Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233])
 by maili.marvell.com (Postfix) with ESMTP id 30C833F708E;
 Fri, 10 Mar 2023 00:09:40 -0800 (PST)
From: Srikanth Yalavarthi <syalavarthi@marvell.com>
To: Srikanth Yalavarthi <syalavarthi@marvell.com>
CC: <dev@dpdk.org>, <sshankarnara@marvell.com>, <jerinj@marvell.com>,
 <aprabhu@marvell.com>, <ptakkar@marvell.com>, <pshukla@marvell.com>
Subject: [PATCH v5 02/12] app/mldev: add common test functions
Date: Fri, 10 Mar 2023 00:09:24 -0800
Message-ID: <20230310080935.2460-3-syalavarthi@marvell.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To: <20230310080935.2460-1-syalavarthi@marvell.com>
References: <20221129070746.20396-1-syalavarthi@marvell.com>
 <20230310080935.2460-1-syalavarthi@marvell.com>
MIME-Version: 1.0
Content-Type: text/plain
X-Proofpoint-GUID: t0dvHJlMH9wZvkiHYf_ysIfy7EXOKJI4
X-Proofpoint-ORIG-GUID: t0dvHJlMH9wZvkiHYf_ysIfy7EXOKJI4
X-Proofpoint-Virus-Version: vendor=baseguard
 engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22
 definitions=2023-03-10_02,2023-03-09_01,2023-02-09_01
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <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>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Added common functions used by all tests. Common code
includes functions to check capabilities, options, and
handle ML devices.

Signed-off-by: Srikanth Yalavarthi <syalavarthi@marvell.com>
---
 app/test-mldev/meson.build   |   1 +
 app/test-mldev/test_common.c | 136 +++++++++++++++++++++++++++++++++++
 app/test-mldev/test_common.h |  27 +++++++
 3 files changed, 164 insertions(+)
 create mode 100644 app/test-mldev/test_common.c
 create mode 100644 app/test-mldev/test_common.h

diff --git a/app/test-mldev/meson.build b/app/test-mldev/meson.build
index 8ca2e1a1c1..964bb9ddc4 100644
--- a/app/test-mldev/meson.build
+++ b/app/test-mldev/meson.build
@@ -12,6 +12,7 @@ sources = files(
         'ml_options.c',
         'ml_test.c',
         'parser.c',
+        'test_common.c',
 )
 
 deps += ['mldev']
diff --git a/app/test-mldev/test_common.c b/app/test-mldev/test_common.c
new file mode 100644
index 0000000000..8c4da4609a
--- /dev/null
+++ b/app/test-mldev/test_common.c
@@ -0,0 +1,136 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2022 Marvell.
+ */
+
+#include <errno.h>
+
+#include <rte_common.h>
+#include <rte_memory.h>
+#include <rte_mldev.h>
+
+#include "ml_common.h"
+#include "test_common.h"
+
+bool
+ml_test_cap_check(struct ml_options *opt)
+{
+	struct rte_ml_dev_info dev_info;
+
+	rte_ml_dev_info_get(opt->dev_id, &dev_info);
+	if (dev_info.max_models == 0) {
+		ml_err("Not enough mldev models supported = %u", dev_info.max_models);
+		return false;
+	}
+
+	return true;
+}
+
+int
+ml_test_opt_check(struct ml_options *opt)
+{
+	uint16_t dev_count;
+	int socket_id;
+
+	RTE_SET_USED(opt);
+
+	dev_count = rte_ml_dev_count();
+	if (dev_count == 0) {
+		ml_err("No ML devices found");
+		return -ENODEV;
+	}
+
+	if (opt->dev_id >= dev_count) {
+		ml_err("Invalid option dev_id = %d", opt->dev_id);
+		return -EINVAL;
+	}
+
+	socket_id = rte_ml_dev_socket_id(opt->dev_id);
+	if (!((opt->socket_id != SOCKET_ID_ANY) || (opt->socket_id != socket_id))) {
+		ml_err("Invalid option, socket_id = %d\n", opt->socket_id);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+void
+ml_test_opt_dump(struct ml_options *opt)
+{
+	ml_options_dump(opt);
+}
+
+int
+ml_test_device_configure(struct ml_test *test, struct ml_options *opt)
+{
+	struct test_common *t = ml_test_priv(test);
+	struct rte_ml_dev_config dev_config;
+	int ret;
+
+	ret = rte_ml_dev_info_get(opt->dev_id, &t->dev_info);
+	if (ret != 0) {
+		ml_err("Failed to get mldev info, dev_id = %d\n", opt->dev_id);
+		return ret;
+	}
+
+	/* configure device */
+	dev_config.socket_id = opt->socket_id;
+	dev_config.nb_models = t->dev_info.max_models;
+	dev_config.nb_queue_pairs = t->dev_info.max_queue_pairs;
+	ret = rte_ml_dev_configure(opt->dev_id, &dev_config);
+	if (ret != 0) {
+		ml_err("Failed to configure ml device, dev_id = %d\n", opt->dev_id);
+		return ret;
+	}
+
+	return 0;
+}
+
+int
+ml_test_device_close(struct ml_test *test, struct ml_options *opt)
+{
+	struct test_common *t = ml_test_priv(test);
+	int ret = 0;
+
+	RTE_SET_USED(t);
+
+	/* close device */
+	ret = rte_ml_dev_close(opt->dev_id);
+	if (ret != 0)
+		ml_err("Failed to close ML device, dev_id = %d\n", opt->dev_id);
+
+	return ret;
+}
+
+int
+ml_test_device_start(struct ml_test *test, struct ml_options *opt)
+{
+	struct test_common *t = ml_test_priv(test);
+	int ret;
+
+	RTE_SET_USED(t);
+
+	/* start device */
+	ret = rte_ml_dev_start(opt->dev_id);
+	if (ret != 0) {
+		ml_err("Failed to start ml device, dev_id = %d\n", opt->dev_id);
+		return ret;
+	}
+
+	return 0;
+}
+
+int
+ml_test_device_stop(struct ml_test *test, struct ml_options *opt)
+{
+	struct test_common *t = ml_test_priv(test);
+	int ret = 0;
+
+	RTE_SET_USED(t);
+
+	/* stop device */
+	ret = rte_ml_dev_stop(opt->dev_id);
+	if (ret != 0)
+		ml_err("Failed to stop ML device, dev_id = %d\n", opt->dev_id);
+
+	return ret;
+}
diff --git a/app/test-mldev/test_common.h b/app/test-mldev/test_common.h
new file mode 100644
index 0000000000..cb286adcd6
--- /dev/null
+++ b/app/test-mldev/test_common.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2022 Marvell.
+ */
+
+#ifndef _ML_TEST_COMMON_
+#define _ML_TEST_COMMON_
+
+#include <rte_mldev.h>
+
+#include "ml_common.h"
+#include "ml_test.h"
+
+struct test_common {
+	struct ml_options *opt;
+	enum ml_test_result result;
+	struct rte_ml_dev_info dev_info;
+};
+
+bool ml_test_cap_check(struct ml_options *opt);
+int ml_test_opt_check(struct ml_options *opt);
+void ml_test_opt_dump(struct ml_options *opt);
+int ml_test_device_configure(struct ml_test *test, struct ml_options *opt);
+int ml_test_device_close(struct ml_test *test, struct ml_options *opt);
+int ml_test_device_start(struct ml_test *test, struct ml_options *opt);
+int ml_test_device_stop(struct ml_test *test, struct ml_options *opt);
+
+#endif /* _ML_TEST_COMMON_ */
-- 
2.17.1