summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Reding2015-12-09 11:37:45 -0600
committerEmil Velikov2015-12-18 11:44:13 -0600
commite744b02375e939e853b4c83979f170bfc89e482c (patch)
treefb717d880ebecf0f61e854317f5d272e820c668c
parent89cca28dfbc0c96c13b1dfa3bc3c947876469159 (diff)
downloadexternal-libdrm-e744b02375e939e853b4c83979f170bfc89e482c.tar.gz
external-libdrm-e744b02375e939e853b4c83979f170bfc89e482c.tar.xz
external-libdrm-e744b02375e939e853b4c83979f170bfc89e482c.zip
tests: Add helper to open a device/module
The new function util_open() encapsulates the standard method employed by tests to open a device or module. There is a verbatim copy of this in almost all test programs, with slight variations in the list of modules. Moving this code into a common helper allows code reuse and makes tests more consistent. Signed-off-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
-rw-r--r--tests/util/kms.c55
-rw-r--r--tests/util/kms.h2
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/util/kms.c b/tests/util/kms.c
index 687b3c3c..57b0191b 100644
--- a/tests/util/kms.c
+++ b/tests/util/kms.c
@@ -41,9 +41,13 @@
41#include "config.h" 41#include "config.h"
42#endif 42#endif
43 43
44#include <errno.h>
44#include <stdint.h> 45#include <stdint.h>
46#include <stdio.h>
45#include <stdlib.h> 47#include <stdlib.h>
48#include <string.h>
46 49
50#include "xf86drm.h"
47#include "xf86drmMode.h" 51#include "xf86drmMode.h"
48 52
49#include "common.h" 53#include "common.h"
@@ -120,3 +124,54 @@ const char *util_lookup_connector_type_name(unsigned int type)
120 return util_lookup_type_name(type, connector_type_names, 124 return util_lookup_type_name(type, connector_type_names,
121 ARRAY_SIZE(connector_type_names)); 125 ARRAY_SIZE(connector_type_names));
122} 126}
127
128static const char * const modules[] = {
129 "i915",
130 "radeon",
131 "nouveau",
132 "vmwgfx",
133 "omapdrm",
134 "exynos",
135 "tilcdc",
136 "msm",
137 "sti",
138 "tegra",
139 "imx-drm",
140 "rockchip",
141 "atmel-hlcdc",
142};
143
144int util_open(const char *device, const char *module)
145{
146 int fd;
147
148 if (module) {
149 fd = drmOpen(module, device);
150 if (fd < 0) {
151 fprintf(stderr, "failed to open device '%s': %s\n",
152 module, strerror(errno));
153 return -errno;
154 }
155 } else {
156 unsigned int i;
157
158 for (i = 0; i < ARRAY_SIZE(modules); i++) {
159 printf("trying to open device '%s'...", modules[i]);
160
161 fd = drmOpen(modules[i], device);
162 if (fd < 0) {
163 printf("failed\n");
164 } else {
165 printf("done\n");
166 break;
167 }
168 }
169
170 if (fd < 0) {
171 fprintf(stderr, "no device found\n");
172 return -ENODEV;
173 }
174 }
175
176 return fd;
177}
diff --git a/tests/util/kms.h b/tests/util/kms.h
index fa9ab699..dde2ed2c 100644
--- a/tests/util/kms.h
+++ b/tests/util/kms.h
@@ -30,4 +30,6 @@ const char *util_lookup_encoder_type_name(unsigned int type);
30const char *util_lookup_connector_status_name(unsigned int type); 30const char *util_lookup_connector_status_name(unsigned int type);
31const char *util_lookup_connector_type_name(unsigned int type); 31const char *util_lookup_connector_type_name(unsigned int type);
32 32
33int util_open(const char *device, const char *module);
34
33#endif /* UTIL_KMS_H */ 35#endif /* UTIL_KMS_H */