[igt-dev] [PATCH i-g-t 1/2] lib/igt_kms: Add try_prop_enum and set_prop_enum for mode objects, v2.

Maarten Lankhorst maarten.lankhorst at linux.intel.com
Wed Jul 25 11:38:36 UTC 2018


This adds the possibility to test arbitrary enumerations in IGT without
having to define mappings for each and every one.

Changes since v1:
- Add commit description.
- Add try_prop_enum, to allow handling unknown enumerations.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
 lib/igt_kms.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h | 31 +++++++++++++++++-
 2 files changed, 120 insertions(+), 1 deletion(-)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index c9e00c3bd6a7..e5272103e243 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -2891,6 +2891,48 @@ uint64_t igt_plane_get_prop(igt_plane_t *plane, enum igt_atomic_plane_properties
 					plane->drm_plane->plane_id, plane->props[prop]);
 }
 
+static bool igt_mode_object_get_prop_enum_value(int drm_fd, uint32_t id, const char *str, uint64_t *val)
+{
+	drmModePropertyPtr prop = drmModeGetProperty(drm_fd, id);
+	int i;
+
+	igt_assert(id);
+	igt_assert(prop);
+
+	for (i = 0; i < prop->count_enums; i++)
+		if (!strcmp(str, prop->enums[i].name)) {
+			*val = prop->enums[i].value;
+			drmModeFreeProperty(prop);
+			return true;
+		}
+
+	return false;
+}
+
+bool igt_plane_try_prop_enum(igt_plane_t *plane,
+			     enum igt_atomic_plane_properties prop,
+			     const char *val)
+{
+	igt_display_t *display = plane->pipe->display;
+	uint64_t uval;
+
+	igt_assert(plane->props[prop]);
+
+	if (!igt_mode_object_get_prop_enum_value(display->drm_fd,
+						 plane->props[prop], val, &uval))
+		return false;
+
+	igt_plane_set_prop_value(plane, prop, uval);
+	return true;
+}
+
+void igt_plane_set_prop_enum(igt_plane_t *plane,
+			     enum igt_atomic_plane_properties prop,
+			     const char *val)
+{
+	igt_assert(igt_plane_try_prop_enum(plane, prop, val));
+}
+
 /**
  * igt_plane_replace_prop_blob:
  * @plane: plane to set property on.
@@ -2942,6 +2984,30 @@ uint64_t igt_output_get_prop(igt_output_t *output, enum igt_atomic_connector_pro
 					output->id, output->props[prop]);
 }
 
+bool igt_output_try_prop_enum(igt_output_t *output,
+			      enum igt_atomic_connector_properties prop,
+			      const char *val)
+{
+	igt_display_t *display = output->display;
+	uint64_t uval;
+
+	igt_assert(output->props[prop]);
+
+	if (!igt_mode_object_get_prop_enum_value(display->drm_fd,
+						 output->props[prop], val, &uval))
+		return false;
+
+	igt_output_set_prop_value(output, prop, uval);
+	return true;
+}
+
+void igt_output_set_prop_enum(igt_output_t *output,
+			      enum igt_atomic_connector_properties prop,
+			      const char *val)
+{
+	igt_assert(igt_output_try_prop_enum(output, prop, val));
+}
+
 /**
  * igt_output_replace_prop_blob:
  * @output: output to set property on.
@@ -2993,6 +3059,30 @@ uint64_t igt_pipe_obj_get_prop(igt_pipe_t *pipe, enum igt_atomic_crtc_properties
 					pipe->crtc_id, pipe->props[prop]);
 }
 
+bool igt_pipe_obj_try_prop_enum(igt_pipe_t *pipe_obj,
+				enum igt_atomic_crtc_properties prop,
+				const char *val)
+{
+	igt_display_t *display = pipe_obj->display;
+	uint64_t uval;
+
+	igt_assert(pipe_obj->props[prop]);
+
+	if (!igt_mode_object_get_prop_enum_value(display->drm_fd,
+						 pipe_obj->props[prop], val, &uval))
+		return false;
+
+	igt_pipe_obj_set_prop_value(pipe_obj, prop, uval);
+	return true;
+}
+
+void igt_pipe_obj_set_prop_enum(igt_pipe_t *pipe_obj,
+				enum igt_atomic_crtc_properties prop,
+				const char *val)
+{
+	igt_assert(igt_pipe_obj_try_prop_enum(pipe_obj, prop, val));
+}
+
 /**
  * igt_pipe_obj_replace_prop_blob:
  * @pipe: pipe to set property on.
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 4222a3418103..3a12f2782eed 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -574,6 +574,14 @@ uint64_t igt_plane_get_prop(igt_plane_t *plane, enum igt_atomic_plane_properties
 		igt_plane_set_prop_changed(plane, prop); \
 	} while (0)
 
+extern bool igt_plane_try_prop_enum(igt_plane_t *plane,
+				    enum igt_atomic_plane_properties prop,
+				    const char *val);
+
+extern void igt_plane_set_prop_enum(igt_plane_t *plane,
+				    enum igt_atomic_plane_properties prop,
+				    const char *val);
+
 extern void igt_plane_replace_prop_blob(igt_plane_t *plane,
 					enum igt_atomic_plane_properties prop,
 					const void *ptr, size_t length);
@@ -609,10 +617,17 @@ uint64_t igt_output_get_prop(igt_output_t *output, enum igt_atomic_connector_pro
 		igt_output_set_prop_changed(output, prop); \
 	} while (0)
 
+extern bool igt_output_try_prop_enum(igt_output_t *output,
+				     enum igt_atomic_connector_properties prop,
+				     const char *val);
+
+extern void igt_output_set_prop_enum(igt_output_t *output,
+				     enum igt_atomic_connector_properties prop,
+				     const char *val);
+
 extern void igt_output_replace_prop_blob(igt_output_t *output,
 					 enum igt_atomic_connector_properties prop,
 					 const void *ptr, size_t length);
-
 /**
  * igt_pipe_obj_has_prop:
  * @pipe: Pipe to check.
@@ -693,6 +708,20 @@ igt_pipe_has_prop(igt_display_t *display, enum pipe pipe,
 #define igt_pipe_set_prop_value(display, pipe, prop, value) \
 	igt_pipe_obj_set_prop_value(&(display)->pipes[(pipe)], prop, value)
 
+extern bool igt_pipe_obj_try_prop_enum(igt_pipe_t *pipe,
+				       enum igt_atomic_crtc_properties prop,
+				       const char *val);
+
+extern void igt_pipe_obj_set_prop_enum(igt_pipe_t *pipe,
+				       enum igt_atomic_crtc_properties prop,
+				       const char *val);
+
+#define igt_pipe_try_prop_enum(display, pipe, prop, val) \
+	igt_pipe_obj_try_prop_enum(&(display)->pipes[(pipe)], prop, val)
+
+#define igt_pipe_set_prop_enum(display, pipe, prop, val) \
+	igt_pipe_obj_set_prop_enum(&(display)->pipes[(pipe)], prop, val)
+
 extern void igt_pipe_obj_replace_prop_blob(igt_pipe_t *pipe,
 					   enum igt_atomic_crtc_properties prop,
 					   const void *ptr, size_t length);
-- 
2.18.0



More information about the igt-dev mailing list