[igt-dev] [PATCH i-g-t v4 2/3] tests: Use i915_get_param where applicable

Lukasz Kalamarz lukasz.kalamarz at intel.com
Tue Dec 4 16:25:25 UTC 2018


Across several tests we check values of a given parameters.
With implementation of i915_get_param we can drop duplicated
lines and use helper function instead.

v2: Fixed errors in argument (fd are named as i915)
v3: Used defined parameters names instead of numbers
v4: Used renamed function and helper has_feature function

Signed-off-by: Lukasz Kalamarz <lukasz.kalamarz at intel.com>

Cc: Michal Winiarski <michal.winiarski at intel.com>
Cc: Katarzyna Dec <katarzyna.dec at intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio at intel.com>
Cc: Petri Latvala <Petri.latvala at intel.com>
Cc: Eric Anholt <eric at anholt.net>
Cc: Antonio Argenziano <antonio.argenziano at intel.com>
Cc: Ankit K Nautiyal <ankit.k.nautiyal at intel.com>
---
 tests/i915/gem_busy.c          | 13 ++-----------
 tests/i915/gem_cs_tlb.c        | 13 +------------
 tests/i915/gem_ctx_isolation.c |  6 +-----
 tests/i915/gem_exec_async.c    | 10 ++--------
 tests/i915/gem_exec_capture.c  |  9 +--------
 tests/i915/gem_exec_fence.c    | 24 ++----------------------
 tests/i915/gem_exec_flush.c    | 11 ++---------
 tests/i915/gem_exec_params.c   | 16 ++--------------
 tests/i915/gem_exec_parse.c    |  7 ++-----
 tests/i915/gem_exec_suspend.c  | 12 +-----------
 tests/i915/gem_mmap_gtt.c      |  9 +++------
 tests/i915/gem_mmap_wc.c       |  7 +------
 tests/i915/hangman.c           |  9 +--------
 tests/prime_vgem.c             |  9 +--------
 14 files changed, 22 insertions(+), 133 deletions(-)

diff --git a/tests/i915/gem_busy.c b/tests/i915/gem_busy.c
index 76b44a5d..7baf7f1f 100644
--- a/tests/i915/gem_busy.c
+++ b/tests/i915/gem_busy.c
@@ -28,6 +28,7 @@
 #include "igt.h"
 #include "igt_rand.h"
 #include "igt_vgem.h"
+#include "ioctl_wrappers.h"
 #include "i915/gem_ring.h"
 
 #define LOCAL_EXEC_NO_RELOC (1<<11)
@@ -401,17 +402,7 @@ static void close_race(int fd)
 
 static bool has_semaphores(int fd)
 {
-	struct drm_i915_getparam gp;
-	int val = -1;
-
-	memset(&gp, 0, sizeof(gp));
-	gp.param = I915_PARAM_HAS_SEMAPHORES;
-	gp.value = &val;
-
-	drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
-	errno = 0;
-
-	return val > 0;
+	return i915_has_feature(fd, I915_PARAM_HAS_SEMAPHORES);
 }
 
 static bool has_extended_busy_ioctl(int fd)
diff --git a/tests/i915/gem_cs_tlb.c b/tests/i915/gem_cs_tlb.c
index 51e1c4e1..f50b7f52 100644
--- a/tests/i915/gem_cs_tlb.c
+++ b/tests/i915/gem_cs_tlb.c
@@ -58,18 +58,7 @@ IGT_TEST_DESCRIPTION("Check whether we correctly invalidate the cs tlb.");
 
 static bool has_softpin(int fd)
 {
-	struct drm_i915_getparam gp;
-	int val = 0;
-
-	memset(&gp, 0, sizeof(gp));
-	gp.param = 37; /* I915_PARAM_HAS_EXEC_SOFTPIN */
-	gp.value = &val;
-
-	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
-		return 0;
-
-	errno = 0;
-	return (val == 1);
+	return i915_has_feature(fd, I915_PARAM_HAS_EXEC_SOFTPIN);
 }
 
 static void *
diff --git a/tests/i915/gem_ctx_isolation.c b/tests/i915/gem_ctx_isolation.c
index 058cf3ec..8e38a3a9 100644
--- a/tests/i915/gem_ctx_isolation.c
+++ b/tests/i915/gem_ctx_isolation.c
@@ -671,14 +671,10 @@ static void preservation(int fd,
 
 static unsigned int __has_context_isolation(int fd)
 {
-	struct drm_i915_getparam gp;
 	int value = 0;
 
-	memset(&gp, 0, sizeof(gp));
-	gp.param = 50; /* I915_PARAM_HAS_CONTEXT_ISOLATION */
-	gp.value = &value;
+	value = i915_get_param(fd, I915_PARAM_HAS_CONTEXT_ISOLATION);
 
-	igt_ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
 	errno = 0;
 
 	return value;
diff --git a/tests/i915/gem_exec_async.c b/tests/i915/gem_exec_async.c
index 9a06af7e..c65a9f07 100644
--- a/tests/i915/gem_exec_async.c
+++ b/tests/i915/gem_exec_async.c
@@ -22,6 +22,7 @@
  */
 
 #include "igt.h"
+#include "ioctl_wrappers.h"
 
 #define LOCAL_OBJECT_ASYNC (1 << 6)
 #define LOCAL_PARAM_HAS_EXEC_ASYNC 43
@@ -173,14 +174,7 @@ static void one(int fd, unsigned ring, uint32_t flags)
 
 static bool has_async_execbuf(int fd)
 {
-	drm_i915_getparam_t gp;
-	int async = -1;
-
-	gp.param = LOCAL_PARAM_HAS_EXEC_ASYNC;
-	gp.value = &async;
-	drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
-
-	return async > 0;
+	return i915_has_feature(fd, LOCAL_PARAM_HAS_EXEC_ASYNC);
 }
 
 igt_main
diff --git a/tests/i915/gem_exec_capture.c b/tests/i915/gem_exec_capture.c
index f26b4102..93b5dd3f 100644
--- a/tests/i915/gem_exec_capture.c
+++ b/tests/i915/gem_exec_capture.c
@@ -509,14 +509,7 @@ static void userptr(int fd, int dir)
 
 static bool has_capture(int fd)
 {
-	drm_i915_getparam_t gp;
-	int async = -1;
-
-	gp.param = LOCAL_PARAM_HAS_EXEC_CAPTURE;
-	gp.value = &async;
-	drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
-
-	return async > 0;
+	return i915_has_feature(fd, LOCAL_PARAM_HAS_EXEC_CAPTURE);
 }
 
 igt_main
diff --git a/tests/i915/gem_exec_fence.c b/tests/i915/gem_exec_fence.c
index ba46595d..a9442e13 100644
--- a/tests/i915/gem_exec_fence.c
+++ b/tests/i915/gem_exec_fence.c
@@ -803,17 +803,7 @@ static void test_fence_flip(int i915)
 
 static bool has_submit_fence(int fd)
 {
-	struct drm_i915_getparam gp;
-	int value = 0;
-
-	memset(&gp, 0, sizeof(gp));
-	gp.param = 0xdeadbeef ^ 51; /* I915_PARAM_HAS_EXEC_SUBMIT_FENCE */
-	gp.value = &value;
-
-	ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
-	errno = 0;
-
-	return value;
+	return i915_has_feature(fd, 0xdeadbeef ^ 51); /* I915_PARAM_HAS_EXEC_SUBMIT_FENCE */
 }
 
 static bool has_syncobj(int fd)
@@ -825,17 +815,7 @@ static bool has_syncobj(int fd)
 
 static bool exec_has_fence_array(int fd)
 {
-	struct drm_i915_getparam gp;
-	int value = 0;
-
-	memset(&gp, 0, sizeof(gp));
-	gp.param = 49; /* I915_PARAM_HAS_EXEC_FENCE_ARRAY */
-	gp.value = &value;
-
-	ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
-	errno = 0;
-
-	return value;
+	return i915_has_feature(fd, I915_PARAM_HAS_EXEC_FENCE_ARRAY);
 }
 
 static void test_invalid_fence_array(int fd)
diff --git a/tests/i915/gem_exec_flush.c b/tests/i915/gem_exec_flush.c
index f820b2a8..197fe23a 100644
--- a/tests/i915/gem_exec_flush.c
+++ b/tests/i915/gem_exec_flush.c
@@ -357,15 +357,8 @@ static void batch(int fd, unsigned ring, int nchild, int timeout,
 {
 	const int gen = intel_gen(intel_get_drm_devid(fd));
 
-	if (flags & CMDPARSER) {
-		int cmdparser = -1;
-                drm_i915_getparam_t gp;
-
-		gp.param = I915_PARAM_CMD_PARSER_VERSION;
-		gp.value = &cmdparser;
-		drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
-		igt_require(cmdparser > 0);
-	}
+	if (flags & CMDPARSER)
+		igt_require(i915_has_feature(fd, I915_PARAM_CMD_PARSER_VERSION));
 
 	intel_detect_and_clear_missed_interrupts(fd);
 	igt_fork(child, nchild) {
diff --git a/tests/i915/gem_exec_params.c b/tests/i915/gem_exec_params.c
index 49c56a8d..1ead75bd 100644
--- a/tests/i915/gem_exec_params.c
+++ b/tests/i915/gem_exec_params.c
@@ -78,24 +78,12 @@ static bool has_ring(int fd, unsigned ring_exec_flags)
 
 static bool has_exec_batch_first(int fd)
 {
-	int val = -1;
-	struct drm_i915_getparam gp = {
-		.param = 48,
-		.value = &val,
-	};
-	ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
-	return val > 0;
+	return i915_has_feature(fd, I915_PARAM_HAS_EXEC_BATCH_FIRST);
 }
 
 static bool has_resource_streamer(int fd)
 {
-	int val = -1;
-	struct drm_i915_getparam gp = {
-		.param = I915_PARAM_HAS_RESOURCE_STREAMER,
-		.value = &val,
-	};
-	ioctl(fd, DRM_IOCTL_I915_GETPARAM , &gp);
-	return val > 0;
+	return i915_has_feature(fd, I915_PARAM_HAS_RESOURCE_STREAMER);
 }
 
 static void test_batch_first(int fd)
diff --git a/tests/i915/gem_exec_parse.c b/tests/i915/gem_exec_parse.c
index b653b1bd..c6bf8eb8 100644
--- a/tests/i915/gem_exec_parse.c
+++ b/tests/i915/gem_exec_parse.c
@@ -61,12 +61,9 @@ static int parser_version;
 static int command_parser_version(int fd)
 {
 	int version = -1;
-	drm_i915_getparam_t gp;
 
-	gp.param = I915_PARAM_CMD_PARSER_VERSION;
-	gp.value = &version;
-
-	if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp) == 0)
+	version = i915_get_param(fd, I915_PARAM_CMD_PARSER_VERSION);
+	if (version >= 1)
 		return version;
 
 	return -1;
diff --git a/tests/i915/gem_exec_suspend.c b/tests/i915/gem_exec_suspend.c
index 43c52d10..2e1be233 100644
--- a/tests/i915/gem_exec_suspend.c
+++ b/tests/i915/gem_exec_suspend.c
@@ -73,17 +73,7 @@ static void test_all(int fd, unsigned flags)
 
 static bool has_semaphores(int fd)
 {
-	struct drm_i915_getparam gp;
-	int val = -1;
-
-	memset(&gp, 0, sizeof(gp));
-	gp.param = I915_PARAM_HAS_SEMAPHORES;
-	gp.value = &val;
-
-	drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
-	errno = 0;
-
-	return val > 0;
+	return i915_has_feature(fd, I915_PARAM_HAS_SEMAPHORES);
 }
 
 static void run_test(int fd, unsigned engine, unsigned flags)
diff --git a/tests/i915/gem_mmap_gtt.c b/tests/i915/gem_mmap_gtt.c
index f6353555..3d55cc64 100644
--- a/tests/i915/gem_mmap_gtt.c
+++ b/tests/i915/gem_mmap_gtt.c
@@ -311,13 +311,10 @@ test_write_gtt(int fd)
 
 static bool is_coherent(int i915)
 {
-	int val = 1; /* by default, we assume GTT is coherent, hence the test */
-	struct drm_i915_getparam gp = {
-		gp.param = 52, /* GTT_COHERENT */
-		gp.value = &val,
-	};
+	int val;
+
+	val = i915_get_param(i915, I915_PARAM_MMAP_GTT_COHERENT);
 
-	ioctl(i915, DRM_IOCTL_I915_GETPARAM, &gp);
 	return val;
 }
 
diff --git a/tests/i915/gem_mmap_wc.c b/tests/i915/gem_mmap_wc.c
index 110883eb..6ad979ce 100644
--- a/tests/i915/gem_mmap_wc.c
+++ b/tests/i915/gem_mmap_wc.c
@@ -85,7 +85,6 @@ create_pointer(int fd)
 static void
 test_invalid_flags(int fd)
 {
-	struct drm_i915_getparam gp;
 	struct local_i915_gem_mmap_v2 arg;
 	uint64_t flag = I915_MMAP_WC;
 	int val = -1;
@@ -95,12 +94,8 @@ test_invalid_flags(int fd)
 	arg.offset = 0;
 	arg.size = 4096;
 
-	memset(&gp, 0, sizeof(gp));
-	gp.param = 30; /* MMAP_VERSION */
-	gp.value = &val;
-
 	/* Do we have the new mmap_ioctl? */
-	drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+	val = i915_get_param(fd, I915_PARAM_MMAP_VERSION);
 
 	if (val >= 1) {
 		/*
diff --git a/tests/i915/hangman.c b/tests/i915/hangman.c
index 6ddae491..6d7f342b 100644
--- a/tests/i915/hangman.c
+++ b/tests/i915/hangman.c
@@ -111,14 +111,7 @@ static FILE *open_error(void)
 
 static bool uses_cmd_parser(void)
 {
-	int parser_version = 0;
-	drm_i915_getparam_t gp;
-
-	gp.param = I915_PARAM_CMD_PARSER_VERSION;
-	gp.value = &parser_version;
-	drmIoctl(device, DRM_IOCTL_I915_GETPARAM, &gp);
-
-	return parser_version > 0;
+	return i915_get_param(device, I915_PARAM_CMD_PARSER_VERSION);
 }
 
 static void check_error_state(const char *expected_ring_name,
diff --git a/tests/prime_vgem.c b/tests/prime_vgem.c
index 60bb951c..addc3e90 100644
--- a/tests/prime_vgem.c
+++ b/tests/prime_vgem.c
@@ -265,14 +265,7 @@ static void test_shrink(int vgem, int i915)
 
 static bool is_coherent(int i915)
 {
-	int val = 1; /* by default, we assume GTT is coherent, hence the test */
-	struct drm_i915_getparam gp = {
-		gp.param = 52, /* GTT_COHERENT */
-		gp.value = &val,
-	};
-
-	ioctl(i915, DRM_IOCTL_I915_GETPARAM, &gp);
-	return val;
+	return i915_get_param(i915, I915_PARAM_MMAP_GTT_COHERENT);
 }
 
 static void test_gtt_interleaved(int vgem, int i915)
-- 
2.17.2



More information about the igt-dev mailing list