GCC Code Coverage Report


Directory: ./
File: device.c
Date: 2025-02-26 18:18:17
Exec Total Coverage
Lines: 68 88 77.3%
Functions: 5 5 100.0%
Branches: 43 58 74.1%

Line Branch Exec Source
1 #include <errno.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include "log.h"
6 #include "private.h"
7
8 struct liftoff_device *
9 57 liftoff_device_create(int drm_fd)
10 {
11 struct liftoff_device *device;
12 drmModeRes *drm_res;
13 drmModePlaneRes *drm_plane_res;
14
15 57 device = calloc(1, sizeof(*device));
16
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→5) taken 57 times.
57 if (device == NULL) {
17 liftoff_log_errno(LIFTOFF_ERROR, "calloc");
18 return NULL;
19 }
20
21 57 liftoff_list_init(&device->planes);
22 57 liftoff_list_init(&device->outputs);
23
24 57 device->drm_fd = dup(drm_fd);
25
1/2
✗ Branch 0 (8→9) not taken.
✓ Branch 1 (8→12) taken 57 times.
57 if (device->drm_fd < 0) {
26 liftoff_log_errno(LIFTOFF_ERROR, "dup");
27 liftoff_device_destroy(device);
28 return NULL;
29 }
30
31 57 drm_res = drmModeGetResources(drm_fd);
32
1/2
✗ Branch 0 (13→14) not taken.
✓ Branch 1 (13→17) taken 57 times.
57 if (drm_res == NULL) {
33 liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetResources");
34 liftoff_device_destroy(device);
35 return NULL;
36 }
37
38 57 device->crtcs_len = (size_t)drm_res->count_crtcs;
39 57 device->crtcs = malloc(device->crtcs_len * sizeof(device->crtcs[0]));
40
1/2
✗ Branch 0 (17→18) not taken.
✓ Branch 1 (17→22) taken 57 times.
57 if (device->crtcs == NULL) {
41 liftoff_log_errno(LIFTOFF_ERROR, "malloc");
42 drmModeFreeResources(drm_res);
43 liftoff_device_destroy(device);
44 return NULL;
45 }
46 57 memcpy(device->crtcs, drm_res->crtcs, device->crtcs_len * sizeof(device->crtcs[0]));
47
48 57 drmModeFreeResources(drm_res);
49
50 57 drm_plane_res = drmModeGetPlaneResources(device->drm_fd);
51
1/2
✗ Branch 0 (24→25) not taken.
✓ Branch 1 (24→28) taken 57 times.
57 if (drm_plane_res == NULL) {
52 liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlaneResources");
53 liftoff_device_destroy(device);
54 return NULL;
55 }
56 57 device->planes_cap = drm_plane_res->count_planes;
57 57 drmModeFreePlaneResources(drm_plane_res);
58
59 57 return device;
60 }
61
62 void
63 57 liftoff_device_destroy(struct liftoff_device *device)
64 {
65 struct liftoff_plane *plane, *tmp;
66
67
1/2
✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 57 times.
57 if (device == NULL) {
68 return;
69 }
70
71 57 close(device->drm_fd);
72
2/2
✓ Branch 0 (8→6) taken 148 times.
✓ Branch 1 (8→9) taken 57 times.
205 liftoff_list_for_each_safe(plane, tmp, &device->planes, link) {
73 148 liftoff_plane_destroy(plane);
74 }
75 57 free(device->crtcs);
76 57 free(device);
77 }
78
79 int
80 56 liftoff_device_register_all_planes(struct liftoff_device *device)
81 {
82 drmModePlaneRes *drm_plane_res;
83 uint32_t i;
84
85 56 drm_plane_res = drmModeGetPlaneResources(device->drm_fd);
86
1/2
✗ Branch 0 (3→4) not taken.
✓ Branch 1 (3→6) taken 56 times.
56 if (drm_plane_res == NULL) {
87 liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlaneResources");
88 return -errno;
89 }
90
91
2/2
✓ Branch 0 (11→7) taken 146 times.
✓ Branch 1 (11→12) taken 56 times.
202 for (i = 0; i < drm_plane_res->count_planes; i++) {
92
1/2
✗ Branch 0 (8→9) not taken.
✓ Branch 1 (8→10) taken 146 times.
146 if (liftoff_plane_create(device, drm_plane_res->planes[i]) == NULL) {
93 return -errno;
94 }
95 }
96 56 drmModeFreePlaneResources(drm_plane_res);
97
98 56 return 0;
99 }
100
101 int
102 1532 device_test_commit(struct liftoff_device *device, drmModeAtomicReq *req,
103 uint32_t flags)
104 {
105 int ret;
106
107 1532 device->test_commit_counter++;
108
109 1532 flags &= ~(uint32_t)DRM_MODE_PAGE_FLIP_EVENT;
110 do {
111 1532 ret = drmModeAtomicCommit(device->drm_fd, req,
112 DRM_MODE_ATOMIC_TEST_ONLY | flags,
113 NULL);
114
2/4
✗ Branch 0 (5→3) not taken.
✓ Branch 1 (5→6) taken 1532 times.
✗ Branch 2 (6→3) not taken.
✓ Branch 3 (6→7) taken 1532 times.
1532 } while (ret == -EINTR || ret == -EAGAIN);
115
116 /* The kernel will return -EINVAL for invalid configuration, -ERANGE for
117 * CRTC coords overflow, and -ENOSPC for invalid SRC coords. */
118
3/8
✓ Branch 0 (7→8) taken 227 times.
✓ Branch 1 (7→13) taken 1305 times.
✗ Branch 2 (8→9) not taken.
✓ Branch 3 (8→13) taken 227 times.
✗ Branch 4 (9→10) not taken.
✗ Branch 5 (9→13) not taken.
✗ Branch 6 (10→11) not taken.
✗ Branch 7 (10→13) not taken.
1532 if (ret != 0 && ret != -EINVAL && ret != -ERANGE && ret != -ENOSPC) {
119 liftoff_log(LIFTOFF_ERROR, "drmModeAtomicCommit: %s",
120 strerror(-ret));
121 }
122
123 1532 return ret;
124 }
125
126 ssize_t
127 5573 core_property_index(const char *name)
128 {
129
2/2
✓ Branch 0 (2→3) taken 1636 times.
✓ Branch 1 (2→4) taken 3937 times.
5573 if (strcmp(name, "FB_ID") == 0) {
130 1636 return LIFTOFF_PROP_FB_ID;
131
2/2
✓ Branch 0 (4→5) taken 148 times.
✓ Branch 1 (4→6) taken 3789 times.
3937 } else if (strcmp(name, "CRTC_ID") == 0) {
132 148 return LIFTOFF_PROP_CRTC_ID;
133
2/2
✓ Branch 0 (6→7) taken 426 times.
✓ Branch 1 (6→8) taken 3363 times.
3789 } else if (strcmp(name, "CRTC_X") == 0) {
134 426 return LIFTOFF_PROP_CRTC_X;
135
2/2
✓ Branch 0 (8→9) taken 425 times.
✓ Branch 1 (8→10) taken 2938 times.
3363 } else if (strcmp(name, "CRTC_Y") == 0) {
136 425 return LIFTOFF_PROP_CRTC_Y;
137
2/2
✓ Branch 0 (10→11) taken 424 times.
✓ Branch 1 (10→12) taken 2514 times.
2938 } else if (strcmp(name, "CRTC_W") == 0) {
138 424 return LIFTOFF_PROP_CRTC_W;
139
2/2
✓ Branch 0 (12→13) taken 424 times.
✓ Branch 1 (12→14) taken 2090 times.
2514 } else if (strcmp(name, "CRTC_H") == 0) {
140 424 return LIFTOFF_PROP_CRTC_H;
141
2/2
✓ Branch 0 (14→15) taken 424 times.
✓ Branch 1 (14→16) taken 1666 times.
2090 } else if (strcmp(name, "SRC_X") == 0) {
142 424 return LIFTOFF_PROP_SRC_X;
143
2/2
✓ Branch 0 (16→17) taken 424 times.
✓ Branch 1 (16→18) taken 1242 times.
1666 } else if (strcmp(name, "SRC_Y") == 0) {
144 424 return LIFTOFF_PROP_SRC_Y;
145
2/2
✓ Branch 0 (18→19) taken 424 times.
✓ Branch 1 (18→20) taken 818 times.
1242 } else if (strcmp(name, "SRC_W") == 0) {
146 424 return LIFTOFF_PROP_SRC_W;
147
2/2
✓ Branch 0 (20→21) taken 424 times.
✓ Branch 1 (20→22) taken 394 times.
818 } else if (strcmp(name, "SRC_H") == 0) {
148 424 return LIFTOFF_PROP_SRC_H;
149
2/2
✓ Branch 0 (22→23) taken 130 times.
✓ Branch 1 (22→24) taken 264 times.
394 } else if (strcmp(name, "zpos") == 0) {
150 130 return LIFTOFF_PROP_ZPOS;
151
2/2
✓ Branch 0 (24→25) taken 48 times.
✓ Branch 1 (24→26) taken 216 times.
264 } else if (strcmp(name, "alpha") == 0) {
152 48 return LIFTOFF_PROP_ALPHA;
153
2/2
✓ Branch 0 (26→27) taken 9 times.
✓ Branch 1 (26→28) taken 207 times.
216 } else if (strcmp(name, "rotation") == 0) {
154 9 return LIFTOFF_PROP_ROTATION;
155 }
156 207 return -1;
157 }
158