mirror of
https://gitlab.freedesktop.org/mesa/drm.git
synced 2025-12-20 08:10:11 +01:00
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>
This commit is contained in:
parent
89cca28dfb
commit
e744b02375
2 changed files with 57 additions and 0 deletions
|
|
@ -41,9 +41,13 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "xf86drm.h"
|
||||||
#include "xf86drmMode.h"
|
#include "xf86drmMode.h"
|
||||||
|
|
||||||
#include "common.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,
|
return util_lookup_type_name(type, connector_type_names,
|
||||||
ARRAY_SIZE(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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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_status_name(unsigned int type);
|
||||||
const char *util_lookup_connector_type_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 */
|
#endif /* UTIL_KMS_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue