DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shani Peretz <shperetz@nvidia.com>
To: <dev@dpdk.org>
Cc: <stephen@networkplumber.org>, Shani Peretz <shperetz@nvidia.com>,
	"Tyler Retzlaff" <roretzla@linux.microsoft.com>
Subject: [PATCH v7 3/4] app/test: add tests to find devices
Date: Wed, 12 Feb 2025 18:38:34 +0200	[thread overview]
Message-ID: <20250212163836.178976-3-shperetz@nvidia.com> (raw)
In-Reply-To: <20250212163836.178976-1-shperetz@nvidia.com>

Added tests to PCI and vdev bus that compare and find devices
in various forms of names under test_devargs.
The tests check the functionality of the rte_cmp_dev_name function by
calling it with different variations of names, like short and full,
full and full, etc.

Signed-off-by: Shani Peretz <shperetz@nvidia.com>
---
 app/test/test_devargs.c | 120 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)

diff --git a/app/test/test_devargs.c b/app/test/test_devargs.c
index 575a49ea82..e510f0491e 100644
--- a/app/test/test_devargs.c
+++ b/app/test/test_devargs.c
@@ -12,7 +12,9 @@
 #include <rte_kvargs.h>
 #include <bus_driver.h>
 #include <rte_class.h>
+#include <rte_bus_vdev.h>
 
+#include "virtual_pmd.h"
 #include "test.h"
 
 /* Check layer arguments. */
@@ -302,6 +304,118 @@ test_invalid_devargs_parsing(void)
 	return fail;
 }
 
+static struct rte_device *
+create_pci_dev(const char *name)
+{
+	int port_id;
+	struct rte_ether_addr rand_ea = {0};
+	rte_eth_random_addr(rand_ea.addr_bytes);
+
+	char pmd_name[RTE_ETH_NAME_MAX_LEN];
+	strlcpy(pmd_name, name, RTE_ETH_NAME_MAX_LEN);
+
+	port_id = virtual_ethdev_create(pmd_name,
+			&rand_ea, rte_socket_id(), 1);
+
+	if (port_id < 0)
+		return NULL;
+
+	return (&rte_eth_devices[port_id])->device;
+}
+
+static int
+test_pci(struct rte_bus *pci_bus, const char *dev_name, const char *name2)
+{
+	struct rte_device *pci_dev = create_pci_dev(dev_name);
+
+	if (pci_dev == NULL)
+		return -1;
+
+	pci_dev->bus = pci_bus;
+
+	if (rte_cmp_dev_name(pci_dev, name2) != 0) {
+		printf("rte_cmp_dev_name(%s, %s) device name (%s) not expected (%s)\n",
+			       pci_dev->name, name2, pci_dev->name, name2);
+		return -1;
+	}
+	return 0;
+}
+
+static int
+test_vdev(struct rte_bus *vdev_bus, const char *dev_name, const char *name2)
+{
+	/* create vdev */
+	if (rte_vdev_init(dev_name, "") < 0) {
+		printf("Failed to create vdev %s\n", dev_name);
+		return -1;
+	}
+
+	struct rte_device *vdev_dev = vdev_bus->find_device(NULL, rte_cmp_dev_name, dev_name);
+	if (vdev_dev == NULL) {
+		printf("Cannot find %s vdev\n", dev_name);
+		rte_vdev_uninit(dev_name);
+		return -1;
+	}
+	int ret = rte_cmp_dev_name(vdev_dev, name2);
+	if (ret != 0) {
+		printf("rte_cmp_dev_name(%s, %s) device name (%s) not expected (%s)\n",
+			       vdev_dev->name, name2, vdev_dev->name, name2);
+		return -1;
+	}
+
+	if (vdev_dev != vdev_bus->find_device(NULL, rte_cmp_dev_name, name2)) {
+		printf("rte_cmp_dev_name(%s, %s) device name (%s) not expected (%s)\n",
+			       vdev_dev->name, name2, vdev_dev->name, name2);
+		return -1;
+	}
+
+	rte_vdev_uninit(dev_name);
+	return 0;
+}
+
+static int
+test_valid_cmp_dev_name(void)
+{
+	struct rte_bus *pci_bus = rte_bus_find_by_name("pci");
+	struct rte_bus *vdev_bus = rte_bus_find_by_name("vdev");
+
+	if (pci_bus) {
+		if ((test_pci(pci_bus, "0000:08:11.0", "08:11.0") != 0) ||
+			(test_pci(pci_bus, "08:12.0",  "0000:08:12.0") != 0) ||
+			(test_pci(pci_bus, "08:13.0",  "08:13.0") != 0) ||
+			(test_pci(pci_bus, "0000:08:14.0",  "0000:08:14.0") != 0))
+			return -1;
+	}
+
+	if (vdev_bus) {
+		if (test_vdev(vdev_bus, "net_null_test0", "net_null_test0") != 0)
+			return -1;
+	}
+	return 0;
+}
+
+static int
+test_invalid_cmp_dev_name(void)
+{
+	struct rte_bus *pci_bus = rte_bus_find_by_name("pci");
+	struct rte_bus *vdev_bus = rte_bus_find_by_name("vdev");
+
+	if (pci_bus) {
+		if ((test_pci(pci_bus, "0000:08:15.0", "08:00.0") == 0) ||
+			(test_pci(pci_bus, "08:16.0",  "0000:08:15.0") == 0) ||
+			(test_pci(pci_bus, "08:17.0",  "08:13.0") == 0) ||
+			(test_pci(pci_bus, "0000:08:18.0",  "0000:08:14.0") == 0))
+			return -1;
+	}
+
+	if (vdev_bus) {
+		if ((test_vdev(vdev_bus, "net_null_test0", "net_null_test") == 0) ||
+			(test_vdev(vdev_bus, "net_null_test1", "net_null_test2") == 0))
+			return -1;
+	}
+	return 0;
+}
+
 static int
 test_devargs(void)
 {
@@ -317,6 +431,12 @@ test_devargs(void)
 	printf("== test devargs parsing invalid case ==\n");
 	if (test_invalid_devargs_parsing() < 0)
 		return -1;
+	printf("== test find device valid case ==\n");
+	if (test_valid_cmp_dev_name() < 0)
+		return -1;
+	printf("== test find device invalid case ==\n");
+	if (test_invalid_cmp_dev_name() < 0)
+		return -1;
 	return 0;
 }
 
-- 
2.34.1


  parent reply	other threads:[~2025-02-12 16:39 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-01 20:01 [PATCH] eal/common: fix inconsistent representation of PCI numbers Shani Peretz
2024-07-01 22:00 ` Stephen Hemminger
2024-07-08 16:51 ` [PATCH v3] " Shani Peretz
2024-07-12 13:49   ` David Marchand
2024-07-12 17:55     ` Thomas Monjalon
2025-01-29  8:54   ` [PATCH v4] bus: " Shani Peretz
2025-01-29  9:45     ` Bruce Richardson
2025-01-29 16:25     ` Stephen Hemminger
2025-02-05 16:36       ` Shani Peretz
2025-02-05 16:42         ` Stephen Hemminger
2025-02-05 17:37           ` Shani Peretz
2025-02-05 18:46             ` Stephen Hemminger
2025-02-05 20:16               ` Shani Peretz
2025-02-06  0:40                 ` Stephen Hemminger
2025-01-29 17:17     ` Stephen Hemminger
2025-01-29 18:06       ` Bruce Richardson
2025-02-05  1:55         ` fengchengwen
2025-02-06  0:08     ` [PATCH v5 0/4] fix comparison between devices Shani Peretz
2025-02-06  0:08       ` [PATCH v5 1/4] bus/pci: fix registration of PCI device Shani Peretz
2025-02-06 11:22         ` Thomas Monjalon
2025-02-06  0:08       ` [PATCH v5 2/4] lib: fix comparison between devices Shani Peretz
2025-02-06  7:55         ` Hemant Agrawal
2025-02-06 11:25         ` Thomas Monjalon
2025-02-10  1:18         ` Xu, Rosen
2025-02-11 17:48         ` Stephen Hemminger
2025-02-11 17:54           ` Bruce Richardson
2025-02-11 18:04             ` Stephen Hemminger
2025-02-06  0:08       ` [PATCH v5 3/4] app/test: add tests to find devices Shani Peretz
2025-02-06  1:03         ` Stephen Hemminger
2025-02-06  0:08       ` [PATCH v5 4/4] lib: change find device and cmp dev name functions Shani Peretz
2025-02-06 10:54         ` [PATCH v6 1/4] bus/pci: fix registration of PCI device Shani Peretz
2025-02-06 10:54           ` [PATCH v6 2/4] lib: fix comparison between devices Shani Peretz
2025-02-06 10:54           ` [PATCH v6 3/4] app/test: add tests to find devices Shani Peretz
2025-02-06 10:54           ` [PATCH v6 4/4] lib: change find device and cmp dev name functions Shani Peretz
2025-02-11 17:04           ` [PATCH v6 1/4] bus/pci: fix registration of PCI device Bruce Richardson
2025-02-12  0:39           ` Stephen Hemminger
2025-02-12 16:38           ` [PATCH v7 " Shani Peretz
2025-02-12 16:38             ` [PATCH v7 2/4] lib: fix comparison between devices Shani Peretz
2025-02-12 16:38             ` Shani Peretz [this message]
2025-02-12 16:38             ` [PATCH v7 4/4] lib: change find device and cmp dev name functions Shani Peretz
2024-10-04 22:21 ` [PATCH] eal/common: fix inconsistent representation of PCI numbers Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250212163836.178976-3-shperetz@nvidia.com \
    --to=shperetz@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=roretzla@linux.microsoft.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).