tests: remove unused getopt header includes
[platform/upstream/intel-gpu-tools.git] / tests / gem_lut_handle.c
index c31c5ff..d3f6f73 100644 (file)
 #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 "drm.h"
-#include "i915_drm.h"
+#include "ioctl_wrappers.h"
 #include "drmtest.h"
 
-#define MI_BATCH_BUFFER_END    (0xA<<23)
 #define BATCH_SIZE             (1024*1024)
 
 #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
@@ -84,9 +82,12 @@ static int exec(int fd, uint32_t handle, unsigned int flags)
        i915_execbuffer2_set_context_id(execbuf, 0);
        execbuf.rsvd2 = 0;
 
-       return drmIoctl(fd,
-                       DRM_IOCTL_I915_GEM_EXECBUFFER2,
-                       &execbuf);
+       if (drmIoctl(fd,
+                    DRM_IOCTL_I915_GEM_EXECBUFFER2,
+                    &execbuf))
+               return -errno;
+
+       return 0;
 }
 
 static int many_exec(int fd, uint32_t batch, int num_exec, int num_reloc, unsigned flags)
@@ -94,17 +95,15 @@ static int many_exec(int fd, uint32_t batch, int num_exec, int num_reloc, unsign
        struct drm_i915_gem_execbuffer2 execbuf;
        struct drm_i915_gem_exec_object2 *gem_exec;
        struct drm_i915_gem_relocation_entry *gem_reloc;
-       unsigned min_handle = 0, max_handle = ~0;
+       unsigned max_handle = batch;
        int ret, n;
 
        gem_exec = calloc(num_exec+1, sizeof(*gem_exec));
        gem_reloc = calloc(num_reloc, sizeof(*gem_reloc));
-       assert(gem_exec && gem_reloc);
+       igt_assert(gem_exec && gem_reloc);
 
        for (n = 0; n < num_exec; n++) {
                gem_exec[n].handle = gem_create(fd, 4096);
-               if (gem_exec[n].handle < min_handle)
-                       min_handle = gem_exec[n].handle;
                if (gem_exec[n].handle > max_handle)
                        max_handle = gem_exec[n].handle;
                gem_exec[n].relocation_count = 0;
@@ -120,18 +119,15 @@ static int many_exec(int fd, uint32_t batch, int num_exec, int num_reloc, unsign
        gem_exec[n].relocation_count = num_reloc;
        gem_exec[n].relocs_ptr = (uintptr_t) gem_reloc;
 
-       if (flags & USE_LUT) {
-               min_handle = 0;
+       if (flags & USE_LUT)
                max_handle = num_exec + 1;
-       }
+       max_handle++;
 
        for (n = 0; n < num_reloc; n++) {
-               unsigned target;
+               uint32_t target;
 
                if (flags & BROKEN) {
-                       target = rand();
-                       if (target <= max_handle && target >= min_handle)
-                               target = target & 1 ? min_handle - target : max_handle + target;
+                       target = -(rand() % 4096) - 1;
                } else {
                        target = rand() % (num_exec + 1);
                        if ((flags & USE_LUT) == 0)
@@ -161,6 +157,8 @@ static int many_exec(int fd, uint32_t batch, int num_exec, int num_reloc, unsign
        ret = drmIoctl(fd,
                       DRM_IOCTL_I915_GEM_EXECBUFFER2,
                       &execbuf);
+       if (ret < 0)
+               ret = -errno;
 
        for (n = 0; n < num_exec; n++)
                gem_close(fd, gem_exec[n].handle);
@@ -171,11 +169,10 @@ static int many_exec(int fd, uint32_t batch, int num_exec, int num_reloc, unsign
        return ret;
 }
 
-#define _fail(x) ((x) == -1 && errno == ENOENT)
-#define fail(x) assert(_fail(x))
-#define pass(x) assert(!_fail(x))
+#define fail(x) igt_assert((x) == -ENOENT)
+#define pass(x) igt_assert((x) == 0)
 
-int main(int argc, char **argv)
+igt_simple_main
 {
        uint32_t batch[2] = {MI_BATCH_BUFFER_END};
        uint32_t handle;
@@ -189,13 +186,15 @@ int main(int argc, char **argv)
        do_or_die(exec(fd, handle, NORMAL));
        fail(exec(fd, handle, BROKEN));
 
-       if (exec(fd, handle, USE_LUT))
-               return 77;
+       igt_skip_on(exec(fd, handle, USE_LUT));
 
        do_or_die(exec(fd, handle, USE_LUT));
        fail(exec(fd, handle, USE_LUT | BROKEN));
 
-       for (i = 2; i <= 65536; i *= 2) {
+       for (i = 2; i <= SLOW_QUICK(65536, 8); i *= 2) {
+               if (many_exec(fd, handle, i+1, i+1, NORMAL) == -ENOSPC)
+                       break;
+
                pass(many_exec(fd, handle, i-1, i-1, NORMAL));
                pass(many_exec(fd, handle, i-1, i, NORMAL));
                pass(many_exec(fd, handle, i-1, i+1, NORMAL));
@@ -236,6 +235,4 @@ int main(int argc, char **argv)
                fail(many_exec(fd, handle, i+1, i, USE_LUT | BROKEN));
                fail(many_exec(fd, handle, i+1, i+1, USE_LUT | BROKEN));
        }
-
-       return 0;
 }