#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
uint32_t *bo_handles;
int *idx_arr;
-int
-main(int argc, char **argv)
+igt_simple_main
{
int fd;
uint32_t *data;
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());
- if (intel_get_total_ram_mb() / 4 > intel_get_total_swap_mb()) {
- printf("not enough swap detected\n");
- return 77;
- }
+ 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);
- if (bo_handles[i] == 0) {
- printf("insufficient address space\n");
- return 77;
- }
+ /* Not enough mmap address space possible. */
+ igt_require(bo_handles[i]);
}
for (i = 0; i < count; i++)
data = gem_mmap(fd, bo_handles[idx_arr[i]],
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);
- }
+ igt_assert_f(data[j] == j,
+ "mismatch at %i: %i\n",
+ j, data[j]);
munmap(data, LINEAR_DWORDS);
}
close(fd);
-
- return 0;
}