drm: kselftest for drm_mm_replace_node()
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 22 Dec 2016 08:36:14 +0000 (08:36 +0000)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 27 Dec 2016 11:37:10 +0000 (12:37 +0100)
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.

v2: Check that we copy across the important (user) details of the node.
The internal details (such as lists and hole tracking) we hope to detect
errors by exercise.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20161222083641.2691-12-chris@chris-wilson.co.uk
drivers/gpu/drm/selftests/drm_mm_selftests.h
drivers/gpu/drm/selftests/test-drm_mm.c

index 727c6d7255e0af1d4fe92e469c4d9ac930b5c95e..dca726baa65dd5a3d4996f613e6e6b19afc6c5e0 100644 (file)
@@ -10,3 +10,4 @@ selftest(init, igt_init)
 selftest(debug, igt_debug)
 selftest(reserve, igt_reserve)
 selftest(insert, igt_insert)
+selftest(replace, igt_replace)
index feb5985abdc265b4ceed3e74e2596edd6b33466c..7914428c9862b01d38d3036a1aef70e6c4dd7b72 100644 (file)
@@ -554,7 +554,7 @@ static bool expect_insert_fail(struct drm_mm *mm, u64 size)
        return false;
 }
 
-static int __igt_insert(unsigned int count, u64 size)
+static int __igt_insert(unsigned int count, u64 size, bool replace)
 {
        DRM_RND_STATE(prng, random_seed);
        const struct insert_mode *mode;
@@ -569,7 +569,7 @@ static int __igt_insert(unsigned int count, u64 size)
        DRM_MM_BUG_ON(!size);
 
        ret = -ENOMEM;
-       nodes = vzalloc(count * sizeof(*nodes));
+       nodes = vmalloc(count * sizeof(*nodes));
        if (!nodes)
                goto err;
 
@@ -582,11 +582,37 @@ static int __igt_insert(unsigned int count, u64 size)
 
        for (mode = insert_modes; mode->name; mode++) {
                for (n = 0; n < count; n++) {
-                       if (!expect_insert(&mm, &nodes[n], size, 0, n, mode)) {
+                       struct drm_mm_node tmp;
+
+                       node = replace ? &tmp : &nodes[n];
+                       memset(node, 0, sizeof(*node));
+                       if (!expect_insert(&mm, node, size, 0, n, mode)) {
                                pr_err("%s insert failed, size %llu step %d\n",
                                       mode->name, size, n);
                                goto out;
                        }
+
+                       if (replace) {
+                               drm_mm_replace_node(&tmp, &nodes[n]);
+                               if (drm_mm_node_allocated(&tmp)) {
+                                       pr_err("replaced old-node still allocated! step %d\n",
+                                              n);
+                                       goto out;
+                               }
+
+                               if (!assert_node(&nodes[n], &mm, size, 0, n)) {
+                                       pr_err("replaced node did not inherit parameters, size %llu step %d\n",
+                                              size, n);
+                                       goto out;
+                               }
+
+                               if (tmp.start != nodes[n].start) {
+                                       pr_err("replaced node mismatch location expected [%llx + %llx], found [%llx + %llx]\n",
+                                              tmp.start, size,
+                                              nodes[n].start, nodes[n].size);
+                                       goto out;
+                               }
+                       }
                }
 
                /* After random insertion the nodes should be in order */
@@ -669,17 +695,44 @@ static int igt_insert(void *ignored)
        for_each_prime_number_from(n, 1, 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);
+               ret = __igt_insert(count, size + 1, false);
+       }
+
+       return 0;
+}
+
+static int igt_replace(void *ignored)
+{
+       const unsigned int count = min_t(unsigned int, BIT(10), max_iterations);
+       unsigned int n;
+       int ret;
+
+       /* Reuse igt_insert to exercise replacement by inserting a dummy node,
+        * then replacing it with the intended node. We want to check that
+        * the tree is intact and all the information we need is carried
+        * across to the target node.
+        */
+
+       for_each_prime_number_from(n, 1, 54) {
+               u64 size = BIT_ULL(n);
+
+               ret = __igt_insert(count, size - 1, true);
                if (ret)
                        return ret;
+
+               ret = __igt_insert(count, size, true);
+               if (ret)
+                       return ret;
+
+               ret = __igt_insert(count, size + 1, true);
        }
 
        return 0;