summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2015-12-09 18:37:45 +0100
committerEmil Velikov <emil.l.velikov@gmail.com>2015-12-18 17:44:13 +0000
commite744b02375e939e853b4c83979f170bfc89e482c (patch)
treefb717d880ebecf0f61e854317f5d272e820c668c
parent89cca28dfbc0c96c13b1dfa3bc3c947876469159 (diff)
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 687b3c3c1cf3..57b0191b2655 100644
--- a/tests/util/kms.c
+++ b/tests/util/kms.c
@@ -41,9 +41,13 @@
#include "config.h"
#endif
+#include <errno.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include "xf86drm.h"
#include "xf86drmMode.h"
#include "common.h"
@@ -120,3 +124,54 @@ const char *util_lookup_connector_type_name(unsigned int type)
return util_lookup_type_name(type, connector_type_names,
ARRAY_SIZE(connector_type_names));
}
+
+static const char * const modules[] = {
+ "i915",
+ "radeon",
+ "nouveau",
+ "vmwgfx",
+ "omapdrm",
+ "exynos",
+ "tilcdc",
+ "msm",
+ "sti",
+ "tegra",
+ "imx-drm",
+ "rockchip",
+ "atmel-hlcdc",
+};
+
+int util_open(const char *device, const char *module)
+{
+ int fd;
+
+ if (module) {
+ fd = drmOpen(module, device);
+ if (fd < 0) {
+ fprintf(stderr, "failed to open device '%s': %s\n",
+ module, strerror(errno));
+ return -errno;
+ }
+ } else {
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(modules); i++) {
+ printf("trying to open device '%s'...", modules[i]);
+
+ fd = drmOpen(modules[i], device);
+ if (fd < 0) {
+ printf("failed\n");
+ } else {
+ printf("done\n");
+ break;
+ }
+ }
+
+ if (fd < 0) {
+ fprintf(stderr, "no device found\n");
+ return -ENODEV;
+ }
+ }
+
+ return fd;
+}
diff --git a/tests/util/kms.h b/tests/util/kms.h
index fa9ab69983ac..dde2ed2c5636 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);
const char *util_lookup_connector_status_name(unsigned int type);
const char *util_lookup_connector_type_name(unsigned int type);
+int util_open(const char *device, const char *module);
+
#endif /* UTIL_KMS_H */