Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] selftests: pci_endpoint: skip when the test device is absent
@ 2026-09-25 13:31 Eva Kurchatova
  2026-09-25 13:36 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Eva Kurchatova @ 2026-09-25 13:31 UTC (permalink / raw)
  To: Manivannan Sadhasivam, Krzysztof Wilczyński,
	Kishon Vijay Abraham I, Frank Li, Shuah Khan
  Cc: linux-kernel, Eva Kurchatova, linux-pci, linux-kselftest

Every fixture opens /dev/pci-endpoint-test.0 and asserts on the result,
so on a machine that has no PCI endpoint test device all 17 cases fail
in fixture setup rather than reporting that the hardware is not there.

Check for the device once before handing over to the harness. Doing it
there rather than in each of the four fixtures keeps it to a single skip,
and leaves the fixtures to fail as before on an open that goes wrong for
any other reason, which is not something to skip over.

The harness parses its own arguments inside test_harness_run(), so only
the plain invocation, the one kselftest makes, turns into a skip, -l and
-h keep working on a machine without the device.

Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
 .../selftests/pci_endpoint/pci_endpoint_test.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c b/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c
index 588d75c97ad1..efec4a84aa15 100644
--- a/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c
+++ b/tools/testing/selftests/pci_endpoint/pci_endpoint_test.c
@@ -286,4 +286,20 @@ TEST_F(pcie_ep_doorbell, DOORBELL_TEST)
 		SKIP(return, "Doorbell test is not supported");
 	EXPECT_FALSE(ret) TH_LOG("Test failed for Doorbell\n");
 }
-TEST_HARNESS_MAIN
+
+static bool test_device_available(void)
+{
+	return access(test_device, F_OK) == 0;
+}
+
+int main(int argc, char **argv)
+{
+	/*
+	 * Only the plain invocation, which is the one kselftest uses, turns
+	 * into a skip, so that -l and -h keep working without the hardware.
+	 */
+	if (argc == 1 && !test_device_available())
+		ksft_exit_skip("no PCI endpoint test device %s\n", test_device);
+
+	return test_harness_run(argc, argv);
+}
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-25 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-25 13:31 [PATCH] selftests: pci_endpoint: skip when the test device is absent Eva Kurchatova
2026-09-25 13:36 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox