summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2015-09-09 18:13:01 +0100
committerEmil Velikov <emil.l.velikov@gmail.com>2015-09-21 17:43:11 +0100
commit8990ed319993c5d1a354adef41c19acc662c81e8 (patch)
tree183df89b9f80a15f0e9b3b66dad4c9dce252058a /tests
parentccedf66b65f6ab245aa6028d7fe9eb603a121b43 (diff)
tests/drmdevice: add drm{Get,Free}Device() example
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Acked-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/drmdevice.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/drmdevice.c b/tests/drmdevice.c
index 4055f450..c3363274 100644
--- a/tests/drmdevice.c
+++ b/tests/drmdevice.c
@@ -23,6 +23,9 @@
#include <stdio.h>
#include <stdlib.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <xf86drm.h>
@@ -62,7 +65,8 @@ int
main(void)
{
drmDevicePtr *devices;
- int ret, max_devices;
+ drmDevicePtr device;
+ int fd, ret, max_devices;
max_devices = drmGetDevices(NULL, 0);
@@ -84,9 +88,24 @@ main(void)
return -1;
}
- for (int i = 0; i < ret; i++)
+ for (int i = 0; i < ret; i++) {
print_device_info(devices[i], i);
+ for (int j = 0; j < DRM_NODE_MAX; j++) {
+ if (devices[i]->available_nodes & 1 << j) {
+ fd = open(devices[i]->nodes[j], O_RDONLY | O_CLOEXEC, 0);
+ if (fd < 0)
+ continue;
+
+ if (drmGetDevice(fd, &device) == 0) {
+ print_device_info(device, -1);
+ drmFreeDevice(&device);
+ }
+ close(fd);
+ }
+ }
+ }
+
drmFreeDevices(devices, ret);
free(devices);
return 0;