2 * Copyright © 2011 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
24 * Ben Widawsky <ben@bwidawsk.net>
29 * This test is useful for finding memory and refcount leaks.
34 #include <sys/ioctl.h>
44 #include "ioctl_wrappers.h"
46 #include "intel_bufmgr.h"
47 #include "intel_batchbuffer.h"
49 #include "intel_chipset.h"
52 int num_contexts = 10;
53 int uncontexted = 0; /* test only context create/destroy */
62 static void init_buffer(drm_intel_bufmgr *bufmgr,
66 buf->bo = drm_intel_bo_alloc(bufmgr, "", size, 4096);
69 buf->tiling = I915_TILING_NONE;
73 static void *work(void *arg)
75 struct intel_batchbuffer *batch;
76 igt_render_copyfunc_t rendercopy = igt_get_render_copyfunc(devid);
77 drm_intel_context *context;
78 drm_intel_bufmgr *bufmgr;
83 td_fd = fd = drm_open_any_render();
87 igt_assert(td_fd >= 0);
89 bufmgr = drm_intel_bufmgr_gem_init(td_fd, 4096);
90 batch = intel_batchbuffer_alloc(bufmgr, devid);
91 context = drm_intel_gem_context_create(bufmgr);
94 for (i = 0; i < iter; i++) {
95 struct igt_buf src, dst;
97 init_buffer(bufmgr, &src, 4096);
98 init_buffer(bufmgr, &dst, 4096);
102 igt_assert(rendercopy);
103 rendercopy(batch, NULL, &src, 0, 0, 0, 0, &dst, 0, 0);
106 ret = drm_intel_bo_subdata(batch->bo, 0, 4096, batch->buffer);
107 igt_assert(ret == 0);
108 intel_batchbuffer_flush_with_context(batch, context);
112 drm_intel_gem_context_destroy(context);
113 intel_batchbuffer_free(batch);
114 drm_intel_bufmgr_destroy(bufmgr);
122 static void parse(int argc, char *argv[])
125 while ((opt = getopt(argc, argv, "i:c:n:muh?")) != -1) {
131 num_contexts = atoi(optarg);
148 int main(int argc, char *argv[])
154 fd = drm_open_any_render();
155 devid = intel_get_drm_devid(fd);
157 if (igt_run_in_simulation()) {
164 threads = calloc(num_contexts, sizeof(*threads));
166 for (i = 0; i < num_contexts; i++)
167 pthread_create(&threads[i], NULL, work, &i);
169 for (i = 0; i < num_contexts; i++) {
171 igt_assert(pthread_join(threads[i], &retval) == 0);