tests: 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 "i915_drm.h"
45 #include "drmtest.h"
46 #include "intel_bufmgr.h"
47 #include "intel_batchbuffer.h"
48 #include "intel_gpu_tools.h"
49
50 static drm_intel_bufmgr *bufmgr;
51 struct intel_batchbuffer *batch;
52 static drm_intel_bo *load_bo;
53
54 int main(int argc, char **argv)
55 {
56         int fd, i;
57
58         igt_skip_on_simulation();
59
60         fd = drm_open_any();
61
62         bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
63         if (!bufmgr) {
64                 fprintf(stderr, "failed to init libdrm\n");
65                 exit(-1);
66         }
67         /* don't enable buffer reuse!! */
68         //drm_intel_bufmgr_gem_enable_reuse(bufmgr);
69
70         batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
71         igt_assert(batch);
72
73         /* put some load onto the gpu to keep the light buffers active for long
74          * enough */
75         for (i = 0; i < 1000; i++) {
76                 load_bo = drm_intel_bo_alloc(bufmgr, "target bo", 1024*4096, 4096);
77                 if (!load_bo) {
78                         fprintf(stderr, "failed to alloc target buffer\n");
79                         exit(-1);
80                 }
81
82                 BEGIN_BATCH(8);
83                 OUT_BATCH(XY_SRC_COPY_BLT_CMD |
84                           XY_SRC_COPY_BLT_WRITE_ALPHA |
85                           XY_SRC_COPY_BLT_WRITE_RGB);
86                 OUT_BATCH((3 << 24) | /* 32 bits */
87                           (0xcc << 16) | /* copy ROP */
88                           4096);
89                 OUT_BATCH(0); /* dst x1,y1 */
90                 OUT_BATCH((1024 << 16) | 512);
91                 OUT_RELOC(load_bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
92                 OUT_BATCH((0 << 16) | 512); /* src x1, y1 */
93                 OUT_BATCH(4096);
94                 OUT_RELOC(load_bo, I915_GEM_DOMAIN_RENDER, 0, 0);
95                 ADVANCE_BATCH();
96
97                 intel_batchbuffer_flush(batch);
98
99                 drm_intel_bo_disable_reuse(load_bo);
100                 drm_intel_bo_unreference(load_bo);
101         }
102
103         drm_intel_bufmgr_destroy(bufmgr);
104
105         close(fd);
106
107         return 0;
108 }