[PATCH i-g-t v3 04/41] tests/vkms_configfs: Test device invalid values
Louis Chauvet
louis.chauvet at bootlin.com
Wed Jul 16 09:22:57 UTC 2025
Le 15/07/2025 à 12:24, José Expósito a écrit :
> 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>
Reviewed-by: Louis Chauvet <louis.chauvet at bootlin.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 aa7cd9e4e..16e5f6725 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)
> @@ -72,6 +77,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_f(ret <= 0, "Error writing '%s' to '%s'", v.value, path);
> +
> + close(fd);
> + }
> +}
> +
> /**
> * SUBTEST: device-default-files
> * Description: Test that creating a VKMS device creates the default files and
> @@ -120,6 +151,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);
> +
> + igt_vkms_get_device_enabled_path(dev, path, sizeof(path));
> +
> + assert_wrong_bool_values(path);
> + igt_assert(!igt_vkms_device_is_enabled(dev));
> +
> + igt_vkms_device_destroy(dev);
> +}
> +
> igt_main
> {
> struct {
> @@ -128,6 +187,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 {
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
More information about the igt-dev
mailing list