[PATCH i-g-t 06/39] tests/vkms_configfs: Test device invalid values

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


For a VKMS device, it is only possible to set invalid values in two
places:

- The device name: The "vkms" name is reserved for the default device
  created by the driver.
- The device enabled status: It should only accept boolean values.

Test that setting wrong values fails and that the device is not
accidentally enabled.

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 6c7d0310c..79023359a 100644
--- a/tests/vkms/vkms_configfs.c
+++ b/tests/vkms/vkms_configfs.c
@@ -24,6 +24,11 @@
 #include "igt.h"
 #include "igt_vkms.h"
 
+struct invalid_value {
+	const char *value;
+	int size;
+};
+
 static void assert_default_files(const char *path,
 				 const char **files, size_t n_files,
 				 const char **dirs, size_t n_dirs)
@@ -63,6 +68,32 @@ static void assert_default_files(const char *path,
 	}
 }
 
+static void assert_wrong_bool_values(const char *path)
+{
+	struct invalid_value invalid_bool_values[] = {
+		{ "", 0 },
+		{ "\0", 1 },
+		{ "-1", 2 },
+		{ "2", 1 },
+		{ "o", 1 },
+		{ "invalid", 8 },
+	};
+	int fd;
+	int ret;
+
+	for (int i = 0; i < ARRAY_SIZE(invalid_bool_values); i++) {
+		struct invalid_value v = invalid_bool_values[i];
+
+		fd = open(path, O_WRONLY);
+		igt_assert_f(fd >= 0, "Error opening '%s'\n", path);
+
+		ret = write(fd, v.value, v.size);
+		igt_assert(ret <= 0);
+
+		close(fd);
+	}
+}
+
 /**
  * SUBTEST: device-default-files
  * Description: Test that creating a VKMS device creates the default files and
@@ -111,6 +142,34 @@ static void test_device_default_values(void)
 	igt_vkms_device_destroy(dev);
 }
 
+/**
+ * SUBTEST: device-wrong-values
+ * Description: Check that setting unexpected values doesn't work.
+ */
+
+static void test_device_wrong_values(void)
+{
+	igt_vkms_t *dev;
+	char path[PATH_MAX];
+
+	/* It is not possible to create devices named "vkms" to avoid clashes
+	 * with the default device created by VKMS
+	 */
+	dev = igt_vkms_device_create("vkms");
+	igt_assert(!dev);
+
+	/* Test invalid values for "enabled" */
+	dev = igt_vkms_device_create(__func__);
+	igt_assert(dev);
+
+	snprintf(path, sizeof(path), "%s/enabled", dev->path);
+
+	assert_wrong_bool_values(path);
+	igt_assert(!igt_vkms_device_is_enabled(dev));
+
+	igt_vkms_device_destroy(dev);
+}
+
 igt_main
 {
 	struct {
@@ -119,6 +178,7 @@ igt_main
 	} tests[] = {
 		{ "device-default-files", test_device_default_files },
 		{ "device-default-values", test_device_default_values },
+		{ "device-wrong-values", test_device_wrong_values },
 	};
 
 	igt_fixture {
-- 
2.48.1



More information about the igt-dev mailing list