lib/igt.cocci: Add s/assert/igt_assert/
[platform/upstream/intel-gpu-tools.git] / tests / gem_unref_active_buffers.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  *    Daniel Vetter <daniel.vetter@ffwll.ch>
25  *
26  */
27
28 /*
29  * Testcase: Unreferencing of active buffers
30  *
31  * Execs buffers and immediately unreferences them, hence the kernel active list
32  * will be the last one to hold a reference on them. Usually libdrm bo caching
33  * prevents that by keeping another reference.
34  */
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <fcntl.h>
39 #include <inttypes.h>
40 #include <errno.h>
41 #include <sys/stat.h>
42 #include <sys/time.h>
43 #include "drm.h"
44 #include "ioctl_wrappers.h"
45 #include "drmtest.h"
46 #include "intel_bufmgr.h"
47 #include "intel_batchbuffer.h"
48 #include "intel_io.h"
49 #include "intel_chipset.h"
50
51 static drm_intel_bufmgr *bufmgr;
52 struct intel_batchbuffer *batch;
53 static drm_intel_bo *load_bo;
54
55 igt_simple_main
56 {
57         int fd, i;
58
59         igt_skip_on_simulation();
60
61         fd = drm_open_any();
62
63         bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
64         igt_assert(bufmgr);
65         /* don't enable buffer reuse!! */
66         //drm_intel_bufmgr_gem_enable_reuse(bufmgr);
67
68         batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
69         igt_assert(batch);
70
71         /* put some load onto the gpu to keep the light buffers active for long
72          * enough */
73         for (i = 0; i < 1000; i++) {
74                 load_bo = drm_intel_bo_alloc(bufmgr, "target bo", 1024*4096, 4096);
75                 igt_assert(load_bo);
76
77                 BLIT_COPY_BATCH_START(batch->devid, 0);
78                 OUT_BATCH((3 << 24) | /* 32 bits */
79                           (0xcc << 16) | /* copy ROP */
80                           4096);
81                 OUT_BATCH(0); /* dst x1,y1 */
82                 OUT_BATCH((1024 << 16) | 512);
83                 OUT_RELOC(load_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
84                 BLIT_RELOC_UDW(batch->devid);
85                 OUT_BATCH((0 << 16) | 512); /* src x1, y1 */
86                 OUT_BATCH(4096);
87                 OUT_RELOC(load_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
88                 BLIT_RELOC_UDW(batch->devid);
89                 ADVANCE_BATCH();
90
91                 intel_batchbuffer_flush(batch);
92
93                 drm_intel_bo_disable_reuse(load_bo);
94                 drm_intel_bo_unreference(load_bo);
95         }
96
97         drm_intel_bufmgr_destroy(bufmgr);
98
99         close(fd);
100 }