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
31 #include "igt_debugfs.h"
34 #include "ioctl_wrappers.h"
38 igt_display_t display;
46 { .r = 0.0, .g = 1.0, .b = 0.0 },
47 { .r = 0.0, .g = 1.0, .b = 1.0 },
50 static uint64_t submit_batch(int fd, unsigned ring_id)
52 const uint32_t batch[] = { MI_NOOP,
53 MI_BATCH_BUFFER_END };
54 struct drm_i915_gem_execbuffer2 execbuf;
55 struct drm_i915_gem_exec_object2 exec;
56 uint64_t presumed_offset;
58 gem_require_ring(fd, ring_id);
60 exec.handle = gem_create(fd, 4096);
61 gem_write(fd, exec.handle, 0, batch, sizeof(batch));
62 exec.relocation_count = 0;
70 execbuf.buffers_ptr = (uintptr_t)&exec;
71 execbuf.buffer_count = 1;
72 execbuf.batch_start_offset = 0;
73 execbuf.batch_len = sizeof(batch);
74 execbuf.cliprects_ptr = 0;
75 execbuf.num_cliprects = 0;
78 execbuf.flags = ring_id;
79 i915_execbuffer2_set_context_id(execbuf, 0);
82 gem_execbuf(fd, &execbuf);
83 gem_sync(fd, exec.handle);
84 presumed_offset = exec.offset;
86 igt_set_stop_rings(igt_to_stop_ring_flag(ring_id));
88 gem_execbuf(fd, &execbuf);
89 gem_sync(fd, exec.handle);
91 igt_assert(igt_get_stop_rings() == STOP_RING_NONE);
92 igt_assert(presumed_offset == exec.offset);
94 gem_close(fd, exec.handle);
99 static void test_bad_command(data_t *data, const char *cmd)
104 ctl = igt_debugfs_fopen("i915_display_crc_ctl", "r+");
105 written = fwrite(cmd, 1, strlen(cmd), ctl);
107 igt_assert_cmpint(written, ==, (strlen(cmd)));
108 igt_assert(ferror(ctl));
109 igt_assert_cmpint(errno, ==, EINVAL);
116 #define TEST_SEQUENCE (1<<0)
119 test_read_crc_for_output(data_t *data, int pipe, igt_output_t *output,
122 igt_display_t *display = &data->display;
123 igt_plane_t *primary;
124 drmModeModeInfo *mode;
125 igt_pipe_crc_t *pipe_crc;
126 igt_crc_t *crcs = NULL;
129 for (c = 0; c < ARRAY_SIZE(colors); c++) {
132 igt_output_set_pipe(output, pipe);
134 igt_debug("Clearing the fb with color (%.02lf,%.02lf,%.02lf)\n",
135 colors[c].r, colors[c].g, colors[c].b);
137 mode = igt_output_get_mode(output);
138 igt_create_color_fb(data->drm_fd,
139 mode->hdisplay, mode->vdisplay,
147 primary = igt_output_get_plane(output, 0);
148 igt_plane_set_fb(primary, &data->fb);
150 igt_display_commit(display);
152 pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
157 igt_pipe_crc_start(pipe_crc);
159 /* wait for N_CRCS vblanks and the corresponding N_CRCS CRCs */
160 igt_pipe_crc_get_crcs(pipe_crc, N_CRCS, &crcs);
162 igt_pipe_crc_stop(pipe_crc);
165 * save the CRC in colors so it can be compared to the CRC of
168 colors[c].crc = crcs[0];
170 crc_str = igt_crc_to_string(&crcs[0]);
171 igt_debug("CRC for this fb: %s\n", crc_str);
175 * make sure the CRC of this fb is different from the ones of
178 for (j = 0; j < c; j++)
179 igt_assert(!igt_crc_equal(&colors[j].crc,
182 /* ensure the CRCs are not all 0s */
183 for (j = 0; j < N_CRCS; j++)
184 igt_assert(!igt_crc_is_null(&crcs[j]));
186 /* and ensure that they'are all equal, we haven't changed the fb */
187 for (j = 0; j < (N_CRCS - 1); j++)
188 igt_assert(igt_crc_equal(&crcs[j], &crcs[j + 1]));
190 if (flags & TEST_SEQUENCE)
191 for (j = 0; j < (N_CRCS - 1); j++)
192 igt_assert(crcs[j].frame + 1 == crcs[j + 1].frame);
195 igt_pipe_crc_free(pipe_crc);
196 igt_remove_fb(data->drm_fd, &data->fb);
197 igt_plane_set_fb(primary, NULL);
199 igt_output_set_pipe(output, PIPE_ANY);
205 static void test_read_crc(data_t *data, int pipe, unsigned flags)
207 igt_display_t *display = &data->display;
208 int valid_connectors = 0;
209 igt_output_t *output;
211 igt_skip_on(pipe >= data->display.n_pipes);
213 for_each_connected_output(display, output) {
215 igt_info("%s: Testing connector %s using pipe %s\n",
216 igt_subtest_name(), igt_output_name(output),
217 kmstest_pipe_name(pipe));
219 valid_connectors += test_read_crc_for_output(data, pipe, output, flags);
222 igt_require_f(valid_connectors, "No connector found for pipe %i\n", pipe);
229 igt_skip_on_simulation();
232 data.drm_fd = drm_open_any();
234 igt_enable_connectors();
236 igt_set_vt_graphics_mode();
238 igt_require_pipe_crc();
240 igt_display_init(&data.display, data.drm_fd);
243 igt_subtest("bad-pipe")
244 test_bad_command(&data, "pipe D none");
246 igt_subtest("bad-source")
247 test_bad_command(&data, "pipe A foo");
249 igt_subtest("bad-nb-words-1")
250 test_bad_command(&data, "pipe foo");
252 igt_subtest("bad-nb-words-3")
253 test_bad_command(&data, "pipe A none option");
255 for (int i = 0; i < 3; i++) {
256 igt_subtest_f("read-crc-pipe-%c", 'A'+i)
257 test_read_crc(&data, i, 0);
259 igt_subtest_f("read-crc-pipe-%c-frame-sequence", 'A'+i)
260 test_read_crc(&data, i, TEST_SEQUENCE);
262 igt_subtest_f("suspend-read-crc-pipe-%c", 'A'+i) {
263 igt_system_suspend_autoresume();
265 test_read_crc(&data, i, 0);
268 igt_subtest_f("hang-read-crc-pipe-%c", 'A'+i) {
269 submit_batch(data.drm_fd, I915_EXEC_RENDER);
271 test_read_crc(&data, i, 0);
276 igt_display_fini(&data.display);