2 * Permission is hereby granted, free of charge, to any person obtaining a
3 * copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation
5 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
6 * and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * Imre Deak <imre.deak@intel.com>
35 #include "testdisplay.h"
36 #include "intel_bufmgr.h"
37 #include "intel_batchbuffer.h"
38 #include "intel_gpu_tools.h"
40 drmModeRes *resources;
42 static drm_intel_bufmgr *bufmgr;
43 struct intel_batchbuffer *batch;
47 TEST_DIRECT_RENDER = 0x01,
51 static int paint_fb(struct kmstest_fb *fb, const char *test_name,
52 const char *mode_format_str, const char *cconf_str)
56 cr = kmstest_get_cairo_ctx(drm_fd, fb);
60 kmstest_paint_color_gradient(cr, 0, 0, fb->width, fb->height, 1, 1, 1);
61 kmstest_paint_test_pattern(cr, fb->width, fb->height);
63 cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL,
64 CAIRO_FONT_WEIGHT_NORMAL);
65 cairo_move_to(cr, fb->width / 2, fb->height / 2);
66 cairo_set_font_size(cr, 36);
67 kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", test_name);
68 kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
69 kmstest_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
74 static void gpu_blit(struct kmstest_fb *dst_fb, struct kmstest_fb *src_fb)
79 dst_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "destination",
82 src_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "source",
86 intel_copy_bo(batch, dst_bo, src_bo, src_fb->width, src_fb->height);
87 intel_batchbuffer_flush(batch);
88 gem_quiescent_gpu(drm_fd);
90 drm_intel_bo_unreference(src_bo);
91 drm_intel_bo_unreference(dst_bo);
94 static int test_format(const char *test_name,
95 struct kmstest_connector_config *cconf,
96 drmModeModeInfo *mode, uint32_t format,
97 enum test_flags flags)
101 struct kmstest_fb fb[2];
102 char *mode_format_str;
106 ret = asprintf(&mode_format_str, "%s @ %dHz / %s",
107 mode->name, mode->vrefresh, kmstest_format_str(format));
109 ret = asprintf(&cconf_str, "pipe %s, encoder %s, connector %s",
110 kmstest_pipe_str(cconf->pipe),
111 kmstest_encoder_type_str(cconf->encoder->encoder_type),
112 kmstest_connector_type_str(cconf->connector->connector_type));
115 printf("Beginning test %s with %s on %s\n",
116 test_name, mode_format_str, cconf_str);
118 width = mode->hdisplay;
119 height = mode->vdisplay;
121 if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[0]))
124 if (!kmstest_create_fb2(drm_fd, width, height, format, false, &fb[1]))
127 if (drmModeSetCrtc(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
128 0, 0, &cconf->connector->connector_id, 1,
131 do_or_die(drmModePageFlip(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
135 if (flags & TEST_DIRECT_RENDER) {
136 paint_fb(&fb[0], test_name, mode_format_str, cconf_str);
137 } else if (flags & TEST_GPU_BLIT) {
138 paint_fb(&fb[1], test_name, mode_format_str, cconf_str);
139 gpu_blit(&fb[0], &fb[1]);
143 printf("Test %s with %s on %s: PASSED\n",
144 test_name, mode_format_str, cconf_str);
145 free(mode_format_str);
148 kmstest_remove_fb(drm_fd, &fb[1]);
149 kmstest_remove_fb(drm_fd, &fb[0]);
154 kmstest_remove_fb(drm_fd, &fb[0]);
156 printf("Test %s with %s on %s: SKIPPED\n",
157 test_name, mode_format_str, cconf_str);
158 free(mode_format_str);
164 static void test_connector(const char *test_name,
165 struct kmstest_connector_config *cconf,
166 enum test_flags flags)
168 const uint32_t *formats;
172 kmstest_get_all_formats(&formats, &format_count);
173 for (i = 0; i < cconf->connector->count_modes; i++) {
176 for (j = 0; j < format_count; j++)
177 test_format(test_name,
178 cconf, &cconf->connector->modes[i],
183 static int run_test(const char *test_name, enum test_flags flags)
187 resources = drmModeGetResources(drm_fd);
190 /* Find any connected displays */
191 for (i = 0; i < resources->count_connectors; i++) {
192 uint32_t connector_id;
195 connector_id = resources->connectors[i];
196 for (j = 0; j < resources->count_crtcs; j++) {
197 struct kmstest_connector_config cconf;
200 ret = kmstest_get_connector_config(drm_fd, connector_id,
205 test_connector(test_name, &cconf, flags);
207 kmstest_free_connector_config(&cconf);
211 drmModeFreeResources(resources);
216 int main(int argc, char **argv)
219 enum test_flags flags;
222 { TEST_DIRECT_RENDER, "direct-render" },
223 { TEST_GPU_BLIT, "gpu-blit" },
227 drmtest_subtest_init(argc, argv);
229 if (!drmtest_only_list_subtests()) {
230 drm_fd = drm_open_any();
232 bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
233 devid = intel_get_drm_devid(drm_fd);
234 batch = intel_batchbuffer_alloc(bufmgr, devid);
236 do_or_die(drmtest_set_vt_graphics_mode());
239 for (i = 0; i < ARRAY_SIZE(tests); i++) {
240 if (drmtest_run_subtest(tests[i].name))
241 run_test(tests[i].name, tests[i].flags);
244 if (!drmtest_only_list_subtests())