public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH igt] lib: Report the error from __gem_create()
@ 2017-10-03 11:50 Chris Wilson
  2017-10-03 12:28 ` ✓ Fi.CI.BAT: success for " Patchwork
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Chris Wilson @ 2017-10-03 11:50 UTC (permalink / raw)
  To: intel-gfx

We have two style of ioctl wrappers. The principle interface does error
checking on behalf of the caller (to avoid having lots of repetitious
code in each test), and for the few cases where the error is important
for the test, we also expose a double underscore version. Fix up
__gem_create() to follow this pattern and report the negative error code
returned by the kernel.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
---
 lib/ioctl_wrappers.c      | 32 +++++++++++++-------------------
 lib/ioctl_wrappers.h      |  2 +-
 tests/gem_create.c        |  5 ++---
 tests/gem_fd_exhaustion.c |  3 +--
 4 files changed, 17 insertions(+), 25 deletions(-)

diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index 51b6b7b6..1b483706 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -551,22 +551,20 @@ uint32_t gem_create_stolen(int fd, uint64_t size)
 	return create.handle;
 }
 
-
-uint32_t __gem_create(int fd, int size)
+int __gem_create(int fd, int size, uint32_t *handle)
 {
-	struct drm_i915_gem_create create;
-	int ret;
-
-	memset(&create, 0, sizeof(create));
-	create.handle = 0;
-	create.size = size;
-	ret = igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
+	struct drm_i915_gem_create create = {
+		.size = size,
+	};
+	int err = 0;
 
-	if (ret < 0)
-		return 0;
+	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0)
+		*handle = create.handle;
+	else
+		err = -errno;
 
 	errno = 0;
-	return create.handle;
+	return err;
 }
 
 /**
@@ -581,15 +579,11 @@ uint32_t __gem_create(int fd, int size)
  */
 uint32_t gem_create(int fd, uint64_t size)
 {
-	struct drm_i915_gem_create create;
+	uint32_t handle;
 
-	memset(&create, 0, sizeof(create));
-	create.handle = 0;
-	create.size = size;
-	do_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
-	igt_assert(create.handle);
+	igt_assert_eq(__gem_create(fd, size, &handle), 0);
 
-	return create.handle;
+	return handle;
 }
 
 /**
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index 090c1251..6ed65fad 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -73,7 +73,7 @@ void gem_sync(int fd, uint32_t handle);
 bool gem_create__has_stolen_support(int fd);
 uint32_t __gem_create_stolen(int fd, uint64_t size);
 uint32_t gem_create_stolen(int fd, uint64_t size);
-uint32_t __gem_create(int fd, int size);
+int __gem_create(int fd, int size, uint32_t *handle);
 uint32_t gem_create(int fd, uint64_t size);
 void gem_execbuf_wr(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
 int __gem_execbuf_wr(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
diff --git a/tests/gem_create.c b/tests/gem_create.c
index de7b8209..25c5e808 100644
--- a/tests/gem_create.c
+++ b/tests/gem_create.c
@@ -95,10 +95,9 @@ static void invalid_flag_test(int fd)
 
 static void invalid_size_test(int fd)
 {
-	int handle;
+	uint32_t handle;
 
-	handle = __gem_create(fd, 0);
-	igt_assert(!handle);
+	igt_assert_eq(__gem_create(fd, 0, &handle), -EINVAL);
 }
 
 /*
diff --git a/tests/gem_fd_exhaustion.c b/tests/gem_fd_exhaustion.c
index 57f2c711..250fe850 100644
--- a/tests/gem_fd_exhaustion.c
+++ b/tests/gem_fd_exhaustion.c
@@ -78,8 +78,7 @@ igt_simple_main
 			if (tmp_fd >= 0 && i < FD_ARR_SZ)
 				fd_arr[i] = tmp_fd;
 
-			handle = __gem_create(fd, 4096);
-			if (handle)
+			if (__gem_create(fd, 4096, &handle) == 0)
 				gem_close(fd, handle);
 
 
-- 
2.14.2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-10-03 13:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-03 11:50 [PATCH igt] lib: Report the error from __gem_create() Chris Wilson
2017-10-03 12:28 ` ✓ Fi.CI.BAT: success for " Patchwork
2017-10-03 12:37 ` [PATCH igt] " Joonas Lahtinen
2017-10-03 13:47 ` ✗ Fi.CI.IGT: failure for " Patchwork
2017-10-03 13:52   ` Chris Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox