igt/gem_userptr_blits: Fix forked access test
[platform/upstream/intel-gpu-tools.git] / tests / gem_largeobject.c
1 /*
2  * Copyright © 2008 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  *    Jesse Barnes <jbarnes@virtuousgeek.org>
25  *
26  */
27
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <fcntl.h>
32 #include <inttypes.h>
33 #include <errno.h>
34 #include <sys/stat.h>
35 #include <sys/ioctl.h>
36 #include "drm.h"
37 #include "ioctl_wrappers.h"
38 #include "drmtest.h"
39
40 /* Should take 64 pages to store the page pointers on 64 bit */
41 #define OBJ_SIZE (128 * 1024 * 1024)
42
43 unsigned char data[OBJ_SIZE];
44
45 static void
46 test_large_object(int fd)
47 {
48         struct drm_i915_gem_create create;
49         struct drm_i915_gem_pin pin;
50         uint32_t obj_size;
51         char *ptr;
52
53         memset(&create, 0, sizeof(create));
54         memset(&pin, 0, sizeof(pin));
55
56         if (gem_aperture_size(fd)*3/4 < OBJ_SIZE/2)
57                 obj_size = OBJ_SIZE / 4;
58         else if (gem_aperture_size(fd)*3/4 < OBJ_SIZE)
59                 obj_size = OBJ_SIZE / 2;
60         else
61                 obj_size = OBJ_SIZE;
62         create.size = obj_size;
63         igt_info("obj size %i\n", obj_size);
64
65         igt_assert(ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0);
66
67         /* prefault */
68         ptr = gem_mmap__gtt(fd, create.handle, obj_size, PROT_WRITE | PROT_READ);
69         *ptr = 0;
70
71         gem_write(fd, create.handle, 0, data, obj_size);
72
73         /* kernel should clean this up for us */
74 }
75
76 igt_simple_main
77 {
78         int fd;
79
80         igt_skip_on_simulation();
81
82         fd = drm_open_any();
83
84         test_large_object(fd);
85 }