[PATCH 09/34] drm: kselftest for drm_mm_insert_node()
Chris Wilson
chris at chris-wilson.co.uk
Mon Dec 12 11:53:25 UTC 2016
Exercise drm_mm_insert_node(), check that we can't overfill a range and
that the lists are correct after reserving/removing.
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 | 209 +++++++++++++++++++++++++++
2 files changed, 210 insertions(+)
diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h
index 639913a69101..0927695c3fd4 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(insert, igt_insert)
selftest(reserve, igt_reserve)
selftest(debug, igt_debug)
selftest(init, igt_init)
diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
index 13b2cfdb4d44..cd57a1de7f89 100644
--- a/drivers/gpu/drm/selftests/test-drm_mm.c
+++ b/drivers/gpu/drm/selftests/test-drm_mm.c
@@ -237,6 +237,215 @@ static int igt_reserve(void *ignored)
return 0;
}
+static int __igt_insert(int count, u64 size)
+{
+ u32 lcg_state = random_seed;
+ struct drm_mm mm;
+ struct drm_mm_node *nodes, *node, *next;
+ int *order, n, o = 0;
+ int ret;
+
+ /* Fill a range with lots of nodes, check it doesn't fail too early */
+
+ ret = -ENOMEM;
+ nodes = vzalloc(count * sizeof(*nodes));
+ if (!nodes)
+ goto err;
+
+ order = drm_random_order(count, &lcg_state);
+ if (!order)
+ goto err_nodes;
+
+ 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++) {
+ int err;
+
+ node = &nodes[n];
+ err = drm_mm_insert_node(&mm, node, 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;
+ }
+
+ if (!drm_mm_node_allocated(node)) {
+ pr_err("inserted node not allocated! step %d, start %llu\n",
+ n, node->start);
+ goto out;
+ }
+ }
+
+ /* Repeated use should then fail */
+ if (1) {
+ struct drm_mm_node tmp;
+
+ memset(&tmp, 0, sizeof(tmp));
+ if (!drm_mm_insert_node(&mm, &tmp, size, 0,
+ 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 = 0;
+ drm_mm_for_each_node(node, &mm) {
+ 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++;
+ }
+
+ for (n = 0; n < count; n++) {
+ drm_mm_for_each_node_in_range(node, &mm, n * size, (n + 1) * size) {
+ if (node->start != n * size) {
+ pr_err("lookup node %d out of order, expected start %llx, found %llx\n",
+ n, n * size, node->start);
+ goto out;
+ }
+ }
+ }
+
+ /* Remove one and reinsert, as the only hole it should refill itself */
+ for (n = 0; n < count; n++) {
+ int err;
+
+ drm_mm_remove_node(&nodes[n]);
+ err = drm_mm_insert_node(&mm, &nodes[n], size, 0,
+ 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 several, reinsert, check full */
+ drm_for_each_prime(n, min(128, count)) {
+ int m;
+
+ for (m = 0; m < n; m++) {
+ node = &nodes[order[(o + m) % count]];
+ drm_mm_remove_node(node);
+ }
+
+ for (m = 0; m < n; m++) {
+ int err;
+
+ node = &nodes[order[(o + m) % count]];
+ err = drm_mm_insert_node(&mm, node, size, 0,
+ DRM_MM_SEARCH_DEFAULT);
+ if (err) {
+ pr_err("insert failed, step %d, start %llu\n",
+ n, node->start);
+ ret = err;
+ goto out;
+ }
+ }
+
+ o += n;
+
+ if (1) {
+ struct drm_mm_node tmp;
+
+ memset(&tmp, 0, sizeof(tmp));
+ if (!drm_mm_insert_node(&mm, &tmp, size, 0,
+ DRM_MM_SEARCH_DEFAULT)) {
+ drm_mm_remove_node(&tmp);
+ pr_err("impossible insert succeeded, start %llu\n",
+ tmp.start);
+ goto out;
+ }
+ }
+
+ m = 0;
+ drm_mm_for_each_node(node, &mm) {
+ if (node->start != m * size) {
+ pr_err("node %d out of order, expected start %llx, found %llx\n",
+ m, m * size, node->start);
+ goto out;
+ }
+
+ if (node->size != size) {
+ pr_err("node %d has wrong size, expected size %llx, found %llx\n",
+ m, size, node->size);
+ goto out;
+ }
+
+ if (node->hole_follows) {
+ pr_err("node %d is followed by a hole!\n", m);
+ goto out;
+ }
+
+ m++;
+ }
+ }
+
+ ret = 0;
+out:
+ drm_mm_for_each_node_safe(node, next, &mm)
+ drm_mm_remove_node(node);
+ drm_mm_takedown(&mm);
+ kfree(order);
+err_nodes:
+ vfree(nodes);
+err:
+ return ret;
+}
+
+static int igt_insert(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);
+ if (ret)
+ return ret;
+
+ ret = __igt_insert(count, size);
+ if (ret)
+ return ret;
+
+ ret = __igt_insert(count, size + 1);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
#include "drm_selftest.c"
static int __init test_drm_mm_init(void)
--
2.11.0
More information about the dri-devel
mailing list