From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Subject: [PATCH 07/10] test/vdev: find device with public API
Date: Fri, 17 Jul 2026 11:30:02 +0200 [thread overview]
Message-ID: <20260717093006.229370-8-david.marchand@redhat.com> (raw)
In-Reply-To: <20260717093006.229370-1-david.marchand@redhat.com>
Checking internal API has little sense as users are not supposed to call
those.
Use public API to achieve similar coverage.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
app/test/test_vdev.c | 85 ++++++++------------------------------------
1 file changed, 15 insertions(+), 70 deletions(-)
diff --git a/app/test/test_vdev.c b/app/test/test_vdev.c
index c300976ace..6951ef7cc3 100644
--- a/app/test/test_vdev.c
+++ b/app/test/test_vdev.c
@@ -2,69 +2,26 @@
* Copyright 2021 6WIND S.A.
*/
-#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <rte_common.h>
#include <rte_dev.h>
-#include <rte_kvargs.h>
-#include <bus_driver.h>
+#include <rte_bus.h>
#include <rte_bus_vdev.h>
#include "test.h"
-#define TEST_VDEV_KEY_NAME "name"
-
-static const char * const valid_keys[] = {
- TEST_VDEV_KEY_NAME,
- NULL,
-};
-
-static int
-cmp_dev_name(const struct rte_device *dev, const void *name)
-{
- return strcmp(rte_dev_name(dev), name);
-}
-
-static int
-cmp_dev_match(const struct rte_device *dev, const void *_kvlist)
-{
- const struct rte_kvargs *kvlist = _kvlist;
- const char *key = TEST_VDEV_KEY_NAME;
- const char *name;
-
- /* no kvlist arg, all devices match */
- if (kvlist == NULL)
- return 0;
-
- /* if key is present in kvlist and does not match, filter device */
- name = rte_kvargs_get(kvlist, key);
- if (name != NULL && strcmp(name, rte_dev_name(dev)) != 0)
- return -1;
-
- return 0;
-}
-
static struct rte_device *
-get_matching_vdev(const char *match_str)
+find_vdev_by_name(const char *name)
{
- struct rte_bus *vdev_bus = rte_bus_find_by_name("vdev");
- struct rte_kvargs *kvargs = NULL;
+ struct rte_dev_iterator it = { 0 };
struct rte_device *dev;
- if (match_str != NULL) {
- kvargs = rte_kvargs_parse(match_str, valid_keys);
- if (kvargs == NULL) {
- printf("Failed to parse match string\n");
- return NULL;
- }
+ RTE_DEV_FOREACH(dev, "bus=vdev", &it) {
+ if (strcmp(rte_dev_name(dev), name) == 0)
+ return dev;
}
-
- dev = vdev_bus->find_device(vdev_bus, NULL, cmp_dev_match, kvargs);
- rte_kvargs_free(kvargs);
-
- return dev;
+ return NULL;
}
static int
@@ -83,7 +40,7 @@ test_vdev_bus(void)
printf("Failed to create vdev net_null_test0\n");
goto fail;
}
- dev0 = vdev_bus->find_device(vdev_bus, NULL, cmp_dev_name, "net_null_test0");
+ dev0 = find_vdev_by_name("net_null_test0");
if (dev0 == NULL) {
printf("Cannot find net_null_test0 vdev\n");
goto fail;
@@ -94,44 +51,32 @@ test_vdev_bus(void)
printf("Failed to create vdev net_null_test1\n");
goto fail;
}
- dev1 = vdev_bus->find_device(vdev_bus, NULL, cmp_dev_name, "net_null_test1");
+ dev1 = find_vdev_by_name("net_null_test1");
if (dev1 == NULL) {
printf("Cannot find net_null_test1 vdev\n");
goto fail;
}
- /* try to match vdevs */
- dev = get_matching_vdev("name=net_null_test0");
+ /* try to find vdevs */
+ dev = find_vdev_by_name("net_null_test0");
if (dev != dev0) {
printf("Cannot match net_null_test0 vdev\n");
goto fail;
}
- dev = get_matching_vdev("name=net_null_test1");
+ dev = find_vdev_by_name("net_null_test1");
if (dev != dev1) {
printf("Cannot match net_null_test1 vdev\n");
goto fail;
}
- dev = get_matching_vdev("name=unexistant");
+ dev = find_vdev_by_name("nonexistent");
if (dev != NULL) {
- printf("Unexistant vdev should not match\n");
- goto fail;
- }
-
- dev = get_matching_vdev("");
- if (dev == NULL || dev == dev1) {
- printf("Cannot match any vdev with empty match string\n");
- goto fail;
- }
-
- dev = get_matching_vdev(NULL);
- if (dev == NULL || dev == dev1) {
- printf("Cannot match any vdev with NULL match string\n");
+ printf("Nonexistent vdev should not match\n");
goto fail;
}
- /* iterate all vdevs, and ensure we find vdev0 and vdev1 */
+ /* iterate all vdevs, and ensure we find dev0 and dev1 */
RTE_DEV_FOREACH(dev, "bus=vdev", &dev_iter) {
if (dev == dev0)
dev0 = NULL;
--
2.54.0
next prev parent reply other threads:[~2026-07-17 9:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 9:29 [PATCH 00/10] Limit usage of internal API in tests David Marchand
2026-07-17 9:29 ` [PATCH 01/10] bbdev: fix stats aggregation from queues David Marchand
2026-07-17 17:22 ` Chautru, Nicolas
2026-07-18 7:47 ` David Marchand
2026-07-17 9:29 ` [PATCH 02/10] bbdev: add per-queue statistics API David Marchand
2026-07-17 9:29 ` [PATCH 03/10] hash: fix GFNI stubs export David Marchand
2026-07-17 9:38 ` Bruce Richardson
2026-07-17 9:55 ` Konstantin Ananyev
2026-07-17 9:29 ` [PATCH 04/10] test: uninline helper for forking David Marchand
2026-07-17 9:39 ` Bruce Richardson
2026-07-17 9:30 ` [PATCH 05/10] test/bonding: get MAC address with public API David Marchand
2026-07-17 9:30 ` [PATCH 06/10] test/devargs: check driver presence " David Marchand
2026-07-17 9:55 ` Bruce Richardson
2026-07-17 10:08 ` David Marchand
2026-07-17 10:14 ` Bruce Richardson
2026-07-17 12:34 ` David Marchand
2026-07-17 12:56 ` Thomas Monjalon
2026-07-17 9:30 ` David Marchand [this message]
2026-07-17 9:30 ` [PATCH 08/10] test: limit internal API usage David Marchand
2026-07-17 9:30 ` [PATCH 09/10] ci: make ABI reference generation faster David Marchand
2026-07-17 9:30 ` [PATCH 10/10] ci: run reference unit tests against ABI David Marchand
2026-07-17 9:35 ` [PATCH 00/10] Limit usage of internal API in tests David Marchand
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=20260717093006.229370-8-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=dev@dpdk.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