]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: drv-net: psp: Better control the used PSP dev
authorCosmin Ratiu <cratiu@nvidia.com>
Fri, 9 Jan 2026 11:08:51 +0000 (13:08 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 10 Jan 2026 22:44:05 +0000 (14:44 -0800)
The PSP responder fails when zero or multiple PSP devices are detected.
There's an option to select the device id to use (-d) but it's
currently not used from the PSP self test. It's also hard to use because
the PSP test doesn't dump the PSP devices so can't choose one.
When zero devices are detected, psp_responder fails which will cause the
parent test to fail as well instead of skipping PSP tests.

Fix both of these problems. Change psp_responder to:
- not fail when no PSP devs are detected.
- get an optional -i ifindex argument instead of -d.
- select the correct PSP dev from the dump corresponding to ifindex or
- select the first PSP dev when -i is not given.
- fail when multiple devs are found and -i is not given.
- warn and continue when the requested ifindex is not found.

Also plumb the ifindex from the Python test.

With these, when there are no PSP devs found or the wrong one is chosen,
psp_responder opens the server socket, listens for control connections
normally, and leaves the skipping of the various test cases which
require a PSP device (~most, but not all of them) to the parent test.
This results in output like:

ok 1 psp.test_case # SKIP No PSP devices found
[...]
ok 12 psp.dev_get_device # SKIP No PSP devices found
ok 13 psp.dev_get_device_bad
ok 14 psp.dev_rotate # SKIP No PSP devices found
[...]

Signed-off-by: Cosmin Ratiu <cratiu@nvidia.com>
Reviewed-by: Carolina Jubran <cjubran@nvidia.com>
Link: https://patch.msgid.link/20260109110851.2952906-2-cratiu@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/drivers/net/lib/py/env.py
tools/testing/selftests/drivers/net/psp.py
tools/testing/selftests/drivers/net/psp_responder.c

index 8b644fd84ff2ce676fc0f6884ee4faa1ef9ec675..63495376e6546c4c22ea1c05a080b8f98699899e 100644 (file)
@@ -170,6 +170,7 @@ class NetDrvEpEnv(NetDrvEnvBase):
         self.remote_ifname = self.resolve_remote_ifc()
         self.remote_dev = ip("-d link show dev " + self.remote_ifname,
                              host=self.remote, json=True)[0]
+        self.remote_ifindex = self.remote_dev['ifindex']
 
         self._required_cmd = {}
 
index 52523bdad2407794a18abb1b28ecd949046c874c..528a421ecf7675b20db43a4345f8333cc03b3bf7 100755 (executable)
@@ -601,8 +601,8 @@ def main() -> None:
         cfg.comm_port = rand_port()
         srv = None
         try:
-            with bkg(responder + f" -p {cfg.comm_port}", host=cfg.remote,
-                     exit_wait=True) as srv:
+            with bkg(responder + f" -p {cfg.comm_port} -i {cfg.remote_ifindex}",
+                     host=cfg.remote, exit_wait=True) as srv:
                 wait_port_listen(cfg.comm_port, host=cfg.remote)
 
                 cfg.comm_sock = socket.create_connection((cfg.remote_addr,
index f309e0d73cbf185c1f3444eb4dba930b16e61fe5..a26e7628bbb135e48282e2a47953680a8064b5f9 100644 (file)
@@ -22,7 +22,7 @@ static bool should_quit;
 
 struct opts {
        int port;
-       int devid;
+       int ifindex;
        bool verbose;
 };
 
@@ -360,7 +360,7 @@ static void usage(const char *name, const char *miss)
        if (miss)
                fprintf(stderr, "Missing argument: %s\n", miss);
 
-       fprintf(stderr, "Usage: %s -p port [-v] [-d psp-dev-id]\n", name);
+       fprintf(stderr, "Usage: %s -p port [-v] [-i ifindex]\n", name);
        exit(EXIT_FAILURE);
 }
 
@@ -368,7 +368,7 @@ static void parse_cmd_opts(int argc, char **argv, struct opts *opts)
 {
        int opt;
 
-       while ((opt = getopt(argc, argv, "vp:d:")) != -1) {
+       while ((opt = getopt(argc, argv, "vp:i:")) != -1) {
                switch (opt) {
                case 'v':
                        opts->verbose = 1;
@@ -376,8 +376,8 @@ static void parse_cmd_opts(int argc, char **argv, struct opts *opts)
                case 'p':
                        opts->port = atoi(optarg);
                        break;
-               case 'd':
-                       opts->devid = atoi(optarg);
+               case 'i':
+                       opts->ifindex = atoi(optarg);
                        break;
                default:
                        usage(argv[0], NULL);
@@ -410,12 +410,11 @@ static int psp_dev_set_ena(struct ynl_sock *ys, __u32 dev_id, __u32 versions)
 int main(int argc, char **argv)
 {
        struct psp_dev_get_list *dev_list;
-       bool devid_found = false;
        __u32 ver_ena, ver_cap;
        struct opts opts = {};
        struct ynl_error yerr;
        struct ynl_sock *ys;
-       int first_id = 0;
+       int devid = -1;
        int ret;
 
        parse_cmd_opts(argc, argv, &opts);
@@ -429,20 +428,19 @@ int main(int argc, char **argv)
        }
 
        dev_list = psp_dev_get_dump(ys);
-       if (ynl_dump_empty(dev_list)) {
-               if (ys->err.code)
-                       goto err_close;
-               fprintf(stderr, "No PSP devices\n");
-               goto err_close_silent;
-       }
+       if (ynl_dump_empty(dev_list) && ys->err.code)
+               goto err_close;
 
        ynl_dump_foreach(dev_list, d) {
-               if (opts.devid) {
-                       devid_found = true;
+               if (opts.ifindex) {
+                       if (d->ifindex != opts.ifindex)
+                               continue;
+                       devid = d->id;
                        ver_ena = d->psp_versions_ena;
                        ver_cap = d->psp_versions_cap;
-               } else if (!first_id) {
-                       first_id = d->id;
+                       break;
+               } else if (devid < 0) {
+                       devid = d->id;
                        ver_ena = d->psp_versions_ena;
                        ver_cap = d->psp_versions_cap;
                } else {
@@ -452,23 +450,21 @@ int main(int argc, char **argv)
        }
        psp_dev_get_list_free(dev_list);
 
-       if (opts.devid && !devid_found) {
-               fprintf(stderr, "PSP device %d requested on cmdline, not found\n",
-                       opts.devid);
-               goto err_close_silent;
-       } else if (!opts.devid) {
-               opts.devid = first_id;
-       }
+       if (opts.ifindex && devid < 0)
+               fprintf(stderr,
+                       "WARN: PSP device with ifindex %d requested on cmdline, not found\n",
+                       opts.ifindex);
 
-       if (ver_ena != ver_cap) {
-               ret = psp_dev_set_ena(ys, opts.devid, ver_cap);
+       if (devid >= 0 && ver_ena != ver_cap) {
+               ret = psp_dev_set_ena(ys, devid, ver_cap);
                if (ret)
                        goto err_close;
        }
 
        ret = run_responder(ys, &opts);
 
-       if (ver_ena != ver_cap && psp_dev_set_ena(ys, opts.devid, ver_ena))
+       if (devid >= 0 && ver_ena != ver_cap &&
+           psp_dev_set_ena(ys, devid, ver_ena))
                fprintf(stderr, "WARN: failed to set the PSP versions back\n");
 
        ynl_sock_destroy(ys);