kms_rotation_crc: Remove useless comments
[platform/upstream/intel-gpu-tools.git] / tests / gem_pread_after_blit.c
1 /*
2  * Copyright © 2009 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Eric Anholt <eric@anholt.net>
25  *
26  */
27
28 /** @file gem_pread_after_blit.c
29  *
30  * This is a test of pread's behavior when getting values out of just-drawn-to
31  * buffers.
32  *
33  * The goal is to catch failure in the whole-buffer-flush or
34  * ranged-buffer-flush paths in the kernel.
35  */
36
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <fcntl.h>
41 #include <inttypes.h>
42 #include <errno.h>
43 #include <sys/stat.h>
44 #include <sys/time.h>
45
46 #include <drm.h>
47
48 #include "ioctl_wrappers.h"
49 #include "drmtest.h"
50 #include "intel_chipset.h"
51 #include "intel_io.h"
52 #include "igt_aux.h"
53
54 static drm_intel_bufmgr *bufmgr;
55 struct intel_batchbuffer *batch;
56 static const int width = 512, height = 512;
57 static const int size = 1024 * 1024;
58
59 #define PAGE_SIZE 4096
60
61 static drm_intel_bo *
62 create_bo(uint32_t val)
63 {
64         drm_intel_bo *bo;
65         uint32_t *vaddr;
66         int i;
67
68         bo = drm_intel_bo_alloc(bufmgr, "src bo", size, 4096);
69
70         /* Fill the BO with dwords starting at start_val */
71         drm_intel_bo_map(bo, 1);
72         vaddr = bo->virtual;
73
74         for (i = 0; i < 1024 * 1024 / 4; i++)
75                 vaddr[i] = val++;
76
77         drm_intel_bo_unmap(bo);
78
79         return bo;
80 }
81
82 static void
83 verify_large_read(drm_intel_bo *bo, uint32_t val)
84 {
85         uint32_t buf[size / 4];
86         int i;
87
88         drm_intel_bo_get_subdata(bo, 0, size, buf);
89
90         for (i = 0; i < size / 4; i++) {
91                 igt_assert_f(buf[i] == val,
92                              "Unexpected value 0x%08x instead of "
93                              "0x%08x at offset 0x%08x (%p)\n",
94                              buf[i], val, i * 4, buf);
95                 val++;
96         }
97 }
98
99 /** This reads at the size that Mesa usees for software fallbacks. */
100 static void
101 verify_small_read(drm_intel_bo *bo, uint32_t val)
102 {
103         uint32_t buf[4096 / 4];
104         int offset, i;
105
106         for (i = 0; i < 4096 / 4; i++)
107                 buf[i] = 0x00c0ffee;
108
109         for (offset = 0; offset < size; offset += PAGE_SIZE) {
110                 drm_intel_bo_get_subdata(bo, offset, PAGE_SIZE, buf);
111
112                 for (i = 0; i < PAGE_SIZE; i += 4) {
113                         igt_assert_f(buf[i / 4] == val,
114                                      "Unexpected value 0x%08x instead of "
115                                      "0x%08x at offset 0x%08x\n",
116                                      buf[i / 4], val, i * 4);
117                         val++;
118                 }
119         }
120 }
121
122 static void do_test(int fd, int cache_level,
123                     drm_intel_bo *src[2],
124                     const uint32_t start[2],
125                     drm_intel_bo *tmp[2],
126                     int loop)
127 {
128         if (cache_level != -1) {
129                 gem_set_caching(fd, tmp[0]->handle, cache_level);
130                 gem_set_caching(fd, tmp[1]->handle, cache_level);
131         }
132
133         do {
134                 /* First, do a full-buffer read after blitting */
135                 intel_copy_bo(batch, tmp[0], src[0], width*height*4);
136                 verify_large_read(tmp[0], start[0]);
137                 intel_copy_bo(batch, tmp[0], src[1], width*height*4);
138                 verify_large_read(tmp[0], start[1]);
139
140                 intel_copy_bo(batch, tmp[0], src[0], width*height*4);
141                 verify_small_read(tmp[0], start[0]);
142                 intel_copy_bo(batch, tmp[0], src[1], width*height*4);
143                 verify_small_read(tmp[0], start[1]);
144
145                 intel_copy_bo(batch, tmp[0], src[0], width*height*4);
146                 verify_large_read(tmp[0], start[0]);
147
148                 intel_copy_bo(batch, tmp[0], src[0], width*height*4);
149                 intel_copy_bo(batch, tmp[1], src[1], width*height*4);
150                 verify_large_read(tmp[0], start[0]);
151                 verify_large_read(tmp[1], start[1]);
152
153                 intel_copy_bo(batch, tmp[0], src[0], width*height*4);
154                 intel_copy_bo(batch, tmp[1], src[1], width*height*4);
155                 verify_large_read(tmp[1], start[1]);
156                 verify_large_read(tmp[0], start[0]);
157
158                 intel_copy_bo(batch, tmp[1], src[0], width*height*4);
159                 intel_copy_bo(batch, tmp[0], src[1], width*height*4);
160                 verify_large_read(tmp[0], start[1]);
161                 verify_large_read(tmp[1], start[0]);
162         } while (--loop);
163 }
164
165 drm_intel_bo *src[2], *dst[2];
166 int fd;
167
168 igt_main
169 {
170         const uint32_t start[2] = {0, 1024 * 1024 / 4};
171
172         igt_skip_on_simulation();
173
174         igt_fixture {
175                 fd = drm_open_any();
176
177                 bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
178                 drm_intel_bufmgr_gem_enable_reuse(bufmgr);
179                 batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
180
181                 src[0] = create_bo(start[0]);
182                 src[1] = create_bo(start[1]);
183
184                 dst[0] = drm_intel_bo_alloc(bufmgr, "dst bo", size, 4096);
185                 dst[1] = drm_intel_bo_alloc(bufmgr, "dst bo", size, 4096);
186         }
187
188         igt_subtest("normal")
189                 do_test(fd, -1, src, start, dst, 1);
190
191         igt_subtest("interruptible") {
192                 igt_fork_signal_helper();
193                 do_test(fd, -1, src, start, dst, 100);
194                 igt_stop_signal_helper();
195         }
196
197         igt_subtest("normal-uncached")
198                 do_test(fd, 0, src, start, dst, 1);
199
200         igt_subtest("interruptible-uncached") {
201                 igt_fork_signal_helper();
202                 do_test(fd, 0, src, start, dst, 100);
203                 igt_stop_signal_helper();
204         }
205
206         igt_subtest("normal-snoop")
207                 do_test(fd, 1, src, start, dst, 1);
208
209         igt_subtest("interruptible-snoop") {
210                 igt_fork_signal_helper();
211                 do_test(fd, 1, src, start, dst, 100);
212                 igt_stop_signal_helper();
213         }
214
215         igt_subtest("normal-display")
216                 do_test(fd, 2, src, start, dst, 1);
217
218         igt_subtest("interruptible-display") {
219                 igt_fork_signal_helper();
220                 do_test(fd, 2, src, start, dst, 100);
221                 igt_stop_signal_helper();
222         }
223
224         igt_fixture {
225                 drm_intel_bo_unreference(src[0]);
226                 drm_intel_bo_unreference(src[1]);
227                 drm_intel_bo_unreference(dst[0]);
228                 drm_intel_bo_unreference(dst[1]);
229
230                 intel_batchbuffer_free(batch);
231                 drm_intel_bufmgr_destroy(bufmgr);
232         }
233
234         close(fd);
235 }