aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--configure.ac1
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/proptest/Makefile.am11
-rw-r--r--tests/proptest/proptest.c317
5 files changed, 331 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 38c6682f..3596a4a8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -89,6 +89,7 @@ tests/updatedraw
89tests/modeprint/modeprint 89tests/modeprint/modeprint
90tests/modetest/modetest 90tests/modetest/modetest
91tests/name_from_fd 91tests/name_from_fd
92tests/proptest/proptest
92tests/kmstest/kmstest 93tests/kmstest/kmstest
93tests/vbltest/vbltest 94tests/vbltest/vbltest
94tests/radeon/radeon_ttm 95tests/radeon/radeon_ttm
diff --git a/configure.ac b/configure.ac
index ee59b030..3a528f2b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -407,6 +407,7 @@ AC_CONFIG_FILES([
407 tests/modeprint/Makefile 407 tests/modeprint/Makefile
408 tests/modetest/Makefile 408 tests/modetest/Makefile
409 tests/kmstest/Makefile 409 tests/kmstest/Makefile
410 tests/proptest/Makefile
410 tests/radeon/Makefile 411 tests/radeon/Makefile
411 tests/vbltest/Makefile 412 tests/vbltest/Makefile
412 tests/exynos/Makefile 413 tests/exynos/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index cd114913..889d2651 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -10,7 +10,7 @@ check_PROGRAMS = \
10 dristat \ 10 dristat \
11 drmstat 11 drmstat
12 12
13SUBDIRS = modeprint 13SUBDIRS = modeprint proptest
14 14
15if HAVE_LIBKMS 15if HAVE_LIBKMS
16SUBDIRS += kmstest modetest 16SUBDIRS += kmstest modetest
diff --git a/tests/proptest/Makefile.am b/tests/proptest/Makefile.am
new file mode 100644
index 00000000..f81a3c00
--- /dev/null
+++ b/tests/proptest/Makefile.am
@@ -0,0 +1,11 @@
1AM_CFLAGS = \
2 -I$(top_srcdir)/include/drm \
3 -I$(top_srcdir)
4
5noinst_PROGRAMS = \
6 proptest
7
8proptest_SOURCES = \
9 proptest.c
10proptest_LDADD = \
11 $(top_builddir)/libdrm.la
diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c
new file mode 100644
index 00000000..4a569211
--- /dev/null
+++ b/tests/proptest/proptest.c
@@ -0,0 +1,317 @@
1/*
2 * Copyright © 2012 Intel 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 * Authors:
24 * Paulo Zanoni <paulo.r.zanoni@intel.com>
25 *
26 */
27
28#include <assert.h>
29#include <errno.h>
30#include <inttypes.h>
31#include <stdlib.h>
32#include <stdio.h>
33#include <string.h>
34
35#include "xf86drm.h"
36#include "xf86drmMode.h"
37
38#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
39
40int fd;
41drmModeResPtr res = NULL;
42
43const char *connector_type_str(uint32_t type)
44{
45 switch (type) {
46 case DRM_MODE_CONNECTOR_Unknown:
47 return "Unknown";
48 case DRM_MODE_CONNECTOR_VGA:
49 return "VGA";
50 case DRM_MODE_CONNECTOR_DVII:
51 return "DVI-I";
52 case DRM_MODE_CONNECTOR_DVID:
53 return "DVI-D";
54 case DRM_MODE_CONNECTOR_DVIA:
55 return "DVI-A";
56 case DRM_MODE_CONNECTOR_Composite:
57 return "Composite";
58 case DRM_MODE_CONNECTOR_SVIDEO:
59 return "SVIDEO";
60 case DRM_MODE_CONNECTOR_LVDS:
61 return "LVDS";
62 case DRM_MODE_CONNECTOR_Component:
63 return "Component";
64 case DRM_MODE_CONNECTOR_9PinDIN:
65 return "9PinDin";
66 case DRM_MODE_CONNECTOR_DisplayPort:
67 return "DisplayPort";
68 case DRM_MODE_CONNECTOR_HDMIA:
69 return "HDMI-A";
70 case DRM_MODE_CONNECTOR_HDMIB:
71 return "HDMI-B";
72 case DRM_MODE_CONNECTOR_TV:
73 return "TV";
74 case DRM_MODE_CONNECTOR_eDP:
75 return "eDP";
76 default:
77 return "Invalid";
78 }
79}
80
81/* dump_blob and dump_prop shamelessly copied from ../modetest/modetest.c */
82static void
83dump_blob(uint32_t blob_id)
84{
85 uint32_t i;
86 unsigned char *blob_data;
87 drmModePropertyBlobPtr blob;
88
89 blob = drmModeGetPropertyBlob(fd, blob_id);
90 if (!blob)
91 return;
92
93 blob_data = blob->data;
94
95 for (i = 0; i < blob->length; i++) {
96 if (i % 16 == 0)
97 printf("\n\t\t\t");
98 printf("%.2hhx", blob_data[i]);
99 }
100 printf("\n");
101
102 drmModeFreePropertyBlob(blob);
103}
104
105static void
106dump_prop(uint32_t prop_id, uint64_t value)
107{
108 int i;
109 drmModePropertyPtr prop;
110
111 prop = drmModeGetProperty(fd, prop_id);
112
113 printf("\t%d", prop_id);
114 if (!prop) {
115 printf("\n");
116 return;
117 }
118
119 printf(" %s:\n", prop->name);
120
121 printf("\t\tflags:");
122 if (prop->flags & DRM_MODE_PROP_PENDING)
123 printf(" pending");
124 if (prop->flags & DRM_MODE_PROP_RANGE)
125 printf(" range");
126 if (prop->flags & DRM_MODE_PROP_IMMUTABLE)
127 printf(" immutable");
128 if (prop->flags & DRM_MODE_PROP_ENUM)
129 printf(" enum");
130 if (prop->flags & DRM_MODE_PROP_BLOB)
131 printf(" blob");
132 printf("\n");
133
134 if (prop->flags & DRM_MODE_PROP_RANGE) {
135 printf("\t\tvalues:");
136 for (i = 0; i < prop->count_values; i++)
137 printf(" %"PRIu64, prop->values[i]);
138 printf("\n");
139 }
140
141 if (prop->flags & DRM_MODE_PROP_ENUM) {
142 printf("\t\tenums:");
143 for (i = 0; i < prop->count_enums; i++)
144 printf(" %s=%llu", prop->enums[i].name,
145 prop->enums[i].value);
146 printf("\n");
147 } else {
148 assert(prop->count_enums == 0);
149 }
150
151 if (prop->flags & DRM_MODE_PROP_BLOB) {
152 printf("\t\tblobs:\n");
153 for (i = 0; i < prop->count_blobs; i++)
154 dump_blob(prop->blob_ids[i]);
155 printf("\n");
156 } else {
157 assert(prop->count_blobs == 0);
158 }
159
160 printf("\t\tvalue:");
161 if (prop->flags & DRM_MODE_PROP_BLOB)
162 dump_blob(value);
163 else
164 printf(" %"PRIu64"\n", value);
165
166 drmModeFreeProperty(prop);
167}
168
169static void listObjectProperties(uint32_t id, uint32_t type)
170{
171 unsigned int i;
172 drmModeObjectPropertiesPtr props;
173
174 props = drmModeObjectGetProperties(fd, id, type);
175
176 if (!props) {
177 printf("\tNo properties: %s.\n", strerror(errno));
178 return;
179 }
180
181 for (i = 0; i < props->count_props; i++)
182 dump_prop(props->props[i], props->prop_values[i]);
183
184 drmModeFreeObjectProperties(props);
185}
186
187static void listConnectorProperties(void)
188{
189 int i;
190 drmModeConnectorPtr c;
191
192 for (i = 0; i < res->count_connectors; i++) {
193 c = drmModeGetConnector(fd, res->connectors[i]);
194
195 if (!c) {
196 fprintf(stderr, "Could not get connector %u: %s\n",
197 res->connectors[i], strerror(errno));
198 continue;
199 }
200
201 printf("Connector %u (%s-%u)\n", c->connector_id,
202 connector_type_str(c->connector_type),
203 c->connector_type_id);
204
205 listObjectProperties(c->connector_id,
206 DRM_MODE_OBJECT_CONNECTOR);
207
208 drmModeFreeConnector(c);
209 }
210}
211
212static void listCrtcProperties(void)
213{
214 int i;
215 drmModeCrtcPtr c;
216
217 for (i = 0; i < res->count_crtcs; i++) {
218 c = drmModeGetCrtc(fd, res->crtcs[i]);
219
220 if (!c) {
221 fprintf(stderr, "Could not get crtc %u: %s\n",
222 res->crtcs[i], strerror(errno));
223 continue;
224 }
225
226 printf("CRTC %u\n", c->crtc_id);
227
228 listObjectProperties(c->crtc_id, DRM_MODE_OBJECT_CRTC);
229
230 drmModeFreeCrtc(c);
231 }
232}
233
234static void listAllProperties(void)
235{
236 listConnectorProperties();
237 listCrtcProperties();
238}
239
240static int setProperty(char *argv[])
241{
242 uint32_t obj_id, obj_type, prop_id;
243 uint64_t value;
244
245 obj_id = atoi(argv[1]);
246
247 if (!strcmp(argv[2], "connector")) {
248 obj_type = DRM_MODE_OBJECT_CONNECTOR;
249 } else if (!strcmp(argv[2], "crtc")) {
250 obj_type = DRM_MODE_OBJECT_CRTC;
251 } else {
252 fprintf(stderr, "Invalid object type.\n");
253 return 1;
254 }
255
256 prop_id = atoi(argv[3]);
257 value = atoll(argv[4]);
258
259 return drmModeObjectSetProperty(fd, obj_id, obj_type, prop_id, value);
260}
261
262static void printUsage(void)
263{
264 printf("Usage:\n"
265" proptest\n"
266" proptest [obj id] [obj type] [prop id] [value]\n"
267"\n"
268"The first form just prints all the existing properties. The second one is\n"
269"used to set the value of a specified property. The object type can be one of\n"
270"the following strings:\n"
271" connector crtc\n"
272"\n"
273"Example:\n"
274" proptest 7 connector 2 1\n"
275"will set property 2 of connector 7 to 1\n");
276}
277
278int main(int argc, char *argv[])
279{
280 char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "msm" };
281 unsigned int i, ret = 0;
282
283 for (i = 0; i < ARRAY_SIZE(modules); i++){
284 fd = drmOpen(modules[i], NULL);
285 if (fd >= 0) {
286 printf("Module %s loaded.\n", modules[i]);
287 break;
288 }
289 }
290
291 if (i == ARRAY_SIZE(modules)) {
292 fprintf(stderr, "Failed to load drm modules.\n");
293 return 1;
294 }
295
296 res = drmModeGetResources(fd);
297 if (!res) {
298 fprintf(stderr, "Failed to get resources: %s\n",
299 strerror(errno));
300 ret = 1;
301 goto done;
302 }
303
304 if (argc < 2) {
305 listAllProperties();
306 } else if (argc == 5) {
307 ret = setProperty(argv);
308 } else {
309 printUsage();
310 ret = 1;
311 }
312
313 drmModeFreeResources(res);
314done:
315 drmClose(fd);
316 return ret;
317}