From patchwork Thu Dec 22 08:36:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9484401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2704E601D2 for ; Thu, 22 Dec 2016 08:37:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20A06282DC for ; Thu, 22 Dec 2016 08:37:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F60B283FD; Thu, 22 Dec 2016 08:37:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AE64A282DC for ; Thu, 22 Dec 2016 08:37:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DB0A56F179; Thu, 22 Dec 2016 08:37:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9463E6F16E; Thu, 22 Dec 2016 08:36:59 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id u144so34759188wmu.0; Thu, 22 Dec 2016 00:36:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=aKisvOYCMOfzt2ZGUPO/Lg6m7wQBaPvzZAgUqnDvApo=; b=rpaZEOUr3btdlniodycM1VdJY4Md0twWBolKJhvEqgV9BYYpdX6AznLWPEoCzC2ZKX EH0/6Xlfjafr5NwfeAU0tFWLauO/xN+KVKL6M3wJcc2QE26yJf9a8OsHchCHcR1/1toN PkcOfzbtiLTsGvnH6NQXztEEz22x03nfaGuAZARlsOJWWcncvs4Go6jo0Y4ZBB7ReDSg OW/Qa+7MvC1A9bqo7CQU2xChUnDlWM+0DVcydM8E7sW6s3UUZJZ8WMQUE28dWcAlqj0w cX1HPZaYGVbJksAf6YyhY2DuPg/TnglbUyAeq7YwQCUlaNa/5ACZNywhwfFxvxhjqYTe SsJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=aKisvOYCMOfzt2ZGUPO/Lg6m7wQBaPvzZAgUqnDvApo=; b=eY0+cLSj8BFbf6ci6jr0y5/XvgMN/foTQ/msRnbk+tGkBMSYcd6JLcNpNO2auPcGAv qUWtIWEeax7wif46E28wiwrWjtYWop+9y5jF/J6925vQM2Czt4w7DdGWCVnzG6BBzaKw griMapWO6i2hvVr1Dtr6k3cO4R6S0hNfznhWwG8QACyCIlg7Ls7eSMviWRlKl5170Nlt qoYoINp5a4S5VFhj9l+pLFuJYMxAqJ0kIBOZ1cHN29JhjMELYJMJo40Kat3V73IH/Htp aQArDl6duO+r9SS2Uhmwn53fWE0ratsvtLAw1MkrXbCuGQFduqX7cU5Kop64z7KnyNuw rhGw== X-Gm-Message-State: AIkVDXLdzDckYV89iH/NAWKJgsWt00paAXKFzLwPUEDz5+YWYRwVjK3sMPbq37TsP67+RQ== X-Received: by 10.28.107.77 with SMTP id g74mr10109406wmc.109.1482395817668; Thu, 22 Dec 2016 00:36:57 -0800 (PST) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id di9sm34442318wjc.37.2016.12.22.00.36.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 00:36:56 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 11/38] drm: kselftest for drm_mm_replace_node() Date: Thu, 22 Dec 2016 08:36:14 +0000 Message-Id: <20161222083641.2691-12-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161222083641.2691-1-chris@chris-wilson.co.uk> References: <20161222083641.2691-1-chris@chris-wilson.co.uk> Cc: intel-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Joonas Lahtinen --- drivers/gpu/drm/selftests/drm_mm_selftests.h | 1 + drivers/gpu/drm/selftests/test-drm_mm.c | 65 +++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index 727c6d7255e0..dca726baa65d 100644 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h @@ -10,3 +10,4 @@ selftest(init, igt_init) selftest(debug, igt_debug) selftest(reserve, igt_reserve) selftest(insert, igt_insert) +selftest(replace, igt_replace) diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c index feb5985abdc2..7914428c9862 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -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;