[PATCH i-g-t 20/39] tests/vkms_configfs: Test enablement without pipeline items

José Expósito jose.exposito89 at gmail.com
Tue Feb 18 16:49:52 UTC 2025


It shouldn't be possible to enable a device without creating and
attaching its pipeline items.

Test that the device is not enabled and also that no actual device was
created using libdrm.

Signed-off-by: José Expósito <jose.exposito89 at gmail.com>
---
 tests/vkms/vkms_configfs.c | 60 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/tests/vkms/vkms_configfs.c b/tests/vkms/vkms_configfs.c
index dc3dbe80d..87d660fff 100644
--- a/tests/vkms/vkms_configfs.c
+++ b/tests/vkms/vkms_configfs.c
@@ -108,6 +108,42 @@ static bool attach(const char *src_path, const char *dst_path,
 	return ret == 0;
 }
 
+static drmDevicePtr find_device(const char *name, drmDevicePtr *devices,
+				int n_devices)
+{
+	drmDevicePtr dev;
+	const char *dev_name;
+
+	for (int i = 0; i < n_devices; i++) {
+		dev = devices[i];
+
+		if (!(dev->available_nodes & BIT(DRM_NODE_PRIMARY)))
+			continue;
+
+		if (dev->bustype != DRM_BUS_PLATFORM)
+			continue;
+
+		dev_name = dev->businfo.platform->fullname;
+		if (strncmp(name, dev_name, strlen(name)) == 0)
+			return dev;
+	}
+
+	return NULL;
+}
+
+static bool device_exists(const char *name)
+{
+	drmDevicePtr devices[64];
+	int n_devices;
+	bool exists;
+
+	n_devices = drmGetDevices(devices, ARRAY_SIZE(devices));
+	exists = !!find_device(name, devices, n_devices);
+	drmFreeDevices(devices, n_devices);
+
+	return exists;
+}
+
 /**
  * SUBTEST: device-default-files
  * Description: Test that creating a VKMS device creates the default files and
@@ -689,6 +725,29 @@ static void test_attach_connector_to_encoder(void)
 	igt_vkms_device_destroy(dev2);
 }
 
+/**
+ * SUBTEST: enable-no-pipeline-items
+ * Description: Try to enable a VKMS device without adding any pipeline items
+ *              and test that it fails.
+ */
+
+static void test_enable_no_pipeline_items(void)
+{
+	igt_vkms_t *dev;
+
+	dev = igt_vkms_device_create(__func__);
+	igt_assert(dev);
+
+	/* Try to enable it and check that the device is not set as enabled */
+	igt_vkms_device_set_enabled(dev, true);
+	igt_assert(!igt_vkms_device_is_enabled(dev));
+
+	/* Check that no actual device was created*/
+	igt_assert(!device_exists(__func__));
+
+	igt_vkms_device_destroy(dev);
+}
+
 igt_main
 {
 	struct {
@@ -711,6 +770,7 @@ igt_main
 		{ "attach-plane-to-crtc", test_attach_plane_to_crtc },
 		{ "attach-encoder-to-crtc", test_attach_encoder_to_crtc },
 		{ "attach-connector-to-encoder", test_attach_connector_to_encoder },
+		{ "enable-no-pipeline-items", test_enable_no_pipeline_items },
 	};
 
 	igt_fixture {
-- 
2.48.1



More information about the igt-dev mailing list