dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Arunpravin <Arunpravin.PaneerSelvam@amd.com>
To: <dri-devel@lists.freedesktop.org>,
	<intel-gfx@lists.freedesktop.org>,
	<amd-gfx@lists.freedesktop.org>
Cc: Arunpravin <Arunpravin.PaneerSelvam@amd.com>,
	matthew.auld@intel.com, tzimmermann@suse.de,
	alexander.deucher@amd.com, christian.koenig@amd.com
Subject: [PATCH v2 2/7] drm/selftests: add drm buddy alloc limit testcase
Date: Tue, 22 Feb 2022 23:18:40 +0530	[thread overview]
Message-ID: <20220222174845.2175-2-Arunpravin.PaneerSelvam@amd.com> (raw)
In-Reply-To: <20220222174845.2175-1-Arunpravin.PaneerSelvam@amd.com>

add a test to check the maximum allocation limit

v2(Matthew Auld):
  - added err = -EINVAL in block NULL check
  - removed unnecessary test succeeded print

Signed-off-by: Arunpravin <Arunpravin.PaneerSelvam@amd.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Acked-by: Christian König <christian.koenig@amd.com>
---
 .../gpu/drm/selftests/drm_buddy_selftests.h   |  1 +
 drivers/gpu/drm/selftests/test-drm_buddy.c    | 59 +++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/drivers/gpu/drm/selftests/drm_buddy_selftests.h b/drivers/gpu/drm/selftests/drm_buddy_selftests.h
index a4bcf3a6dfe3..ebe16162762f 100644
--- a/drivers/gpu/drm/selftests/drm_buddy_selftests.h
+++ b/drivers/gpu/drm/selftests/drm_buddy_selftests.h
@@ -7,3 +7,4 @@
  * Tests are executed in order by igt/drm_buddy
  */
 selftest(sanitycheck, igt_sanitycheck) /* keep first (selfcheck for igt) */
+selftest(buddy_alloc_limit, igt_buddy_alloc_limit)
diff --git a/drivers/gpu/drm/selftests/test-drm_buddy.c b/drivers/gpu/drm/selftests/test-drm_buddy.c
index 51e4d393d22c..0df41e1cb8a6 100644
--- a/drivers/gpu/drm/selftests/test-drm_buddy.c
+++ b/drivers/gpu/drm/selftests/test-drm_buddy.c
@@ -16,6 +16,65 @@
 
 static unsigned int random_seed;
 
+static int igt_buddy_alloc_limit(void *arg)
+{
+	u64 end, size = U64_MAX, start = 0;
+	struct drm_buddy_block *block;
+	unsigned long flags = 0;
+	LIST_HEAD(allocated);
+	struct drm_buddy mm;
+	int err;
+
+	size = end = round_down(size, 4096);
+	err = drm_buddy_init(&mm, size, PAGE_SIZE);
+	if (err)
+		return err;
+
+	if (mm.max_order != DRM_BUDDY_MAX_ORDER) {
+		pr_err("mm.max_order(%d) != %d\n",
+		       mm.max_order, DRM_BUDDY_MAX_ORDER);
+		err = -EINVAL;
+		goto out_fini;
+	}
+
+	err = drm_buddy_alloc_blocks(&mm, start, end, size,
+				     PAGE_SIZE, &allocated, flags);
+
+	if (unlikely(err))
+		goto out_free;
+
+	block = list_first_entry_or_null(&allocated,
+					 struct drm_buddy_block,
+					 link);
+
+	if (!block) {
+		err = -EINVAL;
+		goto out_fini;
+	}
+
+	if (drm_buddy_block_order(block) != mm.max_order) {
+		pr_err("block order(%d) != %d\n",
+		       drm_buddy_block_order(block), mm.max_order);
+		err = -EINVAL;
+		goto out_free;
+	}
+
+	if (drm_buddy_block_size(&mm, block) !=
+	    BIT_ULL(mm.max_order) * PAGE_SIZE) {
+		pr_err("block size(%llu) != %llu\n",
+		       drm_buddy_block_size(&mm, block),
+		       BIT_ULL(mm.max_order) * PAGE_SIZE);
+		err = -EINVAL;
+		goto out_free;
+	}
+
+out_free:
+	drm_buddy_free_list(&mm, &allocated);
+out_fini:
+	drm_buddy_fini(&mm);
+	return err;
+}
+
 static int igt_sanitycheck(void *ignored)
 {
 	pr_info("%s - ok!\n", __func__);
-- 
2.25.1


  reply	other threads:[~2022-02-22 17:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-22 17:48 [PATCH v2 1/7] drm/selftests: Move i915 buddy selftests into drm Arunpravin
2022-02-22 17:48 ` Arunpravin [this message]
2022-02-27 15:18   ` [drm/selftests] 39ec47bbfd: kernel_BUG_at_drivers/gpu/drm/drm_buddy.c kernel test robot
2022-02-28 10:58     ` Christian König
2022-02-28 14:53       ` Paneer Selvam, Arunpravin
2022-02-22 17:48 ` [PATCH v2 3/7] drm/selftests: add drm buddy alloc range testcase Arunpravin
2022-02-22 17:48 ` [PATCH v2 4/7] drm/selftests: add drm buddy optimistic testcase Arunpravin
2022-02-22 17:48 ` [PATCH v2 5/7] drm/selftests: add drm buddy pessimistic testcase Arunpravin
2022-02-22 17:48 ` [PATCH v2 6/7] drm/selftests: add drm buddy smoke testcase Arunpravin
2022-02-22 17:48 ` [PATCH v2 7/7] drm/selftests: add drm buddy pathological testcase Arunpravin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220222174845.2175-2-Arunpravin.PaneerSelvam@amd.com \
    --to=arunpravin.paneerselvam@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    --cc=tzimmermann@suse.de \
    --subject='Re: [PATCH v2 2/7] drm/selftests: add drm buddy alloc limit testcase' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).