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>
34 #include "intel_bufmgr.h"
35 #include "intel_batchbuffer.h"
37 #include "intel_chipset.h"
39 #include "ioctl_wrappers.h"
41 drmModeRes *resources;
43 static drm_intel_bufmgr *bufmgr;
44 struct intel_batchbuffer *batch;
48 TEST_DIRECT_RENDER = 0x01,
52 static int paint_fb(struct igt_fb *fb, const char *test_name,
53 const char *mode_format_str, const char *cconf_str)
57 cr = igt_get_cairo_ctx(drm_fd, fb);
59 igt_paint_color_gradient(cr, 0, 0, fb->width, fb->height, 1, 1, 1);
60 igt_paint_test_pattern(cr, fb->width, fb->height);
62 cairo_move_to(cr, fb->width / 2, fb->height / 2);
63 cairo_set_font_size(cr, 36);
64 igt_cairo_printf_line(cr, align_hcenter, 10, "%s", test_name);
65 igt_cairo_printf_line(cr, align_hcenter, 10, "%s", mode_format_str);
66 igt_cairo_printf_line(cr, align_hcenter, 10, "%s", cconf_str);
73 static void gpu_blit(struct igt_fb *dst_fb, struct igt_fb *src_fb)
79 igt_assert(dst_fb->drm_format == src_fb->drm_format);
80 igt_assert(src_fb->drm_format == DRM_FORMAT_RGB565 ||
81 igt_drm_format_to_bpp(src_fb->drm_format) != 16);
82 bpp = igt_drm_format_to_bpp(src_fb->drm_format);
83 dst_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "destination",
86 src_bo = gem_handle_to_libdrm_bo(bufmgr, drm_fd, "source",
91 src_bo, 0, 0, src_fb->width * bpp / 8,
92 dst_bo, 0, 0, dst_fb->width * bpp / 8,
93 src_fb->width, src_fb->height, bpp);
94 intel_batchbuffer_flush(batch);
95 gem_quiescent_gpu(drm_fd);
97 drm_intel_bo_unreference(src_bo);
98 drm_intel_bo_unreference(dst_bo);
101 static int test_format(const char *test_name,
102 struct kmstest_connector_config *cconf,
103 drmModeModeInfo *mode, uint32_t format,
104 enum test_flags flags)
109 char *mode_format_str;
113 ret = asprintf(&mode_format_str, "%s @ %dHz / %s",
114 mode->name, mode->vrefresh, igt_format_str(format));
116 ret = asprintf(&cconf_str, "pipe %s, encoder %s, connector %s",
117 kmstest_pipe_str(cconf->pipe),
118 kmstest_encoder_type_str(cconf->encoder->encoder_type),
119 kmstest_connector_type_str(cconf->connector->connector_type));
122 igt_info("Beginning test %s with %s on %s\n",
123 test_name, mode_format_str, cconf_str);
125 width = mode->hdisplay;
126 height = mode->vdisplay;
128 if (!igt_create_fb(drm_fd, width, height, format, false, &fb[0]))
131 if (!igt_create_fb(drm_fd, width, height, format, false, &fb[1]))
134 if (drmModeSetCrtc(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
135 0, 0, &cconf->connector->connector_id, 1,
138 do_or_die(drmModePageFlip(drm_fd, cconf->crtc->crtc_id, fb[0].fb_id,
142 if (flags & TEST_DIRECT_RENDER) {
143 paint_fb(&fb[0], test_name, mode_format_str, cconf_str);
144 } else if (flags & TEST_GPU_BLIT) {
145 paint_fb(&fb[1], test_name, mode_format_str, cconf_str);
146 gpu_blit(&fb[0], &fb[1]);
150 igt_info("Test %s with %s on %s: PASSED\n",
151 test_name, mode_format_str, cconf_str);
152 free(mode_format_str);
155 igt_remove_fb(drm_fd, &fb[1]);
156 igt_remove_fb(drm_fd, &fb[0]);
161 igt_remove_fb(drm_fd, &fb[0]);
163 igt_info("Test %s with %s on %s: SKIPPED\n",
164 test_name, mode_format_str, cconf_str);
165 free(mode_format_str);
171 static void test_connector(const char *test_name,
172 struct kmstest_connector_config *cconf,
173 enum test_flags flags)
175 const uint32_t *formats;
179 igt_get_all_formats(&formats, &format_count);
180 for (i = 0; i < format_count; i++)
181 test_format(test_name,
182 cconf, &cconf->connector->modes[i],
186 static int run_test(const char *test_name, enum test_flags flags)
190 resources = drmModeGetResources(drm_fd);
191 igt_assert(resources);
193 /* Find any connected displays */
194 for (i = 0; i < resources->count_connectors; i++) {
195 uint32_t connector_id;
198 connector_id = resources->connectors[i];
199 for (j = 0; j < resources->count_crtcs; j++) {
200 struct kmstest_connector_config cconf;
203 ret = kmstest_get_connector_config(drm_fd, connector_id,
208 test_connector(test_name, &cconf, flags);
210 kmstest_free_connector_config(&cconf);
214 drmModeFreeResources(resources);
222 enum test_flags flags;
225 { TEST_DIRECT_RENDER, "direct-render" },
226 { TEST_GPU_BLIT, "gpu-blit" },
230 igt_skip_on_simulation();
233 drm_fd = drm_open_any();
235 bufmgr = drm_intel_bufmgr_gem_init(drm_fd, 4096);
236 devid = intel_get_drm_devid(drm_fd);
237 batch = intel_batchbuffer_alloc(bufmgr, devid);
239 igt_set_vt_graphics_mode();
242 for (i = 0; i < ARRAY_SIZE(tests); i++) {
243 igt_subtest(tests[i].name)
244 run_test(tests[i].name, tests[i].flags);