aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThierry Reding2015-12-09 11:37:43 -0600
committerEmil Velikov2015-12-18 11:44:08 -0600
commite0ec59efb12eb4e5a548f29df620c3c5e1cd6e4f (patch)
tree847cc67dacf086e25d9432925b62daedb7aaeb22 /tests
parentc13c504ed2778fe5410d4883a7025abd75d0a6a1 (diff)
downloadexternal-libgbm-e0ec59efb12eb4e5a548f29df620c3c5e1cd6e4f.tar.gz
external-libgbm-e0ec59efb12eb4e5a548f29df620c3c5e1cd6e4f.tar.xz
external-libgbm-e0ec59efb12eb4e5a548f29df620c3c5e1cd6e4f.zip
tests: kms: Implement CRTC stealing test
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/kms/Makefile.am11
-rw-r--r--tests/kms/kms-steal-crtc.c161
2 files changed, 172 insertions, 0 deletions
diff --git a/tests/kms/Makefile.am b/tests/kms/Makefile.am
index da464218..f28b729c 100644
--- a/tests/kms/Makefile.am
+++ b/tests/kms/Makefile.am
@@ -18,3 +18,14 @@ libkms_test_la_SOURCES = \
18 18
19libkms_test_la_LIBADD = \ 19libkms_test_la_LIBADD = \
20 $(top_builddir)/libdrm.la 20 $(top_builddir)/libdrm.la
21
22if HAVE_INSTALL_TESTS
23bin_PROGRAMS = \
24 kms-steal-crtc
25else
26noinst_PROGRAMS = \
27 kms-steal-crtc
28endif
29
30kms_steal_crtc_SOURCES = kms-steal-crtc.c
31kms_steal_crtc_LDADD = libkms-test.la ../util/libutil.la $(CAIRO_LIBS)
diff --git a/tests/kms/kms-steal-crtc.c b/tests/kms/kms-steal-crtc.c
new file mode 100644
index 00000000..2f7f327e
--- /dev/null
+++ b/tests/kms/kms-steal-crtc.c
@@ -0,0 +1,161 @@
1/*
2 * Copyright © 2014 NVIDIA Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include <errno.h>
29#include <fcntl.h>
30#include <signal.h>
31#include <stdio.h>
32#include <string.h>
33#include <unistd.h>
34
35#include <drm_fourcc.h>
36
37#include "util/pattern.h"
38#include "libkms-test.h"
39
40static void signal_handler(int signum)
41{
42}
43
44int main(int argc, char *argv[])
45{
46 struct kms_framebuffer *fb;
47 struct kms_screen *screen;
48 struct kms_device *device;
49 unsigned int index = 0;
50 struct sigaction sa;
51 int fd, err;
52 void *ptr;
53
54 if (argc < 2) {
55 fprintf(stderr, "usage: %s DEVICE\n", argv[0]);
56 return 1;
57 }
58
59 memset(&sa, 0, sizeof(sa));
60 sa.sa_handler = signal_handler;
61
62 err = sigaction(SIGINT, &sa, NULL);
63 if (err < 0) {
64 fprintf(stderr, "sigaction() failed: %m\n");
65 return 1;
66 }
67
68 fd = open(argv[1], O_RDWR);
69 if (fd < 0) {
70 fprintf(stderr, "open() failed: %m\n");
71 return 1;
72 }
73
74 device = kms_device_open(fd);
75 if (!device) {
76 fprintf(stderr, "kms_device_open() failed: %m\n");
77 return 1;
78 }
79
80 if (device->num_screens < 1) {
81 fprintf(stderr, "no screens found\n");
82 kms_device_close(device);
83 close(fd);
84 return 1;
85 }
86
87 /* TODO: allow command-line to override */
88 screen = device->screens[0];
89
90 printf("Using screen %s, resolution %ux%u\n", screen->name,
91 screen->width, screen->height);
92
93 fb = kms_framebuffer_create(device, screen->width, screen->height,
94 DRM_FORMAT_XRGB8888);
95 if (!fb) {
96 fprintf(stderr, "kms_framebuffer_create() failed\n");
97 return 1;
98 }
99
100 err = kms_framebuffer_map(fb, &ptr);
101 if (err < 0) {
102 fprintf(stderr, "kms_framebuffer_map() failed: %d\n", err);
103 return 1;
104 }
105
106 util_fill_pattern(fb->format, UTIL_PATTERN_SMPTE, &ptr, fb->width,
107 fb->height, fb->pitch);
108
109 kms_framebuffer_unmap(fb);
110
111 err = kms_screen_set(screen, device->crtcs[index++], fb);
112 if (err < 0) {
113 fprintf(stderr, "kms_screen_set() failed: %d\n", err);
114 return 1;
115 }
116
117 while (true) {
118 int nfds = STDIN_FILENO + 1;
119 struct timeval timeout;
120 fd_set fds;
121
122 memset(&timeout, 0, sizeof(timeout));
123 timeout.tv_sec = 5;
124 timeout.tv_usec = 0;
125
126 FD_ZERO(&fds);
127 FD_SET(STDIN_FILENO, &fds);
128
129 err = select(nfds, &fds, NULL, NULL, &timeout);
130 if (err < 0) {
131 if (errno == EINTR)
132 break;
133
134 fprintf(stderr, "select() failed: %d\n", errno);
135 break;
136 }
137
138 if (err > 0) {
139 if (FD_ISSET(STDIN_FILENO, &fds))
140 break;
141 }
142
143 /* switch CRTC */
144 if (index >= device->num_crtcs)
145 index = 0;
146
147 err = kms_screen_set(screen, device->crtcs[index], fb);
148 if (err < 0) {
149 fprintf(stderr, "kms_screen_set() failed: %d\n", err);
150 break;
151 }
152
153 index++;
154 }
155
156 kms_framebuffer_free(fb);
157 kms_device_close(device);
158 close(fd);
159
160 return 0;
161}