From patchwork Thu Dec 22 08:36:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9484545 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 403F4601D3 for ; Thu, 22 Dec 2016 08:45:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3686527DE0 for ; Thu, 22 Dec 2016 08:45:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29075281C3; Thu, 22 Dec 2016 08:45:25 +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=unavailable 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 A729427DE0 for ; Thu, 22 Dec 2016 08:45:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 813DB6F1C1; Thu, 22 Dec 2016 08:45:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wj0-x242.google.com (mail-wj0-x242.google.com [IPv6:2a00:1450:400c:c01::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5A0376F171; Thu, 22 Dec 2016 08:36:55 +0000 (UTC) Received: by mail-wj0-x242.google.com with SMTP id hb5so1997324wjc.2; Thu, 22 Dec 2016 00:36:55 -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=qQVz0w5RRtY7BF64worwlpVTCbG/ZkLtgjxcg98g67U=; b=IgpayVHsNFjhIJzC1MXBCNzPvMeaOGijkaaxj6gCFjzERPKM+3BttM17nJdLCd7jbw h9vKEND5ZK1FLEtZF8PTq6Q29i6418AEIrVgzg7cYjOCBf4/1engLozJPgr6/MXTrIpW q4e3Lw+BdtfttJDjT118zXoXRgAjC0c3/+M7yZkFlsY7yZ0xonC1V74bZsqYCJ8keeGk AsrwgSnUFOBkkSRSCYs0iE5VXu7zicb6/Lv7NhLY5mxnJtvp2rZzQXaOhM/mO9WryjHe 4plhy/GQH14qkR3776VvN8M3kD14g6UfYf6jT1wugxSuygfys7yR5skSIt2PVp/zO8Mt 5x0Q== 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=qQVz0w5RRtY7BF64worwlpVTCbG/ZkLtgjxcg98g67U=; b=W/GiaA4+2ckGPwcGepMv9nriGiKqNeJK/C8XSwC8YyhhbKwhQtRimIIDf7tf1E1nOL P8WrzkXmOudYx9TvAkJwYwbwydZDnEvRKI3sdMXomLHOl7FOg+kiMk6RKzG3UHOmLUDR id/160qEQdDXtWjsbWSuqvGU/y5COTSwiuChfYIZKAWeabdnPdWOfcC27ND3vSO3zKw5 RRCiJA3ueouP40coFZBolK4zqkbTV8HuMhtLryYX+TdlMEIlFHQfZ0XXlieajwekS5rs rqAvQBzRQ4AyCXXChKG2FeggLjNfgaTUTtlwBZPGXS/UePRkOi7335+GvxR2PQD7r30o CqWA== X-Gm-Message-State: AIkVDXJrp6YB6rsF21Kf/xROaeveEXGNCxrEuabhjbOi47LZxTQAxpULXtP1Ul7OASiAyQ== X-Received: by 10.194.21.35 with SMTP id s3mr7960759wje.192.1482395813103; Thu, 22 Dec 2016 00:36:53 -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.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 00:36:52 -0800 (PST) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 07/38] drm: kselftest for drm_mm_init() Date: Thu, 22 Dec 2016 08:36:10 +0000 Message-Id: <20161222083641.2691-8-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 Simple first test to just exercise initialisation of struct drm_mm. 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 | 114 +++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/drivers/gpu/drm/selftests/drm_mm_selftests.h b/drivers/gpu/drm/selftests/drm_mm_selftests.h index 1610e0a63a5b..844dd29db540 100644 --- a/drivers/gpu/drm/selftests/drm_mm_selftests.h +++ b/drivers/gpu/drm/selftests/drm_mm_selftests.h @@ -6,3 +6,4 @@ * Tests are executed in order by igt/drm_mm */ selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */ +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 682f5f86f465..87ad147670da 100644 --- a/drivers/gpu/drm/selftests/test-drm_mm.c +++ b/drivers/gpu/drm/selftests/test-drm_mm.c @@ -27,6 +27,120 @@ static int igt_sanitycheck(void *ignored) return 0; } +static bool assert_no_holes(const struct drm_mm *mm) +{ + struct drm_mm_node *hole; + u64 hole_start, hole_end; + unsigned long count; + + count = 0; + drm_mm_for_each_hole(hole, mm, hole_start, hole_end) + count++; + if (count) { + pr_err("Expected to find no holes (after reserve), found %lu instead\n", count); + return false; + } + + drm_mm_for_each_node(hole, mm) { + if (hole->hole_follows) { + pr_err("Hole follows node, expected none!\n"); + return false; + } + } + + return true; +} + +static bool assert_one_hole(const struct drm_mm *mm, u64 start, u64 end) +{ + struct drm_mm_node *hole; + u64 hole_start, hole_end; + unsigned long count; + bool ok = true; + + if (end <= start) + return true; + + count = 0; + drm_mm_for_each_hole(hole, mm, hole_start, hole_end) { + if (start != hole_start || end != hole_end) { + if (ok) + pr_err("empty mm has incorrect hole, found (%llx, %llx), expect (%llx, %llx)\n", + hole_start, hole_end, + start, end); + ok = false; + } + count++; + } + if (count != 1) { + pr_err("Expected to find one hole, found %lu instead\n", count); + ok = false; + } + + return ok; +} + +static int igt_init(void *ignored) +{ + const unsigned int size = 4096; + struct drm_mm mm; + struct drm_mm_node tmp; + int ret = -EINVAL; + + /* Start with some simple checks on initialising the struct drm_mm */ + memset(&mm, 0, sizeof(mm)); + if (drm_mm_initialized(&mm)) { + pr_err("zeroed mm claims to be initialized\n"); + return ret; + } + + memset(&mm, 0xff, sizeof(mm)); + drm_mm_init(&mm, 0, size); + if (!drm_mm_initialized(&mm)) { + pr_err("mm claims not to be initialized\n"); + goto out; + } + + if (!drm_mm_clean(&mm)) { + pr_err("mm not empty on creation\n"); + goto out; + } + + /* After creation, it should all be one massive hole */ + if (!assert_one_hole(&mm, 0, size)) { + ret = -EINVAL; + goto out; + } + + memset(&tmp, 0, sizeof(tmp)); + tmp.start = 0; + tmp.size = size; + ret = drm_mm_reserve_node(&mm, &tmp); + if (ret) { + pr_err("failed to reserve whole drm_mm\n"); + goto out; + } + + /* After filling the range entirely, there should be no holes */ + if (!assert_no_holes(&mm)) { + ret = -EINVAL; + goto out; + } + + /* And then after emptying it again, the massive hole should be back */ + drm_mm_remove_node(&tmp); + if (!assert_one_hole(&mm, 0, size)) { + ret = -EINVAL; + goto out; + } + +out: + if (ret) + drm_mm_debug_table(&mm, __func__); + drm_mm_takedown(&mm); + return ret; +} + #include "drm_selftest.c" static int __init test_drm_mm_init(void)