Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: drv-net: psp: Better control the used PSP dev

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>

authored by

Cosmin Ratiu and committed by
Jakub Kicinski
9086984f d0c2d28c

+26 -29
+1
tools/testing/selftests/drivers/net/lib/py/env.py
··· 170 170 self.remote_ifname = self.resolve_remote_ifc() 171 171 self.remote_dev = ip("-d link show dev " + self.remote_ifname, 172 172 host=self.remote, json=True)[0] 173 + self.remote_ifindex = self.remote_dev['ifindex'] 173 174 174 175 self._required_cmd = {} 175 176
+2 -2
tools/testing/selftests/drivers/net/psp.py
··· 601 601 cfg.comm_port = rand_port() 602 602 srv = None 603 603 try: 604 - with bkg(responder + f" -p {cfg.comm_port}", host=cfg.remote, 605 - exit_wait=True) as srv: 604 + with bkg(responder + f" -p {cfg.comm_port} -i {cfg.remote_ifindex}", 605 + host=cfg.remote, exit_wait=True) as srv: 606 606 wait_port_listen(cfg.comm_port, host=cfg.remote) 607 607 608 608 cfg.comm_sock = socket.create_connection((cfg.remote_addr,
+23 -27
tools/testing/selftests/drivers/net/psp_responder.c
··· 22 22 23 23 struct opts { 24 24 int port; 25 - int devid; 25 + int ifindex; 26 26 bool verbose; 27 27 }; 28 28 ··· 360 360 if (miss) 361 361 fprintf(stderr, "Missing argument: %s\n", miss); 362 362 363 - fprintf(stderr, "Usage: %s -p port [-v] [-d psp-dev-id]\n", name); 363 + fprintf(stderr, "Usage: %s -p port [-v] [-i ifindex]\n", name); 364 364 exit(EXIT_FAILURE); 365 365 } 366 366 ··· 368 368 { 369 369 int opt; 370 370 371 - while ((opt = getopt(argc, argv, "vp:d:")) != -1) { 371 + while ((opt = getopt(argc, argv, "vp:i:")) != -1) { 372 372 switch (opt) { 373 373 case 'v': 374 374 opts->verbose = 1; ··· 376 376 case 'p': 377 377 opts->port = atoi(optarg); 378 378 break; 379 - case 'd': 380 - opts->devid = atoi(optarg); 379 + case 'i': 380 + opts->ifindex = atoi(optarg); 381 381 break; 382 382 default: 383 383 usage(argv[0], NULL); ··· 410 410 int main(int argc, char **argv) 411 411 { 412 412 struct psp_dev_get_list *dev_list; 413 - bool devid_found = false; 414 413 __u32 ver_ena, ver_cap; 415 414 struct opts opts = {}; 416 415 struct ynl_error yerr; 417 416 struct ynl_sock *ys; 418 - int first_id = 0; 417 + int devid = -1; 419 418 int ret; 420 419 421 420 parse_cmd_opts(argc, argv, &opts); ··· 428 429 } 429 430 430 431 dev_list = psp_dev_get_dump(ys); 431 - if (ynl_dump_empty(dev_list)) { 432 - if (ys->err.code) 433 - goto err_close; 434 - fprintf(stderr, "No PSP devices\n"); 435 - goto err_close_silent; 436 - } 432 + if (ynl_dump_empty(dev_list) && ys->err.code) 433 + goto err_close; 437 434 438 435 ynl_dump_foreach(dev_list, d) { 439 - if (opts.devid) { 440 - devid_found = true; 436 + if (opts.ifindex) { 437 + if (d->ifindex != opts.ifindex) 438 + continue; 439 + devid = d->id; 441 440 ver_ena = d->psp_versions_ena; 442 441 ver_cap = d->psp_versions_cap; 443 - } else if (!first_id) { 444 - first_id = d->id; 442 + break; 443 + } else if (devid < 0) { 444 + devid = d->id; 445 445 ver_ena = d->psp_versions_ena; 446 446 ver_cap = d->psp_versions_cap; 447 447 } else { ··· 450 452 } 451 453 psp_dev_get_list_free(dev_list); 452 454 453 - if (opts.devid && !devid_found) { 454 - fprintf(stderr, "PSP device %d requested on cmdline, not found\n", 455 - opts.devid); 456 - goto err_close_silent; 457 - } else if (!opts.devid) { 458 - opts.devid = first_id; 459 - } 455 + if (opts.ifindex && devid < 0) 456 + fprintf(stderr, 457 + "WARN: PSP device with ifindex %d requested on cmdline, not found\n", 458 + opts.ifindex); 460 459 461 - if (ver_ena != ver_cap) { 462 - ret = psp_dev_set_ena(ys, opts.devid, ver_cap); 460 + if (devid >= 0 && ver_ena != ver_cap) { 461 + ret = psp_dev_set_ena(ys, devid, ver_cap); 463 462 if (ret) 464 463 goto err_close; 465 464 } 466 465 467 466 ret = run_responder(ys, &opts); 468 467 469 - if (ver_ena != ver_cap && psp_dev_set_ena(ys, opts.devid, ver_ena)) 468 + if (devid >= 0 && ver_ena != ver_cap && 469 + psp_dev_set_ena(ys, devid, ver_ena)) 470 470 fprintf(stderr, "WARN: failed to set the PSP versions back\n"); 471 471 472 472 ynl_sock_destroy(ys);