lib/drmtest: extract gem_create
[platform/upstream/intel-gpu-tools.git] / tests / gen3_mixed_blits.c
1 /*
2  * Copyright © 2011 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  *    Chris Wilson <chris@chris-wilson.co.uk>
25  *
26  */
27
28 /** @file gen3_linear_render_blits.c
29  *
30  * This is a test of doing many blits, with a working set
31  * larger than the aperture size.
32  *
33  * The goal is to simply ensure the basics work.
34  */
35
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <assert.h>
40 #include <fcntl.h>
41 #include <inttypes.h>
42 #include <errno.h>
43 #include <sys/stat.h>
44 #include <sys/time.h>
45 #include <sys/mman.h>
46 #include <sys/ioctl.h>
47 #include "drm.h"
48 #include "i915_drm.h"
49 #include "drmtest.h"
50 #include "intel_gpu_tools.h"
51
52 #include "i915_reg.h"
53 #include "i915_3d.h"
54
55 #define WIDTH (512)
56 #define HEIGHT (512)
57
58 static inline uint32_t pack_float(float f)
59 {
60         union {
61                 uint32_t dw;
62                 float f;
63         } u;
64         u.f = f;
65         return u.dw;
66 }
67
68 static uint64_t
69 gem_aperture_size(int fd)
70 {
71         struct drm_i915_gem_get_aperture aperture;
72
73         aperture.aper_size = 512*1024*1024;
74         (void)drmIoctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture);
75         return aperture.aper_size;
76 }
77
78 static uint32_t fill_reloc(struct drm_i915_gem_relocation_entry *reloc,
79                            uint32_t offset,
80                            uint32_t handle,
81                            uint32_t read_domain,
82                            uint32_t write_domain)
83 {
84         reloc->target_handle = handle;
85         reloc->delta = 0;
86         reloc->offset = offset * sizeof(uint32_t);
87         reloc->presumed_offset = 0;
88         reloc->read_domains = read_domain;
89         reloc->write_domain = write_domain;
90
91         return reloc->presumed_offset + reloc->delta;
92 }
93
94 static void
95 render_copy(int fd,
96             uint32_t dst, int dst_tiling,
97             uint32_t src, int src_tiling,
98             int use_fence)
99 {
100         uint32_t batch[1024], *b = batch;
101         struct drm_i915_gem_relocation_entry reloc[2], *r = reloc;
102         struct drm_i915_gem_exec_object2 obj[3];
103         struct drm_i915_gem_execbuffer2 exec;
104         uint32_t handle;
105         uint32_t tiling_bits;
106         int ret;
107
108         /* invariant state */
109         *b++ = (_3DSTATE_AA_CMD |
110                 AA_LINE_ECAAR_WIDTH_ENABLE |
111                 AA_LINE_ECAAR_WIDTH_1_0 |
112                 AA_LINE_REGION_WIDTH_ENABLE | AA_LINE_REGION_WIDTH_1_0);
113         *b++ = (_3DSTATE_INDEPENDENT_ALPHA_BLEND_CMD |
114                 IAB_MODIFY_ENABLE |
115                 IAB_MODIFY_FUNC | (BLENDFUNC_ADD << IAB_FUNC_SHIFT) |
116                 IAB_MODIFY_SRC_FACTOR |
117                 (BLENDFACT_ONE << IAB_SRC_FACTOR_SHIFT) |
118                 IAB_MODIFY_DST_FACTOR |
119                 (BLENDFACT_ZERO << IAB_DST_FACTOR_SHIFT));
120         *b++ = (_3DSTATE_DFLT_DIFFUSE_CMD);
121         *b++ = (0);
122         *b++ = (_3DSTATE_DFLT_SPEC_CMD);
123         *b++ = (0);
124         *b++ = (_3DSTATE_DFLT_Z_CMD);
125         *b++ = (0);
126         *b++ = (_3DSTATE_COORD_SET_BINDINGS |
127                 CSB_TCB(0, 0) |
128                 CSB_TCB(1, 1) |
129                 CSB_TCB(2, 2) |
130                 CSB_TCB(3, 3) |
131                 CSB_TCB(4, 4) |
132                 CSB_TCB(5, 5) |
133                 CSB_TCB(6, 6) |
134                 CSB_TCB(7, 7));
135         *b++ = (_3DSTATE_RASTER_RULES_CMD |
136                 ENABLE_POINT_RASTER_RULE |
137                 OGL_POINT_RASTER_RULE |
138                 ENABLE_LINE_STRIP_PROVOKE_VRTX |
139                 ENABLE_TRI_FAN_PROVOKE_VRTX |
140                 LINE_STRIP_PROVOKE_VRTX(1) |
141                 TRI_FAN_PROVOKE_VRTX(2) |
142                 ENABLE_TEXKILL_3D_4D |
143                 TEXKILL_4D);
144         *b++ = (_3DSTATE_MODES_4_CMD |
145                 ENABLE_LOGIC_OP_FUNC | LOGIC_OP_FUNC(LOGICOP_COPY) |
146                 ENABLE_STENCIL_WRITE_MASK | STENCIL_WRITE_MASK(0xff) |
147                 ENABLE_STENCIL_TEST_MASK | STENCIL_TEST_MASK(0xff));
148         *b++ = (_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(3) | I1_LOAD_S(4) | I1_LOAD_S(5) | 2);
149         *b++ = (0x00000000);    /* Disable texture coordinate wrap-shortest */
150         *b++ = ((1 << S4_POINT_WIDTH_SHIFT) |
151                 S4_LINE_WIDTH_ONE |
152                 S4_CULLMODE_NONE |
153                 S4_VFMT_XY);
154         *b++ = (0x00000000);    /* Stencil. */
155         *b++ = (_3DSTATE_SCISSOR_ENABLE_CMD | DISABLE_SCISSOR_RECT);
156         *b++ = (_3DSTATE_SCISSOR_RECT_0_CMD);
157         *b++ = (0);
158         *b++ = (0);
159         *b++ = (_3DSTATE_DEPTH_SUBRECT_DISABLE);
160         *b++ = (_3DSTATE_LOAD_INDIRECT | 0);    /* disable indirect state */
161         *b++ = (0);
162         *b++ = (_3DSTATE_STIPPLE);
163         *b++ = (0x00000000);
164         *b++ = (_3DSTATE_BACKFACE_STENCIL_OPS | BFO_ENABLE_STENCIL_TWO_SIDE | 0);
165
166         /* samler state */
167         if (use_fence) {
168                 tiling_bits = MS3_USE_FENCE_REGS;
169         } else {
170                 tiling_bits = 0;
171                 if (src_tiling != I915_TILING_NONE)
172                         tiling_bits = MS3_TILED_SURFACE;
173                 if (src_tiling == I915_TILING_Y)
174                         tiling_bits |= MS3_TILE_WALK;
175         }
176
177 #define TEX_COUNT 1
178         *b++ = (_3DSTATE_MAP_STATE | (3 * TEX_COUNT));
179         *b++ = ((1 << TEX_COUNT) - 1);
180         *b = fill_reloc(r++, b-batch, src, I915_GEM_DOMAIN_SAMPLER, 0); b++;
181         *b++ = (MAPSURF_32BIT | MT_32BIT_ARGB8888 | tiling_bits |
182                 (HEIGHT - 1) << MS3_HEIGHT_SHIFT |
183                 (WIDTH - 1) << MS3_WIDTH_SHIFT);
184         *b++ = ((WIDTH-1) << MS4_PITCH_SHIFT);
185
186         *b++ = (_3DSTATE_SAMPLER_STATE | (3 * TEX_COUNT));
187         *b++ = ((1 << TEX_COUNT) - 1);
188         *b++ = (MIPFILTER_NONE << SS2_MIP_FILTER_SHIFT |
189                 FILTER_NEAREST << SS2_MAG_FILTER_SHIFT |
190                 FILTER_NEAREST << SS2_MIN_FILTER_SHIFT);
191         *b++ = (TEXCOORDMODE_WRAP << SS3_TCX_ADDR_MODE_SHIFT |
192                 TEXCOORDMODE_WRAP << SS3_TCY_ADDR_MODE_SHIFT |
193                 0 << SS3_TEXTUREMAP_INDEX_SHIFT);
194         *b++ = (0x00000000);
195
196         /* render target state */
197         if (use_fence) {
198                 tiling_bits = BUF_3D_USE_FENCE;
199         } else {
200                 tiling_bits = 0;
201                 if (dst_tiling != I915_TILING_NONE)
202                         tiling_bits = BUF_3D_TILED_SURFACE;
203                 if (dst_tiling == I915_TILING_Y)
204                         tiling_bits |= BUF_3D_TILE_WALK_Y;
205         }
206         *b++ = (_3DSTATE_BUF_INFO_CMD);
207         *b++ = (BUF_3D_ID_COLOR_BACK | tiling_bits | WIDTH*4);
208         *b = fill_reloc(r++, b-batch, dst,
209                         I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER);
210         b++;
211
212         *b++ = (_3DSTATE_DST_BUF_VARS_CMD);
213         *b++ = (COLR_BUF_ARGB8888 |
214                 DSTORG_HORT_BIAS(0x8) |
215                 DSTORG_VERT_BIAS(0x8));
216
217         /* draw rect is unconditional */
218         *b++ = (_3DSTATE_DRAW_RECT_CMD);
219         *b++ = (0x00000000);
220         *b++ = (0x00000000);    /* ymin, xmin */
221         *b++ = (DRAW_YMAX(HEIGHT - 1) |
222                 DRAW_XMAX(WIDTH - 1));
223         /* yorig, xorig (relate to color buffer?) */
224         *b++ = (0x00000000);
225
226         /* texfmt */
227         *b++ = (_3DSTATE_LOAD_STATE_IMMEDIATE_1 | I1_LOAD_S(1) | I1_LOAD_S(2) | I1_LOAD_S(6) | 2);
228         *b++ = ((4 << S1_VERTEX_WIDTH_SHIFT) | (4 << S1_VERTEX_PITCH_SHIFT));
229         *b++ = (~S2_TEXCOORD_FMT(0, TEXCOORDFMT_NOT_PRESENT) |
230                 S2_TEXCOORD_FMT(0, TEXCOORDFMT_2D));
231         *b++ = (S6_CBUF_BLEND_ENABLE | S6_COLOR_WRITE_ENABLE |
232                 BLENDFUNC_ADD << S6_CBUF_BLEND_FUNC_SHIFT |
233                 BLENDFACT_ONE << S6_CBUF_SRC_BLEND_FACT_SHIFT |
234                 BLENDFACT_ZERO << S6_CBUF_DST_BLEND_FACT_SHIFT);
235
236         /* pixel shader */
237         *b++ = (_3DSTATE_PIXEL_SHADER_PROGRAM | (1 + 3*3 - 2));
238         /* decl FS_T0 */
239         *b++ = (D0_DCL |
240                 REG_TYPE(FS_T0) << D0_TYPE_SHIFT |
241                 REG_NR(FS_T0) << D0_NR_SHIFT |
242                 ((REG_TYPE(FS_T0) != REG_TYPE_S) ? D0_CHANNEL_ALL : 0));
243         *b++ = (0);
244         *b++ = (0);
245         /* decl FS_S0 */
246         *b++ = (D0_DCL |
247                 (REG_TYPE(FS_S0) << D0_TYPE_SHIFT) |
248                 (REG_NR(FS_S0) << D0_NR_SHIFT) |
249                 ((REG_TYPE(FS_S0) != REG_TYPE_S) ? D0_CHANNEL_ALL : 0));
250         *b++ = (0);
251         *b++ = (0);
252         /* texld(FS_OC, FS_S0, FS_T0 */
253         *b++ = (T0_TEXLD |
254                 (REG_TYPE(FS_OC) << T0_DEST_TYPE_SHIFT) |
255                 (REG_NR(FS_OC) << T0_DEST_NR_SHIFT) |
256                 (REG_NR(FS_S0) << T0_SAMPLER_NR_SHIFT));
257         *b++ = ((REG_TYPE(FS_T0) << T1_ADDRESS_REG_TYPE_SHIFT) |
258                 (REG_NR(FS_T0) << T1_ADDRESS_REG_NR_SHIFT));
259         *b++ = (0);
260
261         *b++ = (PRIM3D_RECTLIST | (3*4 - 1));
262         *b++ = pack_float(WIDTH);
263         *b++ = pack_float(HEIGHT);
264         *b++ = pack_float(WIDTH);
265         *b++ = pack_float(HEIGHT);
266
267         *b++ = pack_float(0);
268         *b++ = pack_float(HEIGHT);
269         *b++ = pack_float(0);
270         *b++ = pack_float(HEIGHT);
271
272         *b++ = pack_float(0);
273         *b++ = pack_float(0);
274         *b++ = pack_float(0);
275         *b++ = pack_float(0);
276
277         *b++ = MI_BATCH_BUFFER_END;
278         if ((b - batch) & 1)
279                 *b++ = 0;
280
281         assert(b - batch <= 1024);
282         handle = gem_create(fd, 4096);
283         gem_write(fd, handle, 0, batch, (b-batch)*sizeof(batch[0]));
284
285         assert(r-reloc == 2);
286
287         tiling_bits = 0;
288         if (use_fence)
289                 tiling_bits = EXEC_OBJECT_NEEDS_FENCE;
290
291         obj[0].handle = dst;
292         obj[0].relocation_count = 0;
293         obj[0].relocs_ptr = 0;
294         obj[0].alignment = 0;
295         obj[0].offset = 0;
296         obj[0].flags = tiling_bits;
297         obj[0].rsvd1 = 0;
298         obj[0].rsvd2 = 0;
299
300         obj[1].handle = src;
301         obj[1].relocation_count = 0;
302         obj[1].relocs_ptr = 0;
303         obj[1].alignment = 0;
304         obj[1].offset = 0;
305         obj[1].flags = tiling_bits;
306         obj[1].rsvd1 = 0;
307         obj[1].rsvd2 = 0;
308
309         obj[2].handle = handle;
310         obj[2].relocation_count = 2;
311         obj[2].relocs_ptr = (uintptr_t)reloc;
312         obj[2].alignment = 0;
313         obj[2].offset = 0;
314         obj[2].flags = 0;
315         obj[2].rsvd1 = obj[2].rsvd2 = 0;
316
317         exec.buffers_ptr = (uintptr_t)obj;
318         exec.buffer_count = 3;
319         exec.batch_start_offset = 0;
320         exec.batch_len = (b-batch)*sizeof(batch[0]);
321         exec.DR1 = exec.DR4 = 0;
322         exec.num_cliprects = 0;
323         exec.cliprects_ptr = 0;
324         exec.flags = 0;
325         exec.rsvd1 = exec.rsvd2 = 0;
326
327         ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &exec);
328         while (ret && errno == EBUSY) {
329                 drmCommandNone(fd, DRM_I915_GEM_THROTTLE);
330                 ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &exec);
331         }
332         assert(ret == 0);
333
334         gem_close(fd, handle);
335 }
336
337 static void blt_copy(int fd, uint32_t dst, uint32_t src)
338 {
339         uint32_t batch[1024], *b = batch;
340         struct drm_i915_gem_relocation_entry reloc[2], *r = reloc;
341         struct drm_i915_gem_exec_object2 obj[3];
342         struct drm_i915_gem_execbuffer2 exec;
343         uint32_t handle;
344         int ret;
345
346         *b++ = (XY_SRC_COPY_BLT_CMD |
347                 XY_SRC_COPY_BLT_WRITE_ALPHA |
348                 XY_SRC_COPY_BLT_WRITE_RGB);
349         *b++ = 3 << 24 | 0xcc << 16 | WIDTH * 4;
350         *b++ = 0;
351         *b++ = HEIGHT << 16 | WIDTH;
352         *b = fill_reloc(r++, b-batch, dst,
353                         I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER); b++;
354         *b++ = 0;
355         *b++ = WIDTH*4;
356         *b = fill_reloc(r++, b-batch, src, I915_GEM_DOMAIN_RENDER, 0); b++;
357
358         *b++ = MI_BATCH_BUFFER_END;
359         if ((b - batch) & 1)
360                 *b++ = 0;
361
362         assert(b - batch <= 1024);
363         handle = gem_create(fd, 4096);
364         gem_write(fd, handle, 0, batch, (b-batch)*sizeof(batch[0]));
365
366         assert(r-reloc == 2);
367
368         obj[0].handle = dst;
369         obj[0].relocation_count = 0;
370         obj[0].relocs_ptr = 0;
371         obj[0].alignment = 0;
372         obj[0].offset = 0;
373         obj[0].flags = EXEC_OBJECT_NEEDS_FENCE;
374         obj[0].rsvd1 = 0;
375         obj[0].rsvd2 = 0;
376
377         obj[1].handle = src;
378         obj[1].relocation_count = 0;
379         obj[1].relocs_ptr = 0;
380         obj[1].alignment = 0;
381         obj[1].offset = 0;
382         obj[1].flags = EXEC_OBJECT_NEEDS_FENCE;
383         obj[1].rsvd1 = 0;
384         obj[1].rsvd2 = 0;
385
386         obj[2].handle = handle;
387         obj[2].relocation_count = 2;
388         obj[2].relocs_ptr = (uintptr_t)reloc;
389         obj[2].alignment = 0;
390         obj[2].offset = 0;
391         obj[2].flags = 0;
392         obj[2].rsvd1 = obj[2].rsvd2 = 0;
393
394         exec.buffers_ptr = (uintptr_t)obj;
395         exec.buffer_count = 3;
396         exec.batch_start_offset = 0;
397         exec.batch_len = (b-batch)*sizeof(batch[0]);
398         exec.DR1 = exec.DR4 = 0;
399         exec.num_cliprects = 0;
400         exec.cliprects_ptr = 0;
401         exec.flags = 0;
402         exec.rsvd1 = exec.rsvd2 = 0;
403
404         ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &exec);
405         while (ret && errno == EBUSY) {
406                 drmCommandNone(fd, DRM_I915_GEM_THROTTLE);
407                 ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, &exec);
408         }
409         assert(ret == 0);
410
411         gem_close(fd, handle);
412 }
413
414
415 static void
416 copy(int fd,
417      uint32_t dst, int dst_tiling,
418      uint32_t src, int src_tiling)
419 {
420 retry:
421         switch (random() % 3) {
422         case 0: render_copy(fd, dst, dst_tiling, src, src_tiling, 0); break;
423         case 1: render_copy(fd, dst, dst_tiling, src, src_tiling, 1); break;
424         case 2: if (dst_tiling == I915_TILING_Y || src_tiling == I915_TILING_Y)
425                         goto retry;
426                 blt_copy(fd, dst, src);
427                 break;
428         }
429 }
430
431 static void *gem_mmap(int fd, uint32_t handle, int size, int prot)
432 {
433         struct drm_i915_gem_mmap_gtt mmap_arg;
434         void *ptr;
435
436         mmap_arg.handle = handle;
437         if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg)) {
438                 assert(0);
439                 return NULL;
440         }
441
442         ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
443         if (ptr == MAP_FAILED) {
444                 assert(0);
445                 ptr = NULL;
446         }
447
448         return ptr;
449 }
450
451 static uint32_t
452 create_bo(int fd, uint32_t val, int tiling)
453 {
454         uint32_t handle;
455         uint32_t *v;
456         int i;
457
458         handle = gem_create(fd, WIDTH*HEIGHT*4);
459         gem_set_tiling(fd, handle, tiling, WIDTH*4);
460
461         /* Fill the BO with dwords starting at val */
462         v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ | PROT_WRITE);
463         for (i = 0; i < WIDTH*HEIGHT; i++)
464                 v[i] = val++;
465         munmap(v, WIDTH*HEIGHT*4);
466
467         return handle;
468 }
469
470 static void
471 check_bo(int fd, uint32_t handle, uint32_t val)
472 {
473         uint32_t *v;
474         int i;
475
476         v = gem_mmap(fd, handle, WIDTH*HEIGHT*4, PROT_READ);
477         for (i = 0; i < WIDTH*HEIGHT; i++) {
478                 if (v[i] != val) {
479                         fprintf(stderr, "Expected 0x%08x, found 0x%08x "
480                                 "at offset 0x%08x\n",
481                                 val, v[i], i * 4);
482                         abort();
483                 }
484                 val++;
485         }
486         munmap(v, WIDTH*HEIGHT*4);
487 }
488
489 int main(int argc, char **argv)
490 {
491         uint32_t *handle, *tiling, *start_val;
492         uint32_t start = 0;
493         int i, fd, count;
494
495         fd = drm_open_any();
496
497         if (!IS_GEN3(intel_get_drm_devid(fd))) {
498                 printf("gen3-only test, doing nothing\n");
499                 return 77;
500         }
501
502         count = 0;
503         if (argc > 1)
504                 count = atoi(argv[1]);
505         if (count == 0)
506                 count = 3 * gem_aperture_size(fd) / (1024*1024) / 2;
507         printf("Using %d 1MiB buffers\n", count);
508
509         handle = malloc(sizeof(uint32_t)*count*3);
510         tiling = handle + count;
511         start_val = tiling + count;
512
513         for (i = 0; i < count; i++) {
514                 handle[i] = create_bo(fd, start, tiling[i] = i % 3);
515                 start_val[i] = start;
516                 start += 1024 * 1024 / 4;
517         }
518
519         printf("Verifying initialisation..."); fflush(stdout);
520         for (i = 0; i < count; i++)
521                 check_bo(fd, handle[i], start_val[i]);
522         printf("done\n");
523
524         printf("Cyclic blits, forward..."); fflush(stdout);
525         for (i = 0; i < count * 32; i++) {
526                 int src = i % count;
527                 int dst = (i + 1) % count;
528
529                 copy(fd, handle[dst], tiling[dst], handle[src], tiling[src]);
530                 start_val[dst] = start_val[src];
531         }
532         printf("verifying..."); fflush(stdout);
533         for (i = 0; i < count; i++)
534                 check_bo(fd, handle[i], start_val[i]);
535         printf("done\n");
536
537         printf("Cyclic blits, backward..."); fflush(stdout);
538         for (i = 0; i < count * 32; i++) {
539                 int src = (i + 1) % count;
540                 int dst = i % count;
541
542                 copy(fd, handle[dst], tiling[dst], handle[src], tiling[src]);
543                 start_val[dst] = start_val[src];
544         }
545         printf("verifying..."); fflush(stdout);
546         for (i = 0; i < count; i++)
547                 check_bo(fd, handle[i], start_val[i]);
548         printf("done\n");
549
550         printf("Random blits..."); fflush(stdout);
551         for (i = 0; i < count * 32; i++) {
552                 int src = random() % count;
553                 int dst = random() % count;
554
555                 while (src == dst)
556                         dst = random() % count;
557
558                         copy(fd, handle[dst], tiling[dst], handle[src], tiling[src]);
559                 start_val[dst] = start_val[src];
560         }
561         printf("verifying..."); fflush(stdout);
562         for (i = 0; i < count; i++)
563                 check_bo(fd, handle[i], start_val[i]);
564         printf("done\n");
565
566         return 0;
567 }