All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Subject: [PATCH libdrm 10/11] tests: kms: Implement CRTC stealing test
Date: Fri, 23 Jan 2015 17:08:23 +0100	[thread overview]
Message-ID: <1422029304-1926-11-git-send-email-thierry.reding@gmail.com> (raw)
In-Reply-To: <1422029304-1926-1-git-send-email-thierry.reding@gmail.com>

From: Thierry Reding <treding@nvidia.com>

This test program sets a mode and framebuffer on a connector and cycles
through all CRTCs, moving the connector to each of them in turn. This is
useful to verify that CRTC stealing is properly handled in the DRM core
and drivers.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 tests/kms/Makefile.am      |  11 ++++
 tests/kms/kms-steal-crtc.c | 161 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 172 insertions(+)
 create mode 100644 tests/kms/kms-steal-crtc.c

diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
index c84bae05d869..10584c8930a4 100644
--- a/tests/kms/Makefile.am
+++ b/tests/kms/Makefile.am
@@ -17,3 +17,14 @@ libkms_test_la_SOURCES = \
 
 libkms_test_la_LIBADD = \
 	$(top_builddir)/libdrm.la
+
+if HAVE_INSTALL_TESTS
+bin_PROGRAMS = \
+	kms-steal-crtc
+else
+noinst_PROGRAMS = \
+	kms-steal-crtc
+endif
+
+kms_steal_crtc_SOURCES = kms-steal-crtc.c
+kms_steal_crtc_LDADD = libkms-test.la ../util/libutil.la
diff --git a/tests/kms/kms-steal-crtc.c b/tests/kms/kms-steal-crtc.c
new file mode 100644
index 000000000000..2f7f327edc16
--- /dev/null
+++ b/tests/kms/kms-steal-crtc.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright © 2014 NVIDIA 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <drm_fourcc.h>
+
+#include "util/pattern.h"
+#include "libkms-test.h"
+
+static void signal_handler(int signum)
+{
+}
+
+int main(int argc, char *argv[])
+{
+	struct kms_framebuffer *fb;
+	struct kms_screen *screen;
+	struct kms_device *device;
+	unsigned int index = 0;
+	struct sigaction sa;
+	int fd, err;
+	void *ptr;
+
+	if (argc < 2) {
+		fprintf(stderr, "usage: %s DEVICE\n", argv[0]);
+		return 1;
+	}
+
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = signal_handler;
+
+	err = sigaction(SIGINT, &sa, NULL);
+	if (err < 0) {
+		fprintf(stderr, "sigaction() failed: %m\n");
+		return 1;
+	}
+
+	fd = open(argv[1], O_RDWR);
+	if (fd < 0) {
+		fprintf(stderr, "open() failed: %m\n");
+		return 1;
+	}
+
+	device = kms_device_open(fd);
+	if (!device) {
+		fprintf(stderr, "kms_device_open() failed: %m\n");
+		return 1;
+	}
+
+	if (device->num_screens < 1) {
+		fprintf(stderr, "no screens found\n");
+		kms_device_close(device);
+		close(fd);
+		return 1;
+	}
+
+	/* TODO: allow command-line to override */
+	screen = device->screens[0];
+
+	printf("Using screen %s, resolution %ux%u\n", screen->name,
+	       screen->width, screen->height);
+
+	fb = kms_framebuffer_create(device, screen->width, screen->height,
+				    DRM_FORMAT_XRGB8888);
+	if (!fb) {
+		fprintf(stderr, "kms_framebuffer_create() failed\n");
+		return 1;
+	}
+
+	err = kms_framebuffer_map(fb, &ptr);
+	if (err < 0) {
+		fprintf(stderr, "kms_framebuffer_map() failed: %d\n", err);
+		return 1;
+	}
+
+	util_fill_pattern(fb->format, UTIL_PATTERN_SMPTE, &ptr, fb->width,
+			  fb->height, fb->pitch);
+
+	kms_framebuffer_unmap(fb);
+
+	err = kms_screen_set(screen, device->crtcs[index++], fb);
+	if (err < 0) {
+		fprintf(stderr, "kms_screen_set() failed: %d\n", err);
+		return 1;
+	}
+
+	while (true) {
+		int nfds = STDIN_FILENO + 1;
+		struct timeval timeout;
+		fd_set fds;
+
+		memset(&timeout, 0, sizeof(timeout));
+		timeout.tv_sec = 5;
+		timeout.tv_usec = 0;
+
+		FD_ZERO(&fds);
+		FD_SET(STDIN_FILENO, &fds);
+
+		err = select(nfds, &fds, NULL, NULL, &timeout);
+		if (err < 0) {
+			if (errno == EINTR)
+				break;
+
+			fprintf(stderr, "select() failed: %d\n", errno);
+			break;
+		}
+
+		if (err > 0) {
+			if (FD_ISSET(STDIN_FILENO, &fds))
+				break;
+		}
+
+		/* switch CRTC */
+		if (index >= device->num_crtcs)
+			index = 0;
+
+		err = kms_screen_set(screen, device->crtcs[index], fb);
+		if (err < 0) {
+			fprintf(stderr, "kms_screen_set() failed: %d\n", err);
+			break;
+		}
+
+		index++;
+	}
+
+	kms_framebuffer_free(fb);
+	kms_device_close(device);
+	close(fd);
+
+	return 0;
+}
-- 
2.1.3

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2015-01-23 16:09 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 16:08 [PATCH libdrm 00/11] Random assortment of fixes and enhancements Thierry Reding
2015-01-23 16:08 ` [PATCH libdrm 01/11] libdrm: valgrind-clear a few more IOCTL arguments Thierry Reding
2015-01-24 23:19   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 02/11] libdrm: Remove gratuitous blank lines Thierry Reding
2015-01-24 23:19   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 03/11] libdrm: Make indentation consistent Thierry Reding
2015-01-24 23:20   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 04/11] tests: Split helpers into library Thierry Reding
2015-01-24 23:24   ` Laurent Pinchart
2015-01-29 15:27   ` [PATCH 04.1/11] SQUASH: tests: misc cleanups Emil Velikov
2015-01-29 15:27   ` [PATCH 04.2/11] SQUASH: util: add android build Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 05/11] tests: Move name tables to libutil Thierry Reding
2015-01-24 23:24   ` Laurent Pinchart
2015-01-29 15:28   ` [PATCH 05.1/11] SQUASH: util: add the kms.[ch] to makefile.sources Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 06/11] xf86drmMode.h: Use consistent padding Thierry Reding
2015-01-24 23:26   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 07/11] xf86drmMode.h: Add DisplayPort MST encoder type Thierry Reding
2015-01-24 23:40   ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 08/11] tests: modetest: Accept connector names Thierry Reding
2015-01-24 23:56   ` Laurent Pinchart
2015-01-26 10:14     ` Thierry Reding
2015-01-26 10:24       ` Laurent Pinchart
2015-01-23 16:08 ` [PATCH libdrm 09/11] tests: Add libkms-test library Thierry Reding
2015-01-29 15:30   ` [PATCH 09.1/11] SQUASH: libkms-test: add missing header to the distribution Emil Velikov
2015-01-23 16:08 ` Thierry Reding [this message]
2015-01-29 15:30   ` [PATCH 10.1/11] SQUASH: kms-steal-crtc: link against cairo Emil Velikov
2015-01-23 16:08 ` [PATCH libdrm 11/11] tests: kms: Implement universal planes test Thierry Reding
2015-01-29 15:31   ` [PATCH 11.1/11] SQUASH: kms-universal-planes: link against cairo Emil Velikov
2015-01-29 15:36 ` [PATCH libdrm 00/11] Random assortment of fixes and enhancements Emil Velikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1422029304-1926-11-git-send-email-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.