1 /* Copyright (c) 2021 Collabora Ltd
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * \brief Tests for libgbm.
28 #include <drm_fourcc.h>
33 #include <sys/types.h>
35 #include "piglit-util.h"
40 #define FORMAT GBM_FORMAT_R8
43 gem_handles_match(struct gbm_device
*gbm
, int fd
, int old_handle
)
46 struct gbm_import_fd_data import
= {
52 struct gbm_bo
*bo
= gbm_bo_import(gbm
, GBM_BO_IMPORT_FD
, &import
, 0);
54 piglit_report_result(PIGLIT_FAIL
);
56 match
= gbm_bo_get_handle(bo
).u32
== old_handle
;
63 main(int argc
, char **argv
)
67 struct gbm_device
*gbm
;
68 struct gbm_bo
*bos
[NUM_PLANES
];
69 struct gbm_bo
*multi_plane_bo
;
70 struct gbm_import_fd_modifier_data import_mod
= {
73 .format
= GBM_FORMAT_YUV420
,
74 .num_fds
= NUM_PLANES
,
75 .modifier
= DRM_FORMAT_MOD_LINEAR
,
78 /* Strip common piglit args. */
79 piglit_strip_arg(&argc
, argv
, "-fbo");
80 piglit_strip_arg(&argc
, argv
, "-auto");
82 nodename
= getenv("WAFFLE_GBM_DEVICE");
84 nodename
= "/dev/dri/renderD128";
85 drm_fd
= open(nodename
, O_RDWR
);
87 perror("Error opening render node");
88 piglit_report_result(PIGLIT_FAIL
);
91 gbm
= gbm_create_device(drm_fd
);
93 piglit_report_result(PIGLIT_FAIL
);
95 for (int i
= 0; i
< NUM_PLANES
; i
++) {
96 bos
[i
] = gbm_bo_create(gbm
, WIDTH
, HEIGHT
, FORMAT
,
97 GBM_BO_USE_RENDERING
| GBM_BO_USE_LINEAR
);
99 piglit_report_result(PIGLIT_FAIL
);
101 import_mod
.fds
[i
] = gbm_bo_get_fd(bos
[i
]);
102 import_mod
.strides
[i
] = gbm_bo_get_stride(bos
[i
]);
103 import_mod
.offsets
[i
] = gbm_bo_get_offset(bos
[i
], 0);
106 multi_plane_bo
= gbm_bo_import(gbm
, GBM_BO_IMPORT_FD_MODIFIER
,
109 piglit_report_result(PIGLIT_FAIL
);
111 for (int i
= 0; i
< NUM_PLANES
; i
++) {
112 int fd
= gbm_bo_get_fd_for_plane(multi_plane_bo
, i
);
114 piglit_report_result(PIGLIT_FAIL
);
116 if (fcntl(fd
, F_GETFL
) == -1 && errno
== EBADF
)
117 piglit_report_result(PIGLIT_FAIL
);
119 if (!gem_handles_match(gbm
, fd
, gbm_bo_get_handle(bos
[i
]).u32
))
120 piglit_report_result(PIGLIT_FAIL
);
122 if (import_mod
.strides
[i
] != gbm_bo_get_stride_for_plane(multi_plane_bo
, i
))
123 piglit_report_result(PIGLIT_FAIL
);
125 if (import_mod
.offsets
[i
] != gbm_bo_get_offset(multi_plane_bo
, i
))
126 piglit_report_result(PIGLIT_FAIL
);
129 piglit_report_result(PIGLIT_PASS
);