2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
33 #include "igt_debugfs.h"
36 struct kmstest_connector_config config;
43 igt_debugfs_t debugfs;
44 drmModeRes *resources;
46 connector_t *connectors;
50 static void test_bad_command(data_t *data, const char *cmd)
54 written = fwrite(cmd, 1, strlen(cmd), data->ctl);
56 igt_assert_cmpint(written, ==, (strlen(cmd)));
57 igt_assert(ferror(data->ctl));
58 igt_assert_cmpint(errno, ==, EINVAL);
61 static void connector_init(data_t *data, connector_t *connector,
62 uint32_t id, uint32_t crtc_id_mask)
66 ret = kmstest_get_connector_config(data->drm_fd, id, crtc_id_mask,
69 connector->valid = true;
71 connector->valid = false;
75 static void connector_fini(connector_t *connector)
77 kmstest_free_connector_config(&connector->config);
81 connector_set_mode(data_t *data, connector_t *connector, drmModeModeInfo *mode)
83 struct kmstest_connector_config *config = &connector->config;
88 fb_id = kmstest_create_fb(data->drm_fd,
89 mode->hdisplay, mode->vdisplay,
90 32 /* bpp */, 24 /* depth */,
95 cr = kmstest_get_cairo_ctx(data->drm_fd, &connector->fb);
96 kmstest_paint_color(cr, 0, 0, mode->hdisplay, mode->vdisplay,
98 igt_assert(cairo_status(cr) == 0);
101 fprintf(stdout, "Using pipe %c, %dx%d\n", pipe_name(config->pipe),
102 mode->hdisplay, mode->vdisplay);
105 ret = drmModeSetCrtc(data->drm_fd,
106 config->crtc->crtc_id,
109 &config->connector->connector_id,
112 igt_assert(ret == 0);
117 static void display_init(data_t *data)
119 data->resources = drmModeGetResources(data->drm_fd);
120 igt_assert(data->resources);
122 data->n_connectors = data->resources->count_connectors;
123 data->connectors = calloc(data->n_connectors, sizeof(connector_t));
124 igt_assert(data->connectors);
127 static void connectors_init(data_t *data, uint32_t crtc_id_mask)
131 for (i = 0; i < data->n_connectors; i++) {
132 uint32_t id = data->resources->connectors[i];
134 connector_init(data, &data->connectors[i], id, crtc_id_mask);
138 static void display_fini(data_t *data)
142 for (i = 0; i < data->n_connectors; i++)
143 connector_fini(&data->connectors[i]);
144 free(data->connectors);
146 drmModeFreeResources(data->resources);
149 #define TEST_SEQUENCE (1<<0)
151 static void test_read_crc(data_t *data, int pipe, unsigned flags)
153 connector_t *connector;
154 igt_pipe_crc_t *pipe_crc;
155 igt_crc_t *crcs = NULL;
156 int valid_connectors = 0, i;
158 connectors_init(data, 1 << pipe);
160 for (i = 0; i < data->n_connectors; i++) {
161 connector = &data->connectors[i];
163 if (!connector->valid)
166 fprintf(stdout, "%s: Testing connector %u\n",
167 igt_subtest_name(), connector->config.connector->connector_id);
169 connector_set_mode(data, connector, &connector->config.default_mode);
171 pipe_crc = igt_pipe_crc_new(&data->debugfs, data->drm_fd,
172 connector->config.pipe,
173 INTEL_PIPE_CRC_SOURCE_AUTO);
179 igt_assert(igt_pipe_crc_start(pipe_crc));
181 /* wait for 3 vblanks and the corresponding 3 CRCs */
182 igt_pipe_crc_get_crcs(pipe_crc, 3, &crcs);
184 igt_pipe_crc_stop(pipe_crc);
186 /* ensure the CRCs are not all 0s */
187 igt_assert(!igt_crc_is_null(&crcs[0]));
188 igt_assert(!igt_crc_is_null(&crcs[1]));
189 igt_assert(!igt_crc_is_null(&crcs[2]));
191 /* and ensure that they'are all equal, we haven't changed the fb */
192 igt_assert(igt_crc_equal(&crcs[0], &crcs[1]));
193 igt_assert(igt_crc_equal(&crcs[1], &crcs[2]));
195 if (flags & TEST_SEQUENCE) {
196 igt_assert(crcs[0].frame + 1 == crcs[1].frame);
197 igt_assert(crcs[1].frame + 1 == crcs[2].frame);
201 igt_pipe_crc_free(pipe_crc);
202 kmstest_remove_fb(data->drm_fd, &connector->fb);
205 igt_require_f(valid_connectors, "No connector found for pipe %i\n", pipe);
213 igt_skip_on_simulation();
218 const char *cmd = "pipe A none";
220 data.drm_fd = drm_open_any();
221 igt_require(data.drm_fd >= 0);
223 igt_set_vt_graphics_mode();
227 igt_debugfs_init(&data.debugfs);
228 data.ctl = igt_debugfs_fopen(&data.debugfs,
229 "i915_display_crc_ctl", "r+");
230 igt_require_f(data.ctl,
231 "No display_crc_ctl found, kernel too old\n");
232 written = fwrite(cmd, 1, strlen(cmd), data.ctl);
233 ret = fflush(data.ctl);
234 igt_require_f((written == strlen(cmd) && ret == 0) || errno != ENODEV,
235 "CRCs not supported on this platform\n");
238 igt_subtest("bad-pipe")
239 test_bad_command(&data, "pipe D none");
241 igt_subtest("bad-source")
242 test_bad_command(&data, "pipe A foo");
244 igt_subtest("bad-nb-words-1")
245 test_bad_command(&data, "pipe foo");
247 igt_subtest("bad-nb-words-3")
248 test_bad_command(&data, "pipe A none option");
250 for (int i = 0; i < 3; i++) {
251 igt_subtest_f("read-crc-pipe-%c", 'A'+i)
252 test_read_crc(&data, i, 0);
254 igt_subtest_f("read-crc-pipe-%c-frame-sequence", 'A'+i)
255 test_read_crc(&data, i, TEST_SEQUENCE);