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 * Daniel Vetter <daniel.vetter@ffwll.ch>
28 /** @file gem_tiled_pread_pwrite.c
30 * This is a test of pread's behavior on tiled objects with respect to the
31 * reported swizzling value.
33 * The goal is to exercise the slow_bit17_copy path for reading on bit17
34 * machines, but will also be useful for catching swizzling value bugs on
39 * Testcase: Exercise swizzle code for swapping
41 * The swizzle checks in the swapin path are at a different place than the ones
42 * for pread/pwrite, so we need to check them separately.
44 * This test obviously needs swap present (and exits if none is detected).
55 #include <sys/ioctl.h>
59 #include "ioctl_wrappers.h"
66 #define LINEAR_DWORDS (4 * WIDTH * HEIGHT)
67 static uint32_t current_tiling_mode;
69 #define PAGE_SIZE 4096
72 create_bo_and_fill(int fd)
78 handle = gem_create(fd, LINEAR_DWORDS);
79 gem_set_tiling(fd, handle, current_tiling_mode, WIDTH * sizeof(uint32_t));
81 /* Fill the BO with dwords starting at start_val */
82 data = gem_mmap(fd, handle, LINEAR_DWORDS, PROT_READ | PROT_WRITE);
83 if (data == NULL && errno == ENOSPC)
86 for (i = 0; i < WIDTH*HEIGHT; i++)
88 munmap(data, LINEAR_DWORDS);
102 current_tiling_mode = I915_TILING_X;
104 igt_skip_on_simulation();
105 intel_purge_vm_caches();
108 /* need slightly more than available memory */
109 count = intel_get_total_ram_mb() + intel_get_total_swap_mb() / 4;
110 bo_handles = calloc(count, sizeof(uint32_t));
111 igt_assert(bo_handles);
113 idx_arr = calloc(count, sizeof(int));
116 igt_log(IGT_LOG_INFO,
117 "Using %d 1MiB objects (available RAM: %ld/%ld, swap: %ld)\n",
119 (long)intel_get_avail_ram_mb(),
120 (long)intel_get_total_ram_mb(),
121 (long)intel_get_total_swap_mb());
123 igt_require(count < intel_get_avail_ram_mb() + intel_get_total_swap_mb());
125 for (i = 0; i < count; i++) {
126 bo_handles[i] = create_bo_and_fill(fd);
127 /* Not enough mmap address space possible. */
128 igt_require(bo_handles[i]);
131 for (i = 0; i < count; i++)
134 igt_permute_array(idx_arr, count,
137 for (i = 0; i < count/2; i++) {
138 /* Check the target bo's contents. */
139 data = gem_mmap(fd, bo_handles[idx_arr[i]],
140 LINEAR_DWORDS, PROT_READ | PROT_WRITE);
141 for (j = 0; j < WIDTH*HEIGHT; j++)
142 igt_assert_f(data[j] == j,
143 "mismatch at %i: %i\n",
145 munmap(data, LINEAR_DWORDS);