From: Thierry Reding <thierry.reding@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Emil Velikov <emil.l.velikov@gmail.com>,
Hyungwon Hwang <human.hwang@samsung.com>
Subject: [PATCH libdrm 09/10] proptest: Use util_open()
Date: Wed, 9 Dec 2015 18:37:47 +0100 [thread overview]
Message-ID: <1449682668-22487-9-git-send-email-thierry.reding@gmail.com> (raw)
In-Reply-To: <1449682668-22487-1-git-send-email-thierry.reding@gmail.com>
From: Thierry Reding <treding@nvidia.com>
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>
---
tests/proptest/proptest.c | 60 ++++++++++++++++++++++++++++++-----------------
1 file changed, 38 insertions(+), 22 deletions(-)
diff --git a/tests/proptest/proptest.c b/tests/proptest/proptest.c
index 11eb6e88cef5..24c634569f2f 100644
--- a/tests/proptest/proptest.c
+++ b/tests/proptest/proptest.c
@@ -27,6 +27,7 @@
#include <assert.h>
#include <errno.h>
+#include <getopt.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
@@ -232,28 +233,32 @@ static int setProperty(char *argv[])
uint32_t obj_id, obj_type, prop_id;
uint64_t value;
- obj_id = atoi(argv[1]);
+ obj_id = atoi(argv[0]);
- if (!strcmp(argv[2], "connector")) {
+ if (!strcmp(argv[1], "connector")) {
obj_type = DRM_MODE_OBJECT_CONNECTOR;
- } else if (!strcmp(argv[2], "crtc")) {
+ } else if (!strcmp(argv[1], "crtc")) {
obj_type = DRM_MODE_OBJECT_CRTC;
} else {
fprintf(stderr, "Invalid object type.\n");
return 1;
}
- prop_id = atoi(argv[3]);
- value = atoll(argv[4]);
+ prop_id = atoi(argv[2]);
+ value = atoll(argv[3]);
return drmModeObjectSetProperty(fd, obj_id, obj_type, prop_id, value);
}
-static void printUsage(void)
+static void usage(const char *program)
{
printf("Usage:\n"
-" proptest\n"
-" proptest [obj id] [obj type] [prop id] [value]\n"
+" %s [options]\n"
+" %s [options] [obj id] [obj type] [prop id] [value]\n"
+"\n"
+"options:\n"
+" -D DEVICE use the given device\n"
+" -M MODULE use the given driver\n"
"\n"
"The first form just prints all the existing properties. The second one is\n"
"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)
"\n"
"Example:\n"
" proptest 7 connector 2 1\n"
-"will set property 2 of connector 7 to 1\n");
+"will set property 2 of connector 7 to 1\n", program, program);
}
int main(int argc, char *argv[])
{
- const char *modules[] = { "i915", "radeon", "nouveau", "vmwgfx", "omapdrm", "msm", "rockchip" };
- unsigned int i, ret = 0;
+ static const char optstr[] = "D:M:";
+ int c, args, ret = 0;
+ char *device = NULL;
+ char *module = NULL;
+
+ while ((c = getopt(argc, argv, optstr)) != -1) {
+ switch (c) {
+ case 'D':
+ device = optarg;
+ break;
+
+ case 'M':
+ module = optarg;
+ break;
- for (i = 0; i < ARRAY_SIZE(modules); i++){
- fd = drmOpen(modules[i], NULL);
- if (fd >= 0) {
- printf("Module %s loaded.\n", modules[i]);
+ default:
+ usage(argv[0]);
break;
}
}
- if (i == ARRAY_SIZE(modules)) {
- fprintf(stderr, "Failed to load drm modules.\n");
+ args = argc - optind;
+
+ fd = util_open(module, device);
+ if (fd < 0)
return 1;
- }
res = drmModeGetResources(fd);
if (!res) {
@@ -291,12 +307,12 @@ int main(int argc, char *argv[])
goto done;
}
- if (argc < 2) {
+ if (args < 1) {
listAllProperties();
- } else if (argc == 5) {
- ret = setProperty(argv);
+ } else if (args == 4) {
+ ret = setProperty(&argv[optind]);
} else {
- printUsage();
+ usage(argv[0]);
ret = 1;
}
--
2.5.0
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2015-12-09 17:38 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-09 17:37 [PATCH libdrm 01/10] tests: Split helpers into library Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 02/10] tests: Move name tables to libutil Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 03/10] proptest: Add Android support Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 04/10] tests: Add libkms-test library Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 05/10] tests: kms: Implement CRTC stealing test Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 06/10] tests: kms: Implement universal planes test Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 07/10] tests: Add helper to open a device/module Thierry Reding
2015-12-09 17:37 ` [PATCH libdrm 08/10] modetest: Use util_open() Thierry Reding
2015-12-09 17:37 ` Thierry Reding [this message]
2015-12-09 17:37 ` [PATCH libdrm 10/10] vbltest: " Thierry Reding
2015-12-12 15:26 ` [PATCH libdrm 01/10] tests: Split helpers into library Emil Velikov
2015-12-14 8:12 ` Thierry Reding
2015-12-14 13:10 ` 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=1449682668-22487-9-git-send-email-thierry.reding@gmail.com \
--to=thierry.reding@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.l.velikov@gmail.com \
--cc=human.hwang@samsung.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox