[PATCH 10/34] drm: kselftest for drm_mm_replace_node()

Chris Wilson chris at chris-wilson.co.uk
Mon Dec 12 11:53:26 UTC 2016


Reuse drm_mm_insert_node() with a temporary node to exercise
drm_mm_replace_node(). We use the previous test in order to exercise the
various lists following replacement.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 drivers/gpu/drm/selftests/drm_mm_selftests.h |  1 +
 drivers/gpu/drm/selftests/test-drm_mm.c      | 45 ++++++++++++++++++++++++----
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h
index 0927695c3fd4..12d91c77244a 100644
--- a/drivers/gpu/drm/selftests/drm_mm_selftests.h
+++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h
@@ -5,6 +5,7 @@
  *
  * Tests are executed in reverse order by igt/drm_mm
  */
+selftest(replace, igt_replace)
 selftest(insert, igt_insert)
 selftest(reserve, igt_reserve)
 selftest(debug, igt_debug)
diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
index cd57a1de7f89..2ea671f34883 100644
--- a/drivers/gpu/drm/selftests/test-drm_mm.c
+++ b/drivers/gpu/drm/selftests/test-drm_mm.c
@@ -237,7 +237,7 @@ static int igt_reserve(void *ignored)
 	return 0;
 }
 
-static int __igt_insert(int count, u64 size)
+static int __igt_insert(int count, u64 size, bool replace)
 {
 	u32 lcg_state = random_seed;
 	struct drm_mm mm;
@@ -264,9 +264,10 @@ static int __igt_insert(int count, u64 size)
 	}
 
 	for (n = 0; n < count; n++) {
+		struct drm_mm_node tmp, *node;
 		int err;
 
-		node = &nodes[n];
+		node = memset(replace ? &tmp : &nodes[n], 0, sizeof(*node));
 		err = drm_mm_insert_node(&mm, node, size, 0,
 					 DRM_MM_SEARCH_DEFAULT);
 		if (err) {
@@ -281,6 +282,20 @@ static int __igt_insert(int count, u64 size)
 			       n, node->start);
 			goto out;
 		}
+
+		if (replace) {
+			drm_mm_replace_node(&tmp, &nodes[n]);
+			if (!drm_mm_node_allocated(&nodes[n])) {
+				pr_err("replaced new-node not allocated! step %d\n",
+				       n);
+				goto out;
+			}
+			if (drm_mm_node_allocated(&tmp)) {
+				pr_err("replaced old-node still allocated! step %d\n",
+				       n);
+				goto out;
+			}
+		}
 	}
 
 	/* Repeated use should then fail */
@@ -430,17 +445,37 @@ static int igt_insert(void *ignored)
 	drm_for_each_prime(n, 54) {
 		u64 size = BIT_ULL(n);
 
-		ret = __igt_insert(count, size - 1);
+		ret = __igt_insert(count, size - 1, false);
 		if (ret)
 			return ret;
 
-		ret = __igt_insert(count, size);
+		ret = __igt_insert(count, size, false);
+		if (ret)
+			return ret;
+
+		ret = __igt_insert(count, size + 1, false);
+	}
+
+	return 0;
+}
+
+static int igt_replace(void *ignored)
+{
+	const unsigned int count = BIT(10);
+	int n, ret;
+
+	drm_for_each_prime(n, 54) {
+		u64 size = BIT_ULL(n);
+
+		ret = __igt_insert(count, size - 1, true);
 		if (ret)
 			return ret;
 
-		ret = __igt_insert(count, size + 1);
+		ret = __igt_insert(count, size, true);
 		if (ret)
 			return ret;
+
+		ret = __igt_insert(count, size + 1, true);
 	}
 
 	return 0;
-- 
2.11.0



More information about the dri-devel mailing list