summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Reding2015-12-09 11:37:47 -0600
committerEmil Velikov2015-12-18 11:44:18 -0600
commit6223481b8de901b5356afdef538726f1fb77bfd1 (patch)
treef75883e33d75084c0b2892f616ab2377c40804c5
parentc26266fcd082a8b67d1f32f5e5351cfa82c7accb (diff)
downloadexternal-libdrm-6223481b8de901b5356afdef538726f1fb77bfd1.tar.gz
external-libdrm-6223481b8de901b5356afdef538726f1fb77bfd1.tar.xz
external-libdrm-6223481b8de901b5356afdef538726f1fb77bfd1.zip
proptest: Use util_open()
Use the new util_open() helper instead of open-coding the method for finding a usable device. While at it, make the command-line interface more consistent with that of modetest by adding the -D and -M options. Signed-off-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
-rw-r--r--tests/proptest/proptest.c60
1 files changed, 38 insertions, 22 deletions
diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c
index 11eb6e88..24c63456 100644
--- a/tests/proptest/proptest.c
+++ b/tests/proptest/proptest.c
@@ -27,6 +27,7 @@
27 27
28#include <assert.h> 28#include <assert.h>
29#include <errno.h> 29#include <errno.h>
30#include <getopt.h>
30#include <inttypes.h> 31#include <inttypes.h>
31#include <stdlib.h> 32#include <stdlib.h>
32#include <stdio.h> 33#include <stdio.h>
@@ -232,28 +233,32 @@ static int setProperty(char *argv[])
232 uint32_t obj_id, obj_type, prop_id; 233 uint32_t obj_id, obj_type, prop_id;
233 uint64_t value; 234 uint64_t value;
234 235
235 obj_id = atoi(argv[1]); 236 obj_id = atoi(argv[0]);
236 237
237 if (!strcmp(argv[2], "connector")) { 238 if (!strcmp(argv[1], "connector")) {
238 obj_type = DRM_MODE_OBJECT_CONNECTOR; 239 obj_type = DRM_MODE_OBJECT_CONNECTOR;
239 } else if (!strcmp(argv[2], "crtc")) { 240 } else if (!strcmp(argv[1], "crtc")) {
240 obj_type = DRM_MODE_OBJECT_CRTC; 241 obj_type = DRM_MODE_OBJECT_CRTC;
241 } else { 242 } else {
242 fprintf(stderr, "Invalid object type.\n"); 243 fprintf(stderr, "Invalid object type.\n");
243 return 1; 244 return 1;
244 } 245 }
245 246
246 prop_id = atoi(argv[3]); 247 prop_id = atoi(argv[2]);
247 value = atoll(argv[4]); 248 value = atoll(argv[3]);
248 249
249 return drmModeObjectSetProperty(fd, obj_id, obj_type, prop_id, value); 250 return drmModeObjectSetProperty(fd, obj_id, obj_type, prop_id, value);
250} 251}
251 252
252static void printUsage(void) 253static void usage(const char *program)
253{ 254{
254 printf("Usage:\n" 255 printf("Usage:\n"
255" proptest\n" 256" %s [options]\n"
256" proptest [obj id] [obj type] [prop id] [value]\n" 257" %s [options] [obj id] [obj type] [prop id] [value]\n"
258"\n"
259"options:\n"
260" -D DEVICE use the given device\n"
261" -M MODULE use the given driver\n"
257"\n" 262"\n"
258"The first form just prints all the existing properties. The second one is\n" 263"The first form just prints all the existing properties. The second one is\n"
259"used to set the value of a specified property. The object type can be one of\n" 264"used to set the value of a specified property. The object type can be one of\n"
@@ -262,26 +267,37 @@ static void printUsage(void)
262"\n" 267"\n"
263"Example:\n" 268"Example:\n"
264" proptest 7 connector 2 1\n" 269" proptest 7 connector 2 1\n"
265"will set property 2 of connector 7 to 1\n"); 270"will set property 2 of connector 7 to 1\n", program, program);
266} 271}
267 272
268int main(int argc, char *argv[]) 273int main(int argc, char *argv[])
269{ 274{
270 const char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "msm", "rockchip" }; 275 static const char optstr[] = "D:M:";
271 unsigned int i, ret = 0; 276 int c, args, ret = 0;
277 char *device = NULL;
278 char *module = NULL;
279
280 while ((c = getopt(argc, argv, optstr)) != -1) {
281 switch (c) {
282 case 'D':
283 device = optarg;
284 break;
285
286 case 'M':
287 module = optarg;
288 break;
272 289
273 for (i = 0; i < ARRAY_SIZE(modules); i++){ 290 default:
274 fd = drmOpen(modules[i], NULL); 291 usage(argv[0]);
275 if (fd >= 0) {
276 printf("Module %s loaded.\n", modules[i]);
277 break; 292 break;
278 } 293 }
279 } 294 }
280 295
281 if (i == ARRAY_SIZE(modules)) { 296 args = argc - optind;
282 fprintf(stderr, "Failed to load drm modules.\n"); 297
298 fd = util_open(module, device);
299 if (fd < 0)
283 return 1; 300 return 1;
284 }
285 301
286 res = drmModeGetResources(fd); 302 res = drmModeGetResources(fd);
287 if (!res) { 303 if (!res) {
@@ -291,12 +307,12 @@ int main(int argc, char *argv[])
291 goto done; 307 goto done;
292 } 308 }
293 309
294 if (argc < 2) { 310 if (args < 1) {
295 listAllProperties(); 311 listAllProperties();
296 } else if (argc == 5) { 312 } else if (args == 4) {
297 ret = setProperty(argv); 313 ret = setProperty(&argv[optind]);
298 } else { 314 } else {
299 printUsage(); 315 usage(argv[0]);
300 ret = 1; 316 ret = 1;
301 } 317 }
302 318