[PATCH 4/9] drm: kselftest for drm_mm_insert_node_in_range()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Exercise drm_mm_insert_node_in_range(), check that we only allocate from
the specified range.

Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
---
 drivers/gpu/drm/drm_mm_selftests.h |   1 +
 drivers/gpu/drm/test-drm_mm.c      | 188 +++++++++++++++++++++++++++++++++++++
 2 files changed, 189 insertions(+)

diff --git a/drivers/gpu/drm/drm_mm_selftests.h b/drivers/gpu/drm/drm_mm_selftests.h
index 97690bf5add3..4070123daffc 100644
--- a/drivers/gpu/drm/drm_mm_selftests.h
+++ b/drivers/gpu/drm/drm_mm_selftests.h
@@ -5,6 +5,7 @@
  *
  * Tests are executed in reverse order by igt/drm_mm
  */
+selftest(insert_range, igt_insert_range)
 selftest(insert, igt_insert)
 selftest(reserve, igt_reserve)
 selftest(init, igt_init)
diff --git a/drivers/gpu/drm/test-drm_mm.c b/drivers/gpu/drm/test-drm_mm.c
index 679f7e703218..494a470e08f3 100644
--- a/drivers/gpu/drm/test-drm_mm.c
+++ b/drivers/gpu/drm/test-drm_mm.c
@@ -474,6 +474,194 @@ static int igt_insert(void *ignored)
 	return 0;
 }
 
+static int __igt_insert_range(int count, u64 size, u64 start, u64 end)
+{
+	struct drm_mm mm;
+	struct drm_mm_node *nodes, *node, *next;
+	int n, start_n, end_n;
+	int ret, err;
+
+	/* Fill a range with lots of nodes, check it doesn't fail too early */
+	pr_debug("%s: count=%d, size=%llx, start=%llx, end=%llx\n",
+		 __func__, count, size, start, end);
+
+	ret = -ENOMEM;
+	nodes = vzalloc(count * sizeof(*nodes));
+	if (!nodes)
+		goto err;
+
+	ret = -EINVAL;
+	drm_mm_init(&mm, 0, count * size);
+	if (!drm_mm_clean(&mm)) {
+		pr_err("mm not empty on creation\n");
+		goto out;
+	}
+
+	for (n = 0; n < count; n++) {
+		err = drm_mm_insert_node(&mm, &nodes[n], size, 0,
+					 DRM_MM_SEARCH_DEFAULT);
+		if (err) {
+			pr_err("insert failed, step %d, start %llu\n",
+			       n, nodes[n].start);
+			ret = err;
+			goto out;
+		}
+	}
+
+	/* Repeated use should then fail */
+	if (1) {
+		struct drm_mm_node tmp;
+
+		memset(&tmp, 0, sizeof(tmp));
+		if (!drm_mm_insert_node_in_range(&mm, &tmp,
+						 size, 0,
+						 start, end,
+						 DRM_MM_SEARCH_DEFAULT)) {
+			drm_mm_remove_node(&tmp);
+			pr_err("impossible insert succeeded, step %d, start %llu\n",
+			       n, tmp.start);
+			goto out;
+		}
+	}
+
+	n = div64_u64(start, size);
+	drm_mm_for_each_node_in_range(node, &mm, start, end) {
+		if (node->start > end) {
+			pr_err("node %d out of rangei [%d, %d]\n",
+			       n,
+			       (int)div64_u64(start, size),
+			       (int)div64_u64(start + size - 1, size));
+			goto out;
+		}
+
+		if (node->start != n * size) {
+			pr_err("node %d out of order, expected start %llx, found %llx\n",
+			       n, n * size, node->start);
+			goto out;
+		}
+
+		if (node->size != size) {
+			pr_err("node %d has wrong size, expected size %llx, found %llx\n",
+			       n, size, node->size);
+			goto out;
+		}
+
+		if (node->hole_follows) {
+			pr_err("node %d is followed by a hole!\n", n);
+			goto out;
+		}
+
+		n++;
+	}
+
+	/* Remove one and reinsert, as the only hole it should refill itself */
+	start_n = div64_u64(start + size - 1, size);
+	end_n = div64_u64(end - size, size);
+	for (n = start_n; n <= end_n; n++) {
+		drm_mm_remove_node(&nodes[n]);
+		err = drm_mm_insert_node_in_range(&mm, &nodes[n], size, 0,
+						  start, end,
+						  DRM_MM_SEARCH_DEFAULT);
+		if (err) {
+			pr_err("reinsert failed, step %d\n", n);
+			ret = err;
+			goto out;
+		}
+
+		if (nodes[n].start != n * size) {
+			pr_err("reinsert node moved, step %d, expected %llx, found %llx\n",
+			       n, n * size, nodes[n].start);
+			goto out;
+		}
+	}
+
+	/* Remove the entire block, reinsert (order will then be undefined) */
+	for (n = start_n; n <= end_n; n++)
+		drm_mm_remove_node(&nodes[n]);
+
+	for (n = start_n; n <= end_n; n++) {
+		err = drm_mm_insert_node_in_range(&mm, &nodes[n], size, 0,
+						  start, end,
+						  DRM_MM_SEARCH_DEFAULT);
+		if (err) {
+			pr_err("reinsert failed, step %d\n", n);
+			ret = err;
+			goto out;
+		}
+	}
+
+	n = div64_u64(start, size);
+	drm_mm_for_each_node_in_range(node, &mm, start, end) {
+		if (node->start > end) {
+			pr_err("node %d out of rangei [%d, %d]\n",
+			       n,
+			       (int)div64_u64(start, size),
+			       (int)div64_u64(start + size - 1, size));
+			goto out;
+		}
+
+		if (node->start != n * size) {
+			pr_err("node %d out of order, expected start %llx, found %llx\n",
+			       n, n * size, node->start);
+			goto out;
+		}
+
+		if (node->size != size) {
+			pr_err("node %d has wrong size, expected size %llx, found %llx\n",
+			       n, size, node->size);
+			goto out;
+		}
+
+		if (node->hole_follows) {
+			pr_err("node %d is followed by a hole!\n", n);
+			goto out;
+		}
+
+		n++;
+	}
+
+	ret = 0;
+out:
+	list_for_each_entry_safe(node, next, &mm.head_node.node_list, node_list)
+		drm_mm_remove_node(node);
+	drm_mm_takedown(&mm);
+	vfree(nodes);
+err:
+	return ret;
+}
+
+static int igt_insert_range(void *ignored)
+{
+	const int max = 4096 * 8192;
+	int ret;
+
+	ret = __igt_insert_range(8192, 4096, 0, max);
+	if (ret)
+		return ret;
+
+	ret = __igt_insert_range(8192, 4096, 1, max);
+	if (ret)
+		return ret;
+
+	ret = __igt_insert_range(8192, 4096, 0, max - 1);
+	if (ret)
+		return ret;
+
+	ret = __igt_insert_range(8192, 4096, 0, max/2);
+	if (ret)
+		return ret;
+
+	ret = __igt_insert_range(8192, 4096, max/2, max);
+	if (ret)
+		return ret;
+
+	ret = __igt_insert_range(8192, 4096, max/4+1, 3*max/4-1);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
 #include "drm_selftest.c"
 
 static int __init test_drm_mm_init(void)
-- 
2.11.0

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




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux