[PATCH i-g-t v3 05/41] lib/vkms: Test plane default files
Louis Chauvet
louis.chauvet at bootlin.com
Wed Jul 16 09:22:44 UTC 2025
Le 15/07/2025 à 12:24, José Expósito a écrit :
> Add a helper to create a plane and a test checking that the default
> files and directories are created.
>
> Signed-off-by: José Expósito <jose.exposito89 at gmail.com>
> ---
> lib/igt_vkms.c | 76 ++++++++++++++++++++++++++++++++++++++
> lib/igt_vkms.h | 4 ++
> tests/vkms/vkms_configfs.c | 33 +++++++++++++++++
> 3 files changed, 113 insertions(+)
>
> diff --git a/lib/igt_vkms.c b/lib/igt_vkms.c
> index 1fd00afd7..1f90e1569 100644
> --- a/lib/igt_vkms.c
> +++ b/lib/igt_vkms.c
> @@ -24,6 +24,13 @@
> #define VKMS_ROOT_DIR_NAME "vkms"
> #define VKMS_FILE_ENABLED "enabled"
>
> +enum vkms_pipeline_item {
> + VKMS_PIPELINE_ITEM_PLANE,
> + VKMS_PIPELINE_ITEM_CRTC,
> + VKMS_PIPELINE_ITEM_ENCODER,
> + VKMS_PIPELINE_ITEM_CONNECTOR,
> +};
Sames as 02/41 can you rename pipeline to something else?
With this modification:
Reviewed-by: Louis Chauvet <louis.chauvet at bootlin.com>
> +
> /**
> * SECTION:igt_vkms
> * @short_description: Helpers to create and configure VKMS devices
> @@ -97,6 +104,48 @@ static void write_bool(const char *path, bool value)
> write_int(path, value ? 1 : 0);
> }
>
> +static const char *get_pipeline_item_dir_name(enum vkms_pipeline_item item)
> +{
> + switch (item) {
> + case VKMS_PIPELINE_ITEM_PLANE:
> + return "planes";
> + case VKMS_PIPELINE_ITEM_CRTC:
> + return "crtcs";
> + case VKMS_PIPELINE_ITEM_ENCODER:
> + return "encoders";
> + case VKMS_PIPELINE_ITEM_CONNECTOR:
> + return "connectors";
> + }
> +
> + igt_assert(!"Cannot be reached: Unknown VKMS pipeline item type");
> +}
> +
> +static void get_pipeline_item_path(igt_vkms_t *dev,
> + enum vkms_pipeline_item item,
> + const char *name, char *path, size_t len)
> +{
> + const char *item_dir_name;
> + int ret;
> +
> + item_dir_name = get_pipeline_item_dir_name(item);
> + ret = snprintf(path, len, "%s/%s/%s", dev->path, item_dir_name, name);
> + igt_assert(ret >= 0 && ret < len);
> +}
> +
> +static void add_pipeline_item(igt_vkms_t *dev, enum vkms_pipeline_item item,
> + const char *name)
> +{
> + char path[PATH_MAX];
> + int ret;
> +
> + get_pipeline_item_path(dev, item, name, path, sizeof(path));
> +
> + ret = mkdir(path, 0777);
> + igt_assert_f(ret == 0,
> + "Unable to mkdir directory '%s'. Got errno=%d (%s)\n",
> + path, errno, strerror(errno));
> +}
> +
> /**
> * igt_require_vkms_configfs:
> *
> @@ -131,6 +180,21 @@ void igt_vkms_get_device_enabled_path(igt_vkms_t *dev, char *path, size_t len)
> igt_assert(ret >= 0 && ret < len);
> }
>
> +/**
> + * igt_vkms_get_plane_path:
> + * @dev: Device containing the plane
> + * @name: Plane name
> + * @path: Output path
> + * @len: Maximum @path length
> + *
> + * Returns the plane path.
> + */
> +void igt_vkms_get_plane_path(igt_vkms_t *dev, const char *name, char *path,
> + size_t len)
> +{
> + get_pipeline_item_path(dev, VKMS_PIPELINE_ITEM_PLANE, name, path, len);
> +}
> +
> /**
> * igt_vkms_device_create:
> * @name: VKMS device name
> @@ -303,3 +367,15 @@ void igt_vkms_device_set_enabled(igt_vkms_t *dev, bool enabled)
>
> write_bool(path, enabled);
> }
> +
> +/**
> + * igt_vkms_device_add_plane:
> + * @dev: Device to add the plane to
> + * @name: Plane name
> + *
> + * Add a new plane to the VKMS device.
> + */
> +void igt_vkms_device_add_plane(igt_vkms_t *dev, const char *name)
> +{
> + add_pipeline_item(dev, VKMS_PIPELINE_ITEM_PLANE, name);
> +}
> diff --git a/lib/igt_vkms.h b/lib/igt_vkms.h
> index d3741b6ee..9062cc42f 100644
> --- a/lib/igt_vkms.h
> +++ b/lib/igt_vkms.h
> @@ -23,6 +23,8 @@ typedef struct igt_vkms {
> void igt_require_vkms_configfs(void);
>
> void igt_vkms_get_device_enabled_path(igt_vkms_t *dev, char *path, size_t len);
> +void igt_vkms_get_plane_path(igt_vkms_t *dev, const char *name, char *path,
> + size_t len);
>
> igt_vkms_t *igt_vkms_device_create(const char *name);
> void igt_vkms_device_destroy(igt_vkms_t *dev);
> @@ -31,4 +33,6 @@ void igt_vkms_destroy_all_devices(void);
> bool igt_vkms_device_is_enabled(igt_vkms_t *dev);
> void igt_vkms_device_set_enabled(igt_vkms_t *dev, bool enabled);
>
> +void igt_vkms_device_add_plane(igt_vkms_t *dev, const char *name);
> +
> #endif /* __IGT_VKMS_H__ */
> diff --git a/tests/vkms/vkms_configfs.c b/tests/vkms/vkms_configfs.c
> index 16e5f6725..1ac85d8f9 100644
> --- a/tests/vkms/vkms_configfs.c
> +++ b/tests/vkms/vkms_configfs.c
> @@ -179,6 +179,38 @@ static void test_device_wrong_values(void)
> igt_vkms_device_destroy(dev);
> }
>
> +/**
> + * SUBTEST: plane-default-files
> + * Description: Test that creating a plane creates the default files and
> + * directories.
> + */
> +
> +static void test_plane_default_files(void)
> +{
> + igt_vkms_t *dev;
> + char path[PATH_MAX];
> +
> + const char *files[] = {
> + "type",
> + };
> +
> + const char *dirs[] = {
> + "possible_crtcs",
> + };
> +
> + dev = igt_vkms_device_create(__func__);
> + igt_assert(dev);
> +
> + igt_vkms_device_add_plane(dev, "plane0");
> + igt_vkms_get_plane_path(dev, "plane0", path, sizeof(path));
> +
> + assert_default_files(path,
> + files, ARRAY_SIZE(files),
> + dirs, ARRAY_SIZE(dirs));
> +
> + igt_vkms_device_destroy(dev);
> +}
> +
> igt_main
> {
> struct {
> @@ -188,6 +220,7 @@ igt_main
> { "device-default-files", test_device_default_files },
> { "device-default-values", test_device_default_values },
> { "device-wrong-values", test_device_wrong_values },
> + { "plane-default-files", test_plane_default_files },
> };
>
> igt_fixture {
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
More information about the igt-dev
mailing list