[Intel-gfx] [PATCH RFC i-g-t] igt: Add a dpms property test

Marta Lofstedt marta.lofstedt at intel.com
Wed Dec 7 11:42:59 UTC 2016


This testcase will set the dpms drm property to
DRM_MODE_DPMS_ON and DPMS_MODE_OFF and check that the
property values was updated and that the new state corresponds
to the crtc active property.

Signed-off-by: Marta Lofstedt <marta.lofstedt at intel.com>
---
 tests/Makefile.sources |   1 +
 tests/drm_dpms.c       | 168 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 169 insertions(+)
 create mode 100644 tests/drm_dpms.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 04dd2d5..6d6e3db 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -14,6 +14,7 @@ VC4_TESTS_M = \
 TESTS_progs_M = \
 	core_get_client_auth \
 	drm_mm \
+	drm_dpms \
 	drv_getparams_basic \
 	drv_selftest \
 	drv_suspend \
diff --git a/tests/drm_dpms.c b/tests/drm_dpms.c
new file mode 100644
index 0000000..0175e7b
--- /dev/null
+++ b/tests/drm_dpms.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+
+static void prepare_pipe(igt_display_t *display, enum pipe pipe,
+			 igt_output_t *output, struct igt_fb *fb)
+{
+	drmModeModeInfo *mode = igt_output_get_mode(output);
+
+	igt_create_pattern_fb(display->drm_fd,
+			      mode->hdisplay,
+			      mode->vdisplay,
+			      DRM_FORMAT_XRGB8888,
+			      LOCAL_DRM_FORMAT_MOD_NONE,
+			      fb);
+
+	igt_output_set_pipe(output, pipe);
+
+	igt_plane_set_fb(igt_output_get_plane(output, IGT_PLANE_PRIMARY), fb);
+
+	igt_display_commit2(display,
+			    display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
+}
+
+static void cleanup_pipe(igt_display_t *display, enum pipe pipe,
+			 igt_output_t *output, struct igt_fb *fb)
+{
+	igt_plane_t *plane;
+
+	for_each_plane_on_pipe(display, pipe, plane)
+		igt_plane_set_fb(plane, NULL);
+
+	igt_output_set_pipe(output, PIPE_NONE);
+
+	igt_display_commit2(display,
+			    display->is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
+
+	igt_remove_fb(display->drm_fd, fb);
+}
+
+static void test_dpms(igt_display_t *display, drmModeConnector *connector,
+		      int crtc_id)
+{
+	uint64_t dpms_state, active;
+
+	kmstest_get_property(display->drm_fd, connector->connector_id,
+			     DRM_MODE_OBJECT_CONNECTOR, "DPMS",
+			     NULL, &dpms_state, NULL);
+
+	if (dpms_state == DRM_MODE_DPMS_OFF) {
+		kmstest_set_connector_dpms(display->drm_fd, connector,
+					   DRM_MODE_DPMS_ON);
+		kmstest_get_property(display->drm_fd, connector->connector_id,
+				     DRM_MODE_OBJECT_CONNECTOR, "DPMS",
+				     NULL, &dpms_state, NULL);
+		igt_assert_eq(dpms_state, DRM_MODE_DPMS_ON);
+		kmstest_get_property(display->drm_fd, crtc_id,
+				     DRM_MODE_OBJECT_CRTC, "ACTIVE",
+				     NULL, &active, NULL);
+		igt_assert(active);
+	} else {
+		kmstest_set_connector_dpms(display->drm_fd, connector,
+					   DRM_MODE_DPMS_OFF);
+		kmstest_get_property(display->drm_fd, connector->connector_id,
+				     DRM_MODE_OBJECT_CONNECTOR, "DPMS",
+				     NULL, &dpms_state, NULL);
+		igt_assert_eq(dpms_state, DRM_MODE_DPMS_OFF);
+		kmstest_get_property(display->drm_fd, crtc_id,
+				     DRM_MODE_OBJECT_CRTC, "ACTIVE",
+				     NULL, &active, NULL);
+		igt_assert(!active);
+	}
+}
+
+static void run_dpms_test(igt_display_t *display, enum pipe pipe,
+			  igt_output_t *output)
+{
+	struct igt_fb fb;
+	bool found;
+	uint64_t original_dpms_state;
+	drmModeConnector *connector = output->config.connector;
+	uint64_t active;
+	int crtc_id = display->pipes[pipe].crtc_id;
+
+	if (pipe != PIPE_NONE)
+		prepare_pipe(display, pipe, output, &fb);
+
+	igt_info("Testing dpms properties on output %s (pipe: %s)\n",
+		 output->name, kmstest_pipe_name(pipe));
+
+	found = kmstest_get_property(display->drm_fd, connector->connector_id,
+				     DRM_MODE_OBJECT_CONNECTOR, "DPMS",
+				     NULL, &original_dpms_state, NULL);
+	if (found) {
+		test_dpms(display, connector, crtc_id);
+		test_dpms(display, connector, crtc_id);
+		kmstest_set_connector_dpms(display->drm_fd, connector,
+					   original_dpms_state);
+	}
+
+	if (pipe != PIPE_NONE)
+		cleanup_pipe(display, pipe, output, &fb);
+}
+
+static void dpms_property(igt_display_t *display)
+{
+	enum pipe pipe;
+	igt_output_t *output;
+
+	for_each_connected_output(display, output) {
+		bool found = false;
+
+		for_each_pipe(display, pipe) {
+			if (!igt_pipe_connector_valid(pipe, output))
+				continue;
+
+			found = true;
+			run_dpms_test(display, pipe, output);
+			break;
+		}
+
+		igt_assert_f(found,
+			     "Connected output should have at least 1 valid crtc\n");
+	}
+}
+
+igt_main
+{
+	igt_display_t display;
+
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		display.drm_fd = drm_open_driver_master(DRIVER_ANY);
+
+		kmstest_set_vt_graphics_mode();
+
+		igt_display_init(&display, display.drm_fd);
+	}
+
+	igt_subtest("dpms_property")
+		dpms_property(&display);
+
+	igt_fixture {
+		igt_display_fini(&display);
+	}
+}
-- 
2.9.3



More information about the Intel-gfx mailing list