gem_tiled_swapping: Purge all page/swap caches first
[platform/upstream/intel-gpu-tools.git] / tests / gem_tiled_swapping.c
index b1431dc..aecd543 100644 (file)
 #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
@@ -91,8 +93,7 @@ create_bo_and_fill(int fd)
 uint32_t *bo_handles;
 int *idx_arr;
 
-int
-main(int argc, char **argv)
+igt_simple_main
 {
        int fd;
        uint32_t *data;
@@ -101,32 +102,30 @@ main(int argc, char **argv)
        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));
        igt_assert(bo_handles);
 
        idx_arr = calloc(count, sizeof(int));
        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++)
@@ -140,15 +139,11 @@ main(int argc, char **argv)
                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;
 }