lib/igt_kms: Unify pipe name helpers
[platform/upstream/intel-gpu-tools.git] / tests / gem_exec_big.c
1 /*
2  * Copyright © 2011,2012 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  *    Daniel Vetter <daniel.vetter@ffwll.ch>
26  *
27  */
28
29 /*
30  * Testcase: run a nop batch which is really big
31  *
32  * Mostly useful to stress-test the error-capture code
33  */
34
35 #include <unistd.h>
36 #include <stdlib.h>
37 #include <stdint.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/ioctl.h>
45 #include <sys/time.h>
46 #include "drm.h"
47 #include "ioctl_wrappers.h"
48 #include "drmtest.h"
49
50 #define BATCH_SIZE              (1024*1024)
51
52 static void exec(int fd, uint32_t handle, uint32_t reloc_ofs)
53 {
54         struct drm_i915_gem_execbuffer2 execbuf;
55         struct drm_i915_gem_exec_object2 gem_exec[1];
56         struct drm_i915_gem_relocation_entry gem_reloc[1];
57         uint32_t tmp;
58
59         gem_reloc[0].offset = reloc_ofs;
60         gem_reloc[0].delta = 0;
61         gem_reloc[0].target_handle = handle;
62         gem_reloc[0].read_domains = I915_GEM_DOMAIN_RENDER;
63         gem_reloc[0].write_domain = 0;
64         gem_reloc[0].presumed_offset = 0;
65
66         gem_exec[0].handle = handle;
67         gem_exec[0].relocation_count = 1;
68         gem_exec[0].relocs_ptr = (uintptr_t) gem_reloc;
69         gem_exec[0].alignment = 0;
70         gem_exec[0].offset = 0;
71         gem_exec[0].flags = 0;
72         gem_exec[0].rsvd1 = 0;
73         gem_exec[0].rsvd2 = 0;
74
75         execbuf.buffers_ptr = (uintptr_t)gem_exec;
76         execbuf.buffer_count = 1;
77         execbuf.batch_start_offset = 0;
78         execbuf.batch_len = 8;
79         execbuf.cliprects_ptr = 0;
80         execbuf.num_cliprects = 0;
81         execbuf.DR1 = 0;
82         execbuf.DR4 = 0;
83         execbuf.flags = 0;
84         i915_execbuffer2_set_context_id(execbuf, 0);
85         execbuf.rsvd2 = 0;
86
87         /* Avoid hitting slowpaths in the reloc processing which might yield a
88          * presumed_offset of -1. Happens when the batch is still busy from the
89          * last round. */
90         gem_sync(fd, handle);
91
92         gem_execbuf(fd, &execbuf);
93
94         igt_warn_on(gem_reloc[0].presumed_offset == -1);
95
96         gem_read(fd, handle, reloc_ofs, &tmp, 4);
97         igt_assert_eq(tmp, gem_reloc[0].presumed_offset);
98 }
99
100 igt_simple_main
101 {
102         uint32_t batch[2] = {MI_BATCH_BUFFER_END};
103         uint32_t handle;
104         int fd;
105         uint32_t reloc_ofs;
106         unsigned batch_size;
107
108         igt_skip_on_simulation();
109
110         fd = drm_open_any();
111
112         for (batch_size = BATCH_SIZE/4; batch_size <= BATCH_SIZE; batch_size += 4096) {
113                 handle = gem_create(fd, batch_size);
114                 gem_write(fd, handle, 0, batch, sizeof(batch));
115
116                 for (reloc_ofs = 4096; reloc_ofs < batch_size; reloc_ofs += 4096) {
117                         igt_debug("batch_size %u, reloc_ofs %u\n",
118                                   batch_size, reloc_ofs);
119                         exec(fd, handle, reloc_ofs);
120                 }
121         }
122
123         gem_close(fd, handle);
124
125         close(fd);
126 }