#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include "drm.h"
-#include "i915_drm.h"
+
+#include <drm.h>
+
+#include "ioctl_wrappers.h"
#include "drmtest.h"
-#include "intel_gpu_tools.h"
+#include "intel_io.h"
+#include "igt_aux.h"
#define WIDTH 512
#define HEIGHT 512
-static uint32_t linear[WIDTH * HEIGHT];
+#define LINEAR_DWORDS (4 * WIDTH * HEIGHT)
static uint32_t current_tiling_mode;
#define PAGE_SIZE 4096
uint32_t *data;
int i;
- handle = gem_create(fd, sizeof(linear));
+ handle = gem_create(fd, LINEAR_DWORDS);
gem_set_tiling(fd, handle, current_tiling_mode, WIDTH * sizeof(uint32_t));
/* Fill the BO with dwords starting at start_val */
- data = gem_mmap(fd, handle, sizeof(linear), PROT_READ | PROT_WRITE);
+ data = gem_mmap(fd, handle, LINEAR_DWORDS, PROT_READ | PROT_WRITE);
+ if (data == NULL && errno == ENOSPC)
+ return 0;
+
for (i = 0; i < WIDTH*HEIGHT; i++)
data[i] = i;
- munmap(data, sizeof(linear));
+ munmap(data, LINEAR_DWORDS);
return handle;
}
uint32_t *bo_handles;
int *idx_arr;
-int
-main(int argc, char **argv)
+igt_simple_main
{
int fd;
uint32_t *data;
int count;
current_tiling_mode = I915_TILING_X;
+ igt_skip_on_simulation();
+ intel_purge_vm_caches();
+
fd = drm_open_any();
- /* need slightly more than total ram */
- count = intel_get_total_ram_mb() * 11 / 10;
+ /* need slightly more than available memory */
+ count = intel_get_total_ram_mb() + intel_get_total_swap_mb() / 4;
bo_handles = calloc(count, sizeof(uint32_t));
- assert(bo_handles);
+ igt_assert(bo_handles);
idx_arr = calloc(count, sizeof(int));
- assert(idx_arr);
+ igt_assert(idx_arr);
- if (intel_get_total_swap_mb() == 0) {
- printf("no swap detected\n");
- return 77;
- }
+ igt_log(IGT_LOG_INFO,
+ "Using %d 1MiB objects (available RAM: %ld/%ld, swap: %ld)\n",
+ count,
+ (long)intel_get_avail_ram_mb(),
+ (long)intel_get_total_ram_mb(),
+ (long)intel_get_total_swap_mb());
- for (i = 0; i < count; i++)
+ igt_require(count < intel_get_avail_ram_mb() + intel_get_total_swap_mb());
+
+ for (i = 0; i < count; i++) {
bo_handles[i] = create_bo_and_fill(fd);
+ /* Not enough mmap address space possible. */
+ igt_require(bo_handles[i]);
+ }
for (i = 0; i < count; i++)
idx_arr[i] = i;
- drmtest_permute_array(idx_arr, count,
- drmtest_exchange_int);
+ igt_permute_array(idx_arr, count,
+ igt_exchange_int);
for (i = 0; i < count/2; i++) {
/* Check the target bo's contents. */
data = gem_mmap(fd, bo_handles[idx_arr[i]],
- sizeof(linear), PROT_READ | PROT_WRITE);
+ LINEAR_DWORDS, PROT_READ | PROT_WRITE);
for (j = 0; j < WIDTH*HEIGHT; j++)
- if (data[j] != j) {
- fprintf(stderr, "mismatch at %i: %i\n",
- j, data[j]);
- exit(1);
- }
- munmap(data, sizeof(linear));
+ igt_assert_f(data[j] == j,
+ "mismatch at %i: %i\n",
+ j, data[j]);
+ munmap(data, LINEAR_DWORDS);
}
close(fd);
-
- return 0;
}