diff mbox

[igt] lib: Run gem_test_engine() in an isolated context

Message ID 20180322141205.16746-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson March 22, 2018, 2:12 p.m. UTC
Ignore the shennigans of the test surrounding the library call to
gem_test_engine() and focus on answering the query of whether the engine
exists and is operational.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 lib/i915/gem_submission.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

Comments

Tvrtko Ursulin March 22, 2018, 3:48 p.m. UTC | #1
On 22/03/2018 14:12, Chris Wilson wrote:
> Ignore the shennigans of the test surrounding the library call to
> gem_test_engine() and focus on answering the query of whether the engine
> exists and is operational.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> ---
>   lib/i915/gem_submission.c | 23 +++++++++++++++++++----
>   1 file changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/i915/gem_submission.c b/lib/i915/gem_submission.c
> index c5e96969..062b8b93 100644
> --- a/lib/i915/gem_submission.c
> +++ b/lib/i915/gem_submission.c
> @@ -22,6 +22,7 @@
>    */
>   
>   #include <errno.h>
> +#include <fcntl.h>
>   #include <stdbool.h>
>   #include <sys/ioctl.h>
>   
> @@ -164,6 +165,17 @@ bool gem_has_guc_submission(int fd)
>   	return gem_submission_method(fd) & GEM_SUBMISSION_GUC;
>   }
>   
> +static int reopen_driver(int fd)
> +{
> +	char path[256];
> +
> +	snprintf(path, sizeof(path), "/proc/self/fd/%d", fd);
> +	fd = open(path, O_RDWR);
> +	igt_assert_lte(0, fd);

We have igt_assert_fd if you want it.

> +
> +	return fd;
> +}
> +
>   static bool is_wedged(int i915)
>   {
>   	int err = 0;
> @@ -183,19 +195,20 @@ static bool is_wedged(int i915)
>   void gem_test_engine(int i915, unsigned int engine)
>   {
>   	const uint32_t bbe = MI_BATCH_BUFFER_END;
> -	struct drm_i915_gem_exec_object2 obj = {
> -		.handle = gem_create(i915, 4096)
> -	};
> +	struct drm_i915_gem_exec_object2 obj = { };
>   	struct drm_i915_gem_execbuffer2 execbuf = {
>   		.buffers_ptr = to_user_pointer(&obj),
>   		.buffer_count = 1,
>   	};
>   
> +	i915 = reopen_driver(i915);
>   	igt_assert(!is_wedged(i915));
> +
> +	obj.handle = gem_create(i915, 4096);
>   	gem_write(i915, obj.handle, 0, &bbe, sizeof(bbe));
>   
>   	if (engine == ALL_ENGINES) {
> -		for_each_engine(i915, engine) {
> +		for_each_physical_engine(i915, engine) {
>   			execbuf.flags = engine;
>   			gem_execbuf(i915, &execbuf);
>   		}
> @@ -207,4 +220,6 @@ void gem_test_engine(int i915, unsigned int engine)
>   	gem_close(i915, obj.handle);
>   
>   	igt_assert(!is_wedged(i915));
> +
> +	close(i915);
>   }
> 

Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Tested-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

Tvrtko
Chris Wilson March 22, 2018, 3:56 p.m. UTC | #2
Quoting Tvrtko Ursulin (2018-03-22 15:48:50)
> 
> On 22/03/2018 14:12, Chris Wilson wrote:
> > Ignore the shennigans of the test surrounding the library call to
> > gem_test_engine() and focus on answering the query of whether the engine
> > exists and is operational.
> > 
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> > ---
> >   lib/i915/gem_submission.c | 23 +++++++++++++++++++----
> >   1 file changed, 19 insertions(+), 4 deletions(-)
> > 
> > diff --git a/lib/i915/gem_submission.c b/lib/i915/gem_submission.c
> > index c5e96969..062b8b93 100644
> > --- a/lib/i915/gem_submission.c
> > +++ b/lib/i915/gem_submission.c
> > @@ -22,6 +22,7 @@
> >    */
> >   
> >   #include <errno.h>
> > +#include <fcntl.h>
> >   #include <stdbool.h>
> >   #include <sys/ioctl.h>
> >   
> > @@ -164,6 +165,17 @@ bool gem_has_guc_submission(int fd)
> >       return gem_submission_method(fd) & GEM_SUBMISSION_GUC;
> >   }
> >   
> > +static int reopen_driver(int fd)
> > +{
> > +     char path[256];
> > +
> > +     snprintf(path, sizeof(path), "/proc/self/fd/%d", fd);
> > +     fd = open(path, O_RDWR);
> > +     igt_assert_lte(0, fd);
> 
> We have igt_assert_fd if you want it.

Done. Pushed this nice bit of rug sweeping.
Nothing to see here, please move along...
-Chris
diff mbox

Patch

diff --git a/lib/i915/gem_submission.c b/lib/i915/gem_submission.c
index c5e96969..062b8b93 100644
--- a/lib/i915/gem_submission.c
+++ b/lib/i915/gem_submission.c
@@ -22,6 +22,7 @@ 
  */
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdbool.h>
 #include <sys/ioctl.h>
 
@@ -164,6 +165,17 @@  bool gem_has_guc_submission(int fd)
 	return gem_submission_method(fd) & GEM_SUBMISSION_GUC;
 }
 
+static int reopen_driver(int fd)
+{
+	char path[256];
+
+	snprintf(path, sizeof(path), "/proc/self/fd/%d", fd);
+	fd = open(path, O_RDWR);
+	igt_assert_lte(0, fd);
+
+	return fd;
+}
+
 static bool is_wedged(int i915)
 {
 	int err = 0;
@@ -183,19 +195,20 @@  static bool is_wedged(int i915)
 void gem_test_engine(int i915, unsigned int engine)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
-	struct drm_i915_gem_exec_object2 obj = {
-		.handle = gem_create(i915, 4096)
-	};
+	struct drm_i915_gem_exec_object2 obj = { };
 	struct drm_i915_gem_execbuffer2 execbuf = {
 		.buffers_ptr = to_user_pointer(&obj),
 		.buffer_count = 1,
 	};
 
+	i915 = reopen_driver(i915);
 	igt_assert(!is_wedged(i915));
+
+	obj.handle = gem_create(i915, 4096);
 	gem_write(i915, obj.handle, 0, &bbe, sizeof(bbe));
 
 	if (engine == ALL_ENGINES) {
-		for_each_engine(i915, engine) {
+		for_each_physical_engine(i915, engine) {
 			execbuf.flags = engine;
 			gem_execbuf(i915, &execbuf);
 		}
@@ -207,4 +220,6 @@  void gem_test_engine(int i915, unsigned int engine)
 	gem_close(i915, obj.handle);
 
 	igt_assert(!is_wedged(i915));
+
+	close(i915);
 }